From 8b1831c7311914ffb793c31773ce34151b37dae5 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sun, 15 Sep 2024 22:29:05 +0200 Subject: [PATCH] action: open the client menu underneath the window menu button It looks slightly awkward when the client menu shows up in the left corner of the view and the window menu button is configured to be on the right side. --- src/action.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/action.c b/src/action.c index a157d6e8..73ef48a5 100644 --- a/src/action.c +++ b/src/action.c @@ -617,6 +617,38 @@ action_list_free(struct wl_list *action_list) } } +static int +get_window_menu_button_offset(struct server *server, struct view *view) +{ + int padding_width = server->theme->padding_width; + int button_width = server->theme->window_button_width; + int button_spacing = server->theme->window_button_spacing; + + struct title_button *b; + + int offset = padding_width; + wl_list_for_each(b, &rc.title_buttons_left, link) { + if (b->type == LAB_SSD_BUTTON_WINDOW_MENU) { + return offset; + } else { + offset += button_width + button_spacing; + } + } + + offset = view->current.width - padding_width; + wl_list_for_each_reverse(b, &rc.title_buttons_right, link) { + if (b->type == LAB_SSD_BUTTON_WINDOW_MENU) { + offset -= button_width; + return offset; + } else { + offset -= button_width + button_spacing; + } + } + + /* no menu button */ + return 0; +} + static void show_menu(struct server *server, struct view *view, const char *menu_name, bool at_cursor, @@ -637,13 +669,17 @@ show_menu(struct server *server, struct view *view, int y = server->seat.cursor->y; /* The client menu needs an active client */ - if (!view && strcasecmp(menu_name, "client-menu") == 0) { + bool is_client_menu = !strcasecmp(menu_name, "client-menu"); + if (!view && is_client_menu) { return; } /* Place menu in the view corner if desired (and menu is not root-menu) */ if (!at_cursor && view) { - x = view->current.x; + /* push the client menu underneath the window menu button */ + int offset = is_client_menu + ? get_window_menu_button_offset(server, view) : 0; + x = view->current.x + offset; y = view->current.y; }