Files
glassMxrph/quickshell/services/TrayService.qml
T
mxandClaude Opus 5.5 99e64a7713 Add glassMxrph shell sources
Initial commit of the Quickshell desktop suite: bar, dock, launcher,
settings, Control Center, dashboard, OSD, lock screen, desktop widgets,
plugin host with the vendored Noctalia/Omarchy compatibility layer,
helpers, packaging, tests and phase documentation.

Includes the optimization work so far: usage widgets and dashboard
gauges no longer animate continuously, desktop widgets pause while
covered, system controls stop flickering on background polls, dock app
matching uses an indexed catalog, and workspace ghosts are created only
for occupied slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:36:17 +02:00

136 lines
4.3 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Services.SystemTray
import "../core"
Singleton {
id: root
readonly property var items: SystemTray.items.values
readonly property var options: ConfigService.ready ? ConfigService.data.tray : ({
enabled: false,
hoverMenus: true,
hoverDelay: 400,
iconSize: 20,
spacing: 8,
background: "pill"
})
property var currentItem: null
property var anchorItem: null
property bool opened: false
property bool closeOnLeave: false
property var windows: []
// Bar windows, for test drivers and hover hand-off.
property var barWindows: []
property var hoveredWindows: []
property var icons: []
// Only click-opened menus grab keyboard focus; hover menus never steal it.
readonly property bool grabbing: opened && !closeOnLeave
readonly property bool pointerInside: (anchorItem && anchorItem.pointerInside) || hoveredWindows.length > 0
onPointerInsideChanged: updateDismissal()
onItemsChanged: if (currentItem && !items.includes(currentItem))
close()
onCurrentItemChanged: if (!currentItem)
close()
onOptionsChanged: if (!options.enabled)
close()
function registerIcon(icon) {
icons = icons.concat([icon]);
}
function unregisterIcon(icon) {
if (anchorItem === icon)
close();
icons = icons.filter(i => i !== icon);
}
function registerBar(window) {
barWindows = barWindows.concat([window]);
}
function unregisterBar(window) {
barWindows = barWindows.filter(w => w !== window);
}
function registerWindow(window) {
windows = windows.concat([window]);
}
function unregisterWindow(window) {
windows = windows.filter(w => w !== window);
setHovered(window, false);
}
function setHovered(window, inside) {
hoveredWindows = hoveredWindows.filter(w => w !== window);
if (inside)
hoveredWindows = hoveredWindows.concat([window]);
}
function updateDismissal() {
if (opened && closeOnLeave && !pointerInside)
leaveTimer.restart();
else
leaveTimer.stop();
}
function open(item, icon, hover) {
if (!options.enabled || !item || !item.hasMenu || !icon)
return false;
ShellState.controlCenterOpen = false;
ShellState.launcherOpen = false;
ShellState.settingsOpen = false;
currentItem = item;
anchorItem = icon;
closeOnLeave = hover;
opened = true;
updateDismissal();
return true;
}
function close() {
opened = false;
leaveTimer.stop();
}
function openById(id, monitor) {
const icon = icons.find(i => i.trayItem && i.trayItem.id === id && (!monitor || i.barScreen.name === monitor));
return icon ? open(icon.trayItem, icon, false) : false;
}
Connections {
target: ShellState
function onControlCenterOpenChanged() {
if (ShellState.controlCenterOpen)
root.close();
}
function onSettingsOpenChanged() {
if (ShellState.settingsOpen)
root.close();
}
function onLauncherOpenChanged() {
if (ShellState.launcherOpen)
root.close();
}
}
Timer {
id: leaveTimer
interval: 300
onTriggered: if (!root.pointerInside)
root.close()
}
IpcHandler {
target: "tray"
function open(id: string, monitor: string): bool {
return root.openById(id, monitor);
}
function close(): void {
root.close();
}
function status(): string {
return JSON.stringify({
opened: root.opened,
grabbing: root.grabbing,
currentId: root.currentItem ? root.currentItem.id : "",
items: root.items.map(i => ({
id: i.id,
title: i.title,
hasMenu: i.hasMenu,
onlyMenu: i.onlyMenu
})),
menus: root.windows.filter(w => w.visible).map(w => w.snapshot())
});
}
}
}