]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/showmenu.c
Use ObConfigValue to parse gravity coords, remove parse special functions from config...
[dana/openbox.git] / openbox / actions / showmenu.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/config_value.h"
4 #include "openbox/client_set.h"
5 #include "openbox/menu.h"
6 #include <glib.h>
7
8 typedef struct {
9     gchar   *name;
10 } Options;
11
12 static gpointer setup_func(GHashTable *config);
13 static void     free_func(gpointer options);
14 static gboolean run_func(const ObClientSet *set,
15                          const ObActionListRun *data, gpointer options);
16
17 void action_showmenu_startup(void)
18 {
19     action_register("ShowMenu", OB_ACTION_DEFAULT_FILTER_SINGLE,
20                     setup_func, free_func, run_func);
21 }
22
23 static gpointer setup_func(GHashTable *config)
24 {
25     ObConfigValue *v;
26     Options *o;
27
28     o = g_slice_new0(Options);
29
30     v = g_hash_table_lookup(config, "menu");
31     if (v && config_value_is_string(v))
32         o->name = g_strdup(config_value_string(v));
33     return o;
34 }
35
36 static void free_func(gpointer options)
37 {
38     Options *o = options;
39     g_free(o->name);
40     g_slice_free(Options, o);
41 }
42
43 /* Always return FALSE because its not interactive */
44 static gboolean run_func(const ObClientSet *set,
45                          const ObActionListRun *data, gpointer options)
46 {
47     Options *o = options;
48     GList *list;
49     struct _ObClient *c;
50
51     /* this can't work on more than one window */
52     if (client_set_size(set) > 1) return FALSE;
53
54     list = client_set_get_all(set);
55     if (list) c = list->data;
56     else c = NULL;
57     g_list_free(list);
58
59     /* you cannot call ShowMenu from inside a menu */
60     if (data->user_act != OB_USER_ACTION_MENU_SELECTION && o->name)
61         menu_show(o->name, data->pointer_x, data->pointer_y,
62                   data->pointer_button != 0, c);
63
64     return FALSE;
65 }