Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions services/Brightness.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,31 @@ Singleton {
signal brightnessChanged()

property var ddcMonitors: []
readonly property list<BrightnessMonitor> monitors: Quickshell.screens.map(screen => monitorComp.createObject(root, {
screen
}))
property list<BrightnessMonitor> monitors: []

// Reconciles `monitors` against the live screen list instead of
// recreating every entry on each change: still-connected screens keep
// their existing BrightnessMonitor (and its running Timers/Processes),
// while ones whose screen disconnected are explicitly destroyed so they
// don't linger as zombie objects reacting to a dead `screen` reference.
function _syncMonitors() {
const next = Quickshell.screens.map(screen => root.monitors.find(m => m.screen === screen) ?? monitorComp.createObject(root, {
screen
}));
for (const m of root.monitors) {
if (!next.includes(m)) m.destroy();
}
root.monitors = next;
}

Component.onCompleted: root._syncMonitors()

Connections {
target: Quickshell
function onScreensChanged() {
root._syncMonitors();
}
}

function getMonitorForScreen(screen: ShellScreen): var {
return monitors.find(m => m.screen === screen);
Expand Down Expand Up @@ -79,11 +101,11 @@ Singleton {

required property ShellScreen screen
readonly property bool isDdc: {
const match = root.ddcMonitors.find(m => screen.model?.includes(m.model) && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
const match = root.ddcMonitors.find(m => screen?.model?.includes(m.model) && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
return !!match;
}
readonly property string busNum: {
const match = root.ddcMonitors.find(m => screen.model?.includes(m.model) && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
const match = root.ddcMonitors.find(m => screen?.model?.includes(m.model) && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
return match?.busNum ?? "";
}
property int rawMaxBrightness: 100
Expand Down