X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fmenuframe.c;h=9127257e010ee69e384f90da0eb61e32af93d17c;hb=34178097d559ef522ea0984091489c209f4e9e0e;hp=57f2943886767a15a4a11a2f842faf8431897766;hpb=73575c10ce3ede1637e4f959b56e1f7d5f110b91;p=chaz%2Fopenbox diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 57f29438..9127257e 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -27,6 +27,7 @@ #include "openbox.h" #include "config.h" #include "obt/prop.h" +#include "obt/keyboard.h" #include "obrender/theme.h" #define PADDING 2 @@ -61,6 +62,19 @@ static Window createWindow(Window parent, gulong mask, RrVisual(ob_rr_inst), mask, attrib); } +static void client_dest(ObClient *client, gpointer data) +{ + GList *it; + + /* menus can be associated with a client, so null those refs since + we are disappearing now */ + for (it = menu_frame_visible; it; it = g_list_next(it)) { + ObMenuFrame *f = it->data; + if (f->client == client) + f->client = NULL; + } +} + void menu_frame_startup(gboolean reconfig) { gint i; @@ -75,6 +89,7 @@ void menu_frame_startup(gboolean reconfig) if (reconfig) return; + client_add_destroy_notify(client_dest, NULL); menu_frame_map = g_hash_table_new(g_int_hash, g_int_equal); } @@ -84,6 +99,7 @@ void menu_frame_shutdown(gboolean reconfig) if (reconfig) return; + client_remove_destroy_notify(client_dest); g_hash_table_destroy(menu_frame_map); } @@ -92,7 +108,7 @@ ObMenuFrame* menu_frame_new(ObMenu *menu, guint show_from, ObClient *client) ObMenuFrame *self; XSetWindowAttributes attr; - self = g_new0(ObMenuFrame, 1); + self = g_slice_new0(ObMenuFrame); self->obwin.type = OB_WINDOW_CLASS_MENUFRAME; self->menu = menu; self->selected = NULL; @@ -135,17 +151,24 @@ void menu_frame_free(ObMenuFrame *self) XDestroyWindow(obt_display, self->window); - g_free(self); + g_slice_free(ObMenuFrame, self); } } +ObtIC* menu_frame_ic(ObMenuFrame *self) +{ + /* menus are always used through a grab right now, so they can always use + the grab input context */ + return grab_input_context(); +} + static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, ObMenuFrame *frame) { ObMenuEntryFrame *self; XSetWindowAttributes attr; - self = g_new0(ObMenuEntryFrame, 1); + self = g_slice_new0(ObMenuEntryFrame); self->entry = entry; self->frame = frame; @@ -193,7 +216,7 @@ static void menu_entry_frame_free(ObMenuEntryFrame *self) g_hash_table_remove(menu_frame_map, &self->bullet); } - g_free(self); + g_slice_free(ObMenuEntryFrame, self); } } @@ -298,7 +321,7 @@ static void menu_frame_place_submenu(ObMenuFrame *self, gint *x, gint *y) void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y, gint *dx, gint *dy) { - Rect *a = NULL; + const Rect *a = NULL; gint pos, half; *dx = *dy = 0; @@ -322,8 +345,6 @@ void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y, *dx = MAX(*dx, a->x - x); *dy = MAX(*dy, a->y - y); } - - g_free(a); } static void menu_entry_frame_render(ObMenuEntryFrame *self) @@ -810,7 +831,7 @@ void menu_frame_render(ObMenuFrame *self) static void menu_frame_update(ObMenuFrame *self) { GList *mit, *fit; - Rect *a; + const Rect *a; gint h; menu_pipe_execute(self->menu); @@ -908,8 +929,6 @@ static void menu_frame_update(ObMenuFrame *self) } } - g_free(a); - menu_frame_render(self); } @@ -1090,22 +1109,6 @@ void menu_frame_hide_all(void) menu_frame_hide(it->data); } -void menu_frame_hide_all_client(ObClient *client) -{ - GList *it = g_list_last(menu_frame_visible); - if (it) { - ObMenuFrame *f = it->data; - if (f->client == client) { - if (config_submenu_show_delay) { - /* remove any submenu open requests */ - obt_main_loop_timeout_remove(ob_main_loop, - submenu_show_timeout); - } - menu_frame_hide(f); - } - } -} - ObMenuFrame* menu_frame_under(gint x, gint y) { ObMenuFrame *ret = NULL; @@ -1263,10 +1266,11 @@ void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state) GSList *acts = self->entry->data.normal.actions; ObClient *client = self->frame->client; ObMenuFrame *frame = self->frame; + guint mods = obt_keyboard_only_modmasks(state); /* release grabs before executing the shit */ - if (!(state & ControlMask)) { - menu_frame_hide_all(); + if (!(mods & ControlMask)) { + event_cancel_all_key_grabs(); frame = NULL; } @@ -1300,7 +1304,7 @@ void menu_frame_select_previous(ObMenuFrame *self) } } } - menu_frame_select(self, it ? it->data : NULL, TRUE); + menu_frame_select(self, it ? it->data : NULL, FALSE); } void menu_frame_select_next(ObMenuFrame *self) @@ -1325,5 +1329,37 @@ void menu_frame_select_next(ObMenuFrame *self) } } } - menu_frame_select(self, it ? it->data : NULL, TRUE); + menu_frame_select(self, it ? it->data : NULL, FALSE); +} + +void menu_frame_select_first(ObMenuFrame *self) +{ + GList *it = NULL; + + if (self->entries) { + for (it = self->entries; it; it = g_list_next(it)) { + ObMenuEntryFrame *e = it->data; + if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) + break; + if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) + break; + } + } + menu_frame_select(self, it ? it->data : NULL, FALSE); +} + +void menu_frame_select_last(ObMenuFrame *self) +{ + GList *it = NULL; + + if (self->entries) { + for (it = g_list_last(self->entries); it; it = g_list_previous(it)) { + ObMenuEntryFrame *e = it->data; + if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) + break; + if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) + break; + } + } + menu_frame_select(self, it ? it->data : NULL, FALSE); }