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
|
import Quickshell
import Quickshell.Io
import QtQuick
Item {
id: root
implicitWidth: row.implicitWidth
implicitHeight: 32
ListModel { id: workspaceModel }
function updateWorkspaces(json) {
try {
const ws = JSON.parse(json)
workspaceModel.clear()
ws.forEach(w => workspaceModel.append({
wsNum: w.num,
wsName: w.name,
wsFocused: w.focused
}))
} catch (_) {}
}
Process {
id: watcher
command: ["swaymsg", "-t", "subscribe", "-m", "[\"workspace\"]"]
running: true
stdout: SplitParser {
onRead: _ => {
if (!refresher.running) refresher.running = true
}
}
}
Process {
id: refresher
command: ["swaymsg", "-t", "get_workspaces", "-r"]
property string buf: ""
stdout: SplitParser {
onRead: line => refresher.buf += line
}
onRunningChanged: {
if (!running && buf !== "") {
root.updateWorkspaces(buf)
buf = ""
}
}
Component.onCompleted: running = true
}
Row {
id: row
anchors {
verticalCenter: parent.verticalCenter
}
spacing: 2
Repeater {
model: workspaceModel
delegate: Rectangle {
required property int wsNum
required property string wsName
required property bool wsFocused
width: 26
height: 26
color: wsFocused ? Theme.focus : Theme.transparent
radius: 3
Text {
anchors.centerIn: parent
text: wsNum
color: Theme.text
font.pixelSize: 12
}
Process {
id: switcher
command: ["swaymsg", "workspace", "number", wsNum.toString()]
}
MouseArea {
anchors.fill: parent
onClicked: {
switcher.running = false
switcher.running = true
}
}
}
}
}
}
|