Merge branch 'backport' into work
[mikachu/openbox.git] / openbox / actions / desktop.c
index 3132a4f..e352aa2 100644 (file)
@@ -21,27 +21,24 @@ typedef struct {
             gboolean wrap;
             ObDirection dir;
         } rel;
-    }
+    };
     gboolean send;
     gboolean follow;
 } Options;
 
-static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
-                                  xmlNodePtr node);
-static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc,
-                                xmlNodePtr node);
+static gpointer setup_go_func(xmlNodePtr node);
+static gpointer setup_send_func(xmlNodePtr node);
 static gboolean run_func(ObActionsData *data, gpointer options);
 
-void action_desktop_startup()
+void action_desktop_startup(void)
 {
-    actions_register("SwitchToDesktop", setup_switch_func, g_free, run_func,
+    actions_register("GoToDesktop", setup_go_func, g_free, run_func,
                      NULL, NULL);
     actions_register("SendToDesktop", setup_send_func, g_free, run_func,
                      NULL, NULL);
 }
 
-static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
-                                  xmlNodePtr node)
+static gpointer setup_go_func(xmlNodePtr node)
 {
     xmlNodePtr n;
     Options *o;
@@ -53,10 +50,9 @@ static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
     /* wrap by default - it's handy! */
     o->rel.wrap = TRUE;
 
-    if ((n = parse_find_node("to", node))) {
-        gchar *s = parse_string(doc, n);
-        if (!g_ascii_strcasecmp(s, "last") ||
-            !g_ascii_strcasecmp(s, "previous"))
+    if ((n = obt_parse_find_node(node, "to"))) {
+        gchar *s = obt_parse_node_string(n);
+        if (!g_ascii_strcasecmp(s, "last"))
             o->type = LAST;
         else if (!g_ascii_strcasecmp(s, "next")) {
             o->type = RELATIVE;
@@ -90,26 +86,28 @@ static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
         }
         else {
             o->type = ABSOLUTE;
-            o->abs.desktop = parse_int(doc, n) - 1;
+            o->abs.desktop = atoi(s) - 1;
         }
         g_free(s);
     }
 
-    if ((n = parse_find_node("wrap", node)))
-        o->rel.wrap = parse_bool(doc, n);
+    if ((n = obt_parse_find_node(node, "wrap")))
+        o->rel.wrap = obt_parse_node_bool(n);
 
     return o;
 }
 
-static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc,
-                                xmlNodePtr node)
+static gpointer setup_send_func(xmlNodePtr node)
 {
-    Options *o = setup_switch_func(i, doc, node);
+    xmlNodePtr n;
+    Options *o;
+
+    o = setup_go_func(node);
     o->send = TRUE;
     o->follow = TRUE;
 
-    if ((n = parse_find_node("follow", node)))
-        o->follow = parse_bool(doc, n);
+    if ((n = obt_parse_find_node(node, "follow")))
+        o->follow = obt_parse_node_bool(n);
 
     return o;
 }
@@ -120,8 +118,6 @@ static gboolean run_func(ObActionsData *data, gpointer options)
     Options *o = options;
     guint d;
 
-    
-
     switch (o->type) {
     case LAST:
         d = screen_last_desktop;
@@ -130,22 +126,27 @@ static gboolean run_func(ObActionsData *data, gpointer options)
         d = o->abs.desktop;
         break;
     case RELATIVE:
-        d = screen_cycle_desktop(o->abs.dir,
-                                 o->abs.wrap,
-                                 o->abs.linear,
-                                 FALSE, TRUE, FALSE);
+        d = screen_find_desktop(screen_desktop,
+                                o->rel.dir, o->rel.wrap, o->rel.linear);
         break;
     }
 
     if (d < screen_num_desktops && d != screen_desktop) {
         gboolean go = TRUE;
 
+        actions_client_move(data, TRUE);
         if (o->send && data->client && client_normal(data->client)) {
             client_set_desktop(data->client, d, o->follow, FALSE);
             go = o->follow;
         }
 
-        if (go) screen_set_desktop(d, TRUE);
+        if (go) {
+            screen_set_desktop(d, TRUE);
+            if (data->client)
+                client_bring_helper_windows(data->client);
+        }
+
+        actions_client_move(data, FALSE);
     }
     return FALSE;
 }