1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/stacking.h"
4 #include "openbox/window.h"
5 #include "openbox/focus_cycle.h"
6 #include "openbox/openbox.h"
7 #include "openbox/misc.h"
8 #include "openbox/client.h"
14 gboolean dock_windows;
15 gboolean desktop_windows;
16 ObDirection direction;
22 static gboolean cycling = FALSE;
24 static gpointer setup_func(xmlNodePtr node);
25 static gpointer setup_cycle_func(xmlNodePtr node);
26 static gpointer setup_target_func(xmlNodePtr node);
27 static void free_func(gpointer options);
28 static gboolean run_func(ObActionsData *data, gpointer options);
29 static gboolean i_input_func(guint initial_state,
33 static void i_cancel_func(gpointer options);
35 static void end_cycle(gboolean cancel, guint state, Options *o);
37 void action_directionalwindows_startup(void)
39 actions_register("DirectionalCycleWindows", setup_cycle_func, free_func,
40 run_func, i_input_func, i_cancel_func);
41 actions_register("DirectionalTargetWindow", setup_target_func, free_func,
42 run_func, NULL, NULL);
45 static gpointer setup_func(xmlNodePtr node)
50 o = g_new0(Options, 1);
54 if ((n = obt_parse_find_node(node, "dialog")))
55 o->dialog = obt_parse_node_bool(n);
56 if ((n = obt_parse_find_node(node, "bar")))
57 o->bar = obt_parse_node_bool(n);
58 if ((n = obt_parse_find_node(node, "raise")))
59 o->raise = obt_parse_node_bool(n);
60 if ((n = obt_parse_find_node(node, "panels")))
61 o->dock_windows = obt_parse_node_bool(n);
62 if ((n = obt_parse_find_node(node, "desktop")))
63 o->desktop_windows = obt_parse_node_bool(n);
64 if ((n = obt_parse_find_node(node, "direction"))) {
65 gchar *s = obt_parse_node_string(n);
66 if (!g_ascii_strcasecmp(s, "north") ||
67 !g_ascii_strcasecmp(s, "up"))
68 o->direction = OB_DIRECTION_NORTH;
69 else if (!g_ascii_strcasecmp(s, "northwest"))
70 o->direction = OB_DIRECTION_NORTHWEST;
71 else if (!g_ascii_strcasecmp(s, "northeast"))
72 o->direction = OB_DIRECTION_NORTHEAST;
73 else if (!g_ascii_strcasecmp(s, "west") ||
74 !g_ascii_strcasecmp(s, "left"))
75 o->direction = OB_DIRECTION_WEST;
76 else if (!g_ascii_strcasecmp(s, "east") ||
77 !g_ascii_strcasecmp(s, "right"))
78 o->direction = OB_DIRECTION_EAST;
79 else if (!g_ascii_strcasecmp(s, "south") ||
80 !g_ascii_strcasecmp(s, "down"))
81 o->direction = OB_DIRECTION_SOUTH;
82 else if (!g_ascii_strcasecmp(s, "southwest"))
83 o->direction = OB_DIRECTION_SOUTHWEST;
84 else if (!g_ascii_strcasecmp(s, "southeast"))
85 o->direction = OB_DIRECTION_SOUTHEAST;
89 if ((n = obt_parse_find_node(node, "finalactions"))) {
92 m = obt_parse_find_node(n->children, "action");
94 ObActionsAct *action = actions_parse(m);
95 if (action) o->actions = g_slist_append(o->actions, action);
96 m = obt_parse_find_node(m->next, "action");
100 o->actions = g_slist_prepend(o->actions,
101 actions_parse_string("Focus"));
102 o->actions = g_slist_prepend(o->actions,
103 actions_parse_string("Raise"));
104 o->actions = g_slist_prepend(o->actions,
105 actions_parse_string("Unshade"));
111 static gpointer setup_cycle_func(xmlNodePtr node)
113 Options *o = setup_func(node);
114 o->interactive = TRUE;
118 static gpointer setup_target_func(xmlNodePtr node)
120 Options *o = setup_func(node);
121 o->interactive = FALSE;
125 static void free_func(gpointer options)
127 Options *o = options;
130 actions_act_unref(o->actions->data);
131 o->actions = g_slist_delete_link(o->actions, o->actions);
137 static gboolean run_func(ObActionsData *data, gpointer options)
139 Options *o = options;
142 end_cycle(FALSE, data->state, o);
144 struct _ObClient *ft;
146 ft = focus_directional_cycle(o->direction,
156 if (o->raise && ft) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
159 return o->interactive;
162 static gboolean i_input_func(guint initial_state,
167 if (e->type == KeyPress) {
168 /* Escape cancels no matter what */
169 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE)) {
170 end_cycle(TRUE, e->xkey.state, options);
174 /* There were no modifiers and they pressed enter */
175 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN) &&
178 end_cycle(FALSE, e->xkey.state, options);
182 /* They released the modifiers */
183 else if (e->type == KeyRelease && initial_state &&
184 (e->xkey.state & initial_state) == 0)
186 end_cycle(FALSE, e->xkey.state, options);
193 static void i_cancel_func(gpointer options)
195 /* we get cancelled when we move focus, but we're not cycling anymore, so
198 end_cycle(TRUE, 0, options);
201 static void end_cycle(gboolean cancel, guint state, Options *o)
203 struct _ObClient *ft;
205 ft = focus_directional_cycle(o->direction,
214 if (g_list_find(client_list, ft))
215 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
216 state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);