cf51d4155f02f482eb386b807ae4d3be849ea4a2
[mikachu/openbox.git] / openbox / action.h
1 /* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
2
3    action.h for the Openbox window manager
4    Copyright (c) 2003        Ben Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #ifndef __action_h
20 #define __action_h
21
22 #include "misc.h"
23 #include "frame.h"
24 #include "parser/parse.h"
25
26 struct _ObClient;
27
28 typedef struct _ObAction ObAction;
29
30 /* These have to all have a Client* at the top even if they don't use it, so
31    that I can set it blindly later on. So every function will have a Client*
32    available (possibly NULL though) if it wants it.
33 */
34
35 struct AnyAction {
36     struct _ObClient *c;
37     gboolean interactive;
38     gint x;
39     gint y;
40     gint button;
41 };
42
43 struct InteractiveAction {
44     struct AnyAction any;
45     gboolean final;
46     gboolean cancel;
47 };
48
49 struct InterDirectionalAction{
50     struct InteractiveAction inter;
51     ObDirection direction;
52 };
53
54 struct DirectionalAction{
55     struct AnyAction any;
56     ObDirection direction;
57 };
58
59 struct Execute {
60     struct AnyAction any;
61     char *path;
62 };
63
64 struct ClientAction {
65     struct AnyAction any;
66 };
67
68 struct Activate {
69     struct AnyAction any;
70     gboolean here; /* bring it to the current desktop */
71 };
72
73 struct MoveResizeRelative {
74     struct AnyAction any;
75     int delta;
76 };
77
78 struct SendToDesktop {
79     struct AnyAction any;
80     guint desk;
81     gboolean follow;
82 };
83
84 struct SendToDesktopDirection {
85     struct InteractiveAction inter;
86     ObDirection dir;
87     gboolean wrap;
88     gboolean linear;
89     gboolean follow;
90 };
91
92 struct Desktop {
93     struct AnyAction any;
94     guint desk;
95 };
96
97 struct Layer {
98     struct AnyAction any;
99     int layer; /* < 0 = below, 0 = normal, > 0 = above */
100 };
101
102 struct DesktopDirection {
103     struct InteractiveAction inter;
104     ObDirection dir;
105     gboolean wrap;
106     gboolean linear;
107 };
108
109 struct MoveResize {
110     struct AnyAction any;
111     gboolean move;
112     gboolean keyboard;
113 };
114
115 struct ShowMenu {
116     struct AnyAction any;
117     char *name;
118 };
119
120 struct CycleWindows {
121     struct InteractiveAction inter;
122     gboolean linear;
123     gboolean forward;
124 };
125
126 union ActionData {
127     struct AnyAction any;
128     struct InteractiveAction inter;
129     struct InterDirectionalAction interdiraction;
130     struct DirectionalAction diraction;
131     struct Execute execute;
132     struct ClientAction client;
133     struct Activate activate;
134     struct MoveResizeRelative relative;
135     struct SendToDesktop sendto;
136     struct SendToDesktopDirection sendtodir;
137     struct Desktop desktop;
138     struct DesktopDirection desktopdir;
139     struct MoveResize moveresize;
140     struct ShowMenu showmenu;
141     struct CycleWindows cycle;
142     struct Layer layer;
143 };
144
145 struct _ObAction {
146     ObUserAction act;
147     /* The func member acts like an enum to tell which one of the structs in
148        the data union are valid.
149     */
150     void (*func)(union ActionData *data);
151     union ActionData data;
152 };
153
154 /* Creates a new Action from the name of the action
155    A few action types need data set after making this call still. Check if
156    the returned action's "func" is one of these.
157    action_execute - the path needs to be set
158    action_restart - the path can optionally be set
159    action_desktop - the destination desktop needs to be set
160    action_send_to_desktop - the destination desktop needs to be set
161    action_move_relative_horz - the delta
162    action_move_relative_vert - the delta
163    action_resize_relative_horz - the delta
164    action_resize_relative_vert - the delta
165 */
166
167 ObAction *action_from_string(char *name, ObUserAction uact);
168 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
169                        ObUserAction uact);
170 void action_free(ObAction *a);
171
172 /*! Executes an action.
173   @param c The client associated with the action. Can be NULL.
174   @param state The keyboard modifiers state at the time the user action occured
175   @param button The mouse button used to execute the action.
176   @param x The x coord at which the user action occured.
177   @param y The y coord at which the user action occured.
178   @param cancel If the action is cancelling an interactive action. This only
179          affects interactive actions, but should generally always be FALSE.
180   @param done If the action is completing an interactive action. This only
181          affects interactive actions, but should generally always be FALSE.
182 */
183 void action_run_full(ObAction *a, struct _ObClient *c,
184                      guint state, guint button, gint x, gint y,
185                      gboolean cancel, gboolean done);
186
187 #define action_run_mouse(a, c, s, b, x, y) \
188     action_run_full(a, c, s, b, x, y, FALSE, FALSE)
189
190 #define action_run_interactive(a, c, s, n, d) \
191     action_run_full(a, c, s, 0, -1, -1, n, d)
192
193 #define action_run_key(a, c, s, x, y) \
194     action_run_full(a, c, s, 0, x, y, FALSE,FALSE)
195
196 #define action_run(a, c, s) \
197     action_run_full(a, c, s, 0, -1, -1, FALSE,FALSE)
198
199 /* Execute */
200 void action_execute(union ActionData *data);
201 /* ActivateAction */
202 void action_activate(union ActionData *data);
203 /* ClientAction */
204 void action_focus(union ActionData *data);
205 /* ClientAction */
206 void action_unfocus(union ActionData *data);
207 /* ClientAction */
208 void action_iconify(union ActionData *data);
209 /* ClientAction */
210 void action_raiselower(union ActionData *data);
211 /* ClientAction */
212 void action_raise(union ActionData *data);
213 /* ClientAction */
214 void action_lower(union ActionData *data);
215 /* ClientAction */
216 void action_close(union ActionData *data);
217 /* ClientAction */
218 void action_kill(union ActionData *data);
219 /* ClientAction */
220 void action_shade(union ActionData *data);
221 /* ClientAction */
222 void action_shadelower(union ActionData *data);
223 /* ClientAction */
224 void action_unshaderaise(union ActionData *data);
225 /* ClientAction */
226 void action_unshade(union ActionData *data);
227 /* ClientAction */
228 void action_toggle_shade(union ActionData *data);
229 /* ClientAction */
230 void action_toggle_omnipresent(union ActionData *data);
231 /* MoveResizeRelative */
232 void action_move_relative_horz(union ActionData *data);
233 /* MoveResizeRelative */
234 void action_move_relative_vert(union ActionData *data);
235 /* MoveResizeRelative */
236 void action_resize_relative_horz(union ActionData *data);
237 /* MoveResizeRelative */
238 void action_resize_relative_vert(union ActionData *data);
239 /* ClientAction */
240 void action_maximize_full(union ActionData *data);
241 /* ClientAction */
242 void action_unmaximize_full(union ActionData *data);
243 /* ClientAction */
244 void action_toggle_maximize_full(union ActionData *data);
245 /* ClientAction */
246 void action_maximize_horz(union ActionData *data);
247 /* ClientAction */
248 void action_unmaximize_horz(union ActionData *data);
249 /* ClientAction */
250 void action_toggle_maximize_horz(union ActionData *data);
251 /* ClientAction */
252 void action_maximize_vert(union ActionData *data);
253 /* ClientAction */
254 void action_unmaximize_vert(union ActionData *data);
255 /* ClientAction */
256 void action_toggle_maximize_vert(union ActionData *data);
257 /* SendToDesktop */
258 void action_send_to_desktop(union ActionData *data);
259 /* SendToDesktopDirection */
260 void action_send_to_desktop_dir(union ActionData *data);
261 /* Desktop */
262 void action_desktop(union ActionData *data);
263 /* DesktopDirection */
264 void action_desktop_dir(union ActionData *data);
265 /* Any */
266 void action_desktop_last(union ActionData *data);
267 /* ClientAction */
268 void action_toggle_decorations(union ActionData *data);
269 /* MoveResize */
270 void action_moveresize(union ActionData *data);
271 /* Any */
272 void action_reconfigure(union ActionData *data);
273 /* Execute */
274 void action_restart(union ActionData *data);
275 /* Any */
276 void action_exit(union ActionData *data);
277 /* ShowMenu */
278 void action_showmenu(union ActionData *data);
279 /* CycleWindows */
280 void action_cycle_windows(union ActionData *data);
281 /* InterDirectionalAction */
282 void action_directional_focus(union ActionData *data);
283 /* DirectionalAction */
284 void action_movetoedge(union ActionData *data);
285 /* DirectionalAction */
286 void action_growtoedge(union ActionData *data);
287 /* Layer */
288 void action_send_to_layer(union ActionData *data);
289 /* Layer */
290 void action_toggle_layer(union ActionData *data);
291 /* Any */
292 void action_toggle_show_desktop(union ActionData *data);
293 /* Any */
294 void action_show_desktop(union ActionData *data);
295 /* Any */
296 void action_unshow_desktop(union ActionData *data);
297
298 #endif