import QtQuick import Quickshell import qs.Common import qs.Services import qs.Widgets Item { id: control property var daemon: null property string screenName: "" readonly property string deviceId: daemon ? daemon.brightnessDeviceForScreen(screenName) : "" readonly property var device: DisplayService.devices ? (DisplayService.devices.find(d => d.id === control.deviceId) || null) : null readonly property bool usable: DisplayService.brightnessAvailable && control.deviceId !== "" readonly property int currentBrightness: { DisplayService.brightnessVersion; return control.deviceId !== "" ? DisplayService.getDeviceBrightness(control.deviceId) : 0; } readonly property int sliderMinimum: { if (!control.device) return 1; const exponential = SessionData.getBrightnessExponential(control.device.id); if (exponential) return 1; return (control.device.class === "backlight" || control.device.class === "ddc") ? 1 : 0; } readonly property int sliderMaximum: { if (!control.device) return 100; const exponential = SessionData.getBrightnessExponential(control.device.id); if (exponential) return 100; return control.device.displayMax || 100; } implicitWidth: 190 height: 38 Component.onCompleted: { if (daemon) daemon.ensureBrightnessMap(); } DankIcon { id: icon anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter name: { if (!control.usable) return "brightness_low"; if (control.currentBrightness <= 33) return "brightness_low"; if (control.currentBrightness <= 66) return "brightness_medium"; return "brightness_high"; } size: Theme.iconSize - 4 color: control.usable ? Theme.primary : Theme.surfaceVariantText } DankSlider { id: slider anchors.left: icon.right anchors.leftMargin: Theme.spacingXS anchors.right: valueLabel.left anchors.rightMargin: Theme.spacingXS anchors.verticalCenter: parent.verticalCenter enabled: control.usable minimum: control.sliderMinimum maximum: control.sliderMaximum showValue: false onSliderValueChanged: newValue => { if (control.usable) DisplayService.setBrightness(newValue, control.deviceId, true); } // The slider writes its own value while dragging, so only follow the // service when the user is not holding it. Binding on value { value: control.currentBrightness when: !slider.isDragging } } StyledText { id: valueLabel anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter width: 34 horizontalAlignment: Text.AlignRight text: control.usable ? control.currentBrightness + (control.device && control.device.class === "ddc" && !SessionData.getBrightnessExponential(control.device.id) ? "" : "%") : "n/a" font.pixelSize: Theme.fontSizeSmall color: Theme.surfaceVariantText } DankTooltipV2 { id: tooltip } MouseArea { anchors.fill: icon hoverEnabled: true acceptedButtons: Qt.NoButton onEntered: tooltip.show(control.deviceId !== "" ? control.screenName + " ยท " + control.deviceId : "No brightness device", icon, 0, 0, "bottom") onExited: tooltip.hide() } }