lockeys-service: added a component registration system to avoid polling when not necessary

This commit is contained in:
Lemmy
2026-02-13 13:31:42 -05:00
parent aa10b9791d
commit 8c776b5504
3 changed files with 45 additions and 3 deletions
+3
View File
@@ -53,6 +53,9 @@ Item {
visible: !root.hideWhenOff || (root.showCaps && LockKeysService.capsLockOn) || (root.showNum && LockKeysService.numLockOn) || (root.showScroll && LockKeysService.scrollLockOn)
Component.onCompleted: LockKeysService.registerComponent("bar-lockkeys:" + (screen?.name || "unknown"))
Component.onDestruction: LockKeysService.unregisterComponent("bar-lockkeys:" + (screen?.name || "unknown"))
implicitHeight: contentHeight
implicitWidth: contentWidth
+15
View File
@@ -298,6 +298,20 @@ Variants {
}
}
// Register/unregister LockKeysService polling based on whether LockKey OSD is enabled
onLockKeyOSDEnabledChanged: {
if (lockKeyOSDEnabled) {
LockKeysService.registerComponent("osd:" + (modelData?.name || "unknown"));
} else {
LockKeysService.unregisterComponent("osd:" + (modelData?.name || "unknown"));
}
}
Component.onCompleted: {
if (lockKeyOSDEnabled) {
LockKeysService.registerComponent("osd:" + (modelData?.name || "unknown"));
}
}
// LockKeys monitoring with a cleaner approach
// Only connect when LockKey OSD is enabled to avoid starting the service unnecessarily
Connections {
@@ -331,6 +345,7 @@ Variants {
}
Component.onDestruction: {
LockKeysService.unregisterComponent("osd:" + (modelData?.name || "unknown"));
if (typeof BrightnessService !== "undefined" && BrightnessService.monitors) {
for (var i = 0; i < BrightnessService.monitors.length; i++) {
try {
+27 -3
View File
@@ -8,6 +8,23 @@ import qs.Commons
Singleton {
id: root
// Component registration - only poll when something needs lock key state
function registerComponent(componentId) {
root._registered[componentId] = true;
root._registered = Object.assign({}, root._registered);
Logger.d("LockKeys", "Component registered:", componentId, "- total:", root._registeredCount);
}
function unregisterComponent(componentId) {
delete root._registered[componentId];
root._registered = Object.assign({}, root._registered);
Logger.d("LockKeys", "Component unregistered:", componentId, "- total:", root._registeredCount);
}
property var _registered: ({})
readonly property int _registeredCount: Object.keys(_registered).length
readonly property bool shouldRun: _registeredCount > 0
property bool capsLockOn: false
property bool numLockOn: false
property bool scrollLockOn: false
@@ -79,10 +96,18 @@ scroll=0; cat /sys/class/leds/input*::scrolllock/brightness 2>/dev/null | grep -
}
}
onShouldRunChanged: {
if (shouldRun) {
// Reset initial check so first poll after re-enable doesn't trigger OSD
root.initialCheckDone = false;
stateCheckProcess.running = true;
}
}
Timer {
id: pollTimer
interval: 200
running: true
running: root.shouldRun
repeat: true
onTriggered: {
if (!stateCheckProcess.running) {
@@ -92,7 +117,6 @@ scroll=0; cat /sys/class/leds/input*::scrolllock/brightness 2>/dev/null | grep -
}
Component.onCompleted: {
Logger.i("LockKeysService", "Service started, performing initial state check.");
stateCheckProcess.running = true;
Logger.i("LockKeysService", "Service started (polling deferred until a consumer registers).");
}
}