1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include "openbox/client.h"
4 #include "openbox/openbox.h"
5 #include "obt/keyboard.h"
31 static gpointer setup_func(xmlNodePtr node);
32 static gpointer setup_send_func(xmlNodePtr node);
33 static void free_func(gpointer o);
34 static gboolean run_func(ObActionsData *data, gpointer options);
36 /* 3.4-compatibility */
37 static gpointer setup_go_last_func(xmlNodePtr node);
38 static gpointer setup_send_last_func(xmlNodePtr node);
39 static gpointer setup_go_abs_func(xmlNodePtr node);
40 static gpointer setup_go_next_func(xmlNodePtr node);
41 static gpointer setup_send_next_func(xmlNodePtr node);
42 static gpointer setup_go_prev_func(xmlNodePtr node);
43 static gpointer setup_send_prev_func(xmlNodePtr node);
44 static gpointer setup_go_left_func(xmlNodePtr node);
45 static gpointer setup_send_left_func(xmlNodePtr node);
46 static gpointer setup_go_right_func(xmlNodePtr node);
47 static gpointer setup_send_right_func(xmlNodePtr node);
48 static gpointer setup_go_up_func(xmlNodePtr node);
49 static gpointer setup_send_up_func(xmlNodePtr node);
50 static gpointer setup_go_down_func(xmlNodePtr node);
51 static gpointer setup_send_down_func(xmlNodePtr node);
53 void action_desktop_startup(void)
55 actions_register("GoToDesktop", setup_func, free_func, run_func);
56 actions_register("SendToDesktop", setup_send_func, free_func, run_func);
57 /* 3.4-compatibility */
58 actions_register("DesktopLast", setup_go_last_func, free_func, run_func);
59 actions_register("SendToDesktopLast", setup_send_last_func,
61 actions_register("Desktop", setup_go_abs_func, free_func, run_func);
62 actions_register("DesktopNext", setup_go_next_func, free_func, run_func);
63 actions_register("SendToDesktopNext", setup_send_next_func,
65 actions_register("DesktopPrevious", setup_go_prev_func,
67 actions_register("SendToDesktopPrevious", setup_send_prev_func,
69 actions_register("DesktopLeft", setup_go_left_func, free_func, run_func);
70 actions_register("SendToDesktopLeft", setup_send_left_func,
72 actions_register("DesktopRight", setup_go_right_func,
74 actions_register("SendToDesktopRight", setup_send_right_func,
76 actions_register("DesktopUp", setup_go_up_func, free_func, run_func);
77 actions_register("SendToDesktopUp", setup_send_up_func,
79 actions_register("DesktopDown", setup_go_down_func, free_func, run_func);
80 actions_register("SendToDesktopDown", setup_send_down_func,
84 static gpointer setup_func(xmlNodePtr node)
89 o = g_slice_new0(Options);
90 /* don't go anywhere if there are no options given */
92 o->u.abs.desktop = screen_desktop;
93 /* wrap by default - it's handy! */
96 if ((n = obt_xml_find_node(node, "to"))) {
97 gchar *s = obt_xml_node_string(n);
98 if (!g_ascii_strcasecmp(s, "last"))
100 else if (!g_ascii_strcasecmp(s, "current"))
102 else if (!g_ascii_strcasecmp(s, "next")) {
104 o->u.rel.linear = TRUE;
105 o->u.rel.dir = OB_DIRECTION_EAST;
107 else if (!g_ascii_strcasecmp(s, "previous")) {
109 o->u.rel.linear = TRUE;
110 o->u.rel.dir = OB_DIRECTION_WEST;
112 else if (!g_ascii_strcasecmp(s, "north") ||
113 !g_ascii_strcasecmp(s, "up")) {
115 o->u.rel.dir = OB_DIRECTION_NORTH;
117 else if (!g_ascii_strcasecmp(s, "south") ||
118 !g_ascii_strcasecmp(s, "down")) {
120 o->u.rel.dir = OB_DIRECTION_SOUTH;
122 else if (!g_ascii_strcasecmp(s, "west") ||
123 !g_ascii_strcasecmp(s, "left")) {
125 o->u.rel.dir = OB_DIRECTION_WEST;
127 else if (!g_ascii_strcasecmp(s, "east") ||
128 !g_ascii_strcasecmp(s, "right")) {
130 o->u.rel.dir = OB_DIRECTION_EAST;
134 o->u.abs.desktop = atoi(s) - 1;
139 if ((n = obt_xml_find_node(node, "wrap")))
140 o->u.rel.wrap = obt_xml_node_bool(n);
145 static gpointer setup_send_func(xmlNodePtr node)
150 o = setup_func(node);
151 if ((n = obt_xml_find_node(node, "desktop"))) {
152 /* 3.4 compatibility */
153 o->u.abs.desktop = obt_xml_node_int(n) - 1;
159 if ((n = obt_xml_find_node(node, "follow")))
160 o->follow = obt_xml_node_bool(n);
165 static void free_func(gpointer o)
167 g_slice_free(Options, o);
170 static gboolean run_func(ObActionsData *data, gpointer options)
172 Options *o = options;
177 d = screen_last_desktop;
183 d = o->u.abs.desktop;
186 d = screen_find_desktop(screen_desktop,
187 o->u.rel.dir, o->u.rel.wrap, o->u.rel.linear);
190 g_assert_not_reached();
193 if (d < screen_num_desktops &&
194 (d != screen_desktop ||
195 (data->client && data->client->desktop != screen_desktop))) {
198 actions_client_move(data, TRUE);
199 if (o->send && data->client && client_normal(data->client)) {
200 client_set_desktop(data->client, d, o->follow, FALSE);
205 screen_set_desktop(d, TRUE);
207 client_bring_helper_windows(data->client);
210 actions_client_move(data, FALSE);
216 /* 3.4-compatilibity */
217 static gpointer setup_follow(xmlNodePtr node)
220 Options *o = g_slice_new0(Options);
223 if ((n = obt_xml_find_node(node, "follow")))
224 o->follow = obt_xml_node_bool(n);
228 static gpointer setup_go_last_func(xmlNodePtr node)
230 Options *o = g_slice_new0(Options);
235 static gpointer setup_send_last_func(xmlNodePtr node)
237 Options *o = setup_follow(node);
242 static gpointer setup_go_abs_func(xmlNodePtr node)
245 Options *o = g_slice_new0(Options);
247 if ((n = obt_xml_find_node(node, "desktop")))
248 o->u.abs.desktop = obt_xml_node_int(n) - 1;
250 o->u.abs.desktop = screen_desktop;
254 static void setup_rel(Options *o, xmlNodePtr node, gboolean lin,
260 o->u.rel.linear = lin;
262 o->u.rel.wrap = TRUE;
264 if ((n = obt_xml_find_node(node, "wrap")))
265 o->u.rel.wrap = obt_xml_node_bool(n);
268 static gpointer setup_go_next_func(xmlNodePtr node)
270 Options *o = g_slice_new0(Options);
271 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
275 static gpointer setup_send_next_func(xmlNodePtr node)
277 Options *o = setup_follow(node);
278 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
282 static gpointer setup_go_prev_func(xmlNodePtr node)
284 Options *o = g_slice_new0(Options);
285 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
289 static gpointer setup_send_prev_func(xmlNodePtr node)
291 Options *o = setup_follow(node);
292 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
296 static gpointer setup_go_left_func(xmlNodePtr node)
298 Options *o = g_slice_new0(Options);
299 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
303 static gpointer setup_send_left_func(xmlNodePtr node)
305 Options *o = setup_follow(node);
306 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
310 static gpointer setup_go_right_func(xmlNodePtr node)
312 Options *o = g_slice_new0(Options);
313 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
317 static gpointer setup_send_right_func(xmlNodePtr node)
319 Options *o = setup_follow(node);
320 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
324 static gpointer setup_go_up_func(xmlNodePtr node)
326 Options *o = g_slice_new0(Options);
327 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
331 static gpointer setup_send_up_func(xmlNodePtr node)
333 Options *o = setup_follow(node);
334 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
338 static gpointer setup_go_down_func(xmlNodePtr node)
340 Options *o = g_slice_new0(Options);
341 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);
345 static gpointer setup_send_down_func(xmlNodePtr node)
347 Options *o = setup_follow(node);
348 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);