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_string(const gchar *name)
106 ObActionsDefinition *def;
107 ObActionsAct *act = NULL;
109 /* find the requested action */
110 for (it = registered; it; it = g_slist_next(it)) {
112 if (!g_ascii_strcasecmp(name, def->name))
117 /* if we found the action */
119 act = g_new(ObActionsAct, 1);
122 actions_definition_ref(act->def);
125 g_message(_("Invalid action '%s' requested. No such action exists."),
131 ObActionsAct* actions_parse(ObParseInst *i,
136 ObActionsAct *act = NULL;
138 if (parse_attr_string("name", node, &name)) {
139 if ((act = actions_parse_string(name)))
140 /* there is more stuff to parse here */
141 act->options = act->def->setup(i, doc, node->children);
149 void actions_act_ref(ObActionsAct *act)
154 void actions_act_unref(ObActionsAct *act)
156 if (act && --act->ref == 0) {
157 /* free the action specific options */
158 act->def->free(act->options);
159 /* unref the definition */
160 actions_definition_unref(act->def);