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
{
29 gboolean allow_interactive
;
31 ObActionsDataSetupFunc setup
;
32 ObActionsDataFreeFunc free
;
36 struct _ObActionsAct
{
39 ObActionsDefinition
*def
;
44 static GSList
*registered
= NULL
;
47 void actions_startup(gboolean reconfig
)
54 void actions_shutdown(gboolean reconfig
)
58 /* free all the registered actions */
60 actions_definition_unref(registered
->data
);
61 registered
= g_slist_delete_link(registered
, registered
);
65 gboolean
actions_register(const gchar
*name
,
66 gboolean allow_interactive
,
67 ObActionsDataSetupFunc setup
,
68 ObActionsDataFreeFunc free
,
72 ObActionsDefinition
*def
;
74 for (it
= registered
; it
; it
= g_slist_next(it
)) {
76 if (!g_ascii_strcasecmp(name
, def
->name
)) /* already registered */
80 def
= g_new(ObActionsDefinition
, 1);
82 def
->name
= g_strdup(name
);
83 def
->allow_interactive
= allow_interactive
;
90 static void actions_definition_ref(ObActionsDefinition
*def
)
95 static void actions_definition_unref(ObActionsDefinition
*def
)
97 if (def
&& --def
->ref
== 0) {
103 ObActionsAct
* actions_parse(ObParseInst
*i
,
109 ObActionsDefinition
*def
;
110 ObActionsAct
*act
= NULL
;
112 if (!parse_attr_string("name", node
, &name
)) return NULL
;
114 /* find the requested action */
115 for (it
= registered
; it
; it
= g_slist_next(it
)) {
117 if (!g_ascii_strcasecmp(name
, def
->name
))
121 /* if we found the action */
123 act
= g_new(ObActionsAct
, 1);
126 actions_definition_ref(act
->def
);
127 act
->options
= def
->setup(i
, doc
, node
->children
);
129 g_message(_("Invalid action '%s' requested. No such action exists."),
137 void actions_act_ref(ObActionsAct
*act
)
142 void actions_act_unref(ObActionsAct
*act
)
144 if (act
&& --act
->ref
== 0) {
145 /* free the action specific options */
146 act
->def
->free(act
->options
);
147 /* unref the definition */
148 actions_definition_unref(act
->def
);