]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: minor refactor of menu_configure()
authorJohan Malm <jgm323@gmail.com>
Tue, 31 Oct 2023 21:13:41 +0000 (21:13 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 24 Mar 2024 21:44:16 +0000 (21:44 +0000)
src/menu/menu.c

index 722f7d5b5b1673118c460981b64c7a24a04d77a1..b10b46cd8ea14cc07bc32553f369d4bbcefec5e8 100644 (file)
@@ -593,6 +593,25 @@ menu_get_full_width(struct menu *menu)
        return width + max_child_width;
 }
 
+static struct wlr_box
+get_submenu_position(struct menuitem *item, enum menu_align align)
+{
+       struct wlr_box pos = { 0 };
+       struct menu *menu = item->parent;
+       struct theme *theme = menu->server->theme;
+       int lx = menu->scene_tree->node.x;
+       int ly = menu->scene_tree->node.y;
+
+       if (align & LAB_MENU_OPEN_RIGHT) {
+               pos.x = lx + menu->size.width - theme->menu_overlap_x;
+       } else {
+               pos.x = lx;
+       }
+       int rel_y = item->tree->node.y;
+       pos.y = ly + rel_y - theme->menu_overlap_y;
+       return pos;
+}
+
 static void
 menu_configure(struct menu *menu, int lx, int ly, enum menu_align align)
 {
@@ -650,14 +669,8 @@ menu_configure(struct menu *menu, int lx, int ly, enum menu_align align)
                if (!item->submenu) {
                        continue;
                }
-               if (align & LAB_MENU_OPEN_RIGHT) {
-                       new_lx = lx + menu->size.width - theme->menu_overlap_x;
-               } else {
-                       new_lx = lx;
-               }
-               rel_y = item->tree->node.y;
-               new_ly = ly + rel_y - theme->menu_overlap_y;
-               menu_configure(item->submenu, new_lx, new_ly, align);
+               struct wlr_box pos = get_submenu_position(item, align);
+               menu_configure(item->submenu, pos.x, pos.y, align);
        }
 }