]> Dogcows Code - chaz/openbox/commitdiff
move logic for add/remove desktop into screen.c
authorDana Jansens <danakj@orodu.net>
Sat, 23 Jun 2007 16:15:46 +0000 (16:15 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 23 Jun 2007 16:15:46 +0000 (16:15 +0000)
openbox/actions/addremovedesktop.c
openbox/screen.c
openbox/screen.h

index 85aeb3f8a8e865a02e704cb77556fbd0701d7199..6a646681f10506c3b3e92ba2be9df40f9d1eed8e 100644 (file)
@@ -1,7 +1,5 @@
 #include "openbox/actions.h"
 #include "openbox/screen.h"
-#include "openbox/client.h"
-#include "openbox/debug.h"
 #include <glib.h>
 
 typedef struct {
@@ -78,66 +76,10 @@ static gboolean run_func(ObActionsData *data, gpointer options)
 
     actions_client_move(data, FALSE);
 
-    if (o->add) {
-        screen_set_num_desktops(screen_num_desktops+1);
-
-        /* move all the clients over */
-        if (o->current) {
-            GList *it;
-
-            for (it = client_list; it; it = g_list_next(it)) {
-                ObClient *c = it->data;
-                if (c->desktop != DESKTOP_ALL && c->desktop >= screen_desktop)
-                    client_set_desktop(c, c->desktop+1, FALSE, TRUE);
-            }
-        }
-    }
-    else if (screen_num_desktops > 1) {
-        guint rmdesktop, movedesktop;
-        GList *it, *stacking_copy;
-
-        /* what desktop are we removing and moving to? */
-        if (o->current)
-            rmdesktop = screen_desktop;
-        else
-            rmdesktop = screen_num_desktops - 1;
-        if (rmdesktop < screen_num_desktops - 1)
-            movedesktop = rmdesktop + 1;
-        else
-            movedesktop = rmdesktop;
-
-        /* make a copy of the list cuz we're changing it */
-        stacking_copy = g_list_copy(stacking_list);
-        for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
-            if (WINDOW_IS_CLIENT(it->data)) {
-                ObClient *c = it->data;
-                guint d = c->desktop;
-                if (d != DESKTOP_ALL && d >= movedesktop) {
-                    client_set_desktop(c, c->desktop - 1, TRUE, TRUE);
-                    ob_debug("moving window %s\n", c->title);
-                }
-                /* raise all the windows that are on the current desktop which
-                   is being merged */
-                if ((screen_desktop == rmdesktop - 1 ||
-                     screen_desktop == rmdesktop) &&
-                    (d == DESKTOP_ALL || d == screen_desktop))
-                {
-                    stacking_raise(CLIENT_AS_WINDOW(c));
-                    ob_debug("raising window %s\n", c->title);
-                }
-            }
-        }
-
-        /* act like we're changing desktops */
-        if (screen_desktop < screen_num_desktops - 1) {
-            gint d = screen_desktop;
-            screen_desktop = screen_last_desktop;
-            screen_set_desktop(d, TRUE);
-            ob_debug("fake desktop change\n");
-        }
-
-        screen_set_num_desktops(screen_num_desktops-1);
-    }
+    if (o->add)
+        screen_add_desktop(o->current);
+    else
+        screen_remove_desktop(o->current);
 
     actions_client_move(data, TRUE);
 
index 7e02bff43accde12621ba2eb7438d99b0a24560d..926b21e45d8ea4d75d400e82f5a4d88986185c62 100644 (file)
@@ -635,6 +635,72 @@ void screen_set_desktop(guint num, gboolean dofocus)
         screen_desktop_user_time = event_curtime;
 }
 
+void screen_add_desktop(gboolean current)
+{
+    screen_set_num_desktops(screen_num_desktops+1);
+
+    /* move all the clients over */
+    if (current) {
+        GList *it;
+
+        for (it = client_list; it; it = g_list_next(it)) {
+            ObClient *c = it->data;
+            if (c->desktop != DESKTOP_ALL && c->desktop >= screen_desktop)
+                client_set_desktop(c, c->desktop+1, FALSE, TRUE);
+        }
+    }
+}
+
+void screen_remove_desktop(gboolean current)
+{
+    guint rmdesktop, movedesktop;
+    GList *it, *stacking_copy;
+
+    if (screen_num_desktops <= 1) return;
+
+    /* what desktop are we removing and moving to? */
+    if (current)
+        rmdesktop = screen_desktop;
+    else
+        rmdesktop = screen_num_desktops - 1;
+    if (rmdesktop < screen_num_desktops - 1)
+        movedesktop = rmdesktop + 1;
+    else
+        movedesktop = rmdesktop;
+
+    /* make a copy of the list cuz we're changing it */
+    stacking_copy = g_list_copy(stacking_list);
+    for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
+        if (WINDOW_IS_CLIENT(it->data)) {
+            ObClient *c = it->data;
+            guint d = c->desktop;
+            if (d != DESKTOP_ALL && d >= movedesktop) {
+                client_set_desktop(c, c->desktop - 1, TRUE, TRUE);
+                ob_debug("moving window %s\n", c->title);
+            }
+            /* raise all the windows that are on the current desktop which
+               is being merged */
+            if ((screen_desktop == rmdesktop - 1 ||
+                 screen_desktop == rmdesktop) &&
+                (d == DESKTOP_ALL || d == screen_desktop))
+            {
+                stacking_raise(CLIENT_AS_WINDOW(c));
+                ob_debug("raising window %s\n", c->title);
+            }
+        }
+    }
+
+    /* act like we're changing desktops */
+    if (screen_desktop < screen_num_desktops - 1) {
+        gint d = screen_desktop;
+        screen_desktop = screen_last_desktop;
+        screen_set_desktop(d, TRUE);
+        ob_debug("fake desktop change\n");
+    }
+
+    screen_set_num_desktops(screen_num_desktops-1);
+}
+
 static void get_row_col(guint d, guint *r, guint *c)
 {
     switch (screen_desktop_layout.orientation) {
index 6ad181953bfe6f3e6b3edb07158f0504ce6aac71..041d9ccda21e43eead6a52b826307d3c1f30f6ea 100644 (file)
@@ -67,6 +67,11 @@ void screen_resize();
 void screen_set_num_desktops(guint num);
 /*! Change the current desktop */
 void screen_set_desktop(guint num, gboolean dofocus);
+/*! Add a new desktop either at the end or inserted at the current desktop */
+void screen_add_desktop(gboolean current);
+/*! Remove a desktop, either at the end or the current desktop */
+void screen_remove_desktop(gboolean current);
+
 /*! Interactively change desktops */
 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                            gboolean dialog, gboolean done, gboolean cancel);
This page took 0.030609 seconds and 4 git commands to generate.