add code for interactive actions
[dana/openbox.git] / openbox / actions.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    actions.h for the Openbox window manager
4    Copyright (c) 2007        Dana 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 #include "misc.h"
20 #include "frame.h"
21 #include "parser/parse.h"
22 #include <glib.h>
23 #include <X11/Xlib.h>
24
25 typedef struct _ObActionsDefinition   ObActionsDefinition;
26 typedef struct _ObActionsAct          ObActionsAct;
27 typedef struct _ObActionsData         ObActionsData;
28 typedef struct _ObActionsAnyData      ObActionsAnyData;
29 typedef struct _ObActionsGlobalData   ObActionsGlobalData;
30 typedef struct _ObActionsClientData   ObActionsClientData;
31 typedef struct _ObActionsSelectorData ObActionsSelectorData;
32
33 typedef gpointer (*ObActionsDataSetupFunc)(ObParseInst *i,
34                                            xmlDocPtr doc, xmlNodePtr node);
35 typedef void     (*ObActionsDataFreeFunc)(gpointer options);
36 typedef gboolean (*ObActionsRunFunc)(ObActionsData *data,
37                                      gpointer options);
38 typedef gboolean (*ObActionsInteractiveInputFunc)(guint initial_state,
39                                                   XEvent *e,
40                                                   gpointer options,
41                                                   gboolean *used);
42 typedef void     (*ObActionsInteractiveCancelFunc)(gpointer options);
43
44 typedef enum {
45     OB_ACTION_TYPE_GLOBAL,
46     OB_ACTION_TYPE_CLIENT
47 } ObActionsType;
48
49 /* These structures are all castable as eachother */
50
51 struct _ObActionsAnyData {
52     ObUserAction uact;
53     Time time;
54     guint state;
55     gint x;
56     gint y;
57 };
58
59 struct _ObActionsGlobalData {
60     ObActionsType type;
61     ObActionsAnyData any;
62 };
63
64 struct _ObActionsClientData {
65     ObActionsType type;
66     ObActionsAnyData any;
67
68     struct _ObClient *c;
69     ObFrameContext context;
70 };
71
72 struct _ObActionsData {
73     ObActionsType type;
74
75     union {
76         ObActionsAnyData      any;
77         ObActionsGlobalData   global;
78         ObActionsClientData   client;
79     };
80 };
81
82 void actions_startup(gboolean reconfigure);
83 void actions_shutdown(gboolean reconfigure);
84
85 /*! If the action is interactive, then i_input and i_cancel are not NULL.
86   Otherwise, they should both be NULL. */
87 gboolean actions_register(const gchar *name,
88                           ObActionsType type,
89                           ObActionsDataSetupFunc setup,
90                           ObActionsDataFreeFunc free,
91                           ObActionsRunFunc run,
92                           ObActionsInteractiveInputFunc i_input,
93                           ObActionsInteractiveCancelFunc i_cancel);
94
95 ObActionsAct* actions_parse(ObParseInst *i,
96                             xmlDocPtr doc,
97                             xmlNodePtr node);
98 ObActionsAct* actions_parse_string(const gchar *name);
99
100 gboolean actions_act_is_interactive(ObActionsAct *act);
101
102 void actions_act_ref(ObActionsAct *act);
103 void actions_act_unref(ObActionsAct *act);
104
105 /*! Pass in a GSList of ObActionsAct's to be run.
106   @return TRUE if an action is in interactive state, FALSE is none are
107 */
108 void actions_run_acts(GSList *acts,
109                       ObUserAction uact,
110                       Time time,
111                       guint state,
112                       gint x,
113                       gint y,
114                       ObFrameContext con,
115                       struct _ObClient *client);
116
117 gboolean actions_interactive_act_running();
118 void actions_interactive_cancel_act();
119
120 gboolean actions_interactive_input_event(XEvent *e);