summaryrefslogtreecommitdiff
path: root/services/Hyprland.qml
blob: 92f1de55b8672f2b5ee3f8fe71e2025a7c985bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pragma Singleton

import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import QtQuick

Singleton {
    id: root

    property list<Client> clients: []
    readonly property var workspaces: Hyprland.workspaces
    readonly property var monitors: Hyprland.monitors
    readonly property Client activeClient: Client {}
    readonly property HyprlandWorkspace activeWorkspace: focusedMonitor?.activeWorkspace ?? null
    readonly property HyprlandMonitor focusedMonitor: Hyprland.monitors.values.find(m => m.lastIpcObject.focused) ?? null

    function reload() {
        Hyprland.refreshWorkspaces();
        Hyprland.refreshMonitors();
        getClients.running = true;
        getActiveClient.running = true;
    }

    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: ["sh", "-c", "hyprctl -j clients | jq -c"]
        stdout: SplitParser {
            onRead: data => {
                const clients = JSON.parse(data);
                root.clients = clients.map(c => clientComp.createObject(root, {
                        lastIpcObject: c
                    })).filter(c => c);
            }
        }
    }

    Process {
        id: getActiveClient
        command: ["sh", "-c", "hyprctl -j activewindow | jq -c"]
        stdout: SplitParser {
            onRead: data => root.activeClient.lastIpcObject = JSON.parse(data)
        }
    }

    component Client: QtObject {
        property var lastIpcObject
        property string address: lastIpcObject?.address ?? ""
        property string wmClass: lastIpcObject?.class ?? ""
        property string title: lastIpcObject?.title ?? ""
        property string initialClass: lastIpcObject?.initialClass ?? ""
        property string initialTitle: lastIpcObject?.initialTitle ?? ""
        property int x: (lastIpcObject?.at ?? [])[0] ?? 0
        property int y: (lastIpcObject?.at ?? [])[1] ?? 0
        property int width: (lastIpcObject?.size ?? [])[0] ?? 0
        property int height: (lastIpcObject?.size ?? [])[1] ?? 0
        property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject?.workspace?.id) ?? null
        property bool floating: lastIpcObject?.floating ?? false
        property bool fullscreen: lastIpcObject?.fullscreen ?? false
        property int pid: lastIpcObject?.pid ?? 0
    }

    Component {
        id: clientComp

        Client {}
    }
}