From 145478b595106cbda209253075e977db7b5577bf Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 8 Dec 2021 15:35:20 +0900 Subject: [PATCH] panel: Restore Alt-F1 and Alt-F3 key binds --- apps/panel.c | 38 ++++++++-------------------------- base/usr/include/toaru/panel.h | 1 + lib/panel_appmenu.c | 13 ++++++++++++ lib/panel_windowlist.c | 17 +++++++++++++++ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/apps/panel.c b/apps/panel.c index af9e23ff..2e9d7d60 100644 --- a/apps/panel.c +++ b/apps/panel.c @@ -435,17 +435,6 @@ static void handle_key_event(struct yutani_msg_key_event * ke) { return; } - /* TODO Alt-F1 = Show the application menu */ - #if 0 - if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) && - (ke->event.keycode == KEY_F1) && - (ke->event.action == KEY_ACTION_DOWN)) { - /* show menu */ - - show_app_menu(); - } - #endif - /* Alt-F2 = Show the command entry window */ if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) && (ke->event.keycode == KEY_F2) && @@ -459,19 +448,11 @@ static void handle_key_event(struct yutani_msg_key_event * ke) { } } - /* Alt-F3 = Show the context menu for the currently active window */ - #if 0 - if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) && - (ke->event.keycode == KEY_F3) && - (ke->event.action == KEY_ACTION_DOWN)) { - foreach(node, window_list) { - struct window_ad * ad = node->value; - if (ad->flags & 1) { - window_show_menu(ad->wid, ad->left, DROPDOWN_OFFSET); - } - } + /* Maybe a plugin wants to handle this key bind */ + foreach(widget_node, widgets_enabled) { + struct PanelWidget * widget = widget_node->value; + widget->onkey(widget, ke); } - #endif /* Releasing Alt when the Alt-Tab switcher is visible */ if ((was_tabbing) && (ke->event.keycode == 0 || ke->event.keycode == KEY_LEFT_ALT) && @@ -668,15 +649,9 @@ static void bind_keys(void) { /* Ctrl-F11 = toggle panel visibility */ yutani_key_bind(yctx, KEY_F11, KEY_MOD_LEFT_CTRL, YUTANI_BIND_STEAL); - /* Alt+F1 = show menu */ - yutani_key_bind(yctx, KEY_F1, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL); - /* Alt+F2 = show app runner */ yutani_key_bind(yctx, KEY_F2, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL); - /* Alt+F3 = window context menu */ - yutani_key_bind(yctx, KEY_F3, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL); - /* This lets us receive all just-modifier key releases */ yutani_key_bind(yctx, KEY_LEFT_ALT, 0, YUTANI_BIND_PASSTHROUGH); @@ -720,6 +695,10 @@ static int widget_update_generic(struct PanelWidget * this) { return 0; } +static int widget_onkey_generic(struct PanelWidget * this, struct yutani_msg_key_event * evt) { + return 0; +} + struct PanelWidget * widget_new(void) { struct PanelWidget * out = calloc(1, sizeof(struct PanelWidget)); out->draw = widget_draw_generic; @@ -728,6 +707,7 @@ struct PanelWidget * widget_new(void) { out->leave = widget_leave_generic; out->enter = widget_enter_generic; out->update = widget_update_generic; + out->onkey = widget_onkey_generic; out->move = mouse_event_ignore; /* move_generic */ out->highlighted = 0; out->fill = 0; diff --git a/base/usr/include/toaru/panel.h b/base/usr/include/toaru/panel.h index 89b82f66..c72ee027 100644 --- a/base/usr/include/toaru/panel.h +++ b/base/usr/include/toaru/panel.h @@ -31,6 +31,7 @@ struct PanelWidget { int (*move)(struct PanelWidget *, struct yutani_msg_window_mouse_event *); int (*draw)(struct PanelWidget *, gfx_context_t * ctx); int (*update)(struct PanelWidget *); + int (*onkey)(struct PanelWidget *, struct yutani_msg_key_event *); }; extern yutani_t * yctx; diff --git a/lib/panel_appmenu.c b/lib/panel_appmenu.c index 72985e78..ce1ede5c 100644 --- a/lib/panel_appmenu.c +++ b/lib/panel_appmenu.c @@ -25,14 +25,27 @@ static int widget_click_appmenu(struct PanelWidget * this, struct yutani_msg_win return 0; } +static int widget_onkey_appmenu(struct PanelWidget * this, struct yutani_msg_key_event * ke) { + if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) && + (ke->event.keycode == KEY_F1) && + (ke->event.action == KEY_ACTION_DOWN)) { + panel_menu_show(this,appmenu); + } + return 0; +} + struct PanelWidget * widget_init_appmenu(void) { appmenu = menu_set_get_root(menu_set_from_description("/etc/panel.menu", launch_application_menu)); appmenu->flags = MENU_FLAG_BUBBLE_CENTER; + /* Bind Alt+F1 */ + yutani_key_bind(yctx, KEY_F1, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL); + struct PanelWidget * widget = widget_new(); widget->width = 130; widget->draw = widget_draw_appmenu; widget->click = widget_click_appmenu; + widget->onkey = widget_onkey_appmenu; list_insert(widgets_enabled, widget); return widget; } diff --git a/lib/panel_windowlist.c b/lib/panel_windowlist.c index 8c4c0312..46847a5a 100644 --- a/lib/panel_windowlist.c +++ b/lib/panel_windowlist.c @@ -193,6 +193,19 @@ static int widget_leave_windowlist(struct PanelWidget * this, struct yutani_msg_ return 1; } +static int widget_onkey_windowlist(struct PanelWidget * this, struct yutani_msg_key_event * ke) { + if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) && + (ke->event.keycode == KEY_F3) && + (ke->event.action == KEY_ACTION_DOWN)) { + foreach(node, window_list) { + struct window_ad * ad = node->value; + if (ad->flags & 1) { + window_show_menu(ad->wid, ad->left + title_width / 2); + } + } + } + return 0; +} struct PanelWidget * widget_init_windowlist(void) { window_menu = menu_create(); @@ -202,6 +215,9 @@ struct PanelWidget * widget_init_windowlist(void) { menu_insert(window_menu, menu_create_separator()); menu_insert(window_menu, menu_create_normal(NULL, NULL, "Close", _window_menu_close)); + /* Alt+F3 = window context menu */ + yutani_key_bind(yctx, KEY_F3, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL); + struct PanelWidget * widget = widget_new(); widget->fill = 1; widget->draw = widget_draw_windowlist; @@ -209,6 +225,7 @@ struct PanelWidget * widget_init_windowlist(void) { widget->right_click = widget_rightclick_windowlist; widget->move = widget_move_windowlist; widget->leave = widget_leave_windowlist; + widget->onkey = widget_onkey_windowlist; list_insert(widgets_enabled, widget); return widget; }