1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

cc: fix brightness tooltip

This commit is contained in:
bbedward
2025-11-23 20:33:52 -05:00
parent 2e9f9f7b7e
commit b773fdca34

View File

@@ -1,6 +1,4 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell
import qs.Common import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
@@ -18,65 +16,69 @@ Row {
height: 40 height: 40
spacing: 0 spacing: 0
DankTooltipV2 {
id: sharedTooltip
}
property string targetDeviceName: { property string targetDeviceName: {
if (!DisplayService.brightnessAvailable || !DisplayService.devices || DisplayService.devices.length === 0) { if (!DisplayService.brightnessAvailable || !DisplayService.devices || DisplayService.devices.length === 0) {
return "" return "";
} }
if (screenName && screenName.length > 0) { if (screenName && screenName.length > 0) {
const pins = SettingsData.brightnessDevicePins || {} const pins = SettingsData.brightnessDevicePins || {};
const pinnedDevice = pins[screenName] const pinnedDevice = pins[screenName];
if (pinnedDevice && pinnedDevice.length > 0) { if (pinnedDevice && pinnedDevice.length > 0) {
const found = DisplayService.devices.find(dev => dev.name === pinnedDevice) const found = DisplayService.devices.find(dev => dev.name === pinnedDevice);
if (found) { if (found) {
return found.name return found.name;
} }
} }
} }
if (deviceName && deviceName.length > 0) { if (deviceName && deviceName.length > 0) {
const found = DisplayService.devices.find(dev => dev.name === deviceName) const found = DisplayService.devices.find(dev => dev.name === deviceName);
if (found) { if (found) {
return found.name return found.name;
} }
} }
const currentDeviceName = DisplayService.currentDevice const currentDeviceName = DisplayService.currentDevice;
if (currentDeviceName) { if (currentDeviceName) {
const found = DisplayService.devices.find(dev => dev.name === currentDeviceName) const found = DisplayService.devices.find(dev => dev.name === currentDeviceName);
if (found) { if (found) {
return found.name return found.name;
} }
} }
const backlight = DisplayService.devices.find(d => d.class === "backlight") const backlight = DisplayService.devices.find(d => d.class === "backlight");
if (backlight) { if (backlight) {
return backlight.name return backlight.name;
} }
const ddc = DisplayService.devices.find(d => d.class === "ddc") const ddc = DisplayService.devices.find(d => d.class === "ddc");
if (ddc) { if (ddc) {
return ddc.name return ddc.name;
} }
return DisplayService.devices.length > 0 ? DisplayService.devices[0].name : "" return DisplayService.devices.length > 0 ? DisplayService.devices[0].name : "";
} }
property var targetDevice: { property var targetDevice: {
if (!targetDeviceName || !DisplayService.devices) { if (!targetDeviceName || !DisplayService.devices) {
return null return null;
} }
return DisplayService.devices.find(dev => dev.name === targetDeviceName) || null return DisplayService.devices.find(dev => dev.name === targetDeviceName) || null;
} }
property real targetBrightness: { property real targetBrightness: {
DisplayService.brightnessVersion DisplayService.brightnessVersion;
if (!targetDeviceName) { if (!targetDeviceName) {
return 0 return 0;
} }
return DisplayService.getDeviceBrightness(targetDeviceName) return DisplayService.getDeviceBrightness(targetDeviceName);
} }
Rectangle { Rectangle {
@@ -94,46 +96,37 @@ Row {
onClicked: { onClicked: {
if (DisplayService.devices && DisplayService.devices.length > 1) { if (DisplayService.devices && DisplayService.devices.length > 1) {
root.iconClicked() root.iconClicked();
} }
} }
onEntered: { onEntered: {
tooltipLoader.active = true const tooltipText = targetDevice ? "bl device: " + targetDevice.name : "Backlight Control";
if (tooltipLoader.item) { sharedTooltip.show(tooltipText, iconArea, 0, 0, "bottom");
const tooltipText = targetDevice ? "bl device: " + targetDevice.name : "Backlight Control"
const globalPos = iconArea.mapToGlobal(iconArea.width / 2, iconArea.height / 2)
const screenY = root.parentScreen?.y ?? 0
const relativeY = globalPos.y - screenY - 55
tooltipLoader.item.show(tooltipText, globalPos.x, relativeY, root.parentScreen)
}
} }
onExited: { onExited: {
if (tooltipLoader.item) { sharedTooltip.hide();
tooltipLoader.item.hide()
}
tooltipLoader.active = false
} }
DankIcon { DankIcon {
anchors.centerIn: parent anchors.centerIn: parent
name: { name: {
if (!DisplayService.brightnessAvailable || !targetDevice) { if (!DisplayService.brightnessAvailable || !targetDevice) {
return "brightness_low" return "brightness_low";
} }
if (targetDevice.class === "backlight" || targetDevice.class === "ddc") { if (targetDevice.class === "backlight" || targetDevice.class === "ddc") {
const brightness = targetBrightness const brightness = targetBrightness;
if (brightness <= 33) if (brightness <= 33)
return "brightness_low" return "brightness_low";
if (brightness <= 66) if (brightness <= 66)
return "brightness_medium" return "brightness_medium";
return "brightness_high" return "brightness_high";
} else if (targetDevice.name.includes("kbd")) { } else if (targetDevice.name.includes("kbd")) {
return "keyboard" return "keyboard";
} else { } else {
return "lightbulb" return "lightbulb";
} }
} }
size: Theme.iconSize size: Theme.iconSize
@@ -149,43 +142,40 @@ Row {
width: parent.width - (Theme.iconSize + Theme.spacingS * 2) width: parent.width - (Theme.iconSize + Theme.spacingS * 2)
enabled: DisplayService.brightnessAvailable && targetDeviceName.length > 0 enabled: DisplayService.brightnessAvailable && targetDeviceName.length > 0
minimum: { minimum: {
if (!targetDevice) return 1 if (!targetDevice)
const isExponential = SessionData.getBrightnessExponential(targetDevice.id) return 1;
const isExponential = SessionData.getBrightnessExponential(targetDevice.id);
if (isExponential) { if (isExponential) {
return 1 return 1;
} }
return (targetDevice.class === "backlight" || targetDevice.class === "ddc") ? 1 : 0 return (targetDevice.class === "backlight" || targetDevice.class === "ddc") ? 1 : 0;
} }
maximum: { maximum: {
if (!targetDevice) return 100 if (!targetDevice)
const isExponential = SessionData.getBrightnessExponential(targetDevice.id) return 100;
const isExponential = SessionData.getBrightnessExponential(targetDevice.id);
if (isExponential) { if (isExponential) {
return 100 return 100;
} }
return targetDevice.displayMax || 100 return targetDevice.displayMax || 100;
} }
value: !isDragging ? targetBrightness : value value: !isDragging ? targetBrightness : value
showValue: true showValue: true
unit: { unit: {
if (!targetDevice) return "%" if (!targetDevice)
const isExponential = SessionData.getBrightnessExponential(targetDevice.id) return "%";
const isExponential = SessionData.getBrightnessExponential(targetDevice.id);
if (isExponential) { if (isExponential) {
return "%" return "%";
} }
return targetDevice.class === "ddc" ? "" : "%" return targetDevice.class === "ddc" ? "" : "%";
} }
onSliderValueChanged: function (newValue) { onSliderValueChanged: function (newValue) {
if (DisplayService.brightnessAvailable && targetDeviceName) { if (DisplayService.brightnessAvailable && targetDeviceName) {
DisplayService.setBrightness(newValue, targetDeviceName, true) DisplayService.setBrightness(newValue, targetDeviceName, true);
} }
} }
thumbOutlineColor: Theme.surfaceContainer thumbOutlineColor: Theme.surfaceContainer
trackColor: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency) trackColor: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
} }
Loader {
id: tooltipLoader
active: false
sourceComponent: DankTooltip {}
}
} }