]> icculus.org git repositories - dana/openbox.git/blob - openbox/menu.h
when a pipe menu is killed, kill all its submenus as well
[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 struct _ObMenu
27 {
28     /* Name of the menu. Used in the showmenu action. */
29     gchar *name;
30     /* Displayed title */
31     gchar *title;
32
33     /* Command to execute to rebuild the menu */
34     gchar *execute;
35
36     /* ObMenuEntry list */
37     GList *entries;
38
39     /* plugin data */
40     gpointer data;
41
42     ObMenuUpdateFunc update_func;
43     ObMenuExecuteFunc execute_func;
44     ObMenuDestroyFunc destroy_func;
45
46     /* Pipe-menu parent, we get destroyed when it is destroyed */
47     ObMenu *pipe_creator;
48 };
49
50 typedef enum
51 {
52     OB_MENU_ENTRY_TYPE_NORMAL,
53     OB_MENU_ENTRY_TYPE_SUBMENU,
54     OB_MENU_ENTRY_TYPE_SEPARATOR
55 } ObMenuEntryType;
56
57 struct _ObNormalMenuEntry {
58     gchar *label;
59
60     /* state */
61     gboolean enabled;
62
63     /* List of ObActions */
64     GSList *actions;
65
66     /* Icon shit */
67     gint icon_width;
68     gint icon_height;
69     RrPixel32 *icon_data;
70
71     /* Mask icon */
72     RrPixmapMask *mask;
73     RrColor *mask_normal_color;
74     RrColor *mask_disabled_color;
75     RrColor *mask_selected_color;
76 };
77
78 struct _ObSubmenuMenuEntry {
79     gchar *name;
80     ObMenu *submenu;
81 };
82
83 struct _ObSeparatorMenuEntry {
84     gchar foo; /* placeholder */
85 };
86
87 struct _ObMenuEntry
88 {
89     ObMenuEntryType type;
90     ObMenu *menu;
91
92     gint id;
93
94     union u {
95         ObNormalMenuEntry normal;
96         ObSubmenuMenuEntry submenu;
97         ObSeparatorMenuEntry separator;
98     } data;
99 };
100
101 void menu_startup(gboolean reconfig);
102 void menu_shutdown(gboolean reconfig);
103
104 ObMenu* menu_new(gchar *name, gchar *title, gpointer data);
105 void menu_free(ObMenu *menu);
106
107 /* Repopulate a pipe-menu by running its command */
108 void menu_pipe_execute(ObMenu *self);
109
110 void menu_show(gchar *name, gint x, gint y, struct _ObClient *client);
111
112 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
113 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
114 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
115
116 /* functions for building menus */
117 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, gchar *label,
118                              GSList *actions);
119 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, gchar *submenu);
120 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id);
121
122 void menu_clear_entries(ObMenu *menu);
123 void menu_entry_remove(ObMenuEntry *self);
124
125 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
126
127 /* fills in the submenus, for use when a menu is being shown */
128 void menu_find_submenus(ObMenu *self);
129
130 #endif