From 331990a4f24aec35c6212af874d70bcc9cace258 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 4 Jan 2010 16:25:13 -0500 Subject: Make the Focus action stop all interactive actions (Fixes bug #4436) Old < 3.4.8 Openbox versions would stop focus cycling when focus moved. Now that is not the case, but you should be able to stop it by Choosing a window explicitly still. --- openbox/actions/focus.c | 10 ++++++++++ openbox/focus_cycle.c | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'openbox') diff --git a/openbox/actions/focus.c b/openbox/actions/focus.c index 8da8ed5e..1b544910 100644 --- a/openbox/actions/focus.c +++ b/openbox/actions/focus.c @@ -6,6 +6,7 @@ typedef struct { gboolean here; + gboolean stop_int; } Options; static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); @@ -27,9 +28,12 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) Options *o; o = g_new0(Options, 1); + o->stop_int = TRUE; if ((n = parse_find_node("here", node))) o->here = parse_bool(doc, n); + if ((n = parse_find_node("stopInteractive", node))) + o->stop_int = parse_bool(doc, n); return o; } @@ -56,11 +60,17 @@ static gboolean run_func(ObActionsData *data, gpointer options) (data->context != OB_FRAME_CONTEXT_CLIENT && data->context != OB_FRAME_CONTEXT_FRAME)) { + if (o->stop_int) + actions_interactive_cancel_act(); + actions_client_move(data, TRUE); client_activate(data->client, TRUE, o->here, FALSE, FALSE, TRUE); actions_client_move(data, FALSE); } } else if (data->context == OB_FRAME_CONTEXT_DESKTOP) { + if (o->stop_int) + actions_interactive_cancel_act(); + /* focus action on the root window. make keybindings work for this openbox instance, but don't focus any specific client */ focus_nothing(); diff --git a/openbox/focus_cycle.c b/openbox/focus_cycle.c index 8d047497..c92b5a54 100644 --- a/openbox/focus_cycle.c +++ b/openbox/focus_cycle.c @@ -55,9 +55,10 @@ void focus_cycle_stop(ObClient *ifclient) { /* stop focus cycling if the given client is a valid focus target, and so the cycling is being disrupted */ - if (focus_cycle_target && ifclient && - (ifclient == focus_cycle_target || - focus_cycle_popup_is_showing(ifclient))) + if (focus_cycle_target && + ((ifclient && (ifclient == focus_cycle_target || + focus_cycle_popup_is_showing(ifclient))) || + !ifclient)) { focus_cycle(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,TRUE); focus_directional_cycle(0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE); -- cgit v1.2.3 From 775f60852a82930e870102a3b3b5a073c3ad6401 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 22 Dec 2009 09:31:24 -0500 Subject: Revert "A fix for delayed hiding of submenus." This reverts commit 1fb198410e9d3ca660d91d1049249db0f2f47732. --- openbox/event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'openbox') diff --git a/openbox/event.c b/openbox/event.c index bbe7038e..a0d26ab7 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -1838,7 +1838,8 @@ static gboolean event_handle_menu(XEvent *ev) break; if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) && - (f = find_active_menu()) && f->selected == e) + (f = find_active_menu()) && f->selected == e && + e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU) { ObMenuEntryFrame *u = menu_entry_frame_under(ev->xcrossing.x_root, ev->xcrossing.y_root); -- cgit v1.2.3 From 15802d87b18b8a7a741c2e8d80ab6e5f79ada13e Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 22 Dec 2009 09:31:38 -0500 Subject: Revert "Fix the delayed hiding of submenus, so that they don't end up hidden while the entry is selected" This reverts commit 8ada991d829671ab5e6dd4c5526b6a0238ba6a16. --- openbox/menuframe.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'openbox') diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 8177f513..3d2bf829 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -1161,8 +1161,6 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, } if (!entry && self->open_submenu) { - /* we moved out of the menu, so move the selection back to the open - submenu */ entry = self->open_submenu; oldchild = NULL; @@ -1180,16 +1178,12 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, /* there is an open submenu */ if (config_submenu_show_delay && !immediate) { - if (entry == self->open_submenu) { - /* we moved onto the entry that has an open submenu, so stop - trying to close the submenu */ + if (old == self->open_submenu) { + /* close the open submenu after a delay if we don't have + it selected */ ob_main_loop_timeout_remove (ob_main_loop, menu_entry_frame_submenu_hide_timeout); - } - else if (old == self->open_submenu) { - /* we just moved off the entry with an open submenu, so - close the open submenu after a delay */ ob_main_loop_timeout_add(ob_main_loop, config_submenu_show_delay * 1000, menu_entry_frame_submenu_hide_timeout, @@ -1204,7 +1198,7 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (self->selected) { menu_entry_frame_render(self->selected); - /* if we've selected a submenu and it wasn't already open, then + /* if we've selected a submenu and it wasn't always open, then show it */ if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU && self->selected != self->open_submenu) -- cgit v1.2.3 From e04522772694682ccd11fc465d861b169675312b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 22 Dec 2009 09:31:50 -0500 Subject: Revert "Don't hide submenus immediately when unselecting the parent's entry" This reverts commit 828c095c8b5a2df96a38faaeb8a0df504e68e70f. --- openbox/event.c | 7 +---- openbox/menuframe.c | 76 +++++++++-------------------------------------------- openbox/menuframe.h | 3 --- 3 files changed, 13 insertions(+), 73 deletions(-) (limited to 'openbox') diff --git a/openbox/event.c b/openbox/event.c index a0d26ab7..41f8eb16 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -1841,12 +1841,7 @@ static gboolean event_handle_menu(XEvent *ev) (f = find_active_menu()) && f->selected == e && e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU) { - ObMenuEntryFrame *u = menu_entry_frame_under(ev->xcrossing.x_root, - ev->xcrossing.y_root); - /* if we're just going from one entry in the menu to the next, - don't unselect stuff first */ - if (!u || e->frame != u->frame) - menu_frame_select(e->frame, NULL, FALSE); + menu_frame_select(e->frame, NULL, FALSE); } break; case MotionNotify: diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 3d2bf829..e0f58956 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -49,8 +49,7 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, ObMenuFrame *frame); static void menu_entry_frame_free(ObMenuEntryFrame *self); static void menu_frame_update(ObMenuFrame *self); -static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data); -static gboolean menu_entry_frame_submenu_show_timeout(gpointer data); +static gboolean menu_entry_frame_submenu_timeout(gpointer data); static void menu_frame_hide(ObMenuFrame *self); static Window createWindow(Window parent, gulong mask, @@ -96,7 +95,6 @@ ObMenuFrame* menu_frame_new(ObMenu *menu, guint show_from, ObClient *client) self->type = Window_Menu; self->menu = menu; self->selected = NULL; - self->open_submenu = NULL; self->client = client; self->direction_right = TRUE; self->show_from = show_from; @@ -986,7 +984,6 @@ gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, self->monitor = parent->monitor; self->parent = parent; self->parent_entry = parent_entry; - parent->open_submenu = parent_entry; /* set up parent's child to be us */ if (parent->child) @@ -1032,10 +1029,8 @@ static void menu_frame_hide(ObMenuFrame *self) if (self->child) menu_frame_hide(self->child); - if (self->parent && self->parent->child == self) { + if (self->parent) self->parent->child = NULL; - self->parent->open_submenu = NULL; - } self->parent = NULL; self->parent_entry = NULL; @@ -1061,10 +1056,7 @@ void menu_frame_hide_all(void) if (config_submenu_show_delay) { /* remove any submenu open requests */ ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_show_timeout); - /* remove any submenu close delays */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_hide_timeout); + menu_entry_frame_submenu_timeout); } if ((it = g_list_last(menu_frame_visible))) menu_frame_hide(it->data); @@ -1078,13 +1070,8 @@ void menu_frame_hide_all_client(ObClient *client) if (f->client == client) { if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove - (ob_main_loop, - menu_entry_frame_submenu_show_timeout); - /* remove any submenu close delays */ - ob_main_loop_timeout_remove - (ob_main_loop, - menu_entry_frame_submenu_hide_timeout); + ob_main_loop_timeout_remove(ob_main_loop, + menu_entry_frame_submenu_timeout); } menu_frame_hide(f); } @@ -1119,6 +1106,7 @@ ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y) for (it = frame->entries; it; it = g_list_next(it)) { ObMenuEntryFrame *e = it->data; + if (RECT_CONTAINS(e->area, x, y)) { ret = e; break; @@ -1128,15 +1116,7 @@ ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y) return ret; } -static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data) -{ - g_assert(menu_frame_visible); - g_assert(((ObMenuFrame*)data)->parent != NULL); - menu_frame_hide((ObMenuFrame*)data); - return FALSE; -} - -static gboolean menu_entry_frame_submenu_show_timeout(gpointer data) +static gboolean menu_entry_frame_submenu_timeout(gpointer data) { g_assert(menu_frame_visible); menu_entry_frame_show_submenu((ObMenuEntryFrame*)data); @@ -1157,57 +1137,25 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (config_submenu_show_delay) { /* remove any submenu open requests */ ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_show_timeout); - } - - if (!entry && self->open_submenu) { - entry = self->open_submenu; - oldchild = NULL; - - /* remove any submenu close delays */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_hide_timeout); + menu_entry_frame_submenu_timeout); } self->selected = entry; if (old) menu_entry_frame_render(old); - - if (oldchild) { - /* there is an open submenu */ - - if (config_submenu_show_delay && !immediate) { - if (old == self->open_submenu) { - /* close the open submenu after a delay if we don't have - it selected */ - ob_main_loop_timeout_remove - (ob_main_loop, - menu_entry_frame_submenu_hide_timeout); - ob_main_loop_timeout_add(ob_main_loop, - config_submenu_show_delay * 1000, - menu_entry_frame_submenu_hide_timeout, - self->child, g_direct_equal, - NULL); - } - } - else - menu_frame_hide(oldchild); - } + if (oldchild) + menu_frame_hide(oldchild); if (self->selected) { menu_entry_frame_render(self->selected); - /* if we've selected a submenu and it wasn't always open, then - show it */ - if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU && - self->selected != self->open_submenu) - { + if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { if (config_submenu_show_delay && !immediate) { /* initiate a new submenu open request */ ob_main_loop_timeout_add(ob_main_loop, config_submenu_show_delay * 1000, - menu_entry_frame_submenu_show_timeout, + menu_entry_frame_submenu_timeout, self->selected, g_direct_equal, NULL); } else { diff --git a/openbox/menuframe.h b/openbox/menuframe.h index 624c3f49..1b1dcc70 100644 --- a/openbox/menuframe.h +++ b/openbox/menuframe.h @@ -53,9 +53,6 @@ struct _ObMenuFrame GList *entries; ObMenuEntryFrame *selected; - /* if a submenu was selected, then this holds the entry for that submenu - until it is closed */ - ObMenuEntryFrame *open_submenu; /* show entries from the menu starting at this index */ guint show_from; -- cgit v1.2.3 From 8968b38338529cd0a7f2ad08a7c2e0d2e76b6e62 Mon Sep 17 00:00:00 2001 From: Alexey Korop Date: Mon, 4 Jan 2010 13:21:12 -0500 Subject: improve submenu hide delay --- openbox/config.c | 4 +++ openbox/config.h | 2 ++ openbox/menuframe.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++---- openbox/menuframe.h | 3 ++ 4 files changed, 97 insertions(+), 6 deletions(-) (limited to 'openbox') diff --git a/openbox/config.c b/openbox/config.c index 73302dfd..a6417646 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -91,6 +91,7 @@ gint config_mouse_screenedgetime; guint config_menu_hide_delay; gboolean config_menu_middle; guint config_submenu_show_delay; +guint config_submenu_hide_delay; gboolean config_menu_client_list_icons; gboolean config_menu_manage_desktops; @@ -812,6 +813,8 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, config_menu_middle = parse_bool(doc, n); if ((n = parse_find_node("submenuShowDelay", node))) config_submenu_show_delay = parse_int(doc, n); + if ((n = parse_find_node("submenuHideDelay", node))) + config_submenu_hide_delay = parse_int(doc, n); if ((n = parse_find_node("applicationIcons", node))) config_menu_client_list_icons = parse_bool(doc, n); if ((n = parse_find_node("manageDesktops", node))) @@ -1016,6 +1019,7 @@ void config_startup(ObParseInst *i) config_menu_hide_delay = 250; config_menu_middle = FALSE; config_submenu_show_delay = 0; + config_submenu_hide_delay = 750; config_menu_client_list_icons = TRUE; config_menu_manage_desktops = TRUE; config_menu_files = NULL; diff --git a/openbox/config.h b/openbox/config.h index 33fcd684..77139368 100644 --- a/openbox/config.h +++ b/openbox/config.h @@ -185,6 +185,8 @@ extern guint config_menu_hide_delay; extern gboolean config_menu_middle; /*! Delay before opening a submenu in milliseconds */ extern guint config_submenu_show_delay; +/*! Delay before closing a submenu in milliseconds */ +extern guint config_submenu_hide_delay; /*! Show icons in client_list_menu */ extern gboolean config_menu_client_list_icons; /*! Show manage desktops in client_list_menu */ diff --git a/openbox/menuframe.c b/openbox/menuframe.c index e0f58956..ff25100e 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -52,6 +52,8 @@ static void menu_frame_update(ObMenuFrame *self); static gboolean menu_entry_frame_submenu_timeout(gpointer data); static void menu_frame_hide(ObMenuFrame *self); +static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data); + static Window createWindow(Window parent, gulong mask, XSetWindowAttributes *attrib) { @@ -972,6 +974,14 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, return TRUE; } +static void remove_submenu_hide_timeout(ObMenuFrame *self /* parent of submenu to hide */) +{ + ob_main_loop_timeout_remove(ob_main_loop, + menu_entry_frame_submenu_hide_timeout); + if (self) + self->submenu_to_hide = NULL; +} + gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, ObMenuEntryFrame *parent_entry) { @@ -985,10 +995,14 @@ gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, self->parent = parent; self->parent_entry = parent_entry; + remove_submenu_hide_timeout(parent); + /* set up parent's child to be us */ - if (parent->child) - menu_frame_hide(parent->child); - parent->child = self; + if ((parent->child) != self) { + if (parent->child) + menu_frame_hide(parent->child); + parent->child = self; + } if (!menu_frame_show(self)) return FALSE; @@ -1020,6 +1034,8 @@ static void menu_frame_hide(ObMenuFrame *self) GList *it = g_list_find(menu_frame_visible, self); gulong ignore_start; + remove_submenu_hide_timeout(self->parent); + if (!it) return; @@ -1123,11 +1139,50 @@ static gboolean menu_entry_frame_submenu_timeout(gpointer data) return FALSE; } +static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data) +{ + menu_frame_hide((ObMenuFrame*)data); + return FALSE; +} + void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, gboolean immediate) { ObMenuEntryFrame *old = self->selected; ObMenuFrame *oldchild = self->child; + ObMenuEntryFrame *temp; + gboolean reselection; + + + if (!oldchild) { + /* self is the last visible (sub)menu */ + if (self->parent && self->parent_entry != self->parent->selected) { + /* Legend: + (config_submenu_hide_delay != 0) + In the parent menu corresponding entry "A" selected, + this submenu ('self') shown, cursor moved in the parent + menu to another entry "B", then cursor moved for the + first time into this submenu. + Results: + parent menu selection is "B" instead of "A", + */ + temp = self->parent->selected; + self->parent->selected = self->parent_entry; + if (temp) + menu_entry_frame_render(temp); + menu_entry_frame_render(self->parent_entry); + } + remove_submenu_hide_timeout(self->parent); + } + else if (oldchild->child) { + /* self is the (at least) grandparent of the last visible submenu */ + menu_frame_hide(oldchild->child); + if (temp = oldchild->selected) { + oldchild->selected = NULL; + menu_entry_frame_render(temp); + } + } + if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) entry = old; @@ -1144,13 +1199,40 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (old) menu_entry_frame_render(old); - if (oldchild) - menu_frame_hide(oldchild); + + reselection = FALSE; + if (oldchild) { + if (self->submenu_to_hide == entry) { + /* Legend: + (config_submenu_hide_delay != 0) + Some entry "A" selected; corresponding submenu shown; + cursor moved to another entry "B" and moved back + to the entry "A", when submenu hide request added, + but submenu not hided. + */ + reselection = TRUE; + remove_submenu_hide_timeout(self); + } + else if (!immediate && config_submenu_hide_delay) { + if (self->submenu_to_hide == NULL) { + ob_main_loop_timeout_add(ob_main_loop, + config_submenu_hide_delay * 1000, + menu_entry_frame_submenu_hide_timeout, + oldchild, g_direct_equal, + NULL); + self->submenu_to_hide = old; + } + } + else + menu_frame_hide(oldchild); + } if (self->selected) { menu_entry_frame_render(self->selected); - if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { + if (!reselection && + (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) + { if (config_submenu_show_delay && !immediate) { /* initiate a new submenu open request */ ob_main_loop_timeout_add(ob_main_loop, diff --git a/openbox/menuframe.h b/openbox/menuframe.h index 1b1dcc70..62df87ca 100644 --- a/openbox/menuframe.h +++ b/openbox/menuframe.h @@ -80,6 +80,9 @@ struct _ObMenuFrame menu until it has seen a KeyPress. this is to avoid having the keybinding used to show the menu end up running something inside the menu */ + ObMenuEntryFrame * submenu_to_hide; /* if exist (single!) submenu hide request + then this variable hold a copy of 'selected' field of the parent menu, + otherwice NULL */ }; struct _ObMenuEntryFrame -- cgit v1.2.3 From b88cf22bc0084bc611453443b5d8355edbe33bfa Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 4 Jan 2010 15:07:10 -0500 Subject: Some fixes for the submenu hide delay code When nothing in a menu is selected, go back to selecting the open submenu. Adjust the LeaveNotify event handling to only respond when there is not a EnterNotify coming for the same menu frame. Change the default submenu show/hide delays. Have the default values for submenu show/hide match the default rc.xml --- openbox/config.c | 4 +- openbox/event.c | 23 ++++++++-- openbox/menuframe.c | 126 ++++++++++++++++++++-------------------------------- openbox/menuframe.h | 4 +- 4 files changed, 71 insertions(+), 86 deletions(-) (limited to 'openbox') diff --git a/openbox/config.c b/openbox/config.c index a6417646..240606a4 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -1018,8 +1018,8 @@ void config_startup(ObParseInst *i) config_menu_hide_delay = 250; config_menu_middle = FALSE; - config_submenu_show_delay = 0; - config_submenu_hide_delay = 750; + config_submenu_show_delay = 200; + config_submenu_hide_delay = 400; config_menu_client_list_icons = TRUE; config_menu_manage_desktops = TRUE; config_menu_files = NULL; diff --git a/openbox/event.c b/openbox/event.c index 41f8eb16..c77d968a 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -1800,6 +1800,15 @@ static gboolean event_handle_menu_keyboard(XEvent *ev) return ret; } +static Bool event_look_for_menu_enter(Display *d, XEvent *ev, XPointer arg) +{ + ObMenuFrame *f = (ObMenuFrame*)arg; + ObMenuEntryFrame *e; + return ev->type == EnterNotify && + (e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) && + !e->ignore_enters && e->frame == f; +} + static gboolean event_handle_menu(XEvent *ev) { ObMenuFrame *f; @@ -1837,11 +1846,17 @@ static gboolean event_handle_menu(XEvent *ev) if (ev->xcrossing.detail == NotifyInferior) break; - if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) && - (f = find_active_menu()) && f->selected == e && - e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU) + if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) { - menu_frame_select(e->frame, NULL, FALSE); + XEvent ce; + + /* check if an EnterNotify event is coming, and if not, then select + nothing in the menu */ + if (XCheckIfEvent(ob_display, &ce, event_look_for_menu_enter, + (XPointer)e->frame)) + XPutBackEvent(ob_display, &ce); + else + menu_frame_select(e->frame, NULL, FALSE); } break; case MotionNotify: diff --git a/openbox/menuframe.c b/openbox/menuframe.c index ff25100e..9e8c8918 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -49,10 +49,10 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, ObMenuFrame *frame); static void menu_entry_frame_free(ObMenuEntryFrame *self); static void menu_frame_update(ObMenuFrame *self); -static gboolean menu_entry_frame_submenu_timeout(gpointer data); +static gboolean submenu_show_timeout(gpointer data); static void menu_frame_hide(ObMenuFrame *self); -static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data); +static gboolean submenu_hide_timeout(gpointer data); static Window createWindow(Window parent, gulong mask, XSetWindowAttributes *attrib) @@ -974,12 +974,13 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, return TRUE; } -static void remove_submenu_hide_timeout(ObMenuFrame *self /* parent of submenu to hide */) +/*! Stop hiding an open submenu. + @child The OnMenuFrame of the submenu to be hidden +*/ +static void remove_submenu_hide_timeout(ObMenuFrame *child) { - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_hide_timeout); - if (self) - self->submenu_to_hide = NULL; + ob_main_loop_timeout_remove_data(ob_main_loop, submenu_hide_timeout, + child, FALSE); } gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, @@ -995,13 +996,12 @@ gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, self->parent = parent; self->parent_entry = parent_entry; - remove_submenu_hide_timeout(parent); - /* set up parent's child to be us */ if ((parent->child) != self) { if (parent->child) menu_frame_hide(parent->child); parent->child = self; + parent->child_entry = parent_entry; } if (!menu_frame_show(self)) @@ -1034,8 +1034,6 @@ static void menu_frame_hide(ObMenuFrame *self) GList *it = g_list_find(menu_frame_visible, self); gulong ignore_start; - remove_submenu_hide_timeout(self->parent); - if (!it) return; @@ -1045,8 +1043,12 @@ static void menu_frame_hide(ObMenuFrame *self) if (self->child) menu_frame_hide(self->child); - if (self->parent) + if (self->parent) { + remove_submenu_hide_timeout(self); + self->parent->child = NULL; + self->parent->child_entry = NULL; + } self->parent = NULL; self->parent_entry = NULL; @@ -1071,8 +1073,7 @@ void menu_frame_hide_all(void) if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + ob_main_loop_timeout_remove(ob_main_loop, submenu_show_timeout); } if ((it = g_list_last(menu_frame_visible))) menu_frame_hide(it->data); @@ -1087,7 +1088,7 @@ void menu_frame_hide_all_client(ObClient *client) if (config_submenu_show_delay) { /* remove any submenu open requests */ ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + submenu_show_timeout); } menu_frame_hide(f); } @@ -1132,15 +1133,16 @@ ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y) return ret; } -static gboolean menu_entry_frame_submenu_timeout(gpointer data) +static gboolean submenu_show_timeout(gpointer data) { g_assert(menu_frame_visible); menu_entry_frame_show_submenu((ObMenuEntryFrame*)data); return FALSE; } -static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data) +static gboolean submenu_hide_timeout(gpointer data) { + g_assert(menu_frame_visible); menu_frame_hide((ObMenuFrame*)data); return FALSE; } @@ -1150,49 +1152,24 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, { ObMenuEntryFrame *old = self->selected; ObMenuFrame *oldchild = self->child; + ObMenuEntryFrame *oldchild_entry = self->child_entry; ObMenuEntryFrame *temp; - gboolean reselection; - - - if (!oldchild) { - /* self is the last visible (sub)menu */ - if (self->parent && self->parent_entry != self->parent->selected) { - /* Legend: - (config_submenu_hide_delay != 0) - In the parent menu corresponding entry "A" selected, - this submenu ('self') shown, cursor moved in the parent - menu to another entry "B", then cursor moved for the - first time into this submenu. - Results: - parent menu selection is "B" instead of "A", - */ - temp = self->parent->selected; - self->parent->selected = self->parent_entry; - if (temp) - menu_entry_frame_render(temp); - menu_entry_frame_render(self->parent_entry); - } - remove_submenu_hide_timeout(self->parent); - } - else if (oldchild->child) { - /* self is the (at least) grandparent of the last visible submenu */ - menu_frame_hide(oldchild->child); - if (temp = oldchild->selected) { - oldchild->selected = NULL; - menu_entry_frame_render(temp); - } - } - + /* if the user selected a separator, ignore it and reselect what we had + selected before */ if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) entry = old; if (old == entry) return; + /* if the user left this menu but we have a submenu open, move the + selection back to that submenu */ + if (!entry && oldchild_entry) + entry = oldchild_entry; + if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + ob_main_loop_timeout_remove(ob_main_loop, submenu_show_timeout); } self->selected = entry; @@ -1200,49 +1177,44 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (old) menu_entry_frame_render(old); - reselection = FALSE; - if (oldchild) { - if (self->submenu_to_hide == entry) { - /* Legend: - (config_submenu_hide_delay != 0) - Some entry "A" selected; corresponding submenu shown; - cursor moved to another entry "B" and moved back - to the entry "A", when submenu hide request added, - but submenu not hided. - */ - reselection = TRUE; - remove_submenu_hide_timeout(self); + if (oldchild_entry) { + /* There is an open submenu */ + if (oldchild_entry == self->selected) { + /* The open submenu has been reselected, so stop hiding the + submenu */ + remove_submenu_hide_timeout(oldchild); } - else if (!immediate && config_submenu_hide_delay) { - if (self->submenu_to_hide == NULL) { + else if (oldchild_entry == old) { + /* The open submenu was selected and is no longer, so hide the + submenu */ + if (!immediate && config_submenu_hide_delay) { ob_main_loop_timeout_add(ob_main_loop, - config_submenu_hide_delay * 1000, - menu_entry_frame_submenu_hide_timeout, - oldchild, g_direct_equal, - NULL); - self->submenu_to_hide = old; + config_submenu_hide_delay * 1000, + submenu_hide_timeout, + oldchild, g_direct_equal, + NULL); } + else + menu_frame_hide(oldchild); } - else - menu_frame_hide(oldchild); } if (self->selected) { menu_entry_frame_render(self->selected); - if (!reselection && - (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) + /* only show if the submenu isn't already showing */ + if (oldchild_entry != self->selected && + self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { if (config_submenu_show_delay && !immediate) { /* initiate a new submenu open request */ ob_main_loop_timeout_add(ob_main_loop, config_submenu_show_delay * 1000, - menu_entry_frame_submenu_timeout, + submenu_show_timeout, self->selected, g_direct_equal, NULL); - } else { + } else menu_entry_frame_show_submenu(self->selected); - } } } } diff --git a/openbox/menuframe.h b/openbox/menuframe.h index 62df87ca..926b844e 100644 --- a/openbox/menuframe.h +++ b/openbox/menuframe.h @@ -50,6 +50,7 @@ struct _ObMenuFrame ObMenuFrame *parent; ObMenuEntryFrame *parent_entry; ObMenuFrame *child; + ObMenuEntryFrame *child_entry; GList *entries; ObMenuEntryFrame *selected; @@ -80,9 +81,6 @@ struct _ObMenuFrame menu until it has seen a KeyPress. this is to avoid having the keybinding used to show the menu end up running something inside the menu */ - ObMenuEntryFrame * submenu_to_hide; /* if exist (single!) submenu hide request - then this variable hold a copy of 'selected' field of the parent menu, - otherwice NULL */ }; struct _ObMenuEntryFrame -- cgit v1.2.3 From e8588737c944f4dc5f94ca67bf0c7e3ff7133004 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 4 Jan 2010 15:26:10 -0500 Subject: Allow infinite delay for submenu show/hide by using a negative value. --- openbox/menuframe.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'openbox') diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 9e8c8918..d8c1691e 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -1160,7 +1160,9 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) entry = old; - if (old == entry) return; + if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU || + old == oldchild_entry)) + return; /* if the user left this menu but we have a submenu open, move the selection back to that submenu */ @@ -1187,15 +1189,14 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, else if (oldchild_entry == old) { /* The open submenu was selected and is no longer, so hide the submenu */ - if (!immediate && config_submenu_hide_delay) { + if (immediate || config_submenu_hide_delay == 0) + menu_frame_hide(oldchild); + else if (config_submenu_hide_delay > 0) ob_main_loop_timeout_add(ob_main_loop, config_submenu_hide_delay * 1000, submenu_hide_timeout, oldchild, g_direct_equal, NULL); - } - else - menu_frame_hide(oldchild); } } @@ -1206,15 +1207,14 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (oldchild_entry != self->selected && self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { - if (config_submenu_show_delay && !immediate) { - /* initiate a new submenu open request */ + if (immediate || config_submenu_hide_delay == 0) + menu_entry_frame_show_submenu(self->selected); + else if (config_submenu_hide_delay > 0) ob_main_loop_timeout_add(ob_main_loop, config_submenu_show_delay * 1000, submenu_show_timeout, self->selected, g_direct_equal, NULL); - } else - menu_entry_frame_show_submenu(self->selected); } } } -- cgit v1.2.3 From f3285a3d0bf118ce0eba0014ea53b11f47d710d6 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 6 Jan 2010 17:30:42 -0500 Subject: Improved menu behaviour Make 'left' key in a menu close it's visible child menu and move to the parent properly. Make clicking on a menu item in a menu close any of its grandchildren and remove focus from its children, effectively focusing the menu item you clicked on. --- openbox/event.c | 7 ++++++- openbox/menuframe.c | 34 +++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'openbox') diff --git a/openbox/event.c b/openbox/event.c index c77d968a..ad9dade6 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -1700,8 +1700,13 @@ static gboolean event_handle_menu_keyboard(XEvent *ev) else if (ob_keycode_match(keycode, OB_KEY_LEFT)) { /* Left goes to the parent menu */ - if (frame->parent) + if (frame->parent) { + /* remove focus from the child */ menu_frame_select(frame, NULL, TRUE); + /* and put it in the parent */ + menu_frame_select(frame->parent, frame->parent->selected, + TRUE); + } ret = TRUE; } diff --git a/openbox/menuframe.c b/openbox/menuframe.c index d8c1691e..088986f8 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -1153,15 +1153,13 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, ObMenuEntryFrame *old = self->selected; ObMenuFrame *oldchild = self->child; ObMenuEntryFrame *oldchild_entry = self->child_entry; - ObMenuEntryFrame *temp; /* if the user selected a separator, ignore it and reselect what we had selected before */ if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) entry = old; - if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU || - old == oldchild_entry)) + if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)) return; /* if the user left this menu but we have a submenu open, move the @@ -1203,18 +1201,24 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (self->selected) { menu_entry_frame_render(self->selected); - /* only show if the submenu isn't already showing */ - if (oldchild_entry != self->selected && - self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) - { - if (immediate || config_submenu_hide_delay == 0) - menu_entry_frame_show_submenu(self->selected); - else if (config_submenu_hide_delay > 0) - ob_main_loop_timeout_add(ob_main_loop, - config_submenu_show_delay * 1000, - submenu_show_timeout, - self->selected, g_direct_equal, - NULL); + if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { + /* only show if the submenu isn't already showing */ + if (oldchild_entry != self->selected) { + if (immediate || config_submenu_hide_delay == 0) + menu_entry_frame_show_submenu(self->selected); + else if (config_submenu_hide_delay > 0) + ob_main_loop_timeout_add(ob_main_loop, + config_submenu_show_delay * 1000, + submenu_show_timeout, + self->selected, g_direct_equal, + NULL); + } + /* hide the grandchildren of this menu. and move the cursor to + the current menu */ + else if (immediate && self->child && self->child->child) { + menu_frame_hide(self->child->child); + menu_frame_select(self->child, NULL, TRUE); + } } } } -- cgit v1.2.3 From f163c46eaf01ced8405fa36a3bf4a5c488f0f5aa Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 6 Jan 2010 18:58:27 -0500 Subject: Fix a crash when moving into a menu on top of a separator and nothing is selected --- openbox/menuframe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'openbox') diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 088986f8..076fe6ef 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -1159,7 +1159,8 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) entry = old; - if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)) + if (old == entry && + (!old || old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)) return; /* if the user left this menu but we have a submenu open, move the -- cgit v1.2.3