1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include "openbox/client.h"
30 static gpointer setup_go_func(xmlNodePtr node);
31 static gpointer setup_send_func(xmlNodePtr node);
32 static gboolean run_func(ObActionsData *data, gpointer options);
34 void action_desktop_startup(void)
36 actions_register("GoToDesktop", setup_go_func, g_free, run_func,
38 actions_register("SendToDesktop", setup_send_func, g_free, run_func,
42 static gpointer setup_go_func(xmlNodePtr node)
47 o = g_new0(Options, 1);
48 /* don't go anywhere if theres no options given */
50 o->abs.desktop = screen_desktop;
51 /* wrap by default - it's handy! */
54 if ((n = obt_parse_find_node(node, "to"))) {
55 gchar *s = obt_parse_node_string(n);
56 if (!g_ascii_strcasecmp(s, "last"))
58 else if (!g_ascii_strcasecmp(s, "current"))
60 else if (!g_ascii_strcasecmp(s, "next")) {
63 o->rel.dir = OB_DIRECTION_EAST;
65 else if (!g_ascii_strcasecmp(s, "previous")) {
68 o->rel.dir = OB_DIRECTION_WEST;
70 else if (!g_ascii_strcasecmp(s, "north") ||
71 !g_ascii_strcasecmp(s, "up")) {
73 o->rel.dir = OB_DIRECTION_NORTH;
75 else if (!g_ascii_strcasecmp(s, "south") ||
76 !g_ascii_strcasecmp(s, "down")) {
78 o->rel.dir = OB_DIRECTION_SOUTH;
80 else if (!g_ascii_strcasecmp(s, "west") ||
81 !g_ascii_strcasecmp(s, "left")) {
83 o->rel.dir = OB_DIRECTION_WEST;
85 else if (!g_ascii_strcasecmp(s, "east") ||
86 !g_ascii_strcasecmp(s, "right")) {
88 o->rel.dir = OB_DIRECTION_EAST;
92 o->abs.desktop = atoi(s) - 1;
97 if ((n = obt_parse_find_node(node, "wrap")))
98 o->rel.wrap = obt_parse_node_bool(n);
103 static gpointer setup_send_func(xmlNodePtr node)
108 o = setup_go_func(node);
112 if ((n = obt_parse_find_node(node, "follow")))
113 o->follow = obt_parse_node_bool(n);
118 /* Always return FALSE because its not interactive */
119 static gboolean run_func(ObActionsData *data, gpointer options)
121 Options *o = options;
126 d = screen_last_desktop;
135 d = screen_find_desktop(screen_desktop,
136 o->rel.dir, o->rel.wrap, o->rel.linear);
140 if (d < screen_num_desktops &&
141 (d != screen_desktop ||
142 (data->client && data->client->desktop != screen_desktop))) {
145 actions_client_move(data, TRUE);
146 if (o->send && data->client && client_normal(data->client)) {
147 client_set_desktop(data->client, d, o->follow, FALSE);
151 if (go) screen_set_desktop(d, TRUE);
152 actions_client_move(data, FALSE);