Brightness: Multi-monitor working (no external modification detected)
This commit is contained in:
parent
0223e3d9d1
commit
4225cbe704
2 changed files with 29 additions and 83 deletions
|
|
@ -14,35 +14,34 @@ Item {
|
||||||
|
|
||||||
// Used to avoid opening the pill on Quickshell startup
|
// Used to avoid opening the pill on Quickshell startup
|
||||||
property bool firstBrightnessReceived: false
|
property bool firstBrightnessReceived: false
|
||||||
property real lastBrightness: -1
|
|
||||||
|
|
||||||
function getIcon() {
|
function getIcon() {
|
||||||
if (!BrightnessService.available) {
|
var brightness = BrightnessService.getMonitorForScreen(screen).brightness
|
||||||
return "brightness_auto"
|
return brightness <= 0 ? "brightness_1" : brightness < 0.33 ? "brightness_low" : brightness < 0.66 ? "brightness_medium" : "brightness_high"
|
||||||
}
|
|
||||||
var brightness = BrightnessService.brightness
|
|
||||||
return brightness <= 0 ? "brightness_1" : brightness < 33 ? "brightness_low" : brightness < 66 ? "brightness_medium" : "brightness_high"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection used to open the pill when brightness changes
|
// Connection used to open the pill when brightness changes
|
||||||
Connections {
|
Connections {
|
||||||
target: BrightnessService.focusedMonitor
|
target: BrightnessService.getMonitorForScreen(screen)
|
||||||
function onBrightnessUpdated() {
|
function onBrightnessUpdated() {
|
||||||
var currentBrightness = BrightnessService.brightness
|
Logger.log("Bar-Brightness", "OnBrightnessUpdated")
|
||||||
|
|
||||||
|
var monitor = BrightnessService.getMonitorForScreen(screen);
|
||||||
|
var currentBrightness = monitor.brightness
|
||||||
|
|
||||||
// Ignore if this is the first time or if brightness hasn't actually changed
|
// Ignore if this is the first time or if brightness hasn't actually changed
|
||||||
if (!firstBrightnessReceived) {
|
if (!firstBrightnessReceived) {
|
||||||
firstBrightnessReceived = true
|
firstBrightnessReceived = true
|
||||||
lastBrightness = currentBrightness
|
monitor.lastBrightness = currentBrightness
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show pill if brightness actually changed (not just loaded from settings)
|
// Only show pill if brightness actually changed (not just loaded from settings)
|
||||||
if (Math.abs(currentBrightness - lastBrightness) > 0.1) {
|
if (Math.abs(currentBrightness - monitor.lastBrightness) > 0.1) {
|
||||||
pill.show()
|
pill.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
lastBrightness = currentBrightness
|
monitor.lastBrightness = currentBrightness
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,21 +51,22 @@ Item {
|
||||||
iconCircleColor: Color.mPrimary
|
iconCircleColor: Color.mPrimary
|
||||||
collapsedIconColor: Color.mOnSurface
|
collapsedIconColor: Color.mOnSurface
|
||||||
autoHide: false // Important to be false so we can hover as long as we want
|
autoHide: false // Important to be false so we can hover as long as we want
|
||||||
text: Math.round(BrightnessService.brightness) + "%"
|
text: Math.round(BrightnessService.getMonitorForScreen(screen).brightness * 100) + "%"
|
||||||
tooltipText: "Brightness: " + Math.round(
|
tooltipText: {
|
||||||
BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod
|
var monitor = BrightnessService.getMonitorForScreen(screen)
|
||||||
+ "\nLeft click for advanced settings.\nScroll up/down to change brightness."
|
return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method
|
||||||
|
+ "\nLeft click for advanced settings.\nScroll up/down to change brightness."
|
||||||
|
}
|
||||||
|
|
||||||
onWheel: function (angle) {
|
onWheel: function (angle) {
|
||||||
if (!BrightnessService.available)
|
var monitor = BrightnessService.getMonitorForScreen(screen)
|
||||||
return
|
|
||||||
|
|
||||||
if (angle > 0) {
|
if (angle > 0) {
|
||||||
BrightnessService.increaseBrightness()
|
monitor.increaseBrightness()
|
||||||
} else if (angle < 0) {
|
} else if (angle < 0) {
|
||||||
BrightnessService.decreaseBrightness()
|
monitor.decreaseBrightness()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
settingsPanel.requestedTab = SettingsPanel.Tab.Brightness
|
settingsPanel.requestedTab = SettingsPanel.Tab.Brightness
|
||||||
settingsPanel.isLoaded = true
|
settingsPanel.isLoaded = true
|
||||||
|
|
|
||||||
|
|
@ -14,73 +14,10 @@ Singleton {
|
||||||
readonly property list<Monitor> monitors: variants.instances
|
readonly property list<Monitor> monitors: variants.instances
|
||||||
property bool appleDisplayPresent: false
|
property bool appleDisplayPresent: false
|
||||||
|
|
||||||
// Public properties for backward compatibility
|
|
||||||
readonly property real brightness: focusedMonitor ? focusedMonitor.brightness * 100 : Settings.data.brightness.lastBrightness
|
|
||||||
readonly property bool available: focusedMonitor !== null
|
|
||||||
readonly property string currentMethod: focusedMonitor ? focusedMonitor.method : Settings.data.brightness.lastMethod
|
|
||||||
readonly property var detectedDisplays: monitors.map(m => ({
|
|
||||||
"name": m.modelData.name,
|
|
||||||
"type": m.isDdc ? "external" : "internal",
|
|
||||||
"method": m.method,
|
|
||||||
"index": m.busNum
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Get the currently focused monitor
|
|
||||||
readonly property Monitor focusedMonitor: {
|
|
||||||
if (monitors.length === 0)
|
|
||||||
return null
|
|
||||||
// For now, return the first monitor. Could be enhanced to detect focused monitor
|
|
||||||
return monitors[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMonitorForScreen(screen: ShellScreen): var {
|
function getMonitorForScreen(screen: ShellScreen): var {
|
||||||
return monitors.find(m => m.modelData === screen)
|
return monitors.find(m => m.modelData === screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
function increaseBrightness(step = null): void {
|
|
||||||
if (focusedMonitor) {
|
|
||||||
var stepSize = step !== null ? step : Settings.data.brightness.brightnessStep
|
|
||||||
focusedMonitor.setBrightness(focusedMonitor.brightness + (stepSize / 100))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function decreaseBrightness(step = null): void {
|
|
||||||
if (focusedMonitor) {
|
|
||||||
var stepSize = step !== null ? step : Settings.data.brightness.brightnessStep
|
|
||||||
focusedMonitor.setBrightness(focusedMonitor.brightness - (stepSize / 100))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBrightness(newBrightness: real): void {
|
|
||||||
if (focusedMonitor) {
|
|
||||||
focusedMonitor.setBrightness(newBrightness / 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBrightnessDebounced(newBrightness: real): void {
|
|
||||||
if (focusedMonitor) {
|
|
||||||
focusedMonitor.setBrightnessDebounced(newBrightness / 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backward compatibility functions
|
|
||||||
function updateBrightness(): void {// No longer needed with the new architecture
|
|
||||||
}
|
|
||||||
|
|
||||||
function setDisplay(displayIndex: int): bool {
|
|
||||||
// No longer needed with the new architecture
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDisplayInfo(): var {
|
|
||||||
return focusedMonitor ? {
|
|
||||||
"name": focusedMonitor.modelData.name,
|
|
||||||
"type": focusedMonitor.isDdc ? "external" : "internal",
|
|
||||||
"method": focusedMonitor.method,
|
|
||||||
"index": focusedMonitor.busNum
|
|
||||||
} : null
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAvailableMethods(): list<string> {
|
function getAvailableMethods(): list<string> {
|
||||||
var methods = []
|
var methods = []
|
||||||
if (monitors.some(m => m.isDdc))
|
if (monitors.some(m => m.isDdc))
|
||||||
|
|
@ -147,6 +84,7 @@ Singleton {
|
||||||
readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal")
|
readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal")
|
||||||
|
|
||||||
property real brightness: getStoredBrightness()
|
property real brightness: getStoredBrightness()
|
||||||
|
property real lastBrightness: 0
|
||||||
property real queuedBrightness: NaN
|
property real queuedBrightness: NaN
|
||||||
|
|
||||||
// Signal for brightness changes
|
// Signal for brightness changes
|
||||||
|
|
@ -207,6 +145,14 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function increaseBrightness(): void {
|
||||||
|
setBrightness(brightness + 0.1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function decreaseBrightness(): void {
|
||||||
|
setBrightness(monitor.brightness - 0.1)
|
||||||
|
}
|
||||||
|
|
||||||
function getStoredBrightness(): real {
|
function getStoredBrightness(): real {
|
||||||
// Try to get stored brightness for this specific monitor
|
// Try to get stored brightness for this specific monitor
|
||||||
var stored = Settings.data.brightness.monitorBrightness.find(m => {
|
var stored = Settings.data.brightness.monitorBrightness.find(m => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue