From 41af9ca07fcaa4687c3f5012bd1b745d88a7b256 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sat, 6 Oct 2012 15:15:51 +0200 Subject: [PATCH] New helper function remove_wwindowstate() The common code in the functions wWindowDeleteSavedState and wWindowDeleteSavedStatesForPID is moved to a new function remove_wwindowstate. --- src/window.c | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/src/window.c b/src/window.c index 12f276a9..3d12c50b 100644 --- a/src/window.c +++ b/src/window.c @@ -109,6 +109,8 @@ static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event); static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event); static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event); +static void remove_wwindowstate(WWindowState *wstate); + /****** Notification Observers ******/ static void appearanceObserver(void *self, WMNotification * notif) @@ -2600,26 +2602,12 @@ void wWindowDeleteSavedState(WMagicNumber id) tmp = windowState; if (tmp == wstate) { windowState = wstate->next; - if (wstate->instance) - wfree(wstate->instance); - if (wstate->class) - wfree(wstate->class); - if (wstate->command) - wfree(wstate->command); - wfree(wstate->state); - wfree(wstate); + remove_wwindowstate(wstate); } else { while (tmp->next) { if (tmp->next == wstate) { tmp->next = wstate->next; - if (wstate->instance) - wfree(wstate->instance); - if (wstate->class) - wfree(wstate->class); - if (wstate->command) - wfree(wstate->command); - wfree(wstate->state); - wfree(wstate); + remove_wwindowstate(wstate); break; } tmp = tmp->next; @@ -2638,27 +2626,14 @@ void wWindowDeleteSavedStatesForPID(pid_t pid) if (tmp->pid == pid) { wstate = windowState; windowState = tmp->next; - if (wstate->instance) - wfree(wstate->instance); - if (wstate->class) - wfree(wstate->class); - if (wstate->command) - wfree(wstate->command); - wfree(wstate->state); - wfree(wstate); + + remove_wwindowstate(wstate); } else { while (tmp->next) { if (tmp->next->pid == pid) { wstate = tmp->next; tmp->next = wstate->next; - if (wstate->instance) - wfree(wstate->instance); - if (wstate->class) - wfree(wstate->class); - if (wstate->command) - wfree(wstate->command); - wfree(wstate->state); - wfree(wstate); + remove_wwindowstate(wstate); break; } tmp = tmp->next; @@ -2666,6 +2641,21 @@ void wWindowDeleteSavedStatesForPID(pid_t pid) } } +static void remove_wwindowstate(WWindowState *wstate) +{ + if (wstate->instance) + wfree(wstate->instance); + + if (wstate->class) + wfree(wstate->class); + + if (wstate->command) + wfree(wstate->command); + + wfree(wstate->state); + wfree(wstate); +} + void wWindowSetOmnipresent(WWindow *wwin, Bool flag) { if (wwin->flags.omnipresent == flag) -- 2.11.4.GIT