]> icculus.org git repositories - dana/openbox.git/blob - openbox/menu.h
fix grabbing and not releasing with menus
[dana/openbox.git] / openbox / menu.h
1 #ifndef __menu_h
2 #define __menu_h
3
4 #include "action.h"
5 #include "window.h"
6 #include "geom.h"
7 #include "render/render.h"
8 #include "parser/parse.h"
9
10 #include <glib.h>
11
12 struct _ObClient;
13 struct _ObMenuFrame;
14 struct _ObMenuEntryFrame;
15
16 typedef struct _ObMenu ObMenu;
17 typedef struct _ObMenuEntry ObMenuEntry;
18 typedef struct _ObNormalMenuEntry ObNormalMenuEntry;
19 typedef struct _ObSubmenuMenuEntry ObSubmenuMenuEntry;
20 typedef struct _ObSeparatorMenuEntry ObSeparatorMenuEntry;
21
22 typedef void (*ObMenuUpdateFunc)(struct _ObMenuFrame *frame, gpointer data);
23 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntry *entry, gpointer data);
24 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
25
26 extern ObParseInst *menu_parse_inst;
27
28 struct _ObMenu
29 {
30     /* Name of the menu. Used in the showmenu action. */
31     gchar *name;
32     /* Displayed title */
33     gchar *title;
34
35     /* ObMenuEntry list */
36     GList *entries;
37
38     /* plugin data */
39     gpointer data;
40
41     ObMenuUpdateFunc update_func;
42     ObMenuExecuteFunc execute_func;
43     ObMenuDestroyFunc destroy_func;
44 };
45
46 typedef enum
47 {
48     OB_MENU_ENTRY_TYPE_NORMAL,
49     OB_MENU_ENTRY_TYPE_SUBMENU,
50     OB_MENU_ENTRY_TYPE_SEPARATOR
51 } ObMenuEntryType;
52
53 struct _ObNormalMenuEntry {
54     gchar *label;
55
56     /* state */
57     gboolean enabled;
58
59     /* List of ObActions */
60     GSList *actions;
61
62     /* Icon shit */
63     gint icon_width;
64     gint icon_height;
65     RrPixel32 *icon_data;
66 };
67
68 struct _ObSubmenuMenuEntry {
69     gchar *name;
70     ObMenu *submenu;
71 };
72
73 struct _ObSeparatorMenuEntry {
74     gchar foo; /* placeholder */
75 };
76
77 struct _ObMenuEntry
78 {
79     ObMenuEntryType type;
80     ObMenu *menu;
81
82     gint id;
83
84     union u {
85         ObNormalMenuEntry normal;
86         ObSubmenuMenuEntry submenu;
87         ObSeparatorMenuEntry separator;
88     } data;
89 };
90
91 void menu_startup();
92 void menu_shutdown();
93
94 ObMenu* menu_new(gchar *name, gchar *title, gpointer data);
95 void menu_free(ObMenu *menu);
96
97 void menu_show(gchar *name, gint x, gint y, struct _ObClient *client);
98
99 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
100 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
101 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
102
103 /* functions for building menus */
104 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, gchar *label,
105                              GSList *actions);
106 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, gchar *submenu);
107 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id);
108
109 void menu_clear_entries(ObMenu *menu);
110 void menu_entry_remove(ObMenuEntry *self);
111
112 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
113
114 /* fills in the submenus, for use when a menu is being shown */
115 void menu_find_submenus(ObMenu *self);
116
117 #endif