]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/showmenu.c
Add action_list_run.c/h with action_list_run() and struct ObActionListRun.
[dana/openbox.git] / openbox / actions / showmenu.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/menu.h"
5 #include <glib.h>
6
7 typedef struct {
8     gchar   *name;
9 } Options;
10
11 static gpointer setup_func(GHashTable *config);
12 static void     free_func(gpointer options);
13 static gboolean run_func(const ObActionListRun *data, gpointer options);
14
15 void action_showmenu_startup(void)
16 {
17     action_register("ShowMenu", OB_ACTION_DEFAULT_FILTER_SINGLE,
18                     setup_func, free_func, run_func);
19 }
20
21 static gpointer setup_func(GHashTable *config)
22 {
23     ObActionValue *v;
24     Options *o;
25
26     o = g_slice_new0(Options);
27
28     v = g_hash_table_lookup(config, "menu");
29     if (v && action_value_is_string(v))
30         o->name = g_strdup(action_value_string(v));
31     return o;
32 }
33
34 static void free_func(gpointer options)
35 {
36     Options *o = options;
37     g_free(o->name);
38     g_slice_free(Options, o);
39 }
40
41 /* Always return FALSE because its not interactive */
42 static gboolean run_func(const ObActionListRun *data, gpointer options)
43 {
44     Options *o = options;
45
46     /* you cannot call ShowMenu from inside a menu */
47     if (data->uact != OB_USER_ACTION_MENU_SELECTION && o->name)
48         menu_show(o->name, data->x, data->y, data->button != 0, data->client);
49
50     return FALSE;
51 }