1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 actions.h for the Openbox window manager
4 Copyright (c) 2007 Dana Jansens
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.
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.
16 See the COPYING file for a copy of the GNU General Public License.
22 static void actions_definition_ref(ObActionsDefinition
*def
);
23 static void actions_definition_unref(ObActionsDefinition
*def
);
25 struct _ObActionsDefinition
{
31 ObActionsDataSetupFunc setup
;
32 ObActionsDataFreeFunc free
;
34 ObActionsInteractiveInputFunc i_input
;
35 ObActionsInteractiveCancelFunc i_cancel
;
38 struct _ObActionsAct
{
41 ObActionsDefinition
*def
;
45 static GSList
*registered
= NULL
;
48 void actions_startup(gboolean reconfig
)
55 void actions_shutdown(gboolean reconfig
)
59 /* free all the registered actions */
61 actions_definition_unref(registered
->data
);
62 registered
= g_slist_delete_link(registered
, registered
);
66 gboolean
actions_register(const gchar
*name
,
68 ObActionsDataSetupFunc setup
,
69 ObActionsDataFreeFunc free
,
71 ObActionsInteractiveInputFunc i_input
,
72 ObActionsInteractiveCancelFunc i_cancel
)
75 ObActionsDefinition
*def
;
77 for (it
= registered
; it
; it
= g_slist_next(it
)) {
79 if (!g_ascii_strcasecmp(name
, def
->name
)) /* already registered */
83 g_assert((i_input
== NULL
) == (i_cancel
== NULL
));
85 def
= g_new(ObActionsDefinition
, 1);
87 def
->name
= g_strdup(name
);
92 def
->i_input
= i_input
;
93 def
->i_cancel
= i_cancel
;
97 static void actions_definition_ref(ObActionsDefinition
*def
)
102 static void actions_definition_unref(ObActionsDefinition
*def
)
104 if (def
&& --def
->ref
== 0) {
110 ObActionsAct
* actions_parse_string(const gchar
*name
)
113 ObActionsDefinition
*def
;
114 ObActionsAct
*act
= NULL
;
116 /* find the requested action */
117 for (it
= registered
; it
; it
= g_slist_next(it
)) {
119 if (!g_ascii_strcasecmp(name
, def
->name
))
124 /* if we found the action */
126 act
= g_new(ObActionsAct
, 1);
129 actions_definition_ref(act
->def
);
132 g_message(_("Invalid action '%s' requested. No such action exists."),
138 ObActionsAct
* actions_parse(ObParseInst
*i
,
143 ObActionsAct
*act
= NULL
;
145 if (parse_attr_string("name", node
, &name
)) {
146 if ((act
= actions_parse_string(name
)))
147 /* there is more stuff to parse here */
148 act
->options
= act
->def
->setup(i
, doc
, node
->children
);
156 gboolean
actions_act_is_interactive(ObActionsAct
*act
)
158 return act
->def
->i_cancel
!= NULL
;
161 void actions_act_ref(ObActionsAct
*act
)
166 void actions_act_unref(ObActionsAct
*act
)
168 if (act
&& --act
->ref
== 0) {
169 /* free the action specific options */
170 act
->def
->free(act
->options
);
171 /* unref the definition */
172 actions_definition_unref(act
->def
);
177 static void actions_setup_data(ObActionsData
*data
,
184 data
->any
.uact
= uact
;
185 data
->any
.time
= time
;
186 data
->any
.state
= state
;
191 void actions_run_acts(GSList
*acts
,
198 struct _ObClient
*client
)
202 for (it
= acts
; it
; it
= g_slist_next(it
)) {
204 ObActionsAct
*act
= it
->data
;
206 data
.type
= act
->def
->type
;
207 actions_setup_data(&data
, uact
, time
, state
, x
, y
);
209 case OB_ACTION_TYPE_GLOBAL
:
211 case OB_ACTION_TYPE_CLIENT
:
212 data
.client
.context
= con
;
213 data
.client
.c
= client
;
216 g_assert_not_reached();
219 /* fire the action's run function with this data */
220 act
->def
->run(&data
, act
->options
);