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) {
196 actions_client_move(data, TRUE);
197 if (o->send && data->client && client_normal(data->client)) {
198 client_set_desktop(data->client, d, o->follow, FALSE);
203 screen_set_desktop(d, TRUE);
205 client_bring_helper_windows(data->client);
208 actions_client_move(data, FALSE);
214 /* 3.4-compatilibity */
215 static gpointer setup_follow(xmlNodePtr node)
218 Options *o = g_slice_new0(Options);
221 if ((n = obt_xml_find_node(node, "follow")))
222 o->follow = obt_xml_node_bool(n);
226 static gpointer setup_go_last_func(xmlNodePtr node)
228 Options *o = g_slice_new0(Options);
233 static gpointer setup_send_last_func(xmlNodePtr node)
235 Options *o = setup_follow(node);
240 static gpointer setup_go_abs_func(xmlNodePtr node)
243 Options *o = g_slice_new0(Options);
245 if ((n = obt_xml_find_node(node, "desktop")))
246 o->u.abs.desktop = obt_xml_node_int(n) - 1;
248 o->u.abs.desktop = screen_desktop;
252 static void setup_rel(Options *o, xmlNodePtr node, gboolean lin,
258 o->u.rel.linear = lin;
260 o->u.rel.wrap = TRUE;
262 if ((n = obt_xml_find_node(node, "wrap")))
263 o->u.rel.wrap = obt_xml_node_bool(n);
266 static gpointer setup_go_next_func(xmlNodePtr node)
268 Options *o = g_slice_new0(Options);
269 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
273 static gpointer setup_send_next_func(xmlNodePtr node)
275 Options *o = setup_follow(node);
276 setup_rel(o, node, TRUE, OB_DIRECTION_EAST);
280 static gpointer setup_go_prev_func(xmlNodePtr node)
282 Options *o = g_slice_new0(Options);
283 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
287 static gpointer setup_send_prev_func(xmlNodePtr node)
289 Options *o = setup_follow(node);
290 setup_rel(o, node, TRUE, OB_DIRECTION_WEST);
294 static gpointer setup_go_left_func(xmlNodePtr node)
296 Options *o = g_slice_new0(Options);
297 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
301 static gpointer setup_send_left_func(xmlNodePtr node)
303 Options *o = setup_follow(node);
304 setup_rel(o, node, FALSE, OB_DIRECTION_WEST);
308 static gpointer setup_go_right_func(xmlNodePtr node)
310 Options *o = g_slice_new0(Options);
311 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
315 static gpointer setup_send_right_func(xmlNodePtr node)
317 Options *o = setup_follow(node);
318 setup_rel(o, node, FALSE, OB_DIRECTION_EAST);
322 static gpointer setup_go_up_func(xmlNodePtr node)
324 Options *o = g_slice_new0(Options);
325 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
329 static gpointer setup_send_up_func(xmlNodePtr node)
331 Options *o = setup_follow(node);
332 setup_rel(o, node, FALSE, OB_DIRECTION_NORTH);
336 static gpointer setup_go_down_func(xmlNodePtr node)
338 Options *o = g_slice_new0(Options);
339 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);
343 static gpointer setup_send_down_func(xmlNodePtr node)
345 Options *o = setup_follow(node);
346 setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH);