Merge branch 'backport' into work
[mikachu/openbox.git] / openbox / actions / showmenu.c
1 #include "openbox/actions.h"
2 #include "openbox/menu.h"
3 #include <glib.h>
4
5 typedef struct {
6     gchar   *name;
7 } Options;
8
9 static gpointer setup_func(xmlNodePtr node);
10 static void     free_func(gpointer options);
11 static gboolean run_func(ObActionsData *data, gpointer options);
12
13 void action_showmenu_startup(void)
14 {
15     actions_register("ShowMenu", setup_func, free_func, run_func,
16                      NULL, NULL);
17 }
18
19 static gpointer setup_func(xmlNodePtr node)
20 {
21     xmlNodePtr n;
22     Options *o;
23
24     o = g_new0(Options, 1);
25
26     if ((n = obt_parse_find_node(node, "menu")))
27         o->name = obt_parse_node_string(n);
28     return o;
29 }
30
31 static void free_func(gpointer options)
32 {
33     Options *o = options;
34     g_free(o->name);
35     g_free(o);
36 }
37
38 /* Always return FALSE because its not interactive */
39 static gboolean run_func(ObActionsData *data, gpointer options)
40 {
41     Options *o = options;
42
43     /* you cannot call ShowMenu from inside a menu */
44     if (data->uact != OB_USER_ACTION_MENU_SELECTION && o->name)
45         menu_show(o->name, data->x, data->y, data->button != 0, data->client);
46
47     return FALSE;
48 }