From e60058d0da96c9caa2d130937a476cad17ff4c92 Mon Sep 17 00:00:00 2001 From: Chad Date: Mon, 24 Aug 2026 18:57:15 +0000 Subject: [PATCH 1/2] Sync System UI brightness slider with KompaktX's overlay brightness KompaktX's overlay-based brightness control (OverlayPanelManager) is the sole path that actually drives the physical backlight, via the screenBrightness field on a persistent overlay window. A ContentObserver on Settings.System.SCREEN_BRIGHTNESS was meant to reapply that value if something cleared it, but it fired on ANY external write to that setting -- including the one the stock System UI brightness slider makes -- and immediately stomped it back to KompaktX's last value. That's why the System UI slider appeared to do nothing while KompaktX was installed. Since applyBrightness() already sets currentBrightnessTarget before writing Settings.System.SCREEN_BRIGHTNESS, a self-triggered observer callback always finds sys == target and is a no-op. A callback where sys != target is therefore reliably an external change. Flip the observer to adopt that external value as the new target instead of reverting it, mirroring applyBrightness()'s side effects (overlay screenBrightness, lockscreen accessibility overlay, and persistence) so the change reaches the physical screen, survives a KompaktX process restart, and applies above the lockscreen too. No UI/range changes: brightness remains a plain linear 0-255 value in both directions, matching the existing stock-slider behavior. --- .../restore/overlay/OverlayPanelManager.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt index 282c108..2392c05 100644 --- a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt +++ b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt @@ -129,7 +129,15 @@ object OverlayPanelManager { stripContext = context loadSavedBrightness(context) - // Watch for system brightness changes and override with our target + // Watch for system brightness changes and adopt them as our new target, so the + // stock System UI slider (or any other writer of Settings.System.SCREEN_BRIGHTNESS) + // stays in sync with KompaktX's overlay instead of being immediately reverted by it. + // + // applyBrightness() below sets currentBrightnessTarget *before* writing + // Settings.System.SCREEN_BRIGHTNESS, so a change we triggered ourselves always finds + // sys == target here and is a no-op. Only a genuinely external write reaches the + // branch below, which is what lets this safely distinguish "someone else changed it" + // from "we just changed it" without an extra flag. brightnessObserver = object : ContentObserver(handler) { override fun onChange(selfChange: Boolean) { val target = currentBrightnessTarget @@ -137,9 +145,15 @@ object OverlayPanelManager { try { val sys = Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS) if (sys != target) { - Settings.System.putInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, target) - val screenVal = if (target <= 0) 0.001f else target / 255f + currentBrightnessTarget = sys + val screenVal = if (sys <= 0) 0.001f else sys / 255f + // Mirror applyBrightness()'s side effects so the externally-set value + // actually reaches the physical backlight (the overlay's screenBrightness + // param drives it, not Settings.System by itself), persists across a + // KompaktX process restart, and still applies above the lockscreen. applyScreenBrightnessToView(brightnessOverlay, screenVal) + com.noti.restore.service.RecentsButtonService.applyAccessibilityBrightness(screenVal) + saveBrightness(context) } } catch (_: Exception) {} } From e3d1a2997aaaa8a5a529f7515155388dfe0abefb Mon Sep 17 00:00:00 2001 From: Chad Date: Mon, 24 Aug 2026 19:14:23 -0500 Subject: [PATCH 2/2] Doesn't adopt/pin from an external SCREEN_BRIGHTNESS write while adaptive is on. --- .../noti/restore/overlay/OverlayPanelManager.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt index 2392c05..6e35c6d 100644 --- a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt +++ b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt @@ -143,6 +143,13 @@ object OverlayPanelManager { val target = currentBrightnessTarget if (target < 0) return try { + // Don't fight Adaptive Brightness: an external write to SCREEN_BRIGHTNESS + // while the system is in automatic mode (e.g. Settings' own Display screen + // mirroring its live auto-brightness value into this setting) is not KompaktX + // being asked to sync anything — adopting it as a new target and pinning the + // overlay to it here would fight Adaptive Brightness the same way reverting + // did before this branch, just with a different stale-ish value. + if (isAdaptiveBrightnessOn(context.contentResolver)) return val sys = Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS) if (sys != target) { currentBrightnessTarget = sys @@ -2333,6 +2340,14 @@ object OverlayPanelManager { } catch (_: Exception) {} } + /** True when the system's own Adaptive Brightness is currently on. */ + private fun isAdaptiveBrightnessOn(resolver: android.content.ContentResolver): Boolean { + return try { + Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE) == + Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC + } catch (_: Exception) { false } + } + /** Re-apply our brightness target after screen wake. Forces both Settings.System and overlay. */ fun reapplyBrightness() { val ctx = stripContext ?: return