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"
11 gboolean dock_windows;
12 gboolean desktop_windows;
13 gboolean all_desktops;
17 ObFocusCyclePopupMode dialog_mode;
21 /* options for after we're done */
22 gboolean cancel; /* did the user cancel or not */
23 guint state; /* keyboard state when finished */
26 static gpointer setup_func(xmlNodePtr node,
27 ObActionsIPreFunc *pre,
28 ObActionsIInputFunc *in,
29 ObActionsICancelFunc *c,
30 ObActionsIPostFunc *post);
31 static gpointer setup_forward_func(xmlNodePtr node,
32 ObActionsIPreFunc *pre,
33 ObActionsIInputFunc *in,
34 ObActionsICancelFunc *c,
35 ObActionsIPostFunc *post);
36 static gpointer setup_backward_func(xmlNodePtr node,
37 ObActionsIPreFunc *pre,
38 ObActionsIInputFunc *in,
39 ObActionsICancelFunc *c,
40 ObActionsIPostFunc *post);
41 static void free_func(gpointer options);
42 static gboolean run_func(ObActionsData *data, gpointer options);
43 static gboolean i_input_func(guint initial_state,
47 static void i_cancel_func(gpointer options);
48 static void i_post_func(gpointer options);
50 void action_cyclewindows_startup(void)
52 actions_register_i("NextWindow", setup_forward_func, free_func, run_func);
53 actions_register_i("PreviousWindow", setup_backward_func, free_func,
57 static gpointer setup_func(xmlNodePtr node,
58 ObActionsIPreFunc *pre,
59 ObActionsIInputFunc *input,
60 ObActionsICancelFunc *cancel,
61 ObActionsIPostFunc *post)
66 o = g_new0(Options, 1);
68 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_LIST;
70 if ((n = obt_parse_find_node(node, "linear")))
71 o->linear = obt_parse_node_bool(n);
72 if ((n = obt_parse_find_node(node, "dialog"))) {
73 if (obt_parse_node_contains(n, "none"))
74 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_NONE;
75 else if (obt_parse_node_contains(n, "icons"))
76 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_ICONS;
78 if ((n = obt_parse_find_node(node, "bar")))
79 o->bar = obt_parse_node_bool(n);
80 if ((n = obt_parse_find_node(node, "raise")))
81 o->raise = obt_parse_node_bool(n);
82 if ((n = obt_parse_find_node(node, "panels")))
83 o->dock_windows = obt_parse_node_bool(n);
84 if ((n = obt_parse_find_node(node, "desktop")))
85 o->desktop_windows = obt_parse_node_bool(n);
86 if ((n = obt_parse_find_node(node, "allDesktops")))
87 o->all_desktops = obt_parse_node_bool(n);
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"));
108 *input = i_input_func;
109 *cancel = i_cancel_func;
114 static gpointer setup_forward_func(xmlNodePtr node,
115 ObActionsIPreFunc *pre,
116 ObActionsIInputFunc *input,
117 ObActionsICancelFunc *cancel,
118 ObActionsIPostFunc *post)
120 Options *o = setup_func(node, pre, input, cancel, post);
125 static gpointer setup_backward_func(xmlNodePtr node,
126 ObActionsIPreFunc *pre,
127 ObActionsIInputFunc *input,
128 ObActionsICancelFunc *cancel,
129 ObActionsIPostFunc *post)
131 Options *o = setup_func(node, pre, input, cancel, post);
136 static void free_func(gpointer options)
138 Options *o = options;
141 actions_act_unref(o->actions->data);
142 o->actions = g_slist_delete_link(o->actions, o->actions);
148 static gboolean run_func(ObActionsData *data, gpointer options)
150 Options *o = options;
151 struct _ObClient *ft;
153 ft = focus_cycle(o->forward,
164 if (o->raise && ft) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
169 static gboolean i_input_func(guint initial_state,
174 Options *o = options;
176 if (e->type == KeyPress) {
177 /* Escape cancels no matter what */
178 if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) {
180 o->state = e->xkey.state;
184 /* There were no modifiers and they pressed enter */
185 else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) &&
189 o->state = e->xkey.state;
193 /* They released the modifiers */
194 else if (e->type == KeyRelease && initial_state &&
195 (e->xkey.state & initial_state) == 0)
198 o->state = e->xkey.state;
205 static void i_cancel_func(gpointer options)
207 Options *o = options;
212 static void i_post_func(gpointer options)
214 Options *o = options;
215 struct _ObClient *ft;
217 ft = focus_cycle(o->forward,
228 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
229 o->state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);