diff options
Diffstat (limited to 'services')
| -rw-r--r-- | services/Hyprland.qml | 101 |
1 files changed, 12 insertions, 89 deletions
diff --git a/services/Hyprland.qml b/services/Hyprland.qml index 7626f53..bef1c34 100644 --- a/services/Hyprland.qml +++ b/services/Hyprland.qml @@ -1,114 +1,37 @@ pragma Singleton import Quickshell -import Quickshell.Io import Quickshell.Hyprland import QtQuick Singleton { id: root - readonly property list<Client> clients: [] + readonly property var toplevels: Hyprland.toplevels readonly property var workspaces: Hyprland.workspaces readonly property var monitors: Hyprland.monitors - property Client activeClient: null - readonly property HyprlandWorkspace activeWorkspace: focusedMonitor?.activeWorkspace ?? null + readonly property HyprlandToplevel activeToplevel: Hyprland.activeToplevel + readonly property HyprlandWorkspace focusedWorkspace: Hyprland.focusedWorkspace readonly property HyprlandMonitor focusedMonitor: Hyprland.focusedMonitor - readonly property int activeWsId: activeWorkspace?.id ?? 1 - property point cursorPos - - function reload() { - Hyprland.refreshWorkspaces(); - Hyprland.refreshMonitors(); - getClients.running = true; - getActiveClient.running = true; - } + readonly property int activeWsId: focusedWorkspace?.id ?? 1 function dispatch(request: string): void { Hyprland.dispatch(request); } - Component.onCompleted: reload() - Connections { target: Hyprland function onRawEvent(event: HyprlandEvent): void { - if (!event.name.endsWith("v2")) - root.reload(); - } - } - - Process { - id: getClients - command: ["hyprctl", "-j", "clients"] - stdout: StdioCollector { - onStreamFinished: { - const clients = JSON.parse(text); - const rClients = root.clients; + if (event.name.endsWith("v2")) + return; - const destroyed = rClients.filter(rc => !clients.find(c => c.address === rc.address)); - for (const client of destroyed) - rClients.splice(rClients.indexOf(client), 1).forEach(c => c.destroy()); - - for (const client of clients) { - const match = rClients.find(c => c.address === client.address); - if (match) { - match.lastIpcObject = client; - } else { - rClients.push(clientComp.createObject(root, { - lastIpcObject: client - })); - } - } - } + if (event.name.includes("mon")) + Hyprland.refreshMonitors(); + else if (event.name.includes("workspace")) + Hyprland.refreshWorkspaces(); + else + Hyprland.refreshToplevels(); } } - - Process { - id: getActiveClient - command: ["hyprctl", "-j", "activewindow"] - stdout: StdioCollector { - onStreamFinished: { - const client = JSON.parse(text); - const rClient = root.activeClient; - if (client.address) { - if (rClient) - rClient.lastIpcObject = client; - else - root.activeClient = clientComp.createObject(root, { - lastIpcObject: client - }); - } else if (rClient) { - rClient.destroy(); - root.activeClient = null; - } - } - } - } - - component Client: QtObject { - required property var lastIpcObject - readonly property string address: lastIpcObject.address - readonly property string wmClass: lastIpcObject.class - readonly property string title: lastIpcObject.title - readonly property string initialClass: lastIpcObject.initialClass - readonly property string initialTitle: lastIpcObject.initialTitle - readonly property int x: lastIpcObject.at[0] - readonly property int y: lastIpcObject.at[1] - readonly property int width: lastIpcObject.size[0] - readonly property int height: lastIpcObject.size[1] - readonly property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject.workspace.id) ?? null - readonly property HyprlandMonitor monitor: Hyprland.monitors.values.find(m => m.id === lastIpcObject.monitor) ?? null - readonly property bool floating: lastIpcObject.floating - readonly property bool fullscreen: lastIpcObject.fullscreen - readonly property int pid: lastIpcObject.pid - readonly property int focusHistoryId: lastIpcObject.focusHistoryID - } - - Component { - id: clientComp - - Client {} - } } |