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;
36 struct _ObActionsAct {
39 ObActionsDefinition *def;
43 static GSList *registered = NULL;
46 void actions_startup(gboolean reconfig)
53 void actions_shutdown(gboolean reconfig)
57 /* free all the registered actions */
59 actions_definition_unref(registered->data);
60 registered = g_slist_delete_link(registered, registered);
64 gboolean actions_register(const gchar *name,
66 ObActionsDataSetupFunc setup,
67 ObActionsDataFreeFunc free,
71 ObActionsDefinition *def;
73 for (it = registered; it; it = g_slist_next(it)) {
75 if (!g_ascii_strcasecmp(name, def->name)) /* already registered */
79 def = g_new(ObActionsDefinition, 1);
81 def->name = g_strdup(name);
89 static void actions_definition_ref(ObActionsDefinition *def)
94 static void actions_definition_unref(ObActionsDefinition *def)
96 if (def && --def->ref == 0) {
102 ObActionsAct* actions_parse_string(const gchar *name)
105 ObActionsDefinition *def;
106 ObActionsAct *act = NULL;
108 /* find the requested action */
109 for (it = registered; it; it = g_slist_next(it)) {
111 if (!g_ascii_strcasecmp(name, def->name))
116 /* if we found the action */
118 act = g_new(ObActionsAct, 1);
121 actions_definition_ref(act->def);
124 g_message(_("Invalid action '%s' requested. No such action exists."),
130 ObActionsAct* actions_parse(ObParseInst *i,
135 ObActionsAct *act = NULL;
137 if (parse_attr_string("name", node, &name)) {
138 if ((act = actions_parse_string(name)))
139 /* there is more stuff to parse here */
140 act->options = act->def->setup(i, doc, node->children);
148 void actions_act_ref(ObActionsAct *act)
153 void actions_act_unref(ObActionsAct *act)
155 if (act && --act->ref == 0) {
156 /* free the action specific options */
157 act->def->free(act->options);
158 /* unref the definition */
159 actions_definition_unref(act->def);
164 static void actions_setup_data(ObActionsData *data,
172 data->any.uact = uact;
173 data->any.time = time;
174 data->any.state = state;
175 data->any.button = button;
180 void actions_run_acts(GSList *acts,
188 struct _ObClient *client,
189 ObActionsInteractiveState interactive)
193 for (it = acts; it; it = g_slist_next(it)) {
195 ObActionsAct *act = it->data;
197 data.type = act->def->type;
198 actions_setup_data(&data, uact, time, state, button, x, y);
200 case OB_ACTION_TYPE_GLOBAL:
202 case OB_ACTION_TYPE_CLIENT:
203 data.client.context = con;
204 data.client.c = client;
206 case OB_ACTION_TYPE_SELECTOR:
207 data.selector.interactive = interactive;
210 g_assert_not_reached();
213 /* fire the action's run function with this data */
214 act->def->run(&data, act->options);