Warp to the top of the combined menu and back.
[mikachu/openbox.git] / openbox / menu.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    menu.h for the Openbox window manager
4    Copyright (c) 2003-2007   Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #ifndef __menu_h
20 #define __menu_h
21
22 #include "window.h"
23 #include "geom.h"
24 #include "obrender/render.h"
25
26 #include <glib.h>
27
28 struct _ObClient;
29 struct _ObMenuFrame;
30 struct _ObMenuEntryFrame;
31
32 typedef struct _ObMenu ObMenu;
33 typedef struct _ObMenuEntry ObMenuEntry;
34 typedef struct _ObNormalMenuEntry ObNormalMenuEntry;
35 typedef struct _ObSubmenuMenuEntry ObSubmenuMenuEntry;
36 typedef struct _ObSeparatorMenuEntry ObSeparatorMenuEntry;
37
38 typedef void (*ObMenuShowFunc)(struct _ObMenuFrame *frame, gpointer data);
39 typedef void (*ObMenuHideFunc)(struct _ObMenuFrame *frame, gpointer data);
40 typedef gboolean (*ObMenuUpdateFunc)(struct _ObMenuFrame *frame,
41                                      gpointer data);
42 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntry *entry,
43                                   struct _ObMenuFrame *frame,
44                                   struct _ObClient *client,
45                                   guint state, gpointer data);
46 typedef void (*ObMenuCleanupFunc)(struct _ObMenu *menu, gpointer data);
47 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
48 /*! @param x is the mouse x coordinate. on return it should be the x coordinate
49              for the menu
50     @param y is the mouse y coordinate. on return it should be the y coordinate
51              for the menu
52 */
53 typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y,
54                                 gboolean mouse, gpointer data);
55
56 struct _ObMenu
57 {
58     /* Name of the menu. Used in the showmenu action. */
59     gchar *name;
60     /* Displayed title */
61     gchar *title;
62     gchar *collate_key;
63     /*! The shortcut key that would be used to activate this menu if it was
64       displayed as a submenu */
65     gunichar shortcut;
66     /*! The shortcut's position in the string */
67     guint shortcut_position;
68     /*! If the shortcut was specified by & and should always be drawn */
69     gboolean shortcut_always_show;
70
71     /*! If the shortcut key should be shown in menu entries even when it
72       is the first character in the string */
73     gboolean show_all_shortcuts;
74
75     /* Command to execute to rebuild the menu */
76     gchar *execute;
77
78     /* ObMenuEntry list */
79     GList *entries;
80
81     /* plugin data */
82     gpointer data;
83
84     ObMenuShowFunc show_func;
85     ObMenuHideFunc hide_func;
86     ObMenuUpdateFunc update_func;
87     ObMenuExecuteFunc execute_func;
88     ObMenuCleanupFunc cleanup_func;
89     ObMenuDestroyFunc destroy_func;
90     ObMenuPlaceFunc place_func;
91
92     gboolean warp;
93
94     /* Pipe-menu parent, we get destroyed when it is destroyed */
95     ObMenu *pipe_creator;
96
97     /* The menu used as the destination for the "More..." entry for this menu*/
98     ObMenu *more_menu;
99 };
100
101 typedef enum
102 {
103     OB_MENU_ENTRY_TYPE_NORMAL,
104     OB_MENU_ENTRY_TYPE_SUBMENU,
105     OB_MENU_ENTRY_TYPE_SEPARATOR
106 } ObMenuEntryType;
107
108 struct _ObNormalMenuEntry {
109     /* Icon stuff.  If you set this, make sure you RrImageRef() it too. */
110     RrImage *icon;
111     gint     icon_alpha;
112
113     gchar *label;
114     gchar *collate_key;
115     /*! The shortcut key that would be used to activate this menu entry */
116     gunichar shortcut;
117     /*! The shortcut's position in the string */
118     guint shortcut_position;
119     /*! If the shortcut was specified by & and should always be drawn */
120     gboolean shortcut_always_show;
121
122     /* state */
123     gboolean enabled;
124
125     /* List of ObActions */
126     GSList *actions;
127
128     /* Mask icon */
129     RrPixmapMask *mask;
130     RrColor *mask_normal_color;
131     RrColor *mask_selected_color;
132     RrColor *mask_disabled_color;
133     RrColor *mask_disabled_selected_color;
134
135     gpointer data;
136 };
137
138 struct _ObSubmenuMenuEntry {
139     /* Icon stuff.  If you set this, make sure you RrImageRef() it too. */
140     RrImage *icon;
141     gint     icon_alpha;
142
143     gchar *name;
144     ObMenu *submenu;
145     
146     guint show_from;
147 };
148
149 struct _ObSeparatorMenuEntry {
150     gchar *label;
151 };
152
153 struct _ObMenuEntry
154 {
155     guint ref;
156
157     ObMenuEntryType type;
158     ObMenu *menu;
159
160     gint id;
161
162     union u {
163         ObNormalMenuEntry normal;
164         ObSubmenuMenuEntry submenu;
165         ObSeparatorMenuEntry separator;
166     } data;
167 };
168
169 void menu_startup(gboolean reconfig);
170 void menu_shutdown(gboolean reconfig);
171
172 void menu_entry_ref(ObMenuEntry *self);
173 void menu_entry_unref(ObMenuEntry *self);
174
175 ObMenu* menu_new(const gchar *name, const gchar *title,
176                  gboolean allow_shortcut_selection, gpointer data);
177 void menu_free(ObMenu *menu);
178
179 /*! Repopulate a pipe-menu by running its command */
180 void menu_pipe_execute(ObMenu *self);
181 /*! Clear a pipe-menu's entries */
182 void menu_clear_pipe_caches(void);
183
184 void menu_show_all_shortcuts(ObMenu *self, gboolean show);
185
186 void menu_show(gchar *name, const GravityPoint *pos, gint monitor,
187                gboolean mouse, gboolean user_positioned,
188                struct _ObClient *client);
189 gboolean menu_hide_delay_reached(void);
190
191 /*! The show function is called right after a menu is shown */
192 void menu_set_show_func(ObMenu *menu, ObMenuShowFunc func);
193 /*! The hide function is called right before a menu is hidden */
194 void menu_set_hide_func(ObMenu *menu, ObMenuHideFunc func);
195 /*! The update function is called when the menu should refresh its
196   contents, generally right before it is shown */
197 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
198 /*! The execute function is called when a user chooses to execute an
199   entry in the menu */
200 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
201 /*! The cleanup function is called after a menu is hidden, allowing it
202   to be cleaned up between uses */
203 void menu_set_cleanup_func(ObMenu *menu, ObMenuCleanupFunc func);
204 /*! The destroy function is called when the menu is being destroyed
205   permanently */
206 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
207 /*! The place function is called when the menu is being shown and allows
208   the menu to choose its initial position */
209 void menu_set_place_func(ObMenu *menu, ObMenuPlaceFunc func);
210
211 /* functions for building menus */
212 /*! @param allow_shortcut this should be false when the label is coming from
213            outside data like window or desktop titles */
214 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, const gchar *label,
215                              GSList *actions, gboolean allow_shortcut);
216 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, const gchar *submenu);
217 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id, const gchar *label);
218
219 /*! This sorts groups of menu entries between consecutive separators */
220 void menu_sort_entries(ObMenu *self);
221
222 void menu_clear_entries(ObMenu *self);
223 void menu_entry_remove(ObMenuEntry *self);
224
225 void menu_entry_set_label(ObMenuEntry *self, const gchar *label,
226                           gboolean allow_shortcut);
227
228 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
229
230 /* fills in the submenus, for use when a menu is being shown */
231 void menu_find_submenus(ObMenu *self);
232
233 ObMenuEntry* menu_get_more(ObMenu *menu, guint show_from);
234
235 #endif