]> Dogcows Code - chaz/openbox/blob - openbox/actions/cyclewindows.c
bbcb6585a11422e22001bf22ab8925af321c13cd
[chaz/openbox] / openbox / actions / cyclewindows.c
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 "gettext.h"
8 #include "obt/keyboard.h"
9
10 typedef struct {
11 gboolean linear;
12 gboolean dock_windows;
13 gboolean desktop_windows;
14 gboolean only_hilite_windows;
15 gboolean all_desktops;
16 gboolean forward;
17 gboolean bar;
18 gboolean raise;
19 ObFocusCyclePopupMode dialog_mode;
20 GSList *actions;
21
22
23 /* options for after we're done */
24 gboolean cancel; /* did the user cancel or not */
25 guint state; /* keyboard state when finished */
26 } Options;
27
28 static gpointer setup_func(xmlNodePtr node,
29 ObActionsIPreFunc *pre,
30 ObActionsIInputFunc *in,
31 ObActionsICancelFunc *c,
32 ObActionsIPostFunc *post);
33 static gpointer setup_forward_func(xmlNodePtr node,
34 ObActionsIPreFunc *pre,
35 ObActionsIInputFunc *in,
36 ObActionsICancelFunc *c,
37 ObActionsIPostFunc *post);
38 static gpointer setup_backward_func(xmlNodePtr node,
39 ObActionsIPreFunc *pre,
40 ObActionsIInputFunc *in,
41 ObActionsICancelFunc *c,
42 ObActionsIPostFunc *post);
43 static void free_func(gpointer options);
44 static gboolean run_func(ObActionsData *data, gpointer options);
45 static gboolean i_input_func(guint initial_state,
46 XEvent *e,
47 ObtIC *ic,
48 gpointer options,
49 gboolean *used);
50 static void i_cancel_func(gpointer options);
51 static void i_post_func(gpointer options);
52
53 void action_cyclewindows_startup(void)
54 {
55 actions_register_i("NextWindow", setup_forward_func, free_func, run_func);
56 actions_register_i("PreviousWindow", setup_backward_func, free_func,
57 run_func);
58 }
59
60 static gpointer setup_func(xmlNodePtr node,
61 ObActionsIPreFunc *pre,
62 ObActionsIInputFunc *input,
63 ObActionsICancelFunc *cancel,
64 ObActionsIPostFunc *post)
65 {
66 xmlNodePtr n;
67 Options *o;
68
69 o = g_slice_new0(Options);
70 o->bar = TRUE;
71 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_LIST;
72
73 if ((n = obt_xml_find_node(node, "linear")))
74 o->linear = obt_xml_node_bool(n);
75 if ((n = obt_xml_find_node(node, "dialog"))) {
76 if (obt_xml_node_contains(n, "none"))
77 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_NONE;
78 else if (obt_xml_node_contains(n, "icons"))
79 o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_ICONS;
80 }
81 if ((n = obt_xml_find_node(node, "bar")))
82 o->bar = obt_xml_node_bool(n);
83 if ((n = obt_xml_find_node(node, "raise")))
84 o->raise = obt_xml_node_bool(n);
85 if ((n = obt_xml_find_node(node, "panels")))
86 o->dock_windows = obt_xml_node_bool(n);
87 if ((n = obt_xml_find_node(node, "hilite")))
88 o->only_hilite_windows = obt_xml_node_bool(n);
89 if ((n = obt_xml_find_node(node, "desktop")))
90 o->desktop_windows = obt_xml_node_bool(n);
91 if ((n = obt_xml_find_node(node, "allDesktops")))
92 o->all_desktops = obt_xml_node_bool(n);
93
94 if ((n = obt_xml_find_node(node, "finalactions"))) {
95 xmlNodePtr m;
96
97 m = obt_xml_find_node(n->children, "action");
98 while (m) {
99 ObActionsAct *action = actions_parse(m);
100 if (action) o->actions = g_slist_append(o->actions, action);
101 m = obt_xml_find_node(m->next, "action");
102 }
103 }
104 else {
105 o->actions = g_slist_prepend(o->actions,
106 actions_parse_string("Focus"));
107 o->actions = g_slist_prepend(o->actions,
108 actions_parse_string("Raise"));
109 o->actions = g_slist_prepend(o->actions,
110 actions_parse_string("Unshade"));
111 }
112
113 *input = i_input_func;
114 *cancel = i_cancel_func;
115 *post = i_post_func;
116 return o;
117 }
118
119 static gpointer setup_forward_func(xmlNodePtr node,
120 ObActionsIPreFunc *pre,
121 ObActionsIInputFunc *input,
122 ObActionsICancelFunc *cancel,
123 ObActionsIPostFunc *post)
124 {
125 Options *o = setup_func(node, pre, input, cancel, post);
126 o->forward = TRUE;
127 return o;
128 }
129
130 static gpointer setup_backward_func(xmlNodePtr node,
131 ObActionsIPreFunc *pre,
132 ObActionsIInputFunc *input,
133 ObActionsICancelFunc *cancel,
134 ObActionsIPostFunc *post)
135 {
136 Options *o = setup_func(node, pre, input, cancel, post);
137 o->forward = FALSE;
138 return o;
139 }
140
141 static void free_func(gpointer options)
142 {
143 Options *o = options;
144
145 while (o->actions) {
146 actions_act_unref(o->actions->data);
147 o->actions = g_slist_delete_link(o->actions, o->actions);
148 }
149
150 g_slice_free(Options, o);
151 }
152
153 static gboolean run_func(ObActionsData *data, gpointer options)
154 {
155 Options *o = options;
156 struct _ObClient *ft;
157
158 ft = focus_cycle(o->forward,
159 o->all_desktops,
160 !o->only_hilite_windows,
161 o->dock_windows,
162 o->desktop_windows,
163 o->linear,
164 TRUE,
165 o->bar,
166 o->dialog_mode,
167 FALSE, FALSE);
168
169 stacking_restore();
170 if (o->raise && ft) stacking_temp_raise(CLIENT_AS_WINDOW(ft));
171
172 return TRUE;
173 }
174
175 static gboolean i_input_func(guint initial_state,
176 XEvent *e,
177 ObtIC *ic,
178 gpointer options,
179 gboolean *used)
180 {
181 Options *o = options;
182 guint mods;
183
184 mods = obt_keyboard_only_modmasks(e->xkey.state);
185 if (e->type == KeyRelease) {
186 /* remove from the state the mask of the modifier key being
187 released, if it is a modifier key being released that is */
188 mods &= ~obt_keyboard_keyevent_to_modmask(e);
189 }
190
191 if (e->type == KeyPress) {
192 KeySym sym = obt_keyboard_keypress_to_keysym(e);
193
194 /* Escape cancels no matter what */
195 if (sym == XK_Escape) {
196 o->cancel = TRUE;
197 o->state = e->xkey.state;
198 return FALSE;
199 }
200
201 /* There were no modifiers and they pressed enter */
202 else if ((sym == XK_Return || sym == XK_KP_Enter) && !initial_state) {
203 o->cancel = FALSE;
204 o->state = e->xkey.state;
205 return FALSE;
206 }
207 }
208 /* They released the modifiers */
209 else if (e->type == KeyRelease && initial_state && !(mods & initial_state))
210 {
211 o->cancel = FALSE;
212 o->state = e->xkey.state;
213 return FALSE;
214 }
215
216 return TRUE;
217 }
218
219 static void i_cancel_func(gpointer options)
220 {
221 Options *o = options;
222 o->cancel = TRUE;
223 o->state = 0;
224 }
225
226 static void i_post_func(gpointer options)
227 {
228 Options *o = options;
229 struct _ObClient *ft;
230
231 ft = focus_cycle(o->forward,
232 o->all_desktops,
233 !o->only_hilite_windows,
234 o->dock_windows,
235 o->desktop_windows,
236 o->linear,
237 TRUE,
238 o->bar,
239 o->dialog_mode,
240 TRUE, o->cancel);
241
242 if (ft)
243 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
244 o->state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);
245
246 stacking_restore();
247 }
This page took 0.043517 seconds and 3 git commands to generate.