New helper function remove_wwindowstate()
authorRodolfo García Peñas (kix) <kix@kix.es>
Sat, 6 Oct 2012 13:15:51 +0000 (6 15:15 +0200)
committerCarlos R. Mafra <crmafra@gmail.com>
Sat, 6 Oct 2012 14:52:29 +0000 (6 15:52 +0100)
The common code in the functions wWindowDeleteSavedState and
wWindowDeleteSavedStatesForPID is moved to a new function remove_wwindowstate.

src/window.c

index 12f276a..3d12c50 100644 (file)
@@ -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)