X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fmenu.c;h=0c285cbf1b4e890975b78122e93e3a604b6f4f7d;hb=12af0aedf2da4f360954cfaaeaf77234b36e4858;hp=2e3fb30bdb13b81afc3f6aa3acadc66f6e77185b;hpb=3c92311b3c88e7da28aabe59d26c10a18c096399;p=chaz%2Fopenbox diff --git a/openbox/menu.c b/openbox/menu.c index 2e3fb30b..0c285cbf 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -4,10 +4,12 @@ #include "stacking.h" #include "client.h" #include "grab.h" +#include "config.h" #include "screen.h" #include "geom.h" #include "plugin.h" #include "misc.h" +#include "parser/parse.h" GHashTable *menu_hash = NULL; GList *menu_visible = NULL; @@ -18,20 +20,22 @@ GList *menu_visible = NULL; #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \ ButtonPressMask | ButtonReleaseMask) -static void parse_menu(xmlDocPtr doc, xmlNodePtr node, void *data) +static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, + gpointer data) { - parse_menu_full(doc, node, data, TRUE); + g_message("%s", __FUNCTION__); + parse_menu_full(i, doc, node, data, TRUE); } -void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, - gboolean newmenu) +void parse_menu_full(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, + gpointer data, gboolean newmenu) { - Action *act; + ObAction *act; xmlNodePtr nact; gchar *id = NULL, *title = NULL, *label = NULL, *plugin; - ObMenu *menu = NULL, *parent; + ObMenu *menu = NULL, *parent = NULL; if (newmenu == TRUE) { if (!parse_attr_string("id", node, &id)) @@ -42,15 +46,18 @@ void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, if (parse_attr_string("plugin", node, &plugin)) { PluginMenuCreateData data; + data.parse_inst = i; data.doc = doc; data.node = node; data.parent = menu; - parent = plugin_create(plugin, &data); + + if (plugin_open_reopen(plugin, i)) + menu = plugin_create(plugin, &data); g_free(plugin); } else menu = menu_new(title, id, data ? *((ObMenu**)data) : NULL); - if (data) + if (data && menu) *((ObMenu**)data) = menu; } else { menu = (ObMenu *)data; @@ -65,14 +72,17 @@ void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, data.doc = doc; data.node = node; data.parent = menu; - parent = plugin_create(plugin, &data); + if (plugin_open_reopen(plugin, i)) + parent = plugin_create(plugin, &data); g_free(plugin); } else { parent = menu; - parse_menu(doc, node, &parent); + parse_menu(i, doc, node, &parent); + } + + if (parent) menu_add_entry(menu, menu_entry_new_submenu(parent->label, parent)); - } } else if (!xmlStrcasecmp(node->name, (const xmlChar*) "item")) { @@ -107,6 +117,8 @@ void menu_destroy_hash_value(ObMenu *self) { GList *it; + if (self->destroy) self->destroy(self); + for (it = self->entries; it; it = it->next) menu_entry_free(it->data); g_list_free(self->entries); @@ -139,19 +151,17 @@ void menu_entry_free(ObMenuEntry *self) RrAppearanceFree(self->a_item); RrAppearanceFree(self->a_disabled); RrAppearanceFree(self->a_hilite); + RrAppearanceFree(self->a_submenu); XDestroyWindow(ob_display, self->item); - + XDestroyWindow(ob_display, self->submenu_pic); g_free(self); } - -void menu_startup() + +void menu_startup(ObParseInst *i) { menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify)menu_destroy_hash_key, (GDestroyNotify)menu_destroy_hash_value); - - parse_register("menu", parse_menu, NULL); - } void menu_shutdown() @@ -159,6 +169,43 @@ void menu_shutdown() g_hash_table_destroy(menu_hash); } +void menu_parse() +{ + ObParseInst *i; + xmlDocPtr doc; + xmlNodePtr node; + gchar *p; + gboolean loaded = FALSE; + + i = parse_startup(); + + if (config_menu_path) + if (!(loaded = + parse_load(config_menu_path, "openbox_menu", &doc, &node))) + g_warning("Failed to load menu from '%s'", config_menu_path); + if (!loaded) { + p = g_build_filename(g_get_home_dir(), ".openbox", "menu", NULL); + if (!(loaded = + parse_load(p, "openbox_menu", &doc, &node))) + g_warning("Failed to load menu from '%s'", p); + g_free(p); + } + if (!loaded) { + p = g_build_filename(RCDIR, "menu", NULL); + if (!(loaded = + parse_load(p, "openbox_menu", &doc, &node))) + g_warning("Failed to load menu from '%s'", p); + g_free(p); + } + + if (loaded) { + parse_register(i, "menu", parse_menu, NULL); + parse_tree(i, doc, node->xmlChildrenNode); + } + + parse_shutdown(i); +} + static Window createWindow(Window parent, unsigned long mask, XSetWindowAttributes *attrib) { @@ -172,7 +219,8 @@ ObMenu *menu_new_full(char *label, char *name, ObMenu *parent, menu_controller_show show, menu_controller_update update, menu_controller_selected selected, menu_controller_hide hide, - menu_controller_mouseover mouseover) + menu_controller_mouseover mouseover, + menu_controller_destroy destroy) { XSetWindowAttributes attrib; ObMenu *self; @@ -190,6 +238,7 @@ ObMenu *menu_new_full(char *label, char *name, ObMenu *parent, self->invalid = TRUE; /* default controllers */ + self->destroy = destroy; self->show = (show != NULL ? show : menu_show_full); self->hide = (hide != NULL ? hide : menu_hide); self->update = (update != NULL ? update : menu_render); @@ -229,7 +278,7 @@ void menu_free(char *name) g_hash_table_remove(menu_hash, name); } -ObMenuEntry *menu_entry_new_full(char *label, Action *action, +ObMenuEntry *menu_entry_new_full(char *label, ObAction *action, ObMenuEntryRenderType render_type, gpointer submenu) { @@ -270,13 +319,17 @@ void menu_add_entry(ObMenu *menu, ObMenuEntry *entry) attrib.event_mask = ENTRY_EVENTMASK; entry->item = createWindow(menu->items, CWEventMask, &attrib); + entry->submenu_pic = createWindow(menu->items, CWEventMask, &attrib); XMapWindow(ob_display, entry->item); + XMapWindow(ob_display, entry->submenu_pic); - entry->a_item = entry->a_disabled = entry->a_hilite = NULL; + entry->a_item = entry->a_disabled = entry->a_hilite = entry->a_submenu + = NULL; menu->invalid = TRUE; g_hash_table_insert(window_map, &entry->item, menu); + g_hash_table_insert(window_map, &entry->submenu_pic, menu); } void menu_show(char *name, int x, int y, ObClient *client) @@ -297,7 +350,7 @@ void menu_show_full(ObMenu *self, int x, int y, ObClient *client) { g_assert(self != NULL); - menu_render(self); + self->update(self); self->client = client; @@ -317,9 +370,8 @@ void menu_hide(ObMenu *self) { XUnmapWindow(ob_display, self->frame); self->shown = FALSE; if (self->open_submenu) - menu_hide(self->open_submenu); + self->open_submenu->hide(self->open_submenu); if (self->parent && self->parent->open_submenu == self) { - self->over = NULL; self->parent->open_submenu = NULL; } @@ -328,6 +380,11 @@ void menu_hide(ObMenu *self) { grab_pointer(FALSE, None); } menu_visible = g_list_remove(menu_visible, self); + if (self->over) { + ((ObMenuEntry *)self->over->data)->hilite = FALSE; + menu_entry_render(self->over->data); + self->over = NULL; + } } } @@ -385,7 +442,8 @@ void menu_entry_fire(ObMenuEntry *self, unsigned int button, unsigned int x, { ObMenu *m; - if (button > 3) return; + /* ignore wheel scrolling */ + if (button == 4 || button == 5) return; if (self->action) { self->action->data.any.c = self->parent->client; @@ -394,7 +452,7 @@ void menu_entry_fire(ObMenuEntry *self, unsigned int button, unsigned int x, /* hide the whole thing */ m = self->parent; while (m->parent) m = m->parent; - menu_hide(m); + m->hide(m); } } @@ -427,7 +485,7 @@ void menu_control_show(ObMenu *self, int x, int y, ObClient *client) stacking_raise(MENU_AS_WINDOW(self)); self->shown = TRUE; } else if (self->shown && self->open_submenu) { - menu_hide(self->open_submenu); + self->open_submenu->hide(self->open_submenu); } } @@ -447,7 +505,7 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter) e = (ObMenuEntry *) self->parent->over->data; e->hilite = FALSE; menu_entry_render(e); - menu_hide(self->parent->open_submenu); + self->parent->open_submenu->hide(self->parent->open_submenu); } if (self->submenu && self->parent->open_submenu != self->submenu) { @@ -461,13 +519,25 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter) ob_rr_theme->bwidth - ob_rr_theme->menu_overlap; /* need to get the width. is this bad?*/ - menu_render(self->submenu); + self->submenu->update(self->submenu); a = screen_physical_area_monitor(self->parent->xin_area); - if (self->submenu->size.width + x >= a->x + a->width) - x = self->parent->location.x - self->submenu->size.width - - ob_rr_theme->bwidth + ob_rr_theme->menu_overlap; + if (self->submenu->size.width + x >= a->x + a->width) { + int newparentx = a->x + a->width + - self->submenu->size.width + - self->parent->size.width + - ob_rr_theme->bwidth + - ob_rr_theme->menu_overlap; + + x = a->x + a->width - self->submenu->size.width + - ob_rr_theme->menu_overlap; + XWarpPointer(ob_display, None, None, 0, 0, 0, 0, + newparentx - self->parent->location.x, 0); + + menu_show_full(self->parent, newparentx, + self->parent->location.y, self->parent->client); + } menu_show_full(self->submenu, x, self->parent->location.y + self->y, @@ -485,6 +555,7 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter) void menu_control_keyboard_nav(unsigned int key) { static ObMenu *current_menu = NULL; + ObMenuEntry *e = NULL; ObKey obkey = OB_NUM_KEYS; @@ -497,6 +568,9 @@ void menu_control_keyboard_nav(unsigned int key) obkey = OB_KEY_RIGHT; else if (key == ob_keycode(OB_KEY_LEFT)) /* users */ obkey = OB_KEY_LEFT; + else if (key == ob_keycode(OB_KEY_RETURN)) + obkey = OB_KEY_RETURN; + if (current_menu == NULL) current_menu = menu_visible->data; @@ -532,38 +606,46 @@ void menu_control_keyboard_nav(unsigned int key) break; } case OB_KEY_RIGHT: { - ObMenuEntry *e; if (current_menu->over == NULL) return; - e = (ObMenuEntry *)current_menu->over->data; if (e->submenu) { + current_menu->mouseover(e, TRUE); current_menu = e->submenu; current_menu->over = current_menu->entries; if (current_menu->over) current_menu->mouseover(current_menu->over->data, TRUE); - } else { - current_menu->mouseover(e, FALSE); - current_menu->over = NULL; - - /* zero is enter */ - menu_entry_fire(e, 0, 0, 0); } break; } - case OB_KEY_LEFT: { + + case OB_KEY_RETURN: { if (current_menu->over == NULL) return; - current_menu->mouseover(current_menu->over->data, FALSE); + e = (ObMenuEntry *)current_menu->over->data; + + current_menu->mouseover(e, FALSE); current_menu->over = NULL; + /* zero is enter */ + menu_entry_fire(e, 0, 0, 0); + } + + case OB_KEY_LEFT: { + if (current_menu->over != NULL) { + current_menu->mouseover(current_menu->over->data, FALSE); + current_menu->over = NULL; + } - menu_hide(current_menu); + current_menu->hide(current_menu); if (current_menu->parent) current_menu = current_menu->parent; break; } + default: + ((ObMenu *)menu_visible->data)->hide(menu_visible->data); + current_menu = NULL; } return; }