summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/Modules/Settings/DisplayWidgetsTab.qml
blob: 59f65137087c99cf6f8c49a0385f07ac0d43c7fa (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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
import QtQuick
import QtQuick.Layouts
import Quickshell
import qs.Common
import qs.Services
import qs.Widgets

Item {
    id: root

    LayoutMirroring.enabled: I18n.isRtl
    LayoutMirroring.childrenInherit: true

    function getBarComponentsFromSettings() {
        const bars = SettingsData.barConfigs || [];
        return bars.map(bar => ({
                    "id": "bar:" + bar.id,
                    "name": bar.name || "Bar",
                    "description": I18n.tr("Individual bar configuration"),
                    "icon": "toolbar",
                    "barId": bar.id
                }));
    }

    property var variantComponents: getVariantComponentsList()

    function getVariantComponentsList() {
        return [...getBarComponentsFromSettings(),
            {
                "id": "dock",
                "name": I18n.tr("Application Dock"),
                "description": I18n.tr("Bottom dock for pinned and running applications"),
                "icon": "dock"
            },
            {
                "id": "notifications",
                "name": I18n.tr("Notification Popups"),
                "description": I18n.tr("Notification toast popups"),
                "icon": "notifications"
            },
            {
                "id": "wallpaper",
                "name": I18n.tr("Wallpaper"),
                "description": I18n.tr("Desktop background images"),
                "icon": "wallpaper"
            },
            {
                "id": "osd",
                "name": I18n.tr("On-Screen Displays"),
                "description": I18n.tr("Volume, brightness, and other system OSDs"),
                "icon": "picture_in_picture"
            },
            {
                "id": "toast",
                "name": I18n.tr("Toast Messages"),
                "description": I18n.tr("System toast notifications"),
                "icon": "campaign"
            },
            {
                "id": "notepad",
                "name": I18n.tr("Notepad Slideout"),
                "description": I18n.tr("Quick note-taking slideout panel"),
                "icon": "sticky_note_2"
            }
        ];
    }

    Connections {
        target: SettingsData
        function onBarConfigsChanged() {
            variantComponents = getVariantComponentsList();
        }
    }

    function getScreenPreferences(componentId) {
        if (componentId.startsWith("bar:")) {
            const barId = componentId.substring(4);
            const barConfig = SettingsData.getBarConfig(barId);
            return barConfig?.screenPreferences || ["all"];
        }
        return SettingsData.screenPreferences && SettingsData.screenPreferences[componentId] || ["all"];
    }

    function setScreenPreferences(componentId, screenNames) {
        if (componentId.startsWith("bar:")) {
            const barId = componentId.substring(4);
            SettingsData.updateBarConfig(barId, {
                "screenPreferences": screenNames
            });
            return;
        }
        var prefs = SettingsData.screenPreferences || {};
        var newPrefs = Object.assign({}, prefs);
        newPrefs[componentId] = screenNames;
        SettingsData.set("screenPreferences", newPrefs);
    }

    function getShowOnLastDisplay(componentId) {
        if (componentId.startsWith("bar:")) {
            const barId = componentId.substring(4);
            const barConfig = SettingsData.getBarConfig(barId);
            return barConfig?.showOnLastDisplay ?? true;
        }
        return SettingsData.showOnLastDisplay && SettingsData.showOnLastDisplay[componentId] || false;
    }

    function setShowOnLastDisplay(componentId, enabled) {
        if (componentId.startsWith("bar:")) {
            const barId = componentId.substring(4);
            SettingsData.updateBarConfig(barId, {
                "showOnLastDisplay": enabled
            });
            return;
        }
        var prefs = SettingsData.showOnLastDisplay || {};
        var newPrefs = Object.assign({}, prefs);
        newPrefs[componentId] = enabled;
        SettingsData.set("showOnLastDisplay", newPrefs);
    }

    DankFlickable {
        anchors.fill: parent
        clip: true
        contentHeight: mainColumn.height + Theme.spacingXL
        contentWidth: width

        Column {
            id: mainColumn
            topPadding: 4

            width: Math.min(550, parent.width - Theme.spacingL * 2)
            anchors.horizontalCenter: parent.horizontalCenter
            spacing: Theme.spacingXL

            StyledRect {
                width: parent.width
                height: screensInfoSection.implicitHeight + Theme.spacingL * 2
                radius: Theme.cornerRadius
                color: Theme.surfaceContainerHigh
                border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
                border.width: 0

                Column {
                    id: screensInfoSection

                    anchors.fill: parent
                    anchors.margins: Theme.spacingL
                    spacing: Theme.spacingM

                    Row {
                        width: parent.width
                        spacing: Theme.spacingM

                        DankIcon {
                            name: "monitor"
                            size: Theme.iconSize
                            color: Theme.primary
                            anchors.verticalCenter: parent.verticalCenter
                        }

                        Column {
                            width: parent.width - Theme.iconSize - Theme.spacingM
                            spacing: Theme.spacingXS
                            anchors.verticalCenter: parent.verticalCenter

                            StyledText {
                                text: I18n.tr("Connected Displays")
                                font.pixelSize: Theme.fontSizeLarge
                                font.weight: Font.Medium
                                color: Theme.surfaceText
                                width: parent.width
                                horizontalAlignment: Text.AlignLeft
                            }

                            StyledText {
                                text: I18n.tr("Configure which displays show shell components")
                                font.pixelSize: Theme.fontSizeSmall
                                color: Theme.surfaceVariantText
                                wrapMode: Text.WordWrap
                                width: parent.width
                                horizontalAlignment: Text.AlignLeft
                            }
                        }
                    }

                    Column {
                        width: parent.width
                        spacing: Theme.spacingS

                        Column {
                            width: parent.width
                            spacing: Theme.spacingXS

                            Row {
                                width: parent.width
                                spacing: Theme.spacingM

                                StyledText {
                                    text: I18n.tr("Available Screens (%1)").arg(Quickshell.screens.length)
                                    font.pixelSize: Theme.fontSizeMedium
                                    font.weight: Font.Medium
                                    color: Theme.surfaceText
                                    horizontalAlignment: Text.AlignLeft
                                }

                                Item {
                                    width: 1
                                    height: 1
                                    Layout.fillWidth: true
                                }

                                Column {
                                    spacing: Theme.spacingXS
                                    anchors.verticalCenter: parent.verticalCenter

                                    StyledText {
                                        text: I18n.tr("Display Name Format")
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceVariantText
                                        anchors.horizontalCenter: parent.horizontalCenter
                                    }

                                    DankButtonGroup {
                                        id: displayModeGroup
                                        model: [I18n.tr("Name"), I18n.tr("Model")]
                                        currentIndex: SettingsData.displayNameMode === "model" ? 1 : 0
                                        onSelectionChanged: (index, selected) => {
                                            if (!selected)
                                                return;
                                            SettingsData.displayNameMode = index === 1 ? "model" : "system";
                                            SettingsData.saveSettings();
                                        }

                                        Connections {
                                            target: SettingsData
                                            function onDisplayNameModeChanged() {
                                                displayModeGroup.currentIndex = SettingsData.displayNameMode === "model" ? 1 : 0;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        Repeater {
                            model: Quickshell.screens

                            delegate: Rectangle {
                                width: parent.width
                                height: screenRow.implicitHeight + Theme.spacingS * 2
                                radius: Theme.cornerRadius
                                color: Theme.surfaceContainerHigh
                                border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.3)
                                border.width: 0

                                Row {
                                    id: screenRow

                                    anchors.fill: parent
                                    anchors.margins: Theme.spacingS
                                    spacing: Theme.spacingM

                                    DankIcon {
                                        name: "desktop_windows"
                                        size: Theme.iconSize - 4
                                        color: Theme.primary
                                        anchors.verticalCenter: parent.verticalCenter
                                    }

                                    Column {
                                        width: parent.width - Theme.iconSize - Theme.spacingM * 2
                                        anchors.verticalCenter: parent.verticalCenter
                                        spacing: Theme.spacingXS / 2

                                        StyledText {
                                            text: SettingsData.getScreenDisplayName(modelData)
                                            font.pixelSize: Theme.fontSizeMedium
                                            font.weight: Font.Medium
                                            color: Theme.surfaceText
                                            width: parent.width
                                            horizontalAlignment: Text.AlignLeft
                                        }

                                        Row {
                                            width: parent.width
                                            spacing: Theme.spacingS

                                            property var wlrOutput: WlrOutputService.wlrOutputAvailable ? WlrOutputService.getOutput(modelData.name) : null
                                            property var currentMode: wlrOutput?.currentMode

                                            StyledText {
                                                text: {
                                                    if (parent.currentMode) {
                                                        return parent.currentMode.width + "×" + parent.currentMode.height + "@" + Math.round(parent.currentMode.refresh / 1000) + "Hz";
                                                    }
                                                    return modelData.width + "×" + modelData.height;
                                                }
                                                font.pixelSize: Theme.fontSizeSmall
                                                color: Theme.surfaceVariantText
                                            }

                                            StyledText {
                                                text: "•"
                                                font.pixelSize: Theme.fontSizeSmall
                                                color: Theme.surfaceVariantText
                                            }

                                            StyledText {
                                                text: SettingsData.displayNameMode === "system" ? (modelData.model || "Unknown Model") : modelData.name
                                                font.pixelSize: Theme.fontSizeSmall
                                                color: Theme.surfaceVariantText
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Column {
                width: parent.width
                spacing: Theme.spacingL

                Repeater {
                    model: root.variantComponents

                    delegate: StyledRect {
                        width: parent.width
                        height: componentSection.implicitHeight + Theme.spacingL * 2
                        radius: Theme.cornerRadius
                        color: Theme.surfaceContainerHigh
                        border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
                        border.width: 0

                        Column {
                            id: componentSection

                            anchors.fill: parent
                            anchors.margins: Theme.spacingL
                            spacing: Theme.spacingM

                            Row {
                                width: parent.width
                                spacing: Theme.spacingM

                                DankIcon {
                                    name: modelData.icon
                                    size: Theme.iconSize
                                    color: Theme.primary
                                    anchors.verticalCenter: parent.verticalCenter
                                }

                                Column {
                                    width: parent.width - Theme.iconSize - Theme.spacingM
                                    spacing: Theme.spacingXS
                                    anchors.verticalCenter: parent.verticalCenter

                                    StyledText {
                                        text: modelData.name
                                        font.pixelSize: Theme.fontSizeLarge
                                        font.weight: Font.Medium
                                        color: Theme.surfaceText
                                        width: parent.width
                                        horizontalAlignment: Text.AlignLeft
                                    }

                                    StyledText {
                                        text: modelData.description
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceVariantText
                                        wrapMode: Text.WordWrap
                                        width: parent.width
                                        horizontalAlignment: Text.AlignLeft
                                    }
                                }
                            }

                            Column {
                                width: parent.width
                                spacing: Theme.spacingS

                                StyledText {
                                    text: I18n.tr("Show on screens:")
                                    font.pixelSize: Theme.fontSizeSmall
                                    color: Theme.surfaceText
                                    font.weight: Font.Medium
                                    width: parent.width
                                    horizontalAlignment: Text.AlignLeft
                                }

                                Column {
                                    property string componentId: modelData.id

                                    width: parent.width
                                    spacing: Theme.spacingXS

                                    DankToggle {
                                        width: parent.width
                                        text: I18n.tr("All displays")
                                        description: I18n.tr("Show on all connected displays")
                                        checked: {
                                            var prefs = root.getScreenPreferences(parent.componentId);
                                            return prefs.includes("all") || (typeof prefs[0] === "string" && prefs[0] === "all");
                                        }
                                        onToggled: checked => {
                                            if (checked) {
                                                root.setScreenPreferences(parent.componentId, ["all"]);
                                            } else {
                                                root.setScreenPreferences(parent.componentId, []);
                                                const cid = parent.componentId;
                                                if (["dankBar", "dock", "notifications", "osd", "toast"].includes(cid) || cid.startsWith("bar:")) {
                                                    root.setShowOnLastDisplay(cid, true);
                                                }
                                            }
                                        }
                                    }

                                    DankToggle {
                                        width: parent.width
                                        text: I18n.tr("Focused monitor only")
                                        description: I18n.tr("Show notifications only on the currently focused monitor")
                                        visible: parent.componentId === "notifications"
                                        checked: SettingsData.notificationFocusedMonitor
                                        onToggled: checked => SettingsData.set("notificationFocusedMonitor", checked)
                                    }

                                    DankToggle {
                                        width: parent.width
                                        text: I18n.tr("Show on Last Display")
                                        description: I18n.tr("Always show when there's only one connected display")
                                        checked: root.getShowOnLastDisplay(parent.componentId)
                                        visible: {
                                            const prefs = root.getScreenPreferences(parent.componentId);
                                            const isAll = prefs.includes("all") || (typeof prefs[0] === "string" && prefs[0] === "all");
                                            const cid = parent.componentId;
                                            const isRelevantComponent = ["dankBar", "dock", "notifications", "osd", "toast", "notepad"].includes(cid) || cid.startsWith("bar:");
                                            return !isAll && isRelevantComponent;
                                        }
                                        onToggled: checked => {
                                            root.setShowOnLastDisplay(parent.componentId, checked);
                                        }
                                    }

                                    Rectangle {
                                        width: parent.width
                                        height: 1
                                        color: Theme.outline
                                        opacity: 0.2
                                        visible: {
                                            var prefs = root.getScreenPreferences(parent.componentId);
                                            return !prefs.includes("all") && !(typeof prefs[0] === "string" && prefs[0] === "all");
                                        }
                                    }

                                    Column {
                                        width: parent.width
                                        spacing: Theme.spacingXS
                                        visible: {
                                            var prefs = root.getScreenPreferences(parent.componentId);
                                            return !prefs.includes("all") && !(typeof prefs[0] === "string" && prefs[0] === "all");
                                        }

                                        Repeater {
                                            model: Quickshell.screens

                                            delegate: DankToggle {
                                                property var screenData: modelData
                                                property string componentId: parent.parent.componentId

                                                width: parent.width
                                                text: SettingsData.getScreenDisplayName(screenData)
                                                description: screenData.width + "×" + screenData.height + " • " + (SettingsData.displayNameMode === "system" ? (screenData.model || "Unknown Model") : screenData.name)
                                                checked: {
                                                    var prefs = root.getScreenPreferences(componentId);
                                                    if (typeof prefs[0] === "string" && prefs[0] === "all")
                                                        return false;
                                                    return SettingsData.isScreenInPreferences(screenData, prefs);
                                                }
                                                onToggled: checked => {
                                                    var currentPrefs = root.getScreenPreferences(componentId);
                                                    if (typeof currentPrefs[0] === "string" && currentPrefs[0] === "all") {
                                                        currentPrefs = [];
                                                    }

                                                    const screenModelIndex = SettingsData.getScreenModelIndex(screenData);

                                                    var newPrefs = currentPrefs.filter(pref => {
                                                        if (typeof pref === "string")
                                                            return false;
                                                        if (pref.modelIndex !== undefined && screenModelIndex >= 0) {
                                                            return !(pref.model === screenData.model && pref.modelIndex === screenModelIndex);
                                                        }
                                                        return pref.name !== screenData.name || pref.model !== screenData.model;
                                                    });

                                                    if (checked) {
                                                        const prefObj = {
                                                            "name": screenData.name,
                                                            "model": screenData.model || ""
                                                        };
                                                        if (screenModelIndex >= 0) {
                                                            prefObj.modelIndex = screenModelIndex;
                                                        }
                                                        newPrefs.push(prefObj);
                                                    }

                                                    root.setScreenPreferences(componentId, newPrefs);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}