summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/quickshell/Modules/ControlCenter/Details/BrightnessDetail.qml
blob: 0d42e627dc29c64d1055474bedcc3bb6079b288d (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
import QtQuick
import Quickshell
import qs.Common
import qs.Services
import qs.Widgets

Rectangle {
    id: root

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

    property string initialDeviceName: ""
    property string instanceId: ""
    property string screenName: ""
    property string screenModel: ""

    signal deviceNameChanged(string newDeviceName)

    property string currentDeviceName: ""

    function getScreenPinKey() {
        if (!screenName)
            return "";
        const screen = Quickshell.screens.find(s => s.name === screenName);
        if (screen) {
            return SettingsData.getScreenDisplayName(screen);
        }
        if (SettingsData.displayNameMode === "model" && screenModel && screenModel.length > 0) {
            return screenModel;
        }
        return screenName;
    }

    function resolveDeviceName() {
        if (!DisplayService.brightnessAvailable || !DisplayService.devices || DisplayService.devices.length === 0) {
            return "";
        }

        const pinKey = getScreenPinKey();
        if (pinKey.length > 0) {
            const pins = SettingsData.brightnessDevicePins || {};
            const pinnedDevice = pins[pinKey];
            if (pinnedDevice && pinnedDevice.length > 0) {
                const found = DisplayService.devices.find(dev => dev.name === pinnedDevice);
                if (found)
                    return found.name;
            }
        }

        if (initialDeviceName && initialDeviceName.length > 0) {
            const found = DisplayService.devices.find(dev => dev.name === initialDeviceName);
            if (found)
                return found.name;
        }

        const currentDeviceNameFromService = DisplayService.currentDevice;
        if (currentDeviceNameFromService) {
            const found = DisplayService.devices.find(dev => dev.name === currentDeviceNameFromService);
            if (found)
                return found.name;
        }

        const backlight = DisplayService.devices.find(d => d.class === "backlight");
        if (backlight)
            return backlight.name;

        const ddc = DisplayService.devices.find(d => d.class === "ddc");
        if (ddc)
            return ddc.name;

        return DisplayService.devices.length > 0 ? DisplayService.devices[0].name : "";
    }

    Component.onCompleted: {
        currentDeviceName = resolveDeviceName();
    }

    property bool isPinnedToScreen: {
        const pinKey = getScreenPinKey();
        if (!pinKey || pinKey.length === 0)
            return false;
        const pins = SettingsData.brightnessDevicePins || {};
        return pins[pinKey] === currentDeviceName;
    }

    function togglePinToScreen() {
        const pinKey = getScreenPinKey();
        if (!pinKey || pinKey.length === 0 || !currentDeviceName || currentDeviceName.length === 0)
            return;
        const pins = JSON.parse(JSON.stringify(SettingsData.brightnessDevicePins || {}));

        if (isPinnedToScreen) {
            delete pins[pinKey];
        } else {
            pins[pinKey] = currentDeviceName;
        }

        SettingsData.set("brightnessDevicePins", pins);
    }

    implicitHeight: {
        if (height > 0) {
            return height;
        }
        return brightnessContent.height + Theme.spacingM;
    }
    radius: Theme.cornerRadius
    color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
    border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.08)
    border.width: 0

    DankFlickable {
        id: brightnessContent
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: Theme.spacingM
        anchors.topMargin: Theme.spacingM
        contentHeight: brightnessColumn.height
        clip: true

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

            Item {
                width: parent.width
                height: 100
                visible: !DisplayService.brightnessAvailable || !DisplayService.devices || DisplayService.devices.length === 0

                Column {
                    anchors.centerIn: parent
                    spacing: Theme.spacingM

                    DankIcon {
                        anchors.horizontalCenter: parent.horizontalCenter
                        name: DisplayService.brightnessAvailable ? "brightness_6" : "error"
                        size: 32
                        color: DisplayService.brightnessAvailable ? Theme.primary : Theme.error
                    }

                    StyledText {
                        anchors.horizontalCenter: parent.horizontalCenter
                        text: DisplayService.brightnessAvailable ? I18n.tr("No brightness devices available") : I18n.tr("Brightness control not available")
                        font.pixelSize: Theme.fontSizeMedium
                        color: Theme.surfaceText
                        horizontalAlignment: Text.AlignHCenter
                    }
                }
            }

            Rectangle {
                width: parent.width
                height: 40
                visible: screenName && screenName.length > 0 && DisplayService.devices && DisplayService.devices.length > 1
                radius: Theme.cornerRadius
                color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)

                Item {
                    anchors.fill: parent
                    anchors.margins: Theme.spacingM

                    Row {
                        anchors.left: parent.left
                        anchors.verticalCenter: parent.verticalCenter
                        spacing: Theme.spacingM

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

                        StyledText {
                            text: root.getScreenPinKey() || I18n.tr("Unknown Monitor")
                            font.pixelSize: Theme.fontSizeMedium
                            color: Theme.surfaceText
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }

                    Rectangle {
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                        width: pinRow.width + Theme.spacingS * 2
                        height: 28
                        radius: height / 2
                        color: isPinnedToScreen ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Theme.withAlpha(Theme.surfaceText, 0.05)

                        Row {
                            id: pinRow
                            anchors.centerIn: parent
                            spacing: 4

                            DankIcon {
                                name: isPinnedToScreen ? "push_pin" : "push_pin"
                                size: 16
                                color: isPinnedToScreen ? Theme.primary : Theme.surfaceText
                                anchors.verticalCenter: parent.verticalCenter
                            }

                            StyledText {
                                text: isPinnedToScreen ? I18n.tr("Pinned") : I18n.tr("Pin")
                                font.pixelSize: Theme.fontSizeSmall
                                color: isPinnedToScreen ? Theme.primary : Theme.surfaceText
                                anchors.verticalCenter: parent.verticalCenter
                            }
                        }

                        DankRipple {
                            id: pinRipple
                            cornerRadius: parent.radius
                        }

                        MouseArea {
                            anchors.fill: parent
                            cursorShape: Qt.PointingHandCursor
                            onPressed: mouse => pinRipple.trigger(mouse.x, mouse.y)
                            onClicked: root.togglePinToScreen()
                        }
                    }
                }
            }

            Repeater {
                model: DisplayService.devices || []
                delegate: Rectangle {
                    required property var modelData
                    required property int index

                    property real deviceBrightness: {
                        DisplayService.brightnessVersion;
                        return DisplayService.getDeviceBrightness(modelData.name);
                    }

                    width: parent.width
                    height: 100
                    radius: Theme.cornerRadius
                    color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
                    border.color: modelData.name === currentDeviceName ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
                    border.width: modelData.name === currentDeviceName ? 2 : 0

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

                        Item {
                            width: parent.width
                            height: Math.max(deviceIconColumn.height, deviceInfoColumn.height, exponentControls.height)

                            Row {
                                anchors.left: parent.left
                                anchors.verticalCenter: parent.verticalCenter
                                spacing: Theme.spacingM

                                Column {
                                    id: deviceIconColumn
                                    anchors.verticalCenter: parent.verticalCenter
                                    spacing: 2

                                    DankIcon {
                                        name: {
                                            const deviceClass = modelData.class || "";
                                            const deviceName = modelData.name || "";

                                            if (deviceClass === "backlight" || deviceClass === "ddc") {
                                                if (deviceBrightness <= 33)
                                                    return "brightness_low";
                                                if (deviceBrightness <= 66)
                                                    return "brightness_medium";
                                                return "brightness_high";
                                            } else if (deviceName.includes("kbd")) {
                                                return "keyboard";
                                            } else {
                                                return "lightbulb";
                                            }
                                        }
                                        size: Theme.iconSize
                                        color: modelData.name === currentDeviceName ? Theme.primary : Theme.surfaceText
                                        anchors.horizontalCenter: parent.horizontalCenter
                                    }

                                    StyledText {
                                        text: Math.round(deviceBrightness) + "%"
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceText
                                        anchors.horizontalCenter: parent.horizontalCenter
                                    }
                                }

                                Column {
                                    id: deviceInfoColumn
                                    anchors.verticalCenter: parent.verticalCenter
                                    width: parent.parent.width - deviceIconColumn.width - exponentControls.width - Theme.spacingM * 3

                                    StyledText {
                                        text: {
                                            const name = modelData.name || "";
                                            const deviceClass = modelData.class || "";
                                            if (deviceClass === "backlight") {
                                                return name.replace("_", " ").replace(/\b\w/g, c => c.toUpperCase());
                                            }
                                            return name;
                                        }
                                        font.pixelSize: Theme.fontSizeMedium
                                        color: Theme.surfaceText
                                        font.weight: modelData.name === currentDeviceName ? Font.Medium : Font.Normal
                                        elide: Text.ElideRight
                                        width: parent.width
                                        horizontalAlignment: Text.AlignLeft
                                    }

                                    StyledText {
                                        text: modelData.name
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceVariantText
                                        elide: Text.ElideRight
                                        width: parent.width
                                        horizontalAlignment: Text.AlignLeft
                                    }

                                    StyledText {
                                        text: {
                                            const deviceClass = modelData.class || "";
                                            if (deviceClass === "backlight")
                                                return I18n.tr("Backlight device");
                                            if (deviceClass === "ddc")
                                                return I18n.tr("DDC/CI monitor");
                                            if (deviceClass === "leds")
                                                return I18n.tr("LED device");
                                            return deviceClass;
                                        }
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceVariantText
                                        elide: Text.ElideRight
                                        width: parent.width
                                        horizontalAlignment: Text.AlignLeft
                                    }
                                }
                            }

                            Row {
                                id: exponentControls
                                width: 140
                                height: 28
                                anchors.right: parent.right
                                anchors.verticalCenter: parent.verticalCenter
                                spacing: Theme.spacingXS
                                visible: SessionData.getBrightnessExponential(modelData.name)
                                z: 1

                                StyledRect {
                                    width: 28
                                    height: 28
                                    radius: Theme.cornerRadius
                                    color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
                                    opacity: SessionData.getBrightnessExponent(modelData.name) > 1.0 ? 1.0 : 0.4

                                    DankIcon {
                                        anchors.centerIn: parent
                                        name: "remove"
                                        size: 14
                                        color: Theme.surfaceText
                                    }

                                    StateLayer {
                                        stateColor: Theme.primary
                                        cornerRadius: parent.radius
                                        enabled: SessionData.getBrightnessExponent(modelData.name) > 1.0
                                        onClicked: {
                                            const current = SessionData.getBrightnessExponent(modelData.name);
                                            const newValue = Math.max(1.0, Math.round((current - 0.1) * 10) / 10);
                                            SessionData.setBrightnessExponent(modelData.name, newValue);
                                        }
                                    }
                                }

                                StyledRect {
                                    width: 50
                                    height: 28
                                    radius: Theme.cornerRadius
                                    color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
                                    border.width: 0

                                    StyledText {
                                        anchors.centerIn: parent
                                        text: SessionData.getBrightnessExponent(modelData.name).toFixed(1)
                                        font.pixelSize: Theme.fontSizeSmall
                                        font.weight: Font.Medium
                                        color: Theme.primary
                                    }
                                }

                                StyledRect {
                                    width: 28
                                    height: 28
                                    radius: Theme.cornerRadius
                                    color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
                                    opacity: SessionData.getBrightnessExponent(modelData.name) < 2.5 ? 1.0 : 0.4

                                    DankIcon {
                                        anchors.centerIn: parent
                                        name: "add"
                                        size: 14
                                        color: Theme.surfaceText
                                    }

                                    StateLayer {
                                        stateColor: Theme.primary
                                        cornerRadius: parent.radius
                                        enabled: SessionData.getBrightnessExponent(modelData.name) < 2.5
                                        onClicked: {
                                            const current = SessionData.getBrightnessExponent(modelData.name);
                                            const newValue = Math.min(2.5, Math.round((current + 0.1) * 10) / 10);
                                            SessionData.setBrightnessExponent(modelData.name, newValue);
                                        }
                                    }
                                }
                            }
                        }

                        Rectangle {
                            width: parent.width
                            height: 24
                            radius: height / 2
                            color: SessionData.getBrightnessExponential(modelData.name) ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Theme.withAlpha(Theme.surfaceText, 0.05)

                            Row {
                                anchors.centerIn: parent
                                spacing: 4

                                DankIcon {
                                    name: "show_chart"
                                    size: 14
                                    color: SessionData.getBrightnessExponential(modelData.name) ? Theme.primary : Theme.surfaceText
                                    anchors.verticalCenter: parent.verticalCenter
                                }

                                StyledText {
                                    text: SessionData.getBrightnessExponential(modelData.name) ? I18n.tr("Exponential") : I18n.tr("Linear")
                                    font.pixelSize: Theme.fontSizeSmall
                                    color: SessionData.getBrightnessExponential(modelData.name) ? Theme.primary : Theme.surfaceText
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                            }

                            DankRipple {
                                id: expToggleRipple
                                cornerRadius: parent.radius
                            }

                            MouseArea {
                                anchors.fill: parent
                                cursorShape: Qt.PointingHandCursor
                                onPressed: mouse => expToggleRipple.trigger(mouse.x, mouse.y)
                                onClicked: {
                                    const currentState = SessionData.getBrightnessExponential(modelData.name);
                                    SessionData.setBrightnessExponential(modelData.name, !currentState);
                                }
                            }
                        }
                    }

                    DankRipple {
                        id: deviceRipple
                        cornerRadius: parent.radius
                    }

                    MouseArea {
                        anchors.fill: parent
                        anchors.bottomMargin: 28
                        anchors.rightMargin: SessionData.getBrightnessExponential(modelData.name) ? 145 : 0
                        hoverEnabled: true
                        cursorShape: Qt.PointingHandCursor
                        onPressed: mouse => deviceRipple.trigger(mouse.x, mouse.y)
                        onClicked: {
                            const pinKey = root.getScreenPinKey();
                            if (pinKey.length > 0 && modelData.name !== currentDeviceName) {
                                const pins = JSON.parse(JSON.stringify(SettingsData.brightnessDevicePins || {}));
                                if (pins[pinKey]) {
                                    delete pins[pinKey];
                                    SettingsData.set("brightnessDevicePins", pins);
                                }
                            }
                            currentDeviceName = modelData.name;
                            deviceNameChanged(modelData.name);
                        }
                    }
                }
            }
        }
    }
}