Merge branch 'backport' into work
[dana/openbox.git] / openbox / actions / addremovedesktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include <glib.h>
4
5 typedef struct {
6     gboolean current;
7     gboolean add;
8 } Options;
9
10 static gpointer setup_func(xmlNodePtr node);
11 static gpointer setup_add_func(xmlNodePtr node);
12 static gpointer setup_remove_func(xmlNodePtr node);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14 /* 3.4-compatibility */
15 static gpointer setup_addcurrent_func(xmlNodePtr node);
16 static gpointer setup_addlast_func(xmlNodePtr node);
17 static gpointer setup_removecurrent_func(xmlNodePtr node);
18 static gpointer setup_removelast_func(xmlNodePtr node);
19
20 void action_addremovedesktop_startup(void)
21 {
22     actions_register("AddDesktop", setup_add_func, g_free, run_func);
23     actions_register("RemoveDesktop", setup_remove_func, g_free, run_func);
24
25     /* 3.4-compatibility */
26     actions_register("AddDesktopLast", setup_addlast_func, g_free, run_func);
27     actions_register("RemoveDesktopLast", setup_removelast_func,
28                      g_free, run_func);
29     actions_register("AddDesktopCurrent", setup_addcurrent_func,
30                      g_free, run_func);
31     actions_register("RemoveDesktopCurrent", setup_removecurrent_func,
32                      g_free, run_func);
33 }
34
35 static gpointer setup_func(xmlNodePtr node)
36 {
37     xmlNodePtr n;
38     Options *o;
39
40     o = g_new0(Options, 1);
41
42     if ((n = obt_xml_find_node(node, "where"))) {
43         gchar *s = obt_xml_node_string(n);
44         if (!g_ascii_strcasecmp(s, "last"))
45             o->current = FALSE;
46         else if (!g_ascii_strcasecmp(s, "current"))
47             o->current = TRUE;
48         g_free(s);
49     }
50
51     return o;
52 }
53
54 static gpointer setup_add_func(xmlNodePtr node)
55 {
56     Options *o = setup_func(node);
57     o->add = TRUE;
58     return o;
59 }
60
61 static gpointer setup_remove_func(xmlNodePtr node)
62 {
63     Options *o = setup_func(node);
64     o->add = FALSE;
65     return o;
66 }
67
68 /* Always return FALSE because its not interactive */
69 static gboolean run_func(ObActionsData *data, gpointer options)
70 {
71     Options *o = options;
72
73     actions_client_move(data, TRUE);
74
75     if (o->add)
76         screen_add_desktop(o->current);
77     else
78         screen_remove_desktop(o->current);
79
80     actions_client_move(data, FALSE);
81
82     return FALSE;
83 }
84
85 /* 3.4-compatibility */
86 static gpointer setup_addcurrent_func(xmlNodePtr node)
87 {
88     Options *o = setup_add_func(node);
89     o->current = TRUE;
90     return o;
91 }
92
93 static gpointer setup_addlast_func(xmlNodePtr node)
94 {
95     Options *o = setup_add_func(node);
96     o->current = FALSE;
97     return o;
98 }
99
100 static gpointer setup_removecurrent_func(xmlNodePtr node)
101 {
102     Options *o = setup_remove_func(node);
103     o->current = TRUE;
104     return o;
105 }
106
107 static gpointer setup_removelast_func(xmlNodePtr node)
108 {
109     Options *o = setup_remove_func(node);
110     o->current = FALSE;
111     return o;
112 }