forked from Shinonome/dots-hyprland
fix(SysTrayItem): anchor popup menu to icon instead of fixed coordinates
- Improved anchor positioning to make the expanded menu follow the icon dynamically rather than using fixed absolute coordinates. - Replaced manual `rect` calculations with direct `item: root` binding. - Updated `gravity` and `edges` logic to properly support both vertical and horizontal bar orientations.
This commit is contained in:
@@ -29,6 +29,11 @@ Item {
|
||||
}
|
||||
|
||||
function setExtraWindowAndGrabFocus(window) {
|
||||
if (root.activeMenu && root.activeMenu !== window) {
|
||||
if (typeof root.activeMenu.close === "function")
|
||||
root.activeMenu.close();
|
||||
root.activeMenu = null;
|
||||
}
|
||||
root.activeMenu = window;
|
||||
root.grabFocus();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,11 @@ MouseArea {
|
||||
item.activate();
|
||||
break;
|
||||
case Qt.RightButton:
|
||||
if (item.hasMenu) menu.open();
|
||||
if (item.hasMenu)
|
||||
if (menu.active && menu.item && typeof menu.item.close === "function")
|
||||
menu.item.close();
|
||||
else
|
||||
menu.open();
|
||||
break;
|
||||
}
|
||||
event.accepted = true;
|
||||
@@ -44,15 +48,16 @@ MouseArea {
|
||||
sourceComponent: SysTrayMenu {
|
||||
Component.onCompleted: this.open();
|
||||
trayItemMenuHandle: root.item.menu
|
||||
anchor {
|
||||
window: root.QsWindow.window
|
||||
rect.x: root.x + (Config.options.bar.vertical ? 0 : QsWindow.window?.width)
|
||||
rect.y: root.y + (Config.options.bar.vertical ? QsWindow.window?.height : 0)
|
||||
rect.height: root.height
|
||||
rect.width: root.width
|
||||
edges: Config.options.bar.bottom ? (Edges.Top | Edges.Left) : (Edges.Bottom | Edges.Right)
|
||||
gravity: Config.options.bar.bottom ? (Edges.Top | Edges.Left) : (Edges.Bottom | Edges.Right)
|
||||
}
|
||||
anchor {
|
||||
window: root.QsWindow.window
|
||||
item: root
|
||||
gravity: Config.options.bar.vertical
|
||||
? (Config.options.bar.bottom ? Edges.Left : Edges.Right)
|
||||
: (Config.options.bar.bottom ? Edges.Top : Edges.Bottom)
|
||||
edges: Config.options.bar.vertical
|
||||
? (Config.options.bar.bottom ? Edges.Left : Edges.Right)
|
||||
: (Config.options.bar.bottom ? Edges.Top : Edges.Bottom)
|
||||
}
|
||||
onMenuOpened: (window) => root.menuOpened(window);
|
||||
onMenuClosed: {
|
||||
root.menuClosed();
|
||||
|
||||
Reference in New Issue
Block a user