From d36c5a977958fe0c0e927aa431c0b840b7a72f92 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:36:42 +0700 Subject: [PATCH] sideright: make idle inhibitor synced on ags restart --- .config/ags/modules/sideright/quicktoggles.js | 21 +++++++------------ .config/ags/scripts/wayland-idle-inhibitor.py | 2 ++ scriptdata/dependencies.conf | 3 +-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 39036cece..5cbe8d850 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -89,7 +89,6 @@ export const HyprToggleIcon = async (icon, name, hyprlandConfigValue, props = {} export const ModuleNightLight = (props = {}) => Widget.Button({ // TODO: Make this work attribute: { enabled: false, - yellowlight: undefined, }, className: 'txt-small sidebar-iconbutton', tooltipText: 'Night Light', @@ -142,27 +141,21 @@ export const ModuleInvertColors = async (props = {}) => { export const ModuleIdleInhibitor = (props = {}) => Widget.Button({ // TODO: Make this work attribute: { enabled: false, - inhibitor: undefined, }, className: 'txt-small sidebar-iconbutton', tooltipText: 'Keep system awake', onClicked: (self) => { self.attribute.enabled = !self.attribute.enabled; self.toggleClassName('sidebar-button-active', self.attribute.enabled); - if (self.attribute.enabled) { - self.attribute.inhibitor = Utils.subprocess( - [`${App.configDir}/scripts/wayland-idle-inhibitor.py`], - (output) => print(output), - (err) => logError(err), - self, - ); - } - else { - self.attribute.inhibitor.force_exit(); - } + if (self.attribute.enabled) Utils.execAsync(['bash', '-c', `pidof wayland-idle-inhibitor.py || ${App.configDir}/scripts/wayland-idle-inhibitor.py`]).catch(print) + else Utils.execAsync('pkill -f wayland-idle-inhibitor.py').catch(print); }, child: MaterialIcon('coffee', 'norm'), - setup: setupCursorHover, + setup: (self) => { + setupCursorHover(self); + self.attribute.enabled = !!exec('pidof wayland-idle-inhibitor.py'); + self.toggleClassName('sidebar-button-active', self.attribute.enabled); + }, ...props, }); diff --git a/.config/ags/scripts/wayland-idle-inhibitor.py b/.config/ags/scripts/wayland-idle-inhibitor.py index 5a6d0e442..4a4f8f8ce 100755 --- a/.config/ags/scripts/wayland-idle-inhibitor.py +++ b/.config/ags/scripts/wayland-idle-inhibitor.py @@ -4,6 +4,7 @@ import sys from dataclasses import dataclass from signal import SIGINT, SIGTERM, signal from threading import Event +import setproctitle from pywayland.client.display import Display from pywayland.protocol.idle_inhibit_unstable_v1.zwp_idle_inhibit_manager_v1 import ( @@ -78,4 +79,5 @@ def main() -> None: if __name__ == "__main__": + setproctitle.setproctitle("wayland-idle-inhibitor.py") main() diff --git a/scriptdata/dependencies.conf b/scriptdata/dependencies.conf index eff05caab..3a5496cb8 100644 --- a/scriptdata/dependencies.conf +++ b/scriptdata/dependencies.conf @@ -22,8 +22,7 @@ webp-pixbuf-loader gtk-layer-shell gtk3 gtksourceview3 gobject-introspection upo polkit-gnome gnome-keyring gnome-control-center blueberry networkmanager brightnessctl wlsunset gnome-bluetooth-3.0 ### Widgets -# wayland-idle-inhibitor-git : providing `wayland-idle-inhibitor.py' used by the `Keep system awake' button in `.config/ags/widgets/sideright/quicktoggles.js'. -wayland-idle-inhibitor-git hypridle-git hyprlock-git wlogout wl-clipboard hyprpicker-git grim tesseract slurp anyrun-git +python-pywayland python-psutil hypridle-git hyprlock-git wlogout wl-clipboard hyprpicker-git grim tesseract slurp anyrun-git ### Fonts and Themes adw-gtk3-git qt5ct gradience-git fontconfig lexend-fonts-git ttf-jetbrains-mono-nerd ttf-material-symbols-variable-git ttf-space-mono-nerd fish foot starship