1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include "openbox/client.h"
29 static gpointer setup_go_func(xmlNodePtr node);
30 static gpointer setup_send_func(xmlNodePtr node);
31 static gboolean run_func(ObActionsData *data, gpointer options);
32 /* 3.4-compatibility */
33 static gpointer setup_go_last_func(xmlNodePtr node);
34 static gpointer setup_send_last_func(xmlNodePtr node);
35 static gpointer setup_go_abs_func(xmlNodePtr node);
36 static gpointer setup_send_abs_func(xmlNodePtr node);
37 static gpointer setup_go_next_func(xmlNodePtr node);
38 static gpointer setup_send_next_func(xmlNodePtr node);
39 static gpointer setup_go_prev_func(xmlNodePtr node);
40 static gpointer setup_send_prev_func(xmlNodePtr node);
41 static gpointer setup_go_left_func(xmlNodePtr node);
42 static gpointer setup_send_left_func(xmlNodePtr node);
43 static gpointer setup_go_right_func(xmlNodePtr node);
44 static gpointer setup_send_right_func(xmlNodePtr node);
45 static gpointer setup_go_up_func(xmlNodePtr node);
46 static gpointer setup_send_up_func(xmlNodePtr node);
47 static gpointer setup_go_down_func(xmlNodePtr node);
48 static gpointer setup_send_down_func(xmlNodePtr node);
50 void action_desktop_startup(void)
52 actions_register("GoToDesktop", setup_go_func, g_free, run_func);
53 actions_register("SendToDesktop", setup_send_func, g_free, run_func);
54 /* 3.4-compatibility */
55 actions_register("DesktopLast", setup_go_last_func, g_free, run_func);
56 actions_register("SendToDesktopLast", setup_send_last_func,
58 actions_register("Desktop", setup_go_abs_func, g_free, run_func);
59 actions_register("SendToDesktop", setup_send_abs_func, g_free, run_func);
60 actions_register("DesktopNext", setup_go_next_func, g_free, run_func);
61 actions_register("SendToDesktopNext", setup_send_next_func,
63 actions_register("DesktopPrevious", setup_go_prev_func, g_free, run_func);
64 actions_register("SendToDesktopPrevious", setup_send_prev_func,
66 actions_register("DesktopLeft", setup_go_left_func, g_free, run_func);
67 actions_register("SendToDesktopLeft", setup_send_left_func,
69 actions_register("DesktopRight", setup_go_right_func, g_free, run_func);
70 actions_register("SendToDesktopRight", setup_send_right_func,
72 actions_register("DesktopUp", setup_go_up_func, g_free, run_func);
73 actions_register("SendToDesktopUp", setup_send_up_func, g_free, run_func);
74 actions_register("DesktopDown", setup_go_down_func, g_free, run_func);
75 actions_register("SendToDesktopDown", setup_send_down_func,
79 static gpointer setup_go_func(xmlNodePtr node)
84 o = g_new0(Options, 1);
85 /* don't go anywhere if there are no options given */
87 o->u.abs.desktop = screen_desktop;
88 /* wrap by default - it's handy! */
91 if ((n = obt_parse_find_node(node, "to"))) {
92 gchar *s = obt_parse_node_string(n);
93 if (!g_ascii_strcasecmp(s, "last"))
95 else if (!g_ascii_strcasecmp(s, "next")) {
97 o->u.rel.linear = TRUE;
98 o->u.rel.dir = OB_DIRECTION_EAST;
100 else if (!g_ascii_strcasecmp(s, "previous")) {
102 o->u.rel.linear = TRUE;
103 o->u.rel.dir = OB_DIRECTION_WEST;
105 else if (!g_ascii_strcasecmp(s, "north") ||
106 !g_ascii_strcasecmp(s, "up")) {
108 o->u.rel.dir = OB_DIRECTION_NORTH;
110 else if (!g_ascii_strcasecmp(s, "south") ||
111 !g_ascii_strcasecmp(s, "down")) {
113 o->u.rel.dir = OB_DIRECTION_SOUTH;
115 else if (!g_ascii_strcasecmp(s, "west") ||
116 !g_ascii_strcasecmp(s, "left")) {
118 o->u.rel.dir = OB_DIRECTION_WEST;
120 else if (!g_ascii_strcasecmp(s, "east") ||
121 !g_ascii_strcasecmp(s, "right")) {
123 o->u.rel.dir = OB_DIRECTION_EAST;
127 o->u.abs.desktop = atoi(s) - 1;
132 if ((n = obt_parse_find_node(node, "wrap")))
133 o->u.rel.wrap = obt_parse_node_bool(n);
138 static gpointer setup_send_func(xmlNodePtr node)
143 o = setup_go_func(node);
147 if ((n = obt_parse_find_node(node, "follow")))
148 o->follow = obt_parse_node_bool(n);
153 /* Always return FALSE because its not interactive */
154 static gboolean run_func(ObActionsData *data, gpointer options)
156 Options *o = options;
161 d = screen_last_desktop;
164 d = o->u.abs.desktop;
167 d = screen_find_desktop(screen_desktop,
168 o->u.rel.dir, o->u.rel.wrap, o->u.rel.linear);
171 g_assert_not_reached();
174 if (d < screen_num_desktops && d != screen_desktop) {
177 actions_client_move(data, TRUE);
178 if (o->send && data->client && client_normal(data->client)) {
179 client_set_desktop(data->client, d, o->follow, FALSE);
184 screen_set_desktop(d, TRUE);
186 client_bring_helper_windows(data->client);
189 actions_client_move(data, FALSE);
194 /* 3.4-compatilibity */
195 static gpointer setup_follow(xmlNodePtr node)
198 Options *o = g_new0(Options, 1);
201 if ((n = obt_parse_find_node(node, "follow")))
202 o->follow = obt_parse_node_bool(n);
206 static gpointer setup_go_last_func(xmlNodePtr node)
208 Options *o = g_new0(Options, 1);
213 static gpointer setup_send_last_func(xmlNodePtr node)
215 Options *o = setup_follow(node);
220 static gpointer setup_go_abs_func(xmlNodePtr node)
223 Options *o = g_new0(Options, 1);
225 if ((n = obt_parse_find_node(node, "desktop")))
226 o->u.abs.desktop = obt_parse_node_int(n) - 1;
228 o->u.abs.desktop = screen_desktop;
232 static gpointer setup_send_abs_func(xmlNodePtr node)
235 Options *o = setup_follow(node);
237 if ((n = obt_parse_find_node(node, "desktop")))
238 o->u.abs.desktop = obt_parse_node_int(n) - 1;
240 o->u.abs.desktop = screen_desktop;
244 static void setup_rel(Options *o, xmlNodePtr node, gboolean lin, ObDirection dir)
249 o->u.rel.linear = lin;
251 o->u.rel.wrap = TRUE;
253 if ((n = obt_parse_find_node(node, "wrap")))
254 o->u.rel.wrap = obt_parse_node_bool(n);
257 static gpointer setup_go_next_func(xmlNodePtr node)
259 Options *o = g_new0(Options, 1);
260 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
264 static gpointer setup_send_next_func(xmlNodePtr node)
266 Options *o = setup_follow(node);
267 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
271 static gpointer setup_go_prev_func(xmlNodePtr node)
273 Options *o = g_new0(Options, 1);
274 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
278 static gpointer setup_send_prev_func(xmlNodePtr node)
280 Options *o = setup_follow(node);
281 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
285 static gpointer setup_go_left_func(xmlNodePtr node)
287 Options *o = g_new0(Options, 1);
288 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
292 static gpointer setup_send_left_func(xmlNodePtr node)
294 Options *o = setup_follow(node);
295 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
299 static gpointer setup_go_right_func(xmlNodePtr node)
301 Options *o = g_new0(Options, 1);
302 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
306 static gpointer setup_send_right_func(xmlNodePtr node)
308 Options *o = setup_follow(node);
309 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
313 static gpointer setup_go_up_func(xmlNodePtr node)
315 Options *o = g_new0(Options, 1);
316 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
320 static gpointer setup_send_up_func(xmlNodePtr node)
322 Options *o = setup_follow(node);
323 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
327 static gpointer setup_go_down_func(xmlNodePtr node)
329 Options *o = g_new0(Options, 1);
330 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);
334 static gpointer setup_send_down_func(xmlNodePtr node)
336 Options *o = setup_follow(node);
337 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);