Add Wayland display server support for power management
Added support for both X11 and Wayland environments: Display Server Detection: - Auto-detects Wayland via WAYLAND_DISPLAY environment variable - Falls back to X11 commands if not Wayland - Works seamlessly on both display servers Wayland-specific tools: - wlopm - Wayland output power management (keeps display on) - wlr-randr - Output management for wlroots compositors - ydotool - Mouse movement for Wayland (alternative to xdotool) - systemd-inhibit integration for idle prevention Enhanced display keep-alive script: - Detects display server type on startup - Uses appropriate commands based on environment - Wayland: wlopm, wlr-randr, ydotool - X11: xset, xdotool, xrandr - Both: tvservice for HDMI power control App-level improvements (main.py): - Detects Wayland via os.environ check - Executes Wayland-specific commands when detected - Maintains X11 compatibility for older systems Installation improvements: - Auto-installs Wayland tools if Wayland is detected - Attempts to install: wlopm, wlr-randr, ydotool - Graceful fallback if packages unavailable This ensures HDMI power management works correctly on: - Raspberry Pi OS with X11 (older versions) - Raspberry Pi OS with Wayland (Bookworm and newer) - Any Linux system using either display server
This commit is contained in:
69
src/main.py
69
src/main.py
@@ -930,34 +930,55 @@ class SignagePlayer(Widget):
|
||||
def signal_screen_activity(self, dt):
|
||||
"""Signal screen activity to prevent power saving/sleep
|
||||
|
||||
Uses multiple methods to keep display awake:
|
||||
1. xset s reset - Reset screensaver timeout
|
||||
2. xset dpms force on - Force display on
|
||||
3. xdotool - Move mouse to trigger activity
|
||||
4. tvservice - Keep HDMI powered on (Raspberry Pi)
|
||||
5. xrandr - Disable monitor power saving
|
||||
Supports both X11 and Wayland display servers.
|
||||
Uses multiple methods to keep display awake.
|
||||
"""
|
||||
try:
|
||||
# Method 1: Reset screensaver timer using xset
|
||||
os.system('DISPLAY=:0 xset s reset 2>/dev/null')
|
||||
# Detect display server type
|
||||
is_wayland = os.environ.get('WAYLAND_DISPLAY') is not None
|
||||
|
||||
# Method 2: Force display on
|
||||
os.system('DISPLAY=:0 xset dpms force on 2>/dev/null')
|
||||
|
||||
# Method 3: Disable DPMS
|
||||
os.system('DISPLAY=:0 xset -dpms 2>/dev/null')
|
||||
|
||||
# Method 4: Move mouse slightly (subtle, user won't notice)
|
||||
if os.system('DISPLAY=:0 xdotool mousemove_relative 1 1 2>/dev/null') == 0:
|
||||
os.system('DISPLAY=:0 xdotool mousemove_relative -1 -1 2>/dev/null')
|
||||
|
||||
# Method 5: Keep HDMI powered on (Raspberry Pi specific)
|
||||
os.system('/usr/bin/tvservice -p 2>/dev/null')
|
||||
|
||||
# Method 6: Disable monitor power saving via xrandr
|
||||
os.system('DISPLAY=:0 xrandr --output HDMI-1 --power-profile performance 2>/dev/null || true')
|
||||
if is_wayland:
|
||||
# Wayland-specific commands
|
||||
|
||||
Logger.debug("SignagePlayer: Screen activity signal sent (display kept awake)")
|
||||
# Method 1: Use wlopm (Wayland output power management)
|
||||
os.system('wlopm --on \* 2>/dev/null || true')
|
||||
|
||||
# Method 2: Use wlr-randr for wlroots compositors
|
||||
os.system('wlr-randr --output HDMI-A-1 --on 2>/dev/null || true')
|
||||
|
||||
# Method 3: Simulate activity via ydotool (Wayland's xdotool alternative)
|
||||
if os.system('which ydotool 2>/dev/null') == 0:
|
||||
os.system('ydotool mousemove -x 1 -y 1 2>/dev/null || true')
|
||||
os.system('ydotool mousemove -x -1 -y -1 2>/dev/null || true')
|
||||
|
||||
# Method 4: Keep HDMI powered on (works on both)
|
||||
os.system('/usr/bin/tvservice -p 2>/dev/null')
|
||||
|
||||
Logger.debug("SignagePlayer: Wayland screen activity signal sent")
|
||||
|
||||
else:
|
||||
# X11-specific commands (original code)
|
||||
|
||||
# Method 1: Reset screensaver timer using xset
|
||||
os.system('DISPLAY=:0 xset s reset 2>/dev/null')
|
||||
|
||||
# Method 2: Force display on
|
||||
os.system('DISPLAY=:0 xset dpms force on 2>/dev/null')
|
||||
|
||||
# Method 3: Disable DPMS
|
||||
os.system('DISPLAY=:0 xset -dpms 2>/dev/null')
|
||||
|
||||
# Method 4: Move mouse slightly (subtle, user won't notice)
|
||||
if os.system('DISPLAY=:0 xdotool mousemove_relative 1 1 2>/dev/null') == 0:
|
||||
os.system('DISPLAY=:0 xdotool mousemove_relative -1 -1 2>/dev/null')
|
||||
|
||||
# Method 5: Keep HDMI powered on (Raspberry Pi specific)
|
||||
os.system('/usr/bin/tvservice -p 2>/dev/null')
|
||||
|
||||
# Method 6: Disable monitor power saving via xrandr
|
||||
os.system('DISPLAY=:0 xrandr --output HDMI-1 --power-profile performance 2>/dev/null || true')
|
||||
|
||||
Logger.debug("SignagePlayer: X11 screen activity signal sent")
|
||||
|
||||
except Exception as e:
|
||||
Logger.debug(f"SignagePlayer: Screen activity signal failed (non-critical): {e}")
|
||||
|
||||
Reference in New Issue
Block a user