From 867ba642c6dc39f6179ba6862de440d3cccadde8 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 13 Oct 2024 23:36:00 +0200 Subject: [PATCH] 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 &