Files
2026-07-26 21:16:55 +02:00

54 lines
1.7 KiB
QML

pragma Singleton
import Quickshell
import Quickshell.Wayland
// Shell-wide UI state. The menus are per-screen surfaces, but only one may be
// open at a time and only on one screen, so ownership lives here rather than in
// the panel instances.
Singleton {
id: root
// Id of the open menu ("launcher", "bluetooth"), or "" when none is open.
property string openMenu: ""
// Name of the screen it is open on, or "" when closed.
property string menuScreen: ""
// Best guess at the screen the user is looking at, used when a menu is
// opened by keybind rather than by clicking a specific panel.
function focusedScreenName(): string {
const active = ToplevelManager.activeToplevel;
if (active && active.screens.length > 0)
return active.screens[0].name;
return Quickshell.screens.length > 0 ? Quickshell.screens[0].name : "";
}
function isOpen(menu: string, screenName: string): bool {
return screenName !== "" && root.openMenu === menu && root.menuScreen === screenName;
}
function open(menu: string, screenName: string): void {
// Closed first: moving a menu between screens would otherwise map the
// outgoing menu onto the incoming screen for one binding pass.
root.openMenu = "";
root.menuScreen = screenName || root.focusedScreenName();
root.openMenu = menu;
}
function close(): void {
root.openMenu = "";
root.menuScreen = "";
}
function toggle(menu: string, screenName: string): void {
const target = screenName || root.focusedScreenName();
if (root.openMenu === menu && root.menuScreen === target)
root.close();
else
root.open(menu, target);
}
}