]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: correctly center menu opened with <position {x,y}="center">
authortokyo4j <hrak1529@gmail.com>
Fri, 8 Nov 2024 11:55:13 +0000 (20:55 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 8 Nov 2024 21:33:34 +0000 (21:33 +0000)
Prior to this commit, a menu opened with:

  <action name="ShowMenu">
    <position x="center" y="center" />
  </action>

was not correctly centered when menu.items.padding.x is non-zero.

src/action.c

index 0afce12675220c4103a7e0625ef5bc47082324d3..3df81df2be7eb404d2affeb63015c76e3c0ce339 100644 (file)
@@ -688,19 +688,9 @@ show_menu(struct server *server, struct view *view, struct cursor_context *ctx,
        if (pos_x && pos_y) {
                struct output *output = output_nearest_to(server,
                                server->seat.cursor->x, server->seat.cursor->y);
-               struct menuitem *item;
-               struct theme *theme = server->theme;
-               int max_width = theme->menu_min_width;
-
-               wl_list_for_each(item, &menu->menuitems, link) {
-                       if (item->native_width > max_width) {
-                               max_width = item->native_width < theme->menu_max_width
-                                       ? item->native_width : theme->menu_max_width;
-                       }
-               }
 
                if (!strcasecmp(pos_x, "center")) {
-                       x = (output->usable_area.width / 2) - (max_width / 2);
+                       x = (output->usable_area.width - menu->size.width) / 2;
                } else if (strchr(pos_x, '%')) {
                        x = (output->usable_area.width * atoi(pos_x)) / 100;
                } else {