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"
8 #include "obt/keyboard.h"
12 gboolean dock_windows;
13 gboolean desktop_windows;
14 gboolean all_desktops;
18 ObFocusCyclePopupMode dialog_mode;
22 /* options for after we're done */
23 gboolean cancel; /* did the user cancel or not */
24 guint state; /* keyboard state when finished */
27 static gpointer setup_func(xmlNodePtr node,
28 ObActionsIPreFunc *pre,
29 ObActionsIInputFunc *in,
30 ObActionsICancelFunc *c,
31 ObActionsIPostFunc *post);
32 static gpointer setup_forward_func(xmlNodePtr node,
33 ObActionsIPreFunc *pre,
34 ObActionsIInputFunc *in,
35 ObActionsICancelFunc *c,
36 ObActionsIPostFunc *post);
37 static gpointer setup_backward_func(xmlNodePtr node,
38 ObActionsIPreFunc *pre,
39 ObActionsIInputFunc *in,
40 ObActionsICancelFunc *c,
41 ObActionsIPostFunc *post);
42 static void free_func(gpointer options);
43 static gboolean run_func(ObActionsData *data, gpointer options);
44 static gboolean i_input_func(guint initial_state,
48 static void i_cancel_func(gpointer options);
49 static void i_post_func(gpointer options);
51 void action_cyclewindows_startup(void)
53 actions_register_i("NextWindow", setup_forward_func, free_func, run_func);
54 actions_register_i("PreviousWindow", setup_backward_func, free_func,
58 static gpointer setup_func(xmlNodePtr node,
59 ObActionsIPreFunc *pre,
60 ObActionsIInputFunc *input,
61 ObActionsICancelFunc *cancel,
62 ObActionsIPostFunc *post)
67 o = g_new0(Options, 1);
69 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_LIST;
71 if ((n = obt_xml_find_node(node, "linear")))
72 o->linear = obt_xml_node_bool(n);
73 if ((n = obt_xml_find_node(node, "dialog"))) {
74 if (obt_xml_node_contains(n, "none"))
75 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_NONE;
76 else if (obt_xml_node_contains(n, "icons"))
77 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_ICONS;
79 if ((n = obt_xml_find_node(node, "bar")))
80 o->bar = obt_xml_node_bool(n);
81 if ((n = obt_xml_find_node(node, "raise")))
82 o->raise = obt_xml_node_bool(n);
83 if ((n = obt_xml_find_node(node, "panels")))
84 o->dock_windows = obt_xml_node_bool(n);
85 if ((n = obt_xml_find_node(node, "desktop")))
86 o->desktop_windows = obt_xml_node_bool(n);
87 if ((n = obt_xml_find_node(node, "allDesktops")))
88 o->all_desktops = obt_xml_node_bool(n);
90 if ((n = obt_xml_find_node(node, "finalactions"))) {
93 m = obt_xml_find_node(n->children, "action");
95 ObActionsAct *action = actions_parse(m);
96 if (action) o->actions = g_slist_append(o->actions, action);
97 m = obt_xml_find_node(m->next, "action");
101 o->actions = g_slist_prepend(o->actions,
102 actions_parse_string("Focus"));
103 o->actions = g_slist_prepend(o->actions,
104 actions_parse_string("Raise"));
105 o->actions = g_slist_prepend(o->actions,
106 actions_parse_string("Unshade"));
109 *input = i_input_func;
110 *cancel = i_cancel_func;
115 static gpointer setup_forward_func(xmlNodePtr node,
116 ObActionsIPreFunc *pre,
117 ObActionsIInputFunc *input,
118 ObActionsICancelFunc *cancel,
119 ObActionsIPostFunc *post)
121 Options *o = setup_func(node, pre, input, cancel, post);
126 static gpointer setup_backward_func(xmlNodePtr node,
127 ObActionsIPreFunc *pre,
128 ObActionsIInputFunc *input,
129 ObActionsICancelFunc *cancel,
130 ObActionsIPostFunc *post)
132 Options *o = setup_func(node, pre, input, cancel, post);
137 static void free_func(gpointer options)
139 Options *o = options;
142 actions_act_unref(o->actions->data);
143 o->actions = g_slist_delete_link(o->actions, o->actions);
149 static gboolean run_func(ObActionsData *data, gpointer options)
151 Options *o = options;
152 struct _ObClient *ft;
154 ft = focus_cycle(o->forward,
165 if (o->raise && ft) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
170 static gboolean i_input_func(guint initial_state,
175 Options *o = options;
178 mods = obt_keyboard_only_modmasks(e->xkey.state);
179 if (e->type == KeyRelease) {
180 /* remove from the state the mask of the modifier key being
181 released, if it is a modifier key being released that is */
182 mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
185 if (e->type == KeyPress) {
186 /* Escape cancels no matter what */
187 if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) {
189 o->state = e->xkey.state;
193 /* There were no modifiers and they pressed enter */
194 else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) &&
198 o->state = e->xkey.state;
202 /* They released the modifiers */
203 else if (e->type == KeyRelease && initial_state && !(mods & initial_state))
206 o->state = e->xkey.state;
213 static void i_cancel_func(gpointer options)
215 Options *o = options;
220 static void i_post_func(gpointer options)
222 Options *o = options;
223 struct _ObClient *ft;
225 ft = focus_cycle(o->forward,
236 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
237 o->state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);