2003-04-14 21:26:01 +00:00
|
|
|
#include "menu.h"
|
2003-04-15 18:29:55 +00:00
|
|
|
#include "openbox.h"
|
2003-04-16 05:36:51 +00:00
|
|
|
#include "stacking.h"
|
2003-07-10 17:03:05 +00:00
|
|
|
#include "client.h"
|
2003-04-16 18:09:11 +00:00
|
|
|
#include "grab.h"
|
2003-05-09 23:15:28 +00:00
|
|
|
#include "screen.h"
|
|
|
|
#include "geom.h"
|
|
|
|
#include "plugin.h"
|
2003-07-21 23:19:03 +00:00
|
|
|
#include "misc.h"
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-05-21 23:58:40 +00:00
|
|
|
GHashTable *menu_hash = NULL;
|
2003-07-21 23:19:03 +00:00
|
|
|
GList *menu_visible = NULL;
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-07-22 16:14:42 +00:00
|
|
|
#define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
|
2003-05-09 23:15:28 +00:00
|
|
|
LeaveWindowMask)
|
2003-04-16 05:36:51 +00:00
|
|
|
#define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
|
2003-04-15 18:29:55 +00:00
|
|
|
#define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
|
|
|
|
ButtonPressMask | ButtonReleaseMask)
|
|
|
|
|
2003-06-22 08:32:35 +00:00
|
|
|
static void parse_menu(xmlDocPtr doc, xmlNodePtr node, void *data)
|
2003-07-17 01:40:27 +00:00
|
|
|
{
|
|
|
|
parse_menu_full(doc, node, data, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data,
|
|
|
|
gboolean newmenu)
|
2003-06-22 08:32:35 +00:00
|
|
|
{
|
|
|
|
Action *act;
|
|
|
|
xmlNodePtr nact;
|
|
|
|
|
2003-07-17 01:40:27 +00:00
|
|
|
gchar *id = NULL, *title = NULL, *label = NULL, *plugin;
|
|
|
|
ObMenu *menu = NULL, *parent;
|
2003-06-22 08:32:35 +00:00
|
|
|
|
2003-07-17 01:40:27 +00:00
|
|
|
if (newmenu == TRUE) {
|
2003-07-23 01:45:44 +00:00
|
|
|
if (!parse_attr_string("id", node, &id))
|
2003-07-17 01:40:27 +00:00
|
|
|
goto parse_menu_fail;
|
2003-07-23 01:45:44 +00:00
|
|
|
if (!parse_attr_string("label", node, &title))
|
2003-07-17 01:40:27 +00:00
|
|
|
goto parse_menu_fail;
|
|
|
|
g_message("menu label %s", title);
|
2003-06-22 08:32:35 +00:00
|
|
|
|
2003-07-23 01:45:44 +00:00
|
|
|
if (parse_attr_string("plugin", node, &plugin)) {
|
2003-07-23 03:58:50 +00:00
|
|
|
PluginMenuCreateData data;
|
|
|
|
data.doc = doc;
|
|
|
|
data.node = node;
|
|
|
|
data.parent = menu;
|
2003-07-23 01:45:44 +00:00
|
|
|
parent = plugin_create(plugin, &data);
|
|
|
|
g_free(plugin);
|
|
|
|
} else
|
|
|
|
menu = menu_new(title, id, data ? *((ObMenu**)data) : NULL);
|
|
|
|
|
2003-07-17 01:40:27 +00:00
|
|
|
if (data)
|
|
|
|
*((ObMenu**)data) = menu;
|
|
|
|
} else {
|
|
|
|
menu = (ObMenu *)data;
|
|
|
|
}
|
2003-07-23 01:45:44 +00:00
|
|
|
|
|
|
|
node = node->xmlChildrenNode;
|
2003-07-17 01:40:27 +00:00
|
|
|
|
2003-06-22 08:32:35 +00:00
|
|
|
while (node) {
|
|
|
|
if (!xmlStrcasecmp(node->name, (const xmlChar*) "menu")) {
|
2003-07-17 01:40:27 +00:00
|
|
|
if (parse_attr_string("plugin", node, &plugin)) {
|
2003-07-22 16:41:08 +00:00
|
|
|
PluginMenuCreateData data;
|
|
|
|
data.doc = doc;
|
|
|
|
data.node = node;
|
|
|
|
data.parent = menu;
|
2003-07-17 01:40:27 +00:00
|
|
|
parent = plugin_create(plugin, &data);
|
2003-07-19 23:58:45 +00:00
|
|
|
g_free(plugin);
|
2003-07-17 01:40:27 +00:00
|
|
|
} else {
|
|
|
|
parent = menu;
|
2003-07-23 01:45:44 +00:00
|
|
|
parse_menu(doc, node, &parent);
|
2003-07-17 01:40:27 +00:00
|
|
|
menu_add_entry(menu, menu_entry_new_submenu(parent->label,
|
|
|
|
parent));
|
|
|
|
}
|
|
|
|
|
2003-06-22 08:32:35 +00:00
|
|
|
}
|
|
|
|
else if (!xmlStrcasecmp(node->name, (const xmlChar*) "item")) {
|
|
|
|
if (parse_attr_string("label", node, &label)) {
|
|
|
|
if ((nact = parse_find_node("action", node->xmlChildrenNode)))
|
|
|
|
act = action_parse(doc, nact);
|
|
|
|
else
|
|
|
|
act = NULL;
|
|
|
|
if (act)
|
|
|
|
menu_add_entry(menu, menu_entry_new(label, act));
|
|
|
|
else
|
|
|
|
menu_add_entry(menu, menu_entry_new_separator(label));
|
|
|
|
g_free(label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_menu_fail:
|
|
|
|
g_free(id);
|
|
|
|
g_free(title);
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_control_show(ObMenu *self, int x, int y, ObClient *client);
|
2003-04-22 03:48:34 +00:00
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_destroy_hash_key(ObMenu *menu)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-05-21 23:58:40 +00:00
|
|
|
g_free(menu);
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_destroy_hash_value(ObMenu *self)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
|
|
|
GList *it;
|
|
|
|
|
2003-04-16 04:16:24 +00:00
|
|
|
for (it = self->entries; it; it = it->next)
|
|
|
|
menu_entry_free(it->data);
|
|
|
|
g_list_free(self->entries);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-04-16 04:16:24 +00:00
|
|
|
g_free(self->label);
|
|
|
|
g_free(self->name);
|
|
|
|
|
2003-05-16 18:10:10 +00:00
|
|
|
g_hash_table_remove(window_map, &self->title);
|
|
|
|
g_hash_table_remove(window_map, &self->frame);
|
|
|
|
g_hash_table_remove(window_map, &self->items);
|
2003-04-16 04:16:24 +00:00
|
|
|
|
2003-05-11 19:50:30 +00:00
|
|
|
stacking_remove(self);
|
|
|
|
|
2003-06-21 00:42:47 +00:00
|
|
|
RrAppearanceFree(self->a_title);
|
2003-07-19 23:58:45 +00:00
|
|
|
RrAppearanceFree(self->a_items);
|
2003-04-16 05:36:51 +00:00
|
|
|
XDestroyWindow(ob_display, self->title);
|
|
|
|
XDestroyWindow(ob_display, self->frame);
|
|
|
|
XDestroyWindow(ob_display, self->items);
|
2003-04-16 04:16:24 +00:00
|
|
|
|
|
|
|
g_free(self);
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_entry_free(ObMenuEntry *self)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-04-16 04:16:24 +00:00
|
|
|
g_free(self->label);
|
|
|
|
action_free(self->action);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-05-16 18:10:10 +00:00
|
|
|
g_hash_table_remove(window_map, &self->item);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-06-21 00:42:47 +00:00
|
|
|
RrAppearanceFree(self->a_item);
|
|
|
|
RrAppearanceFree(self->a_disabled);
|
|
|
|
RrAppearanceFree(self->a_hilite);
|
2003-04-16 05:36:51 +00:00
|
|
|
XDestroyWindow(ob_display, self->item);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-04-16 04:16:24 +00:00
|
|
|
g_free(self);
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void menu_startup()
|
|
|
|
{
|
2003-06-21 02:14:53 +00:00
|
|
|
/*
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenu *m;
|
|
|
|
ObMenu *s;
|
|
|
|
ObMenu *t;
|
2003-04-16 18:09:11 +00:00
|
|
|
Action *a;
|
2003-06-22 08:32:35 +00:00
|
|
|
*/
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-04-14 21:26:01 +00:00
|
|
|
menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
|
2003-06-21 02:24:18 +00:00
|
|
|
(GDestroyNotify)menu_destroy_hash_key,
|
2003-04-16 04:16:24 +00:00
|
|
|
(GDestroyNotify)menu_destroy_hash_value);
|
|
|
|
|
2003-06-22 08:32:35 +00:00
|
|
|
parse_register("menu", parse_menu, NULL);
|
|
|
|
|
|
|
|
/*
|
2003-05-21 23:58:40 +00:00
|
|
|
m = menu_new("sex menu", "root", NULL);
|
2003-05-09 23:15:28 +00:00
|
|
|
|
2003-04-16 18:09:11 +00:00
|
|
|
a = action_from_string("execute");
|
|
|
|
a->data.execute.path = g_strdup("xterm");
|
|
|
|
menu_add_entry(m, menu_entry_new("xterm", a));
|
|
|
|
a = action_from_string("restart");
|
|
|
|
menu_add_entry(m, menu_entry_new("restart", a));
|
2003-05-09 23:15:28 +00:00
|
|
|
menu_add_entry(m, menu_entry_new_separator("--"));
|
2003-04-16 18:09:11 +00:00
|
|
|
a = action_from_string("exit");
|
|
|
|
menu_add_entry(m, menu_entry_new("exit", a));
|
2003-06-22 08:32:35 +00:00
|
|
|
*/
|
2003-05-21 23:58:40 +00:00
|
|
|
|
|
|
|
/*
|
2003-05-09 23:15:28 +00:00
|
|
|
s = menu_new("subsex menu", "submenu", m);
|
|
|
|
a = action_from_string("execute");
|
|
|
|
a->data.execute.path = g_strdup("xclock");
|
|
|
|
menu_add_entry(s, menu_entry_new("xclock", a));
|
|
|
|
|
|
|
|
menu_add_entry(m, menu_entry_new_submenu("subz", s));
|
|
|
|
|
|
|
|
s = menu_new("empty", "chub", m);
|
|
|
|
menu_add_entry(m, menu_entry_new_submenu("empty", s));
|
|
|
|
|
|
|
|
s = menu_new("", "s-club", m);
|
|
|
|
menu_add_entry(m, menu_entry_new_submenu("empty", s));
|
|
|
|
|
|
|
|
s = menu_new(NULL, "h-club", m);
|
|
|
|
menu_add_entry(m, menu_entry_new_submenu("empty", s));
|
|
|
|
|
|
|
|
s = menu_new(NULL, "g-club", m);
|
|
|
|
|
|
|
|
a = action_from_string("execute");
|
|
|
|
a->data.execute.path = g_strdup("xterm");
|
|
|
|
menu_add_entry(s, menu_entry_new("xterm", a));
|
|
|
|
a = action_from_string("restart");
|
|
|
|
menu_add_entry(s, menu_entry_new("restart", a));
|
|
|
|
menu_add_entry(s, menu_entry_new_separator("--"));
|
|
|
|
a = action_from_string("exit");
|
|
|
|
menu_add_entry(s, menu_entry_new("exit", a));
|
|
|
|
|
|
|
|
menu_add_entry(m, menu_entry_new_submenu("long", s));
|
2003-05-21 23:58:40 +00:00
|
|
|
*/
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void menu_shutdown()
|
|
|
|
{
|
|
|
|
g_hash_table_destroy(menu_hash);
|
|
|
|
}
|
|
|
|
|
2003-04-15 18:29:55 +00:00
|
|
|
static Window createWindow(Window parent, unsigned long mask,
|
|
|
|
XSetWindowAttributes *attrib)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-04-15 18:29:55 +00:00
|
|
|
return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
|
2003-06-21 00:42:47 +00:00
|
|
|
RrDepth(ob_rr_inst), InputOutput,
|
|
|
|
RrVisual(ob_rr_inst), mask, attrib);
|
2003-04-15 18:29:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
|
2003-04-22 03:48:34 +00:00
|
|
|
menu_controller_show show, menu_controller_update update)
|
2003-04-15 18:29:55 +00:00
|
|
|
{
|
|
|
|
XSetWindowAttributes attrib;
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenu *self;
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
self = g_new0(ObMenu, 1);
|
2003-05-11 19:44:33 +00:00
|
|
|
self->obwin.type = Window_Menu;
|
2003-04-15 18:29:55 +00:00
|
|
|
self->label = g_strdup(label);
|
|
|
|
self->name = g_strdup(name);
|
|
|
|
self->parent = parent;
|
2003-05-09 23:15:28 +00:00
|
|
|
self->open_submenu = NULL;
|
2003-04-15 18:29:55 +00:00
|
|
|
|
|
|
|
self->entries = NULL;
|
|
|
|
self->shown = FALSE;
|
2003-05-09 23:15:28 +00:00
|
|
|
self->invalid = TRUE;
|
|
|
|
|
|
|
|
/* default controllers */
|
2003-04-22 03:48:34 +00:00
|
|
|
self->show = show;
|
|
|
|
self->hide = NULL;
|
|
|
|
self->update = update;
|
|
|
|
self->mouseover = NULL;
|
|
|
|
self->selected = NULL;
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
self->plugin = NULL;
|
|
|
|
self->plugin_data = NULL;
|
|
|
|
|
2003-04-15 18:29:55 +00:00
|
|
|
attrib.override_redirect = TRUE;
|
2003-04-16 18:09:11 +00:00
|
|
|
attrib.event_mask = FRAME_EVENTMASK;
|
2003-07-10 19:01:41 +00:00
|
|
|
self->frame = createWindow(RootWindow(ob_display, ob_screen),
|
2003-06-22 08:32:35 +00:00
|
|
|
CWOverrideRedirect|CWEventMask, &attrib);
|
2003-04-16 04:16:24 +00:00
|
|
|
attrib.event_mask = TITLE_EVENTMASK;
|
2003-04-16 05:36:51 +00:00
|
|
|
self->title = createWindow(self->frame, CWEventMask, &attrib);
|
|
|
|
self->items = createWindow(self->frame, 0, &attrib);
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-06-22 08:32:35 +00:00
|
|
|
self->a_title = self->a_items = NULL;
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-04-16 05:36:51 +00:00
|
|
|
XMapWindow(ob_display, self->title);
|
|
|
|
XMapWindow(ob_display, self->items);
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-05-16 18:10:10 +00:00
|
|
|
g_hash_table_insert(window_map, &self->frame, self);
|
|
|
|
g_hash_table_insert(window_map, &self->title, self);
|
|
|
|
g_hash_table_insert(window_map, &self->items, self);
|
2003-04-15 18:29:55 +00:00
|
|
|
g_hash_table_insert(menu_hash, g_strdup(name), self);
|
2003-05-11 19:50:30 +00:00
|
|
|
|
2003-05-16 15:16:33 +00:00
|
|
|
stacking_add(MENU_AS_WINDOW(self));
|
2003-05-11 23:31:43 +00:00
|
|
|
stacking_raise(MENU_AS_WINDOW(self));
|
2003-05-11 19:50:30 +00:00
|
|
|
|
2003-04-15 18:29:55 +00:00
|
|
|
return self;
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
2003-04-15 18:29:55 +00:00
|
|
|
void menu_free(char *name)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
|
|
|
g_hash_table_remove(menu_hash, name);
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *menu_entry_new_full(char *label, Action *action,
|
|
|
|
ObMenuEntryRenderType render_type,
|
2003-04-15 18:29:55 +00:00
|
|
|
gpointer submenu)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *menu_entry = g_new0(ObMenuEntry, 1);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
|
|
|
menu_entry->label = g_strdup(label);
|
|
|
|
menu_entry->render_type = render_type;
|
2003-04-15 18:29:55 +00:00
|
|
|
menu_entry->action = action;
|
2003-04-14 21:26:01 +00:00
|
|
|
|
2003-04-16 05:36:51 +00:00
|
|
|
menu_entry->hilite = FALSE;
|
|
|
|
menu_entry->enabled = TRUE;
|
|
|
|
|
2003-04-14 21:26:01 +00:00
|
|
|
menu_entry->submenu = submenu;
|
|
|
|
|
|
|
|
return menu_entry;
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_entry_set_submenu(ObMenuEntry *entry, ObMenu *submenu)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-04-15 18:29:55 +00:00
|
|
|
g_assert(entry != NULL);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
|
|
|
entry->submenu = submenu;
|
|
|
|
|
|
|
|
if(entry->parent != NULL)
|
|
|
|
entry->parent->invalid = TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_add_entry(ObMenu *menu, ObMenuEntry *entry)
|
2003-04-14 21:26:01 +00:00
|
|
|
{
|
2003-04-15 18:29:55 +00:00
|
|
|
XSetWindowAttributes attrib;
|
|
|
|
|
2003-05-10 15:12:27 +00:00
|
|
|
g_assert(menu != NULL);
|
|
|
|
g_assert(entry != NULL);
|
|
|
|
g_assert(entry->item == None);
|
2003-04-14 21:26:01 +00:00
|
|
|
|
|
|
|
menu->entries = g_list_append(menu->entries, entry);
|
|
|
|
entry->parent = menu;
|
|
|
|
|
2003-04-16 05:36:51 +00:00
|
|
|
attrib.event_mask = ENTRY_EVENTMASK;
|
|
|
|
entry->item = createWindow(menu->items, CWEventMask, &attrib);
|
|
|
|
XMapWindow(ob_display, entry->item);
|
2003-06-22 08:32:35 +00:00
|
|
|
|
|
|
|
entry->a_item = entry->a_disabled = entry->a_hilite = NULL;
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-04-14 21:26:01 +00:00
|
|
|
menu->invalid = TRUE;
|
2003-04-16 04:16:24 +00:00
|
|
|
|
2003-05-16 18:10:10 +00:00
|
|
|
g_hash_table_insert(window_map, &entry->item, menu);
|
2003-04-14 21:26:01 +00:00
|
|
|
}
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-07-10 06:38:42 +00:00
|
|
|
void menu_show(char *name, int x, int y, ObClient *client)
|
2003-04-15 18:29:55 +00:00
|
|
|
{
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenu *self;
|
2003-05-09 23:15:28 +00:00
|
|
|
|
2003-04-15 18:29:55 +00:00
|
|
|
self = g_hash_table_lookup(menu_hash, name);
|
|
|
|
if (!self) {
|
|
|
|
g_warning("Attempted to show menu '%s' but it does not exist.",
|
|
|
|
name);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-22 08:32:35 +00:00
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
menu_show_full(self, x, y, client);
|
|
|
|
}
|
2003-04-16 05:36:51 +00:00
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_show_full(ObMenu *self, int x, int y, ObClient *client)
|
2003-05-09 23:15:28 +00:00
|
|
|
{
|
|
|
|
g_assert(self != NULL);
|
|
|
|
|
|
|
|
menu_render(self);
|
2003-04-22 03:48:34 +00:00
|
|
|
|
2003-04-22 01:04:29 +00:00
|
|
|
self->client = client;
|
2003-04-15 18:29:55 +00:00
|
|
|
|
2003-06-25 18:43:42 +00:00
|
|
|
if (!self->shown) {
|
2003-07-21 23:19:03 +00:00
|
|
|
if (!(self->parent && self->parent->shown)) {
|
2003-06-25 18:43:42 +00:00
|
|
|
grab_pointer(TRUE, None);
|
|
|
|
grab_keyboard(TRUE);
|
|
|
|
}
|
2003-07-21 23:19:03 +00:00
|
|
|
menu_visible = g_list_append(menu_visible, self);
|
2003-06-25 18:43:42 +00:00
|
|
|
}
|
|
|
|
|
2003-04-22 03:48:34 +00:00
|
|
|
if (self->show) {
|
2003-05-09 23:15:28 +00:00
|
|
|
self->show(self, x, y, client);
|
2003-04-22 03:48:34 +00:00
|
|
|
} else {
|
|
|
|
menu_control_show(self, x, y, client);
|
2003-04-16 18:09:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_hide(ObMenu *self) {
|
2003-04-16 18:09:11 +00:00
|
|
|
if (self->shown) {
|
|
|
|
XUnmapWindow(ob_display, self->frame);
|
|
|
|
self->shown = FALSE;
|
2003-05-09 23:15:28 +00:00
|
|
|
if (self->open_submenu)
|
|
|
|
menu_hide(self->open_submenu);
|
2003-07-23 03:58:50 +00:00
|
|
|
if (self->parent && self->parent->open_submenu == self) {
|
|
|
|
ObMenuEntry *e;
|
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
self->parent->open_submenu = NULL;
|
|
|
|
|
2003-07-23 03:58:50 +00:00
|
|
|
e = menu_find_entry_by_submenu(self->parent, self);
|
|
|
|
if (self->parent->mouseover)
|
|
|
|
self->parent->mouseover(e, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(e, FALSE);
|
|
|
|
menu_entry_render(e);
|
|
|
|
}
|
|
|
|
|
2003-07-21 23:19:03 +00:00
|
|
|
if (!(self->parent && self->parent->shown)) {
|
2003-06-25 18:43:42 +00:00
|
|
|
grab_keyboard(FALSE);
|
|
|
|
grab_pointer(FALSE, None);
|
|
|
|
}
|
2003-07-21 23:19:03 +00:00
|
|
|
menu_visible = g_list_remove(menu_visible, self);
|
2003-04-16 18:09:11 +00:00
|
|
|
}
|
2003-04-16 05:36:51 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_clear(ObMenu *self) {
|
2003-05-10 14:51:27 +00:00
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = self->entries; it; it = it->next) {
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *entry = it->data;
|
2003-05-10 14:51:27 +00:00
|
|
|
menu_entry_free(entry);
|
|
|
|
}
|
|
|
|
self->entries = NULL;
|
2003-05-14 03:34:29 +00:00
|
|
|
self->invalid = TRUE;
|
2003-05-10 14:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *menu_find_entry(ObMenu *menu, Window win)
|
2003-04-16 05:36:51 +00:00
|
|
|
{
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = menu->entries; it; it = it->next) {
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *entry = it->data;
|
2003-04-16 05:36:51 +00:00
|
|
|
if (entry->item == win)
|
|
|
|
return entry;
|
2003-04-15 18:29:55 +00:00
|
|
|
}
|
2003-04-16 05:36:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-07-22 16:41:08 +00:00
|
|
|
ObMenuEntry *menu_find_entry_by_submenu(ObMenu *menu, ObMenu *submenu)
|
|
|
|
{
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = menu->entries; it; it = it->next) {
|
|
|
|
ObMenuEntry *entry = it->data;
|
|
|
|
if (entry->submenu == submenu)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenuEntry *menu_find_entry_by_pos(ObMenu *menu, int x, int y)
|
2003-06-25 18:43:42 +00:00
|
|
|
{
|
|
|
|
if (x < 0 || x >= menu->size.width || y < 0 || y >= menu->size.height)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
y -= menu->title_h + ob_rr_theme->bwidth;
|
|
|
|
if (y < 0) return NULL;
|
|
|
|
|
|
|
|
g_message ("%d %p", y/menu->item_h, g_list_nth_data(menu->entries, y / menu->item_h));
|
|
|
|
return g_list_nth_data(menu->entries, y / menu->item_h);
|
|
|
|
}
|
|
|
|
|
2003-07-10 19:27:12 +00:00
|
|
|
void menu_entry_fire(ObMenuEntry *self)
|
2003-04-16 18:09:11 +00:00
|
|
|
{
|
2003-07-10 19:27:12 +00:00
|
|
|
ObMenu *m;
|
2003-04-16 18:09:11 +00:00
|
|
|
|
|
|
|
if (self->action) {
|
|
|
|
self->action->data.any.c = self->parent->client;
|
|
|
|
self->action->func(&self->action->data);
|
|
|
|
|
|
|
|
/* hide the whole thing */
|
|
|
|
m = self->parent;
|
|
|
|
while (m->parent) m = m->parent;
|
|
|
|
menu_hide(m);
|
|
|
|
}
|
|
|
|
}
|
2003-04-22 03:48:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Default menu controller action for showing.
|
|
|
|
*/
|
|
|
|
|
2003-07-21 23:19:03 +00:00
|
|
|
void menu_control_show(ObMenu *self, int x, int y, ObClient *client)
|
|
|
|
{
|
2003-06-27 04:20:30 +00:00
|
|
|
guint i;
|
|
|
|
Rect *a = NULL;
|
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
g_assert(!self->invalid);
|
|
|
|
|
2003-07-10 05:44:23 +00:00
|
|
|
for (i = 0; i < screen_num_monitors; ++i) {
|
|
|
|
a = screen_physical_area_monitor(i);
|
2003-06-27 04:20:30 +00:00
|
|
|
if (RECT_CONTAINS(*a, x, y))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_assert(a != NULL);
|
|
|
|
self->xin_area = i;
|
|
|
|
|
|
|
|
POINT_SET(self->location,
|
|
|
|
MIN(x, a->x + a->width - 1 - self->size.width),
|
|
|
|
MIN(y, a->y + a->height - 1 - self->size.height));
|
2003-06-25 18:43:42 +00:00
|
|
|
XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
|
2003-05-09 23:15:28 +00:00
|
|
|
|
|
|
|
if (!self->shown) {
|
|
|
|
XMapWindow(ob_display, self->frame);
|
2003-05-11 19:50:30 +00:00
|
|
|
stacking_raise(MENU_AS_WINDOW(self));
|
2003-05-09 23:15:28 +00:00
|
|
|
self->shown = TRUE;
|
|
|
|
} else if (self->shown && self->open_submenu) {
|
|
|
|
menu_hide(self->open_submenu);
|
|
|
|
}
|
|
|
|
}
|
2003-04-22 03:48:34 +00:00
|
|
|
|
2003-07-21 23:19:03 +00:00
|
|
|
void menu_control_mouseover(ObMenuEntry *self, gboolean enter)
|
|
|
|
{
|
2003-05-09 23:15:28 +00:00
|
|
|
int x;
|
2003-06-27 04:20:30 +00:00
|
|
|
Rect *a;
|
2003-07-22 16:41:08 +00:00
|
|
|
ObMenuEntry *e;
|
2003-06-27 04:20:30 +00:00
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
if (enter) {
|
|
|
|
if (self->parent->open_submenu && self->submenu
|
|
|
|
!= self->parent->open_submenu)
|
2003-07-22 16:41:08 +00:00
|
|
|
{
|
|
|
|
e = menu_find_entry_by_submenu(self->parent,
|
|
|
|
self->parent->open_submenu);
|
|
|
|
e->hilite = FALSE;
|
|
|
|
menu_entry_render(e);
|
2003-05-09 23:15:28 +00:00
|
|
|
menu_hide(self->parent->open_submenu);
|
2003-07-22 16:41:08 +00:00
|
|
|
}
|
2003-05-09 23:15:28 +00:00
|
|
|
|
2003-06-29 01:44:31 +00:00
|
|
|
if (self->submenu && self->parent->open_submenu != self->submenu) {
|
2003-05-09 23:15:28 +00:00
|
|
|
self->parent->open_submenu = self->submenu;
|
|
|
|
|
|
|
|
/* shouldn't be invalid since it must be displayed */
|
|
|
|
g_assert(!self->parent->invalid);
|
|
|
|
/* TODO: I don't understand why these bevels should be here.
|
|
|
|
Something must be wrong in the width calculation */
|
|
|
|
x = self->parent->location.x + self->parent->size.width +
|
2003-07-22 16:14:42 +00:00
|
|
|
ob_rr_theme->bwidth - ob_rr_theme->menu_overlap;
|
2003-05-09 23:15:28 +00:00
|
|
|
|
|
|
|
/* need to get the width. is this bad?*/
|
|
|
|
menu_render(self->submenu);
|
|
|
|
|
2003-07-10 05:44:23 +00:00
|
|
|
a = screen_physical_area_monitor(self->parent->xin_area);
|
2003-06-27 04:20:30 +00:00
|
|
|
|
|
|
|
if (self->submenu->size.width + x >= a->x + a->width)
|
2003-05-09 23:15:28 +00:00
|
|
|
x = self->parent->location.x - self->submenu->size.width -
|
2003-07-22 16:14:42 +00:00
|
|
|
ob_rr_theme->bwidth + ob_rr_theme->menu_overlap;
|
2003-05-09 23:15:28 +00:00
|
|
|
|
|
|
|
menu_show_full(self->submenu, x,
|
2003-05-21 23:58:40 +00:00
|
|
|
self->parent->location.y + self->y,
|
|
|
|
self->parent->client);
|
2003-05-09 23:15:28 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-22 16:41:08 +00:00
|
|
|
|
|
|
|
if (enter || !self->submenu ||
|
|
|
|
menu_find_entry_by_submenu(self->parent,
|
|
|
|
self->parent->open_submenu) != self)
|
|
|
|
self->hilite = enter;
|
2003-04-22 03:48:34 +00:00
|
|
|
}
|
2003-07-21 23:19:03 +00:00
|
|
|
|
|
|
|
ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
|
|
|
|
{
|
|
|
|
GList *it = NULL;
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case OB_KEY_DOWN: {
|
|
|
|
if (over != NULL) {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, FALSE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
|
|
|
|
it = over->parent->entries;
|
|
|
|
while (it != NULL && it->data != over)
|
|
|
|
it = it->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it && it->next)
|
|
|
|
over = (ObMenuEntry *)it->next->data;
|
|
|
|
else if (over == NULL) {
|
|
|
|
if (menu_visible && ((ObMenu *)menu_visible->data)->entries)
|
|
|
|
over = (ObMenuEntry *)
|
|
|
|
(((ObMenu *)menu_visible->data)->entries)->data;
|
|
|
|
else
|
|
|
|
over = NULL;
|
|
|
|
} else {
|
|
|
|
over = (over->parent->entries != NULL ?
|
|
|
|
over->parent->entries->data : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (over) {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, TRUE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, TRUE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_KEY_UP: {
|
|
|
|
if (over != NULL) {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, FALSE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
|
|
|
|
it = g_list_last(over->parent->entries);
|
|
|
|
while (it != NULL && it->data != over)
|
|
|
|
it = it->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it && it->prev)
|
|
|
|
over = (ObMenuEntry *)it->prev->data;
|
|
|
|
else if (over == NULL) {
|
|
|
|
it = g_list_last(menu_visible);
|
|
|
|
if (it != NULL) {
|
|
|
|
it = g_list_last(((ObMenu *)it->data)->entries);
|
|
|
|
over = (ObMenuEntry *)(it != NULL ? it->data : NULL);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
over = (over->parent->entries != NULL ?
|
|
|
|
g_list_last(over->parent->entries)->data :
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, TRUE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, TRUE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_KEY_RETURN: {
|
|
|
|
if (over == NULL)
|
|
|
|
return over;
|
|
|
|
|
|
|
|
if (over->submenu) {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, FALSE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
|
|
|
|
if (over->submenu->entries)
|
|
|
|
over = over->submenu->entries->data;
|
|
|
|
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, TRUE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, TRUE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, FALSE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
|
|
|
|
menu_entry_fire(over);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_KEY_ESCAPE: {
|
|
|
|
if (over != NULL) {
|
|
|
|
if (over->parent->mouseover)
|
|
|
|
over->parent->mouseover(over, FALSE);
|
|
|
|
else
|
|
|
|
menu_control_mouseover(over, FALSE);
|
|
|
|
menu_entry_render(over);
|
|
|
|
|
|
|
|
menu_hide(over->parent);
|
|
|
|
} else {
|
|
|
|
it = g_list_last(menu_visible);
|
|
|
|
if (it) {
|
|
|
|
menu_hide((ObMenu *)it->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
over = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_error("Unknown key");
|
|
|
|
}
|
|
|
|
|
|
|
|
return over;
|
|
|
|
}
|