-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWallpaperShufflerWidget.qml
More file actions
511 lines (449 loc) · 18.8 KB
/
WallpaperShufflerWidget.qml
File metadata and controls
511 lines (449 loc) · 18.8 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Common
import qs.Services
import qs.Widgets
import qs.Modules.Plugins
PluginComponent {
id: root
// Expand tilde to home directory
function expandPath(path) {
if (path.startsWith("~/")) {
return Quickshell.env("HOME") + path.substring(1);
}
return path;
}
property string wallpaperPath: {
var path = pluginData.wallpaperPath || "~/Pictures";
return expandPath(path);
}
property string shuffleInfoPath: wallpaperPath + "/.dms-wallpaper-shuffler"
property string currentWallpaper: ""
property string nextWallpaper: ""
property int currentIndex: 0
property int totalWallpapers: 0
property int shuffleInterval: (pluginData.shuffleInterval || 1800) * 1000
property string scriptPath: Qt.resolvedUrl("shuffle-wallpapers").toString().replace("file://", "")
property string getWallpaperScriptPath: Qt.resolvedUrl("get-current-wallpaper").toString().replace("file://", "")
popoutWidth: 420
popoutHeight: 690
// Invisible preloader images - keep thumbnails cached for instant display
Item {
visible: false
Image {
id: currentPreloader
source: root.currentWallpaper ? "file://" + root.currentWallpaper : ""
sourceSize.width: 800
sourceSize.height: 450
asynchronous: true
cache: true
}
Image {
id: nextPreloader
source: root.nextWallpaper ? "file://" + root.nextWallpaper : ""
sourceSize.width: 800
sourceSize.height: 450
asynchronous: true
cache: true
}
}
popoutContent: Component {
Column {
width: parent.width
spacing: Theme.spacingM
// Header with close button
Item {
width: parent.width
height: 40
StyledText {
text: I18n.tr("Wallpaper Shuffler")
font.pixelSize: Theme.fontSizeLarge + 4
font.weight: Font.Bold
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
Rectangle {
width: 32
height: 32
radius: 16
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
color: closeArea.containsMouse ? Theme.errorHover : "transparent"
DankIcon {
anchors.centerIn: parent
name: "close"
size: Theme.iconSize - 4
color: closeArea.containsMouse ? Theme.error : Theme.onSurface
}
MouseArea {
id: closeArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onPressed: {
if (closePopout) {
closePopout();
}
}
}
}
}
// Folder path section
Rectangle {
width: parent.width
height: pathColumn.height + Theme.spacingM * 2
radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHigh, 0.4)
border.width: 0
Column {
id: pathColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingXS
Row {
spacing: Theme.spacingXS
width: parent.width
DankIcon {
name: "folder"
size: Theme.iconSize - 4
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: I18n.tr("Shuffle Folder")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
font.weight: Font.Medium
anchors.verticalCenter: parent.verticalCenter
}
}
StyledText {
text: root.wallpaperPath || "~/Pictures"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width
elide: Text.ElideMiddle
}
}
}
// Current wallpaper section
Rectangle {
width: parent.width
height: currentColumn.height + Theme.spacingM * 2
radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHigh, 0.4)
border.width: 0
Column {
id: currentColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingS
Row {
spacing: Theme.spacingXS
width: parent.width
DankIcon {
name: "image"
size: Theme.iconSize - 4
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: I18n.tr("Current Wallpaper")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
font.weight: Font.Medium
anchors.verticalCenter: parent.verticalCenter
}
}
// Current wallpaper preview
Rectangle {
width: parent.width
height: 180
radius: Theme.cornerRadius
color: Theme.surfaceContainer
border.color: Theme.outlineLight
border.width: 1
clip: true
CachingImage {
id: currentImage
anchors.fill: parent
source: root.currentWallpaper ? "file://" + root.currentWallpaper : ""
sourceSize.width: 800
sourceSize.height: 450
fillMode: Image.PreserveAspectFit
asynchronous: true
cache: true
visible: root.currentWallpaper !== ""
Rectangle {
anchors.fill: parent
color: "transparent"
border.color: Theme.outlineLight
border.width: 1
radius: Theme.cornerRadius
}
}
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
visible: !root.currentWallpaper
DankIcon {
name: "broken_image"
size: 48
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("No wallpaper set")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
StyledText {
text: root.currentWallpaper ? root.currentWallpaper.split('/').pop() : I18n.tr("None")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width
elide: Text.ElideMiddle
horizontalAlignment: Text.AlignHCenter
}
}
}
// Next wallpaper section
Rectangle {
width: parent.width
height: nextColumn.height + Theme.spacingM * 2
radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHigh, 0.4)
border.width: 0
Column {
id: nextColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingS
Row {
spacing: Theme.spacingXS
width: parent.width
DankIcon {
name: "skip_next"
size: Theme.iconSize - 4
color: Theme.secondary
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: I18n.tr("Next Wallpaper")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
font.weight: Font.Medium
anchors.verticalCenter: parent.verticalCenter
}
}
// Next wallpaper preview
Rectangle {
width: parent.width
height: 180
radius: Theme.cornerRadius
color: Theme.surfaceContainer
border.color: Theme.outlineLight
border.width: 1
clip: true
CachingImage {
id: nextImage
anchors.fill: parent
source: root.nextWallpaper ? "file://" + root.nextWallpaper : ""
sourceSize.width: 800
sourceSize.height: 450
fillMode: Image.PreserveAspectFit
asynchronous: true
cache: true
visible: root.nextWallpaper !== ""
Rectangle {
anchors.fill: parent
color: "transparent"
border.color: Theme.outlineLight
border.width: 1
radius: Theme.cornerRadius
}
}
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
visible: !root.nextWallpaper
DankIcon {
name: "image_not_supported"
size: 40
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("No next wallpaper")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
StyledText {
text: root.nextWallpaper ? root.nextWallpaper.split('/').pop() : I18n.tr("None")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width
elide: Text.ElideMiddle
horizontalAlignment: Text.AlignHCenter
}
}
}
}
}
Component.onCompleted: {
console.log("=== Wallpaper Shuffler Widget Started ===");
console.log("Plugin Data:", JSON.stringify(pluginData));
console.log("Wallpaper Path (configured):", pluginData.wallpaperPath);
console.log("Wallpaper Path (expanded):", root.wallpaperPath);
console.log("Shuffle Interval:", root.shuffleInterval, "ms");
console.log("Shuffle Script Path:", root.scriptPath);
console.log("Get Wallpaper Script Path:", root.getWallpaperScriptPath);
// Immediately restore the current wallpaper from shuffle state to prevent
// system wallpaper daemon from taking over on boot
restoreCurrentWallpaperProcess.running = true;
}
// Read wallpaper info
Process {
id: wallpaperInfoProcess
command: ["bash", root.getWallpaperScriptPath, root.wallpaperPath]
running: false
stdout: StdioCollector {
onStreamFinished: {
const output = text.trim();
const lines = output.split('\n');
if (lines.length >= 4) {
currentWallpaper = lines[0] || "";
nextWallpaper = lines[1] || "";
currentIndex = parseInt(lines[2]) || 0;
totalWallpapers = parseInt(lines[3]) || 0;
console.log("Wallpaper info updated:", currentIndex, "/", totalWallpapers);
console.log("Current:", currentWallpaper);
console.log("Next:", nextWallpaper);
} else {
console.log("get-current-wallpaper returned invalid data:", output);
}
}
}
onExited: exitCode => {
if (exitCode !== 0) {
console.log("get-current-wallpaper script failed, exit code:", exitCode);
}
}
}
// Shuffle wallpaper process
Process {
id: shuffleProcess
command: []
running: false
onRunningChanged: {
console.log("Shuffle process running:", running);
if (!running) {
console.log("Wallpaper shuffled successfully");
// Update wallpaper info after shuffling
wallpaperInfoProcess.running = true;
}
}
onExited: (exitCode, exitStatus) => {
console.log("Shuffle process exited with code:", exitCode);
}
}
// Timer to shuffle wallpapers
Timer {
interval: root.shuffleInterval
running: true
repeat: true
triggeredOnStart: true
onTriggered: {
console.log("Timer triggered - starting shuffle process");
console.log("Using wallpaper path:", root.wallpaperPath);
shuffleProcess.command = ["bash", root.scriptPath, root.wallpaperPath];
shuffleProcess.running = true;
}
}
// Process to restore current wallpaper on startup (before timer fires)
Process {
id: restoreCurrentWallpaperProcess
command: ["bash", "-c",
`WALLPAPER_DIR="${root.wallpaperPath}"
SHUFFLE_FILE="$WALLPAPER_DIR/.dms-wallpaper-shuffler/wallpaper_shuffle_list"
CURRENT_INDEX_FILE="$WALLPAPER_DIR/.dms-wallpaper-shuffler/wallpaper_current_index"
# Check if shuffle state exists
if [ -f "$SHUFFLE_FILE" ] && [ -f "$CURRENT_INDEX_FILE" ]; then
current_index=$(cat "$CURRENT_INDEX_FILE")
current_wallpaper=$(sed -n "${current_index}p" "$SHUFFLE_FILE")
if [ -n "$current_wallpaper" ] && [ -f "$current_wallpaper" ]; then
echo "Restoring wallpaper: $current_wallpaper" >&2
dms ipc call wallpaper set "$current_wallpaper"
else
echo "No valid wallpaper to restore" >&2
fi
else
echo "No shuffle state found, will create on first timer trigger" >&2
fi`
]
running: false
onExited: exitCode => {
console.log("Wallpaper restoration completed with code:", exitCode);
// Now update the widget info
wallpaperInfoProcess.running = true;
}
}
// Update wallpaper info periodically
Timer {
interval: 5000
running: true
repeat: true
triggeredOnStart: true
onTriggered: wallpaperInfoProcess.running = true
}
horizontalBarPill: Component {
Row {
spacing: Theme.spacingXS
rightPadding: Theme.spacingXS
StyledText {
text: " "
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
visible: root.showCounter
text: root.totalWallpapers > 0 ? `${root.currentIndex}/${root.totalWallpapers}` : "--"
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
}
}
verticalBarPill: Component {
Column {
spacing: Theme.spacingXS
StyledText {
text: " "
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
visible: root.showCounter
text: root.totalWallpapers > 0 ? `${root.currentIndex}/${root.totalWallpapers}` : "--"
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
}