Add all the action names used in 3.4 so configs don't break
[mikachu/openbox.git] / openbox / actions / addremovedesktop.c
index 85aeb3f..1e7f0b5 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 {
@@ -9,36 +7,43 @@ typedef struct {
     gboolean add;
 } Options;
 
-static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
-static gpointer setup_add_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
-static gpointer setup_remove_func(ObParseInst *i,
-                                  xmlDocPtr doc, xmlNodePtr node);
-static void     free_func(gpointer options);
+static gpointer setup_func(xmlNodePtr node);
+static gpointer setup_add_func(xmlNodePtr node);
+static gpointer setup_remove_func(xmlNodePtr node);
 static gboolean run_func(ObActionsData *data, gpointer options);
+/* 3.4-compatibility */
+static gpointer setup_addcurrent_func(xmlNodePtr node);
+static gpointer setup_addlast_func(xmlNodePtr node);
+static gpointer setup_removecurrent_func(xmlNodePtr node);
+static gpointer setup_removelast_func(xmlNodePtr node);
 
-void action_addremovedesktop_startup()
+void action_addremovedesktop_startup(void)
 {
-    actions_register("AddDesktop",
-                     setup_add_func,
-                     free_func,
-                     run_func,
+    actions_register("AddDesktop", setup_add_func, g_free, run_func,
                      NULL, NULL);
-    actions_register("RemoveDesktop",
-                     setup_remove_func,
-                     free_func,
-                     run_func,
+    actions_register("RemoveDesktop", setup_remove_func, g_free, run_func,
+                     NULL, NULL);
+
+    /* 3.4-compatibility */
+    actions_register("AddDesktopLast", setup_addlast_func, g_free, run_func,
+                     NULL, NULL);
+    actions_register("RemoveDesktopLast", setup_removelast_func, g_free, run_func,
+                     NULL, NULL);
+    actions_register("AddDesktopCurrent", setup_addcurrent_func, g_free, run_func,
+                     NULL, NULL);
+    actions_register("RemoveDesktopCurrent", setup_removecurrent_func, g_free, run_func,
                      NULL, NULL);
 }
 
-static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
+static gpointer setup_func(xmlNodePtr node)
 {
     xmlNodePtr n;
     Options *o;
 
     o = g_new0(Options, 1);
 
-    if ((n = parse_find_node("where", node))) {
-        gchar *s = parse_string(doc, n);
+    if ((n = obt_parse_find_node(node, "where"))) {
+        gchar *s = obt_parse_node_string(n);
         if (!g_ascii_strcasecmp(s, "last"))
             o->current = FALSE;
         else if (!g_ascii_strcasecmp(s, "current"))
@@ -49,97 +54,62 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
     return o;
 }
 
-static gpointer setup_add_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
+static gpointer setup_add_func(xmlNodePtr node)
 {
-    Options *o = setup_func(i, doc, node);
+    Options *o = setup_func(node);
     o->add = TRUE;
     return o;
 }
 
-static gpointer setup_remove_func(ObParseInst *i,
-                                  xmlDocPtr doc, xmlNodePtr node)
+static gpointer setup_remove_func(xmlNodePtr node)
 {
-    Options *o = setup_func(i, doc, node);
+    Options *o = setup_func(node);
     o->add = FALSE;
     return o;
 }
 
-static void free_func(gpointer options)
-{
-    Options *o = options;
-
-    g_free(o);
-}
-
 /* Always return FALSE because its not interactive */
 static gboolean run_func(ObActionsData *data, gpointer options)
 {
     Options *o = options;
 
+    actions_client_move(data, TRUE);
+
+    if (o->add)
+        screen_add_desktop(o->current);
+    else
+        screen_remove_desktop(o->current);
+
     actions_client_move(data, FALSE);
 
-    if (o->add) {
-        screen_set_num_desktops(screen_num_desktops+1);
+    return FALSE;
+}
 
-        /* move all the clients over */
-        if (o->current) {
-            GList *it;
+/* 3.4-compatibility */
+static gpointer setup_addcurrent_func(xmlNodePtr node)
+{
+    Options *o = setup_add_func(node);
+    o->current = TRUE;
+    return o;
+}
 
-            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);
-    }
+static gpointer setup_addlast_func(xmlNodePtr node)
+{
+    Options *o = setup_add_func(node);
+    o->current = FALSE;
+    return o;
+}
 
-    actions_client_move(data, TRUE);
+static gpointer setup_removecurrent_func(xmlNodePtr node)
+{
+    Options *o = setup_remove_func(node);
+    o->current = TRUE;
+    return o;
+}
 
-    return FALSE;
+static gpointer setup_removelast_func(xmlNodePtr node)
+{
+    Options *o = setup_remove_func(node);
+    o->current = FALSE;
+    return o;
 }