From 08680646bb2b3d33726fa8b08db2c3fb71d88f8e Mon Sep 17 00:00:00 2001 From: Sunderland93 Date: Tue, 23 Jul 2024 23:25:29 +0400 Subject: [PATCH] Inhibit idle by stop swayidle.service Qtile had limited support for the wp-idle-inhibit protocol so wayland-idle-inhibit doesn't work as expected. We can inhibit idle by stopping swayidle.service --- debian/changelog | 6 +++ usr/bin/wayland-idle-inhibitor.py | 81 ---------------------------- usr/share/qtile/scripts/idle-inhibit | 16 +++--- 3 files changed, 14 insertions(+), 89 deletions(-) delete mode 100755 usr/bin/wayland-idle-inhibitor.py diff --git a/debian/changelog b/debian/changelog index 8de1e6f..e787308 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +tileos-settings-qtile (1.1.4~tileos) unstable; urgency=medium + + * Inhibit idle by stop swayidle.service + + -- Aleksey Samoilov Tue, 23 Jul 2024 23:24:39 +0400 + tileos-settings-qtile (1.1.3~tileos) unstable; urgency=medium * Fix swayidle autorestart diff --git a/usr/bin/wayland-idle-inhibitor.py b/usr/bin/wayland-idle-inhibitor.py deleted file mode 100755 index d44dc02..0000000 --- a/usr/bin/wayland-idle-inhibitor.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 - -import sys -from dataclasses import dataclass -from signal import SIGINT, SIGTERM, signal -from threading import Event - -from pywayland.client.display import Display -from pywayland.protocol.idle_inhibit_unstable_v1.zwp_idle_inhibit_manager_v1 import ( - ZwpIdleInhibitManagerV1, -) -from pywayland.protocol.wayland.wl_compositor import WlCompositor -from pywayland.protocol.wayland.wl_registry import WlRegistryProxy -from pywayland.protocol.wayland.wl_surface import WlSurface - - -@dataclass -class GlobalRegistry: - surface: WlSurface | None = None - inhibit_manager: ZwpIdleInhibitManagerV1 | None = None - - -def handle_registry_global( - wl_registry: WlRegistryProxy, id_num: int, iface_name: str, version: int -) -> None: - global_registry: GlobalRegistry = wl_registry.user_data or GlobalRegistry() - - if iface_name == "wl_compositor": - compositor = wl_registry.bind(id_num, WlCompositor, version) - global_registry.surface = compositor.create_surface() # type: ignore - elif iface_name == "zwp_idle_inhibit_manager_v1": - global_registry.inhibit_manager = wl_registry.bind( - id_num, ZwpIdleInhibitManagerV1, version - ) - - -def main() -> None: - done = Event() - signal(SIGINT, lambda _, __: done.set()) - signal(SIGTERM, lambda _, __: done.set()) - - global_registry = GlobalRegistry() - - display = Display() - display.connect() - - registry = display.get_registry() # type: ignore - registry.user_data = global_registry - registry.dispatcher["global"] = handle_registry_global - - def shutdown() -> None: - display.dispatch() - display.roundtrip() - display.disconnect() - - display.dispatch() - display.roundtrip() - - if global_registry.surface is None or global_registry.inhibit_manager is None: - print("Wayland seems not to support idle_inhibit_unstable_v1 protocol.") - shutdown() - sys.exit(1) - - inhibitor = global_registry.inhibit_manager.create_inhibitor( # type: ignore - global_registry.surface - ) - - display.dispatch() - display.roundtrip() - - print("Inhibiting idle...") - done.wait() - print("Shutting down...") - - inhibitor.destroy() - - shutdown() - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/usr/share/qtile/scripts/idle-inhibit b/usr/share/qtile/scripts/idle-inhibit index 9b08fe0..9d66bd2 100755 --- a/usr/share/qtile/scripts/idle-inhibit +++ b/usr/share/qtile/scripts/idle-inhibit @@ -2,13 +2,13 @@ # Qtile idle-inhibitor toggle function toggle { - if pgrep -f "wayland-idle-inhibitor" > /dev/null + if pgrep -f "swayidle" > /dev/null then - pkill -f wayland-idle-inhibitor - notify-send -r 5556 -u normal " Screensaver Enabled" - else - /usr/bin/wayland-idle-inhibitor.py & + systemctl --user stop swayidle.service notify-send -r 5556 -u normal " Screensaver Disabled" + else + systemctl --user start swayidle.service + notify-send -r 5556 -u normal " Screensaver Enabled" fi } @@ -17,11 +17,11 @@ case $1 in toggle ;; *) - if pgrep -f "wayland-idle-inhibitor" > /dev/null + if pgrep -f "swayidle" > /dev/null then - icon="" - else icon="" + else + icon="" fi printf "%s" "$icon" ;;