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"
7 #include "openbox/client.h"
13 gboolean dock_windows;
14 gboolean desktop_windows;
15 gboolean all_desktops;
22 static gboolean cycling = FALSE;
24 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
25 static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc,
27 static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc,
29 static void free_func(gpointer options);
30 static gboolean run_func(ObActionsData *data, gpointer options);
31 static gboolean i_input_func(guint initial_state,
35 static void i_cancel_func(gpointer options);
37 static void end_cycle(gboolean cancel, guint state, Options *o);
39 void action_cyclewindows_startup(void)
41 actions_register("NextWindow", setup_forward_func, free_func,
42 run_func, i_input_func, i_cancel_func);
43 actions_register("PreviousWindow", setup_backward_func, free_func,
44 run_func, i_input_func, i_cancel_func);
47 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
52 o = g_new0(Options, 1);
56 if ((n = parse_find_node("linear", node)))
57 o->linear = parse_bool(doc, n);
58 if ((n = parse_find_node("dialog", node)))
59 o->dialog = parse_bool(doc, n);
60 if ((n = parse_find_node("bar", node)))
61 o->bar = parse_bool(doc, n);
62 if ((n = parse_find_node("raise", node)))
63 o->raise = parse_bool(doc, n);
64 if ((n = parse_find_node("panels", node)))
65 o->dock_windows = parse_bool(doc, n);
66 if ((n = parse_find_node("desktop", node)))
67 o->desktop_windows = parse_bool(doc, n);
68 if ((n = parse_find_node("allDesktops", node)))
69 o->all_desktops = parse_bool(doc, n);
71 if ((n = parse_find_node("finalactions", node))) {
74 m = parse_find_node("action", n->xmlChildrenNode);
76 ObActionsAct *action = actions_parse(i, doc, m);
77 if (action) o->actions = g_slist_append(o->actions, action);
78 m = parse_find_node("action", m->next);
82 o->actions = g_slist_prepend(o->actions,
83 actions_parse_string("Focus"));
84 o->actions = g_slist_prepend(o->actions,
85 actions_parse_string("Raise"));
86 o->actions = g_slist_prepend(o->actions,
87 actions_parse_string("Unshade"));
93 static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc,
96 Options *o = setup_func(i, doc, node);
101 static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc,
104 Options *o = setup_func(i, doc, node);
109 static void free_func(gpointer options)
111 Options *o = options;
114 actions_act_unref(o->actions->data);
115 o->actions = g_slist_delete_link(o->actions, o->actions);
121 static gboolean run_func(ObActionsData *data, gpointer options)
123 Options *o = options;
124 struct _ObClient *ft;
126 ft = focus_cycle(o->forward,
138 if (o->raise && ft) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
143 static gboolean i_input_func(guint initial_state,
148 if (e->type == KeyPress) {
149 /* Escape cancels no matter what */
150 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE)) {
151 end_cycle(TRUE, e->xkey.state, options);
155 /* There were no modifiers and they pressed enter */
156 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN) &&
159 end_cycle(FALSE, e->xkey.state, options);
163 /* They released the modifiers */
164 else if (e->type == KeyRelease && initial_state &&
165 (e->xkey.state & initial_state) == 0)
167 end_cycle(FALSE, e->xkey.state, options);
174 static void i_cancel_func(gpointer options)
176 /* we get cancelled when we move focus, but we're not cycling anymore, so
179 end_cycle(TRUE, 0, options);
182 static void end_cycle(gboolean cancel, guint state, Options *o)
184 struct _ObClient *ft;
186 ft = focus_cycle(o->forward,
198 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
199 state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);