aboutsummaryrefslogtreecommitdiff
path: root/.config/swayrbar/scripts
diff options
context:
space:
mode:
authorLuca Matei Pintilie <luca@lucamatei.com>2024-07-11 17:53:42 +0000
committerLuca Matei Pintilie <luca@lucamatei.com>2024-07-11 17:53:42 +0000
commitd7a21e259b80010ce7368e8aaa0863886a947085 (patch)
tree73584e30416fec4264aeea9b1a20aae9846f02ee /.config/swayrbar/scripts
parent9c0ae0039bb239291b0fdf42a2a205aff0356916 (diff)
downloaddotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar.gz
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar.bz2
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar.lz
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar.xz
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.tar.zst
dotfiles-d7a21e259b80010ce7368e8aaa0863886a947085.zip
swayrbar: add config
Diffstat (limited to '.config/swayrbar/scripts')
-rwxr-xr-x.config/swayrbar/scripts/brightness-status23
-rwxr-xr-x.config/swayrbar/scripts/idle-status10
-rwxr-xr-x.config/swayrbar/scripts/idle-toggle11
-rwxr-xr-x.config/swayrbar/scripts/temp-status6
-rwxr-xr-x.config/swayrbar/scripts/wayland-idle-inhibitor.py95
5 files changed, 145 insertions, 0 deletions
diff --git a/.config/swayrbar/scripts/brightness-status b/.config/swayrbar/scripts/brightness-status
new file mode 100755
index 0000000..562ee62
--- /dev/null
+++ b/.config/swayrbar/scripts/brightness-status
@@ -0,0 +1,23 @@
+#!/usr/bin/env sh
+
+brightness_path=/sys/class/backlight/*/brightness
+brightness_max_path=/sys/class/backlight/*/max_brightness
+
+if [ -f "${brightness_path}" ]
+then
+ brightness="$(cat $brightness_path)"
+fi
+
+if [ -f "${brightness_max_path}" ]
+then
+ brightness_max="$(cat /sys/class/backlight/*/max_brightness)"
+fi
+
+if [ -n "${brightness}" ] && [ -n "${brightness_max}" ]
+then
+ level=$(echo "scale=2; $brightness / $brightness_max * 100" | bc)
+
+ printf " "
+ printf "%.0f\n" $level
+fi
+
diff --git a/.config/swayrbar/scripts/idle-status b/.config/swayrbar/scripts/idle-status
new file mode 100755
index 0000000..9420e64
--- /dev/null
+++ b/.config/swayrbar/scripts/idle-status
@@ -0,0 +1,10 @@
+#!/usr/bin/env sh
+pid_file="/tmp/wayland-idle-inhibitor-$(id --user).pid"
+pid=$(cat "${pid_file}")
+if [ -n "${pid}" ] && kill -0 "${pid}"
+then
+ echo -n " "
+else
+ echo -n " "
+fi
+
diff --git a/.config/swayrbar/scripts/idle-toggle b/.config/swayrbar/scripts/idle-toggle
new file mode 100755
index 0000000..fd1a796
--- /dev/null
+++ b/.config/swayrbar/scripts/idle-toggle
@@ -0,0 +1,11 @@
+#!/usr/bin/env sh
+pid_file="/tmp/wayland-idle-inhibitor-$(id --user).pid"
+pid=$(cat "${pid_file}")
+if [ -n "${pid}" ]
+then
+ kill -- "${pid}"
+ rm "${pid_file}"
+else
+ nohup "${HOME}/.config/swayrbar/scripts/wayland-idle-inhibitor.py" > /dev/null 2>&1 & echo $! > "${pid_file}"
+fi
+
diff --git a/.config/swayrbar/scripts/temp-status b/.config/swayrbar/scripts/temp-status
new file mode 100755
index 0000000..60220d2
--- /dev/null
+++ b/.config/swayrbar/scripts/temp-status
@@ -0,0 +1,6 @@
+#!/usr/bin/env sh
+
+temps="$(cat /sys/class/hwmon/hwmon*/temp*_input)"
+temp=$(echo \("$(echo -n "$temps" | tr '\n' '+')) / $(echo "$temps" | wc -l) / 1000" | bc)
+
+echo -n "$temp" °C
diff --git a/.config/swayrbar/scripts/wayland-idle-inhibitor.py b/.config/swayrbar/scripts/wayland-idle-inhibitor.py
new file mode 100755
index 0000000..6ce90cf
--- /dev/null
+++ b/.config/swayrbar/scripts/wayland-idle-inhibitor.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+
+# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+# Everyone is permitted to copy and distribute verbatim or modified
+# copies of this license document, and changing it is allowed as long
+# as the name is changed.
+
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+
+
+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()