-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverlay.qml
More file actions
358 lines (306 loc) · 12.1 KB
/
Copy pathOverlay.qml
File metadata and controls
358 lines (306 loc) · 12.1 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import QtQuick
import qs.Commons
// The pre-Quattro theme switcher: a filterable textual list on the left, the
// selected theme's preview on the right. Summon it with
// omarchy-shell shell summon io.github.bruce-forte.old-theme-switcher '{}'
// Enter applies the theme through `omarchy theme set`; nothing is written back
// to the caller, so the summon returns immediately.
Item {
id: root
property var themes: []
property string filterText: ""
property int selectedIndex: 0
property bool opened: false
property bool loaded: false
property color scrim: Color.menu.scrim
property color background: Color.menu.background
property color foreground: Color.menu.text
property color border: Color.menu.border
property color selectedBackground: Color.menu.selectedBackground
property color selectedText: Color.menu.selectedText
// themes.sh already bounds what it emits, but the overlay lives in the
// long-lived shell process, so it enforces the same limits itself rather than
// trusting its helper: an oversized payload is dropped instead of parsed, and
// only an absolute path is ever handed to the preview loader.
readonly property int maxPayloadChars: 4 * 1024 * 1024
readonly property int maxThemes: 500
readonly property string pluginDir: String(Qt.resolvedUrl(".")).replace(/^file:\/\//, "").replace(/\/$/, "")
readonly property var filtered: {
var needle = filterText.toLowerCase()
if (!needle) return themes
var out = []
for (var i = 0; i < themes.length; i++) {
if (String(themes[i].name).toLowerCase().indexOf(needle) !== -1)
out.push(themes[i])
}
return out
}
readonly property var currentItem: (selectedIndex >= 0 && selectedIndex < filtered.length) ? filtered[selectedIndex] : null
readonly property string currentName: currentItem ? String(currentItem.name) : ""
readonly property string currentPreview: {
if (!currentItem) return ""
var path = String(currentItem.preview || "")
return path.charAt(0) === "/" ? path : ""
}
onFilteredChanged: if (selectedIndex >= filtered.length) selectedIndex = Math.max(0, filtered.length - 1)
function selectAdjacent(step) {
if (filtered.length === 0) return
var next = selectedIndex + step
if (next < 0) next = filtered.length - 1
else if (next >= filtered.length) next = 0
selectedIndex = next
list.positionViewAtIndex(next, ListView.Contain)
}
function indexForName(name) {
for (var i = 0; i < filtered.length; i++) {
if (String(filtered[i].name) === name) return i
}
return 0
}
function applySelected() {
if (!currentName) {
close()
return
}
Quickshell.execDetached(["omarchy-theme-set", currentName])
opened = false
}
// Lifecycle hooks invoked by omarchy-shell summon/hide.
function open(payload) {
filterText = ""
opened = true
listProc.running = true
}
function close() {
opened = false
}
function toggle() {
if (opened) close()
else open("")
}
// Theme names, their previews, and which one is live. Re-read on every
// summon so an installed or removed theme shows up without a shell restart.
Process {
id: listProc
command: [root.pluginDir + "/themes.sh"]
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: {
var raw = String(text || "")
if (raw.length > root.maxPayloadChars) {
console.warn("old-theme-switcher: theme list is " + raw.length
+ " chars, over the " + root.maxPayloadChars + " limit — ignoring it")
raw = ""
}
var payload = {}
try {
payload = JSON.parse(raw || "{}") || {}
} catch (e) {
payload = {}
}
var rows = Array.isArray(payload.rows) ? payload.rows : []
root.themes = rows.length > root.maxThemes ? rows.slice(0, root.maxThemes) : rows
root.loaded = true
root.selectedIndex = root.indexForName(String(payload.current || ""))
Qt.callLater(function() {
list.positionViewAtIndex(root.selectedIndex, ListView.Contain)
list.forceActiveFocus()
})
}
}
}
PanelWindow {
id: panel
visible: root.opened && root.loaded
anchors { top: true; bottom: true; left: true; right: true }
color: "transparent"
WlrLayershell.namespace: "omarchy-old-theme-switcher"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.keyboardFocus: panel.visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
exclusionMode: ExclusionMode.Ignore
Rectangle {
anchors.fill: parent
color: root.scrim
}
MouseArea {
anchors.fill: parent
onClicked: root.close()
}
Rectangle {
id: card
anchors.centerIn: parent
readonly property int contentMargin: Style.space(14)
readonly property int columnGap: Style.space(14)
// Previews are screenshots of a desktop, so the pane is shaped like one:
// sized 16:9 the image fills it edge to edge instead of letterboxing.
readonly property real previewAspect: 16 / 9
readonly property int previewWidth: Math.round((width - contentMargin * 2 - columnGap) * 0.66)
width: Math.min(parent.width - Style.space(80), Style.space(1100))
height: Math.min(parent.height - Style.space(120),
Math.round(previewWidth / previewAspect) + contentMargin * 2)
color: root.background
radius: Style.space(8)
border.width: Style.spacing.hairline
border.color: root.border
// Swallow clicks so only the scrim dismisses.
MouseArea { anchors.fill: parent; onClicked: {} }
Item {
anchors.fill: parent
anchors.margins: card.contentMargin
Item {
id: listColumn
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
width: parent.width - card.columnGap - card.previewWidth
Item {
id: header
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: Style.font.title + Style.space(16)
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.right: parent.right
elide: Text.ElideRight
color: root.foreground
font.family: Style.font.menuFamily
font.pixelSize: Style.font.title
text: root.filterText ? "Theme: " + root.filterText : "Theme"
}
}
Rectangle {
id: headerRule
anchors.top: header.bottom
anchors.left: parent.left
anchors.right: parent.right
height: Style.spacing.hairline
color: root.border
opacity: 0.5
}
ListView {
id: list
anchors.top: headerRule.bottom
anchors.topMargin: Style.space(6)
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
clip: true
focus: true
model: root.filtered
currentIndex: root.selectedIndex
highlightMoveDuration: 0
Keys.priority: Keys.BeforeItem
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
if (root.filterText) root.filterText = ""
else root.close()
event.accepted = true
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
root.applySelected()
event.accepted = true
} else if (event.key === Qt.Key_Up || (event.key === Qt.Key_Tab && event.modifiers & Qt.ShiftModifier) || event.key === Qt.Key_Backtab
|| (event.key === Qt.Key_P && event.modifiers === Qt.ControlModifier)) {
root.selectAdjacent(-1)
event.accepted = true
} else if (event.key === Qt.Key_Down || event.key === Qt.Key_Tab
|| (event.key === Qt.Key_N && event.modifiers === Qt.ControlModifier)) {
root.selectAdjacent(1)
event.accepted = true
} else if (event.key === Qt.Key_Home) {
root.selectedIndex = 0
list.positionViewAtIndex(0, ListView.Contain)
event.accepted = true
} else if (event.key === Qt.Key_End) {
root.selectedIndex = Math.max(0, root.filtered.length - 1)
list.positionViewAtIndex(root.selectedIndex, ListView.Contain)
event.accepted = true
} else if (Util.editsFilter(event, root.filterText)) {
root.filterText = Util.editedFilter(event, root.filterText)
event.accepted = true
} else if (event.text && event.text.length === 1 && event.text.charCodeAt(0) >= 32 && event.text.charCodeAt(0) !== 127
&& (event.modifiers === Qt.NoModifier || event.modifiers === Qt.ShiftModifier)) {
root.filterText += event.text
event.accepted = true
}
}
delegate: Rectangle {
id: row
required property int index
required property var modelData
width: ListView.view.width
height: Style.font.body + Style.space(14)
radius: Style.space(4)
color: index === root.selectedIndex ? root.selectedBackground : "transparent"
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: Style.space(8)
anchors.right: parent.right
anchors.rightMargin: Style.space(8)
elide: Text.ElideRight
color: index === root.selectedIndex ? root.selectedText : root.foreground
font.family: Style.font.menuFamily
font.pixelSize: Style.font.body
text: String(row.modelData.name)
}
MouseArea {
anchors.fill: parent
onClicked: root.selectedIndex = row.index
onDoubleClicked: {
root.selectedIndex = row.index
root.applySelected()
}
}
}
}
}
Rectangle {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: listColumn.right
anchors.leftMargin: card.columnGap
anchors.right: parent.right
color: Util.alpha(root.foreground, 0.06)
radius: Style.space(6)
clip: true
// Fit rather than crop, and decode at the pane's true device
// resolution: cropping a preview decoded to the pane's width had to
// scale it back up to cover the pane's height, which is what made it
// blurry. Mipmapping keeps the (always downward) scale clean.
//
// sourceSize caps the decode at pane resolution rather than the
// image's own, and asynchronous keeps the decode off the GUI thread,
// so a preview that is slow or impossible to decode ends as
// "No preview" instead of a frozen shell.
Image {
id: preview
anchors.fill: parent
source: Util.fileUrl(root.currentPreview)
fillMode: Image.PreserveAspectFit
asynchronous: true
cache: true
smooth: true
mipmap: true
sourceSize.width: Math.round(width * Screen.devicePixelRatio)
sourceSize.height: Math.round(height * Screen.devicePixelRatio)
visible: status === Image.Ready
}
Text {
anchors.centerIn: parent
visible: !preview.visible
color: root.foreground
opacity: 0.6
font.family: Style.font.menuFamily
font.pixelSize: Style.font.body
text: root.currentName ? "No preview" : "No matches"
}
}
}
}
}
}