Add all the action names used in 3.4 so configs don't break
[mikachu/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                      NULL, NULL);
24     actions_register("RemoveDesktop", setup_remove_func, g_free, run_func,
25                      NULL, NULL);
26
27     /* 3.4-compatibility */
28     actions_register("AddDesktopLast", setup_addlast_func, g_free, run_func,
29                      NULL, NULL);
30     actions_register("RemoveDesktopLast", setup_removelast_func, g_free, run_func,
31                      NULL, NULL);
32     actions_register("AddDesktopCurrent", setup_addcurrent_func, g_free, run_func,
33                      NULL, NULL);
34     actions_register("RemoveDesktopCurrent", setup_removecurrent_func, g_free, run_func,
35                      NULL, NULL);
36 }
37
38 static gpointer setup_func(xmlNodePtr node)
39 {
40     xmlNodePtr n;
41     Options *o;
42
43     o = g_new0(Options, 1);
44
45     if ((n = obt_parse_find_node(node, "where"))) {
46         gchar *s = obt_parse_node_string(n);
47         if (!g_ascii_strcasecmp(s, "last"))
48             o->current = FALSE;
49         else if (!g_ascii_strcasecmp(s, "current"))
50             o->current = TRUE;
51         g_free(s);
52     }
53
54     return o;
55 }
56
57 static gpointer setup_add_func(xmlNodePtr node)
58 {
59     Options *o = setup_func(node);
60     o->add = TRUE;
61     return o;
62 }
63
64 static gpointer setup_remove_func(xmlNodePtr node)
65 {
66     Options *o = setup_func(node);
67     o->add = FALSE;
68     return o;
69 }
70
71 /* Always return FALSE because its not interactive */
72 static gboolean run_func(ObActionsData *data, gpointer options)
73 {
74     Options *o = options;
75
76     actions_client_move(data, TRUE);
77
78     if (o->add)
79         screen_add_desktop(o->current);
80     else
81         screen_remove_desktop(o->current);
82
83     actions_client_move(data, FALSE);
84
85     return FALSE;
86 }
87
88 /* 3.4-compatibility */
89 static gpointer setup_addcurrent_func(xmlNodePtr node)
90 {
91     Options *o = setup_add_func(node);
92     o->current = TRUE;
93     return o;
94 }
95
96 static gpointer setup_addlast_func(xmlNodePtr node)
97 {
98     Options *o = setup_add_func(node);
99     o->current = FALSE;
100     return o;
101 }
102
103 static gpointer setup_removecurrent_func(xmlNodePtr node)
104 {
105     Options *o = setup_remove_func(node);
106     o->current = TRUE;
107     return o;
108 }
109
110 static gpointer setup_removelast_func(xmlNodePtr node)
111 {
112     Options *o = setup_remove_func(node);
113     o->current = FALSE;
114     return o;
115 }