From b0ca57ac4ae56dcf138ca3250800b962317c5f60 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 21:56:51 +0200 Subject: [PATCH 1/5] Add custom service to watch monitor updates --- home/.config/hyprland-monitord/added.sh | 8 ++ home/.config/hyprland-monitord/removed.sh | 6 + .../systemd/user/hyprland-monitord.service | 10 ++ .../hyprland-monitord.service | 1 + .../scripts/gui/hyprland/hyprland-monitord | 111 ++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100755 home/.config/hyprland-monitord/added.sh create mode 100755 home/.config/hyprland-monitord/removed.sh create mode 100644 home/.config/systemd/user/hyprland-monitord.service create mode 120000 home/.config/systemd/user/wayland-session.target.wants/hyprland-monitord.service create mode 100755 home/.local/bin/scripts/gui/hyprland/hyprland-monitord diff --git a/home/.config/hyprland-monitord/added.sh b/home/.config/hyprland-monitord/added.sh new file mode 100755 index 0000000..2ae53cb --- /dev/null +++ b/home/.config/hyprland-monitord/added.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +MONITOR_ID="$1" +MONITOR_NAME="$2" +MONITOR_DESCRIPTION="$3" + +eww open bar1 diff --git a/home/.config/hyprland-monitord/removed.sh b/home/.config/hyprland-monitord/removed.sh new file mode 100755 index 0000000..e9b0900 --- /dev/null +++ b/home/.config/hyprland-monitord/removed.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail + +MONITOR_NAME="$1" + +eww close bar1 diff --git a/home/.config/systemd/user/hyprland-monitord.service b/home/.config/systemd/user/hyprland-monitord.service new file mode 100644 index 0000000..3b2836d --- /dev/null +++ b/home/.config/systemd/user/hyprland-monitord.service @@ -0,0 +1,10 @@ +[Unit] +Description="Daemon watching for Hyprland monitor updates" +PartOf=graphical-session.target + +[Service] +ExecStart=%h/.local/bin/scripts/gui/hyprland/hyprland-monitord +Restart=on-failure + +[Install] +WantedBy=wayland-session.target diff --git a/home/.config/systemd/user/wayland-session.target.wants/hyprland-monitord.service b/home/.config/systemd/user/wayland-session.target.wants/hyprland-monitord.service new file mode 120000 index 0000000..72f9575 --- /dev/null +++ b/home/.config/systemd/user/wayland-session.target.wants/hyprland-monitord.service @@ -0,0 +1 @@ +/home/itsdrike/.config/systemd/user/hyprland-monitord.service \ No newline at end of file diff --git a/home/.local/bin/scripts/gui/hyprland/hyprland-monitord b/home/.local/bin/scripts/gui/hyprland/hyprland-monitord new file mode 100755 index 0000000..d7aa508 --- /dev/null +++ b/home/.local/bin/scripts/gui/hyprland/hyprland-monitord @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Simple script that listens for changes in monitor configuration and performs +# certain configured actions. + +# Copyright 2024 ItsDrike +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 59 Temple +# Place, Suite 330, Boston, MA 02111-1307 USA + +SCRIPTS_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/hyprland-monitord" +ADD_SCRIPT="$SCRIPTS_DIR/added.sh" +REMOVE_SCRIPT="$SCRIPTS_DIR/removed.sh" + +if [ "$#" -ne 0 ]; then + >&2 echo "CLI arguments are not supported" + exit 1 +fi + +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + >&2 echo "Hyprland is not running, IPC not available" + exit 1 +fi + +SOCKET_PATH="${XDG_RUNTIME_DIR:-/run/user/$UID}/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" + +# Older versions of hyprland used a different socket path +# (if someone still actually needs this condition, please for gods sake update) +if ! [ -S "$SOCKET_PATH" ]; then + SOCKET_PATH="/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" +fi + +if ! [ -S "$SOCKET_PATH" ]; then + >&2 echo "Hyprland IPC socket2 file wasn't found!" + exit 1 +fi + +# Will block and listen to the hyprland socket messages, outputting them. +# Generally used like: hyprland_ipc | while read line; do handle $line; done +# Read for output format and available events +# Note: requires openbsd version of netcat. +# $1 - Optional event to listen for (no event filtering will be done if not provided) +hyprland_ipc() { + if [ "$#" -eq 0 ]; then + nc -U "$SOCKET_PATH" | while read -r line; do + echo "$line" + done + else + nc -U "$SOCKET_PATH" | while read -r line; do + if echo "$line" | grep -E "$1>>" >/dev/null; then + echo "$line" | awk -F '>>' '{print $2}' + fi + done + fi +} + +# Function ran whenever the monitoraddedv2 event is emitted +handle_add() { + local monitor_id + local monitor_name + local monitor_description + monitor_id="$(echo "$1" | cut -d',' -f1)" + monitor_name="$(echo "$1" | cut -d',' -f2)" + monitor_description="$(echo "$1" | cut -d',' -f3)" + + >&2 echo "Monitor added: $monitor_id;$monitor_name;$monitor_description" + + if [ -f "$ADD_SCRIPT" ]; then + "$ADD_SCRIPT" "$monitor_id" "$monitor_name" "$monitor_description" + else + >&2 echo "Add script file not found ($ADD_SCRIPT)" + fi +} + +# Function ran whenever the monitorremoved event is emitted +handle_remove() { + local monitor_name + monitor_name="$1" + + >&2 echo "Monitor removed: $monitor_name" + + if [ -f "$REMOVE_SCRIPT" ]; then + "$REMOVE_SCRIPT" "$monitor_name" + else + >&2 echo "Remove script file not found ($REMOVE_SCRIPT)" + fi +} + +>&2 echo "Listening for monitor IPC events" + +hyprland_ipc "monitoraddedv2" | while read -r line; do + handle_add "$line" +done & + +hyprland_ipc "monitorremoved" | while read -r line; do + handle_remove "$line" +done & + +wait From e90cada8979e307ba18233440cd310529d66ae2b Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 21:57:17 +0200 Subject: [PATCH 2/5] Make hyprland-move-window script executable --- home/.local/bin/scripts/gui/hyprland/hyprland-move-window | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 home/.local/bin/scripts/gui/hyprland/hyprland-move-window diff --git a/home/.local/bin/scripts/gui/hyprland/hyprland-move-window b/home/.local/bin/scripts/gui/hyprland/hyprland-move-window old mode 100644 new mode 100755 From b9aaebc10ce79515f1006f22f5f937ef4d59a4ba Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 22:00:36 +0200 Subject: [PATCH 3/5] Add another qualculate shortcut --- home/.config/hypr/hyprland.d/keybinds.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/home/.config/hypr/hyprland.d/keybinds.conf b/home/.config/hypr/hyprland.d/keybinds.conf index 875672b..c2075b9 100644 --- a/home/.config/hypr/hyprland.d/keybinds.conf +++ b/home/.config/hypr/hyprland.d/keybinds.conf @@ -30,6 +30,7 @@ bind = SUPER_SHIFT, V, exec, clipman pick -t wofi bind = SUPER, Return, exec, kitty bind = SUPER, X, exec, pcmanfm-qt bind = SUPER, B, exec, firefox +bind = SUPER, C, exec, qalculate-gtk bind = , XF86Calculator, exec, qalculate-gtk # ##################### From d9c71e23102721a24fd5898c5467d8389ef6a72b Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 23:17:13 +0200 Subject: [PATCH 4/5] Make docker use btrfs --- root/etc/docker/daemon.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 root/etc/docker/daemon.json diff --git a/root/etc/docker/daemon.json b/root/etc/docker/daemon.json new file mode 100644 index 0000000..993b8de --- /dev/null +++ b/root/etc/docker/daemon.json @@ -0,0 +1,3 @@ +{ + "storage-driver": "btrfs" +} From 867ba642c6dc39f6179ba6862de440d3cccadde8 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 23:36:00 +0200 Subject: [PATCH 5/5] Add support for init script to hyprland-monitord --- home/.config/hyprland-monitord/init.sh | 22 +++++++++++++++++++ .../scripts/gui/hyprland/hyprland-monitord | 7 ++++++ 2 files changed, 29 insertions(+) create mode 100755 home/.config/hyprland-monitord/init.sh diff --git a/home/.config/hyprland-monitord/init.sh b/home/.config/hyprland-monitord/init.sh new file mode 100755 index 0000000..4236d92 --- /dev/null +++ b/home/.config/hyprland-monitord/init.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +MONITORS_AMT="$(hyprctl monitors -j | jq length)" + +if [ "$MONITORS_AMT" -lt 1 ]; then + >&2 echo "You seem to have 0 monitors..." + exit 1 +fi + +if [ "$MONITORS_AMT" -eq 2 ]; then + eww open bar1 +fi + +if [ "$MONITORS_AMT" -eq 1 ]; then + eww active-windows | grep "bar1" && eww close bar1 +fi + +if [ "$MONITORS_AMT" -gt 2 ]; then + >&2 echo "Unexpected monitor configuration (more than 2 monitors)" + exit 1 +fi diff --git a/home/.local/bin/scripts/gui/hyprland/hyprland-monitord b/home/.local/bin/scripts/gui/hyprland/hyprland-monitord index d7aa508..8395a8e 100755 --- a/home/.local/bin/scripts/gui/hyprland/hyprland-monitord +++ b/home/.local/bin/scripts/gui/hyprland/hyprland-monitord @@ -21,6 +21,7 @@ set -euo pipefail # Place, Suite 330, Boston, MA 02111-1307 USA SCRIPTS_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/hyprland-monitord" +INIT_SCRIPT="$SCRIPTS_DIR/init.sh" ADD_SCRIPT="$SCRIPTS_DIR/added.sh" REMOVE_SCRIPT="$SCRIPTS_DIR/removed.sh" @@ -100,6 +101,12 @@ handle_remove() { >&2 echo "Listening for monitor IPC events" +if [ -f "$INIT_SCRIPT" ]; then + "$INIT_SCRIPT" +else + >&2 echo "Init script file not found ($INIT_SCRIPT)" +fi + hyprland_ipc "monitoraddedv2" | while read -r line; do handle_add "$line" done &