Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
1.74k stars 94 forks source link

Menu.popup_at_widget not honoring menu_anchor argument #446

Open yari-dog opened 3 weeks ago

yari-dog commented 3 weeks ago

When calling popup_at_window, passing it menu_ancho does not effect the placement of the menu, with it reverting to the equivalent of NORTH_WEST (1).

I've written a (pretty bad) widget setup to demonstrate this, where clicking the menu item will increment the menu_anchor and then the widget_anchor once menu_anchor loops back around to 1:

    let widget_anchor = 1;
    let menu_anchor = 1;

    const button = Widget.Button({
    cursor: 'pointer',
    class_name: 'quick-setting-toggle-button',
    child: MaterialIcon(icon, 'medium', {}),
    onPrimaryClick: (self, event) => {
        menu.popup_at_widget(self, widget_anchor, menu_anchor, event);
    }, 
    })

    const menu = Widget.Menu({
    ...props,
    css: 'background-color: red;',
    children: [
        Widget.MenuItem({
        label: '^ ^\n^ ^',
        onActivate: (self) => {
            button.on_primary_click = (button, event) => {
            if (widget_anchor === 10) {
                widget_anchor = 1;
            }
            if (menu_anchor === 10) {
                widget_anchor++;
                menu_anchor = 1;
            }
            else {
                menu_anchor++;
            }
            const widget_gravity = Gdk.Gravity[Object.keys(Gdk.Gravity)[widget_anchor - 1]];
            const menu_gravity = Gdk.Gravity[Object.keys(Gdk.Gravity)[menu_anchor - 1]];
            console.log('anchors', widget_anchor, menu_anchor, widget_gravity, menu_gravity);
            menu.popup_at_widget(button, widget_gravity, menu_gravity, event);
            }
        },
        }),
    ],
    on_popup: (self, flipped_rect, final_rect, flipped_x, flipped_y) => {
        console.log('popup', flipped_rect, final_rect, flipped_x, flipped_y, self.menu_type_hint, self.anchor_hints, self.rect_anchor_dx, self.rect_anchor_dy);
    },
    });

regardless of the value passed to menu_anchor, the menu will always behave as though it was set to 1. image i've also attached the output of the two console.log calls image

Aylur commented 1 week ago

what are you trying to achieve here? not sure why but some gravity pairings work as expected and some don't, not sure why, would have to dig into gtk/gtk-layer-shell this is not something that we can fix in gjs I think

yari-dog commented 1 week ago

I was trying to get the anchor of the menu to be north-east, and got carried away within sanity checking myself aha, but that does make sense. What I ended up finding with that test code was that menu_anchor is /always/ ignored, and widget_anchor is /always/ honoured (with menu_anchor always being 1 (north west))