summaryrefslogtreecommitdiff
path: root/services/Hyprland.qml
blob: 9ca1d0e9be2bff82426afbc70c9bf5f19851a44c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
pragma Singleton
pragma ComponentBehavior: Bound

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

Singleton {
    id: root

    property list<var> clients: []
    property list<var> monitors: []
    property list<var> workspaces: []
    property var activeClient: null
    property var activeWorkspace: null
    property var focusedMonitor: null

    function reload() {
        getClients.running = true;
        getMonitors.running = true;
        getWorkspaces.running = true;
        getActiveClient.running = true;
        getActiveWorkspace.running = true;
    }

    Component.onCompleted: reload()

    Connections {
        target: Hyprland
        function onRawEvent(event: string): void {
            if (!event.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`]
        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);
            }
        }

        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 {
        id: getActiveClient
        type: "activewindow"
        prop: "activeClient"
        array: false
        function transform(client) {
            return transformClient(client);
        }
    }

    HyprData {
        id: getActiveWorkspace
        type: "activeworkspace"
        prop: "activeWorkspace"
        array: false
        function transform(workspace) {
            return transformWorkspace(workspace);
        }
    }
}