refactor: move idle inhibitor logic into Quickshell
This commit is contained in:
parent
706756d6fa
commit
2d5b25daa3
5 changed files with 25 additions and 148 deletions
8
flake.lock
generated
8
flake.lock
generated
|
|
@ -112,11 +112,11 @@
|
|||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1759976594,
|
||||
"narHash": "sha256-bTrBPRu8CM4YHRSDT6mI5SylEHshujSb2r++C6O/vug=",
|
||||
"rev": "6e1fb585e30d3503dd120f19e64535005357ffc7",
|
||||
"lastModified": 1762840613,
|
||||
"narHash": "sha256-Gda8Ewcs/V4p1Ek18BU+/J874a+KkSm8bA6m9zTsLqU=",
|
||||
"rev": "589aaaf95f487a5f939a2bc4ae0b7ee0b71e0f4c",
|
||||
"type": "tarball",
|
||||
"url": "https://git.tokinanpa.dev/api/v1/repos/toki/quickshell-toki-night/archive/6e1fb585e30d3503dd120f19e64535005357ffc7.tar.gz"
|
||||
"url": "https://git.tokinanpa.dev/api/v1/repos/toki/quickshell-toki-night/archive/589aaaf95f487a5f939a2bc4ae0b7ee0b71e0f4c.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
imports = [
|
||||
./hyprland.nix
|
||||
./idle.nix
|
||||
./quickshell.nix
|
||||
./wltools.nix
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
{ pkgs, lib, ... }:
|
||||
let
|
||||
wayland-idle-inhibitor = pkgs.stdenv.mkDerivation {
|
||||
pname = "wayland-idle-inhibitor";
|
||||
version = "1.0.0";
|
||||
|
||||
buildInputs = [
|
||||
(pkgs.python312.withPackages (ps: with ps; [
|
||||
pywayland
|
||||
]))
|
||||
];
|
||||
|
||||
dontUnpack = true;
|
||||
installPhase = ''
|
||||
install -Dm755 ${./idle/wayland-idle-inhibitor.py} \
|
||||
$out/bin/wayland-idle-inhibitor
|
||||
'';
|
||||
};
|
||||
in {
|
||||
|
||||
services.hypridle.enable = true;
|
||||
services.hypridle.settings = {
|
||||
general = {
|
||||
before_sleep_cmd = "hyprlock";
|
||||
};
|
||||
|
||||
listener = [
|
||||
{
|
||||
timeout = 120;
|
||||
on-timeout = "hyprlock --grace 180";
|
||||
}
|
||||
{
|
||||
timeout = 600;
|
||||
on-timeout = "systemctl suspend";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Idle inhibiting
|
||||
|
||||
home.packages = [
|
||||
wayland-idle-inhibitor
|
||||
];
|
||||
|
||||
systemd.user.services.wayland-pipewire-idle-inhibit = {
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
|
||||
Unit = {
|
||||
Description = "Inhibit Wayland idling when media is played through pipewire";
|
||||
Documentation = "https://github.com/rafaelrc7/wayland-pipewire-idle-inhibit";
|
||||
After = [ "graphical-session-pre.target" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
ConditionEnvironment = "WAYLAND_DISPLAY";
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = "${lib.getExe pkgs.wayland-pipewire-idle-inhibit}";
|
||||
Restart = "always";
|
||||
RestartSec = "10";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
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()
|
||||
|
|
@ -9,6 +9,27 @@
|
|||
imv
|
||||
];
|
||||
|
||||
# Hypridle
|
||||
|
||||
services.hypridle.enable = true;
|
||||
services.hypridle.settings = {
|
||||
general = {
|
||||
before_sleep_cmd = "hyprlock";
|
||||
};
|
||||
|
||||
listener = [
|
||||
{
|
||||
timeout = 120;
|
||||
on-timeout = "hyprlock --grace 180";
|
||||
}
|
||||
{
|
||||
timeout = 600;
|
||||
on-timeout = "systemctl suspend";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
# Hyprlock
|
||||
|
||||
programs.hyprlock.enable = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue