From 588e7fcffc5f696cce72d271154bd0b53bc2d880 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 28 Apr 2025 00:17:39 +1000 Subject: hyprland: use qs hyprland service Also use models --- .vscode/settings.json | 3 + services/Hyprland.qml | 167 ++++++++++++++------------------------------------ 2 files changed, 50 insertions(+), 120 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9634af6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.defaultFormatter": "theqtcompany.qt-qml" +} diff --git a/services/Hyprland.qml b/services/Hyprland.qml index 9ca1d0e..2e24989 100644 --- a/services/Hyprland.qml +++ b/services/Hyprland.qml @@ -1,5 +1,4 @@ pragma Singleton -pragma ComponentBehavior: Bound import Quickshell import Quickshell.Io @@ -9,151 +8,79 @@ import QtQuick Singleton { id: root - property list clients: [] - property list monitors: [] - property list workspaces: [] + readonly property ListModel clients: ListModel {} + readonly property var workspaces: Hyprland.workspaces + readonly property var monitors: Hyprland.monitors property var activeClient: null - property var activeWorkspace: null - property var focusedMonitor: null + property HyprlandWorkspace activeWorkspace: null + property HyprlandMonitor focusedMonitor: Hyprland.monitors.values.find(m => m.lastIpcObject.focused) ?? null + + Component.onCompleted: reload() function reload() { + Hyprland.refreshWorkspaces(); + Hyprland.refreshMonitors(); getClients.running = true; - getMonitors.running = true; - getWorkspaces.running = true; getActiveClient.running = true; getActiveWorkspace.running = true; } - Component.onCompleted: reload() + function dispatch(request: string): void { + Hyprland.dispatch(request); + } Connections { target: Hyprland - function onRawEvent(event: string): void { - if (!event.endsWith("v2")) + + function onRawEvent(event: HyprlandEvent): void { + if (!event.name.endsWith("v2")) root.reload(); } } - component HyprData: Process { - id: proc - - required property string type - property string prop: type - property bool array: true - function transform(data) { - return data; - } - - command: ["bash", "-c", `hyprctl -j ${type} | jq -c`] + Process { + id: getClients + command: ["bash", "-c", "hyprctl -j clients | jq -c"] stdout: SplitParser { onRead: data => { - root[proc.prop] = proc.array ? JSON.parse(data).map(proc.transform) : proc.transform(JSON.parse(data)); - if (proc.type === "monitors") - root.focusedMonitor = root.monitors.find(m => m.focused); + const clients = JSON.parse(data); + root.clients.clear(); + for (const client of clients) { + root.clients.append({ + lastIpcObject: client, + address: client.address, + class: client.class, + title: client.title + }); + } } } - - function transformClient(client) { - if (!client.address) - return null; - - return { - address: client.address, - x: client.at[0], - y: client.at[1], - width: client.size[0], - height: client.size[1], - workspace: transformWorkspace(client.workspace), - floating: client.floating, - monitor: client.monitor, - wmClass: client.class, - title: client.title, - initialClass: client.initialClass, - initialTitle: client.initialTitle, - pid: client.pid, - xwayland: client.xwayland, - pinned: client.pinned, - fullscreen: client.fullscreen, - focusHistoryId: client.focusHistoryID, - inhibitingIdle: client.inhibitingIdle - }; - } - - function transformMonitor(monitor) { - return { - id: monitor.id, - name: monitor.name, - description: monitor.description, - make: monitor.make, - model: monitor.model, - serial: monitor.serial, - x: monitor.x, - y: monitor.y, - width: monitor.width, - height: monitor.height, - refreshRate: monitor.refreshRate, - activeWorkspace: transformWorkspace(monitor.activeWorkspace), - specialWorkspace: transformWorkspace(monitor.specialWorkspace), - reserved: monitor.reserved, - scale: monitor.scale, - transform: monitor.transform, - focused: monitor.focused, - dpms: monitor.dpms, - vrr: monitor.vrr, - disabled: monitor.disabled - }; - } - - function transformWorkspace(workspace) { - return { - id: workspace.id, - name: workspace.name, - special: workspace.name.startsWith("special:") - }; - } } - HyprData { - id: getClients - type: "clients" - function transform(client) { - return transformClient(client); - } - } - - HyprData { - id: getMonitors - type: "monitors" - function transform(monitor) { - return transformMonitor(monitor); - } - } - - HyprData { - id: getWorkspaces - type: "workspaces" - function transform(workspace) { - return transformWorkspace(workspace); - } - } - - HyprData { + Process { id: getActiveClient - type: "activewindow" - prop: "activeClient" - array: false - function transform(client) { - return transformClient(client); + command: ["bash", "-c", "hyprctl -j activewindow | jq -c"] + stdout: SplitParser { + onRead: data => { + const client = JSON.parse(data); + root.activeClient = { + lastIpcObject: client, + address: client.address, + class: client.class, + title: client.title + }; + } } } - HyprData { + Process { id: getActiveWorkspace - type: "activeworkspace" - prop: "activeWorkspace" - array: false - function transform(workspace) { - return transformWorkspace(workspace); + command: ["bash", "-c", "hyprctl -j activeworkspace | jq -c"] + stdout: SplitParser { + onRead: data => { + const ws = JSON.parse(data); + root.activeWorkspace = root.workspaces.values.find(w => w.id === ws.id) ?? null; + } } } } -- cgit v1.2.3-freya