Browse Source

feat(spoolbuddy): auto-wake display on NFC tag scan or scale activity (#945)

  Display now powers on via wlopm when the daemon detects an NFC tag or
  weight change while the screen is blanked.  The daemon only re-blanks
  screens it woke itself — touch-based wake/blank stays with swayidle so
  the two don't conflict.  Daemon discovers the Wayland session from the
  shared runtime dir since it runs as a systemd service outside the
  compositor.
maziggy 1 month ago
parent
commit
f135605908
1 changed files with 14 additions and 3 deletions
  1. 14 3
      spoolbuddy/daemon/display_control.py

+ 14 - 3
spoolbuddy/daemon/display_control.py

@@ -27,6 +27,7 @@ class DisplayControl:
         self._blank_timeout = 0  # seconds, 0 = disabled
         self._last_activity = time.monotonic()
         self._blanked = False
+        self._daemon_woke = False  # True when the daemon woke the display (NFC/scale)
         self._wlopm_path = shutil.which("wlopm")
         self._wayland_env: dict[str, str] | None = None
         self._output = os.environ.get("SPOOLBUDDY_DISPLAY_OUTPUT", "HDMI-A-1")
@@ -141,10 +142,20 @@ class DisplayControl:
 
     def _blank(self):
         self._blanked = True
-        self._wlopm(on=False)
-        logger.debug("Screen idle timeout reached, HDMI off")
+        # Only power off HDMI if the daemon was responsible for the last wake.
+        # Touch-based wake/blank is managed entirely by swayidle — if we called
+        # wlopm --off here unconditionally, we'd fight swayidle because the
+        # daemon never sees touch events and its idle timer would expire while
+        # the user is still interacting via the touchscreen.
+        if self._daemon_woke:
+            self._daemon_woke = False
+            self._wlopm(on=False)
+            logger.debug("Daemon wake idle timeout reached, HDMI off")
+        else:
+            logger.debug("Screen idle timeout reached (swayidle manages HDMI)")
 
     def _unblank(self):
         self._blanked = False
+        self._daemon_woke = True
         self._wlopm(on=True)
-        logger.debug("Activity detected, HDMI on")
+        logger.debug("Activity detected (NFC/scale), HDMI on")