From b814d5523b7edc2b3eeae73b33bbfea5a27d0f20 Mon Sep 17 00:00:00 2001 From: verse91 Date: Fri, 23 Jan 2026 13:10:16 +0700 Subject: [PATCH 1/2] fix: brightness not return default value during idles/lock --- cli.sh | 56 +++++++++++++++++++++++++------- modules/services/IdleService.qml | 26 +++++++++++++++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/cli.sh b/cli.sh index 97505a76..a759106e 100755 --- a/cli.sh +++ b/cli.sh @@ -283,14 +283,30 @@ brightness) bash "${SCRIPT_DIR}/scripts/brightness_list.sh" >"${BRIGHTNESS_SAVE_FILE}.tmp" 2>/dev/null || { echo "Warning: Could not query current brightness" } + # Skip saving if brightness is 0 (screen off state) and we already have a save if [ -f "${BRIGHTNESS_SAVE_FILE}.tmp" ]; then - while IFS=: read -r name bright method; do - if [ -n "$name" ] && [ -n "$bright" ]; then - echo "${name}:${bright}" + # Check if all values are 0 or very low (screen off state) + ALL_ZERO=true + while IFS=: read -r name bright; do + if [ -n "$bright" ] && [ "$bright" -gt 5 ]; then + ALL_ZERO=false + break fi - done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE" - rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" - echo "Saved current brightness for all monitors" + done <"${BRIGHTNESS_SAVE_FILE}.tmp" + + # Only save if not all zero, OR if no previous save exists + if [ "$ALL_ZERO" = true ] && [ -f "$BRIGHTNESS_SAVE_FILE" ]; then + echo "Skipped saving - brightness at 0 (keeping previous save)" + rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" + else + while IFS=: read -r name bright; do + if [ -n "$name" ] && [ -n "$bright" ]; then + echo "${name}:${bright}" + fi + done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE" + rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" + echo "Saved current brightness for all monitors" + fi fi else # Save specific monitor @@ -352,14 +368,30 @@ brightness) echo "Warning: Could not query current brightness" } # Convert format from name:brightness:method to name:brightness + # Skip saving if brightness is 0 (screen off state) and we already have a save if [ -f "${BRIGHTNESS_SAVE_FILE}.tmp" ]; then - while IFS=: read -r name bright method; do - if [ -n "$name" ] && [ -n "$bright" ]; then - echo "${name}:${bright}" + # Check if all values are 0 or very low (screen off state) + ALL_ZERO=true + while IFS=: read -r name bright; do + if [ -n "$bright" ] && [ "$bright" -gt 5 ]; then + ALL_ZERO=false + break fi - done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE" - rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" - echo "Saved current brightness for all monitors" + done <"${BRIGHTNESS_SAVE_FILE}.tmp" + + # Only save if not all zero, OR if no previous save exists + if [ "$ALL_ZERO" = true ] && [ -f "$BRIGHTNESS_SAVE_FILE" ]; then + echo "Skipped saving - brightness at 0 (keeping previous save)" + rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" + else + while IFS=: read -r name bright; do + if [ -n "$name" ] && [ -n "$bright" ]; then + echo "${name}:${bright}" + fi + done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE" + rm -f "${BRIGHTNESS_SAVE_FILE}.tmp" + echo "Saved current brightness for all monitors" + fi fi else # Save specific monitor diff --git a/modules/services/IdleService.qml b/modules/services/IdleService.qml index 5bacb5c5..5a01f66a 100644 --- a/modules/services/IdleService.qml +++ b/modules/services/IdleService.qml @@ -60,6 +60,8 @@ Singleton { // Master Idle Logic property int elapsedIdleTime: 0 property var triggeredListeners: [] // Keeps track of indices that have fired + property bool resumeCooldown: false // Prevent immediate resume after listener triggers + property bool pendingReset: false // Track if reset was requested during cooldown // Master Monitor: Detects "absence of activity" almost immediately IdleMonitor { @@ -72,6 +74,26 @@ Singleton { idleTimer.start(); } else { idleTimer.stop(); + // If in cooldown, defer the reset + if (root.resumeCooldown) { + root.pendingReset = true; + } else { + root.resetIdleState(); + } + } + } + } + + // Cooldown timer - prevents resume for a short period after listener triggers + Timer { + id: cooldownTimer + interval: 1500 // 1.5 seconds - enough for lockscreen to fully load + repeat: false + onTriggered: { + root.resumeCooldown = false; + // Execute pending reset if activity happened during cooldown and user is still active + if (root.pendingReset && !masterMonitor.isIdle) { + root.pendingReset = false; root.resetIdleState(); } } @@ -99,6 +121,10 @@ Singleton { console.log("Idle timer " + tVal + "s reached: " + listener.onTimeout); executionProc.command = ["sh", "-c", listener.onTimeout]; executionProc.running = true; + + // Activate cooldown to prevent immediate resume from listener-caused activity + root.resumeCooldown = true; + cooldownTimer.restart(); } root.triggeredListeners.push(i); } From 4bb009753e07981947797b6ecc5551171a280ac4 Mon Sep 17 00:00:00 2001 From: verse91 Date: Fri, 23 Jan 2026 13:29:13 +0700 Subject: [PATCH 2/2] feat: Skip idle actions if media is playing - Skip idle listener triggers when MprisController.isPlaying is true - Reset elapsed idle time while media plays - Prevents screen dimming/lock while watching YouTube, Spotify, etc --- modules/services/IdleService.qml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/services/IdleService.qml b/modules/services/IdleService.qml index 5a01f66a..81d9140c 100644 --- a/modules/services/IdleService.qml +++ b/modules/services/IdleService.qml @@ -6,6 +6,7 @@ import Quickshell import Quickshell.Io import Quickshell.Wayland import qs.config +import qs.modules.services Singleton { id: root @@ -110,6 +111,12 @@ Singleton { } function checkListeners() { + // Skip idle actions if media is playing (YouTube, Spotify, etc.) + if (MprisController.isPlaying) { + root.elapsedIdleTime = 0; // Reset timer while media plays + return; + } + let listeners = Config.system.idle.listeners; for (let i = 0; i < listeners.length; i++) { let listener = listeners[i];