1 #include "openbox/actions.h"
2 #include "openbox/stacking.h"
3 #include "openbox/window.h"
4 #include "openbox/event.h"
5 #include "openbox/focus_cycle.h"
6 #include "openbox/openbox.h"
12 gboolean dock_windows;
13 gboolean desktop_windows;
14 gboolean all_desktops;
21 static gboolean cycling = FALSE;
23 static gpointer setup_func(xmlNodePtr node);
24 static gpointer setup_forward_func(xmlNodePtr node);
25 static gpointer setup_backward_func(xmlNodePtr node);
26 static void free_func(gpointer options);
27 static gboolean run_func(ObActionsData *data, gpointer options);
28 static gboolean i_input_func(guint initial_state,
32 static void i_cancel_func(gpointer options);
34 static void end_cycle(gboolean cancel, guint state, Options *o);
36 void action_cyclewindows_startup(void)
38 actions_register("NextWindow", setup_forward_func, free_func,
39 run_func, i_input_func, i_cancel_func);
40 actions_register("PreviousWindow", setup_backward_func, free_func,
41 run_func, i_input_func, i_cancel_func);
44 static gpointer setup_func(xmlNodePtr node)
49 o = g_new0(Options, 1);
53 if ((n = obt_parse_find_node(node, "linear")))
54 o->linear = obt_parse_node_bool(n);
55 if ((n = obt_parse_find_node(node, "dialog")))
56 o->dialog = obt_parse_node_bool(n);
57 if ((n = obt_parse_find_node(node, "bar")))
58 o->bar = obt_parse_node_bool(n);
59 if ((n = obt_parse_find_node(node, "raise")))
60 o->raise = obt_parse_node_bool(n);
61 if ((n = obt_parse_find_node(node, "panels")))
62 o->dock_windows = obt_parse_node_bool(n);
63 if ((n = obt_parse_find_node(node, "desktop")))
64 o->desktop_windows = obt_parse_node_bool(n);
65 if ((n = obt_parse_find_node(node, "allDesktops")))
66 o->all_desktops = obt_parse_node_bool(n);
68 if ((n = obt_parse_find_node(node, "finalactions"))) {
71 m = obt_parse_find_node(n->children, "action");
73 ObActionsAct *action = actions_parse(m);
74 if (action) o->actions = g_slist_prepend(o->actions, action);
75 m = obt_parse_find_node(m->next, "action");
79 o->actions = g_slist_prepend(o->actions,
80 actions_parse_string("Focus"));
81 o->actions = g_slist_prepend(o->actions,
82 actions_parse_string("Raise"));
83 o->actions = g_slist_prepend(o->actions,
84 actions_parse_string("Unshade"));
90 static gpointer setup_forward_func(xmlNodePtr node)
92 Options *o = setup_func(node);
97 static gpointer setup_backward_func(xmlNodePtr node)
99 Options *o = setup_func(node);
104 static void free_func(gpointer options)
106 Options *o = options;
109 actions_act_unref(o->actions->data);
110 o->actions = g_slist_delete_link(o->actions, o->actions);
116 static gboolean run_func(ObActionsData *data, gpointer options)
118 Options *o = options;
119 struct _ObClient *ft;
121 ft = focus_cycle(o->forward,
133 if (o->raise) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
138 static gboolean i_input_func(guint initial_state,
143 if (e->type == KeyPress) {
144 /* Escape cancels no matter what */
145 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE)) {
146 end_cycle(TRUE, e->xkey.state, options);
150 /* There were no modifiers and they pressed enter */
151 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN) &&
154 end_cycle(FALSE, e->xkey.state, options);
158 /* They released the modifiers */
159 else if (e->type == KeyRelease && initial_state &&
160 (e->xkey.state & initial_state) == 0)
162 end_cycle(FALSE, e->xkey.state, options);
169 static void i_cancel_func(gpointer options)
171 /* we get cancelled when we move focus, but we're not cycling anymore, so
174 end_cycle(TRUE, 0, options);
177 static void end_cycle(gboolean cancel, guint state, Options *o)
179 struct _ObClient *ft;
181 ft = focus_cycle(o->forward,
193 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
194 state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);