aboutsummaryrefslogtreecommitdiffstats
path: root/appearance/AppearancePanel.qml
blob: 708682cdf136838fb2d10172782c9cb490b13b9f (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
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
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import Quickshell
import Quickshell.Wayland
import QtQuick

Scope {
    id: root

    property string monitor: "DP-1"
    property bool open: false
    property string tab: "wallpaper"
    property string notice: ""

    // What the mock screens show. Hovering a thumbnail previews it on the
    // targeted screen; the other keeps whatever is currently set.
    property string hovering: ""

    readonly property var screenObj:
        Quickshell.screens.find(s => s.name === root.monitor) ?? Quickshell.screens[0]

    function show(which) {
        if (which) root.tab = which;
        root.notice = "";
        // Schemes and wallpapers can both have changed since this shell
        // started, which for an autostarted one is the whole session.
        Udt.refresh();
        Wallpapers.refresh();
        root.open = true;
    }
    function close() { root.open = false; }
    function toggle(which) { root.open ? close() : show(which); }

    Connections {
        target: Udt
        function onApplied(scheme, ok, message) {
            // install.sh reloads nothing, so the panel has to say what is
            // still showing the old scheme rather than pretend it is done.
            root.notice = ok
                ? `${scheme} applied. Reload: hyprctl reload, waybar, kitty, conky. Qt and GTK apps need restarting.`
                : `failed: ${message}`;
        }
    }

    Connections {
        target: Wallpapers
        function onApplied(ok, message) {
            root.notice = ok ? "" : `wallpaper failed: ${message}`;
            if (ok) root.close();
        }
    }

    // Quickshell exits once no window is visible, and this panel is closed
    // most of the time. See AGENTS.md.
    PanelWindow {
        visible: true
        implicitWidth: 1
        implicitHeight: 1
        color: "transparent"
        exclusionMode: ExclusionMode.Ignore
        mask: Region {}
        WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
    }

    LazyLoader {
        active: root.open

        PanelWindow {
            id: win
            screen: root.screenObj

            anchors { top: true; left: true; right: true; bottom: true }
            color: "transparent"
            exclusionMode: ExclusionMode.Ignore
            WlrLayershell.layer: WlrLayer.Overlay
            WlrLayershell.namespace: "quickshell-appearance"
            WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive

            Rectangle {
                anchors.fill: parent
                color: "#000000"
                opacity: 0.5
                MouseArea { anchors.fill: parent; onClicked: root.close() }
            }

            // Keys reach a focused item, never the window itself.
            Item {
                anchors.fill: parent
                focus: true
                Keys.onEscapePressed: root.close()
                Keys.onPressed: event => {
                    if (event.key === Qt.Key_Tab) {
                        root.tab = root.tab === "theme" ? "wallpaper" : "theme";
                        event.accepted = true;
                    }
                }
            }

            Rectangle {
                anchors.centerIn: parent
                width: win.width - 120
                height: win.height - 100
                radius: 14
                color: Qt.alpha(Theme.base, 0.72)
                border.width: 1
                border.color: Qt.alpha(Theme.text, 0.12)

                MouseArea { anchors.fill: parent }

                Column {
                    anchors.fill: parent
                    anchors.margins: 20
                    spacing: 16

                    Row {
                        spacing: 8
                        Tab {
                            text: "Wallpaper"
                            selected: root.tab === "wallpaper"
                            onClicked: root.tab = "wallpaper"
                        }
                        Tab {
                            text: "Theme"
                            selected: root.tab === "theme"
                            onClicked: root.tab = "theme"
                        }
                        Item { width: 12; height: 1 }
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            text: "Tab switches · Esc closes"
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                            color: Theme.overlay
                        }
                    }

                    Text {
                        visible: root.notice !== ""
                        width: parent.width
                        wrapMode: Text.Wrap
                        text: root.notice
                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
                        color: root.notice.indexOf("failed") === 0 ? Theme.red : Theme.green
                    }

                    Loader {
                        width: parent.width
                        height: parent.height - y
                        sourceComponent: root.tab === "theme" ? themeTab : wallpaperTab
                    }
                }
            }
        }
    }

    // --- theme ------------------------------------------------------------

    Component {
        id: themeTab

        Flickable {
            contentHeight: col.implicitHeight
            clip: true

            Column {
                id: col
                width: parent.width
                spacing: 10

                Repeater {
                    model: Udt.names

                    Rectangle {
                        required property string modelData
                        readonly property var sw: Udt.swatches[modelData] ?? ({})
                        readonly property bool isCurrent: Udt.current === modelData

                        width: col.width
                        implicitHeight: 96
                        radius: 10
                        color: hover.hovered ? Qt.alpha(Theme.surface, 0.75)
                                             : Qt.alpha(Theme.surface, 0.35)
                        border.width: 1
                        border.color: isCurrent ? Qt.alpha(Theme.accent, 0.6) : "transparent"

                        HoverHandler { id: hover }
                        MouseArea {
                            anchors.fill: parent
                            enabled: !Udt.applying && !isCurrent
                            cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
                            onClicked: Udt.apply(modelData)
                        }

                        Row {
                            anchors.fill: parent
                            anchors.margins: 14
                            spacing: 16

                            // A mock of the desktop in that scheme's colours:
                            // swatches alone say what the colours are, this
                            // says how they sit together.
                            Rectangle {
                                anchors.verticalCenter: parent.verticalCenter
                                width: 150; height: 68
                                radius: 6
                                color: sw.bg ?? Theme.base
                                border.width: 1
                                border.color: Qt.alpha(sw.text ?? Theme.text, 0.15)
                                clip: true

                                Column {
                                    anchors.fill: parent
                                    anchors.margins: 7
                                    spacing: 5

                                    Row {
                                        spacing: 4
                                        Rectangle {
                                            width: 26; height: 8; radius: 2
                                            color: sw.accent ?? Theme.accent
                                        }
                                        Rectangle {
                                            width: 16; height: 8; radius: 2
                                            color: sw.surface ?? Theme.surface
                                        }
                                        Rectangle {
                                            width: 16; height: 8; radius: 2
                                            color: sw.surface ?? Theme.surface
                                        }
                                    }

                                    Rectangle {
                                        width: parent.width; height: 20; radius: 3
                                        color: sw.surface ?? Theme.surface

                                        Rectangle {
                                            anchors.verticalCenter: parent.verticalCenter
                                            x: 5; width: 60; height: 5; radius: 2
                                            color: Qt.alpha(sw.text ?? Theme.text, 0.75)
                                        }
                                        Rectangle {
                                            anchors.verticalCenter: parent.verticalCenter
                                            anchors.right: parent.right
                                            anchors.rightMargin: 5
                                            width: 22; height: 9; radius: 3
                                            color: sw.accent ?? Theme.accent
                                        }
                                    }

                                    Row {
                                        spacing: 4
                                        Rectangle { width: 9; height: 9; radius: 5; color: sw.green ?? Theme.green }
                                        Rectangle { width: 9; height: 9; radius: 5; color: sw.yellow ?? Theme.yellow }
                                        Rectangle { width: 9; height: 9; radius: 5; color: sw.red ?? Theme.red }
                                    }
                                }
                            }

                            Column {
                                anchors.verticalCenter: parent.verticalCenter
                                spacing: 8

                                Row {
                                    spacing: 8
                                    Text {
                                        text: modelData
                                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize; bold: true }
                                        color: Theme.text
                                    }
                                    Text {
                                        anchors.verticalCenter: parent.verticalCenter
                                        visible: isCurrent
                                        text: "current"
                                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                                        color: Theme.accent
                                    }
                                    Text {
                                        anchors.verticalCenter: parent.verticalCenter
                                        visible: Udt.applying
                                        text: "applying…"
                                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                                        color: Theme.overlay
                                    }
                                }

                                Row {
                                    spacing: 5
                                    Repeater {
                                        model: [sw.bg, sw.surface, sw.text, sw.accent,
                                                sw.green, sw.yellow, sw.red]
                                        Rectangle {
                                            required property var modelData
                                            visible: modelData !== undefined && modelData !== ""
                                            width: 22; height: 22; radius: 4
                                            color: modelData ?? "transparent"
                                            border.width: 1
                                            border.color: Qt.alpha(Theme.text, 0.1)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // --- wallpaper --------------------------------------------------------

    Component {
        id: wallpaperTab

        Row {
            spacing: 20

            Column {
                width: parent.width - mockPane.width - parent.spacing
                height: parent.height
                spacing: 12

                Row {
                    spacing: 8
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        text: "Set on"
                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
                        color: Theme.subtext
                    }
                    Tab {
                        text: "Horizontal"
                        selected: Wallpapers.target === "H"
                        onClicked: Wallpapers.target = "H"
                    }
                    Tab {
                        text: "Vertical"
                        selected: Wallpapers.target === "V"
                        onClicked: Wallpapers.target = "V"
                    }
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        text: Wallpapers.scanning ? "scanning…"
                            : Wallpapers.applying ? "applying…"
                            : Wallpapers.files.length + " wallpapers"
                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                        color: Theme.overlay
                    }
                }

                GridView {
                    width: parent.width
                    height: parent.height - y
                    clip: true
                    cellWidth: Math.floor(width / Math.max(1, Math.floor(width / 300)))
                    cellHeight: cellWidth * 9 / 16 + 26
                    // Several hundred files: only the visible thumbnails decode.
                    cacheBuffer: cellHeight * 2
                    model: Wallpapers.files

                    delegate: Item {
                        required property string modelData
                        width: GridView.view.cellWidth
                        height: GridView.view.cellHeight

                        Rectangle {
                            readonly property bool staged:
                                Wallpapers.pendingH === modelData || Wallpapers.pendingV === modelData

                            anchors.fill: parent
                            anchors.margins: 6
                            radius: 8
                            color: Qt.alpha(Theme.surface, thumbHover.hovered ? 0.8 : 0.3)
                            border.width: staged ? 2 : 1
                            border.color: staged ? Theme.accent
                                        : thumbHover.hovered ? Qt.alpha(Theme.accent, 0.6)
                                        : "transparent"
                            clip: true

                            HoverHandler {
                                id: thumbHover
                                // Hovering previews this image on the mock
                                // screen it would actually land on.
                                onHoveredChanged:
                                    root.hovering = hovered ? modelData
                                                 : (root.hovering === modelData ? "" : root.hovering)
                            }
                            MouseArea {
                                anchors.fill: parent
                                enabled: !Wallpapers.applying
                                cursorShape: Qt.PointingHandCursor
                                onClicked: Wallpapers.pick(modelData)
                            }

                            Column {
                                anchors.fill: parent
                                anchors.margins: 6
                                spacing: 4

                                Image {
                                    width: parent.width
                                    height: parent.height - 18
                                    source: "file://" + modelData
                                    asynchronous: true
                                    cache: false
                                    fillMode: Image.PreserveAspectCrop
                                    // Decode at display size: full-resolution
                                    // wallpapers would be megabytes each in memory.
                                    sourceSize.width: 480
                                }

                                Text {
                                    width: parent.width
                                    elide: Text.ElideMiddle
                                    text: Wallpapers.basename(modelData)
                                    font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 5 }
                                    color: Theme.subtext
                                }
                            }
                        }
                    }
                }
            }

            // The two screens as they sit on the desk: DP-3 rotated upright on
            // the left, DP-1 wide on the right, centred against each other the
            // way Hyprland has them. Hovering a thumbnail fills the screen it
            // would be set on; the other keeps what is on it now.
            Item {
                id: mockPane
                // A third of the panel rather than a fixed width, so the
                // preview keeps its share when the panel is resized.
                width: Math.round(parent.width * 0.33)
                height: parent.height

                // Divisor is the two panels side by side plus the gap; the
                // bezels and stands are drawn outside that, hence the margin.
                readonly property real scale: (width * 0.92) / (1080 + 2560 + 160)

                Column {
                    anchors.centerIn: parent
                    spacing: 14

                    Row {
                        spacing: Math.round(160 * mockPane.scale)

                        MockScreen {
                            anchors.verticalCenter: parent.verticalCenter
                            label: "DP-3"
                            targeted: Wallpapers.target === "V"
                            source: (targeted && root.hovering !== "")
                                    ? root.hovering : Wallpapers.shown("V")
                            // DP-3 has transform=1, so it stands upright.
                            panelWidth: Math.round(1080 * mockPane.scale)
                            panelHeight: Math.round(1920 * mockPane.scale)
                        }

                        MockScreen {
                            anchors.verticalCenter: parent.verticalCenter
                            label: "DP-1"
                            targeted: Wallpapers.target === "H"
                            source: (targeted && root.hovering !== "")
                                    ? root.hovering : Wallpapers.shown("H")
                            panelWidth: Math.round(2560 * mockPane.scale)
                            panelHeight: Math.round(1080 * mockPane.scale)
                        }
                    }

                    Text {
                        anchors.horizontalCenter: parent.horizontalCenter
                        width: mockPane.width
                        horizontalAlignment: Text.AlignHCenter
                        wrapMode: Text.Wrap
                        text: root.hovering !== "" ? Wallpapers.basename(root.hovering)
                            : Wallpapers.dirty ? "click Apply to set"
                            : "click a wallpaper to stage it"
                        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                        color: Theme.overlay
                    }

                    Row {
                        anchors.horizontalCenter: parent.horizontalCenter
                        spacing: 8

                        Tab {
                            text: Wallpapers.applying ? "applying…" : "Apply"
                            selected: Wallpapers.dirty && !Wallpapers.applying
                            enabled: Wallpapers.dirty && !Wallpapers.applying
                            onClicked: Wallpapers.apply()
                        }
                        Tab {
                            text: "Reset"
                            enabled: Wallpapers.dirty && !Wallpapers.applying
                            onClicked: Wallpapers.clearPending()
                        }
                    }
                }
            }
        }
    }
}