From e4b1ce6a10ae30f6adef5742fea752b12fb9b9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Mon, 12 Feb 2024 09:48:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(hypr):=20script=20to=20move=20?= =?UTF-8?q?a=20window=20into=20their=20specified=20workspace=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit made by https://github.com/moguay, thanks! --- .config/hypr/configs/binds.conf | 1 + .config/hypr/scripts/move_by_rules | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 .config/hypr/scripts/move_by_rules diff --git a/.config/hypr/configs/binds.conf b/.config/hypr/configs/binds.conf index 898a3e3d..cfa70dd8 100644 --- a/.config/hypr/configs/binds.conf +++ b/.config/hypr/configs/binds.conf @@ -72,6 +72,7 @@ bind = SUPERSHIFT, H, movewindow, l bind = SUPERSHIFT, L, movewindow, r bind = SUPERSHIFT, K, movewindow, u bind = SUPERSHIFT, J, movewindow, d +bind = SUPERSHIFT, 51, exec, ~/.config/hypr/scripts/move_by_rules # Center and split bind = SUPER, S, togglesplit diff --git a/.config/hypr/scripts/move_by_rules b/.config/hypr/scripts/move_by_rules new file mode 100755 index 00000000..f76cb739 --- /dev/null +++ b/.config/hypr/scripts/move_by_rules @@ -0,0 +1,24 @@ +#!/usr/bin/bash + +# Script created by: https://github.com/moguay + +# Retrieve the active class of the window +active_class=$(hyprctl -j activewindow | jq '.class') +active_class=$(echo "$active_class" | tr -d \") + +# Read the file and store lines containing 'workspace' in an array +grep 'workspace' ~/.config/hypr/themes/luna/rules.conf | while IFS= read -r line; do + workspace_value=$(echo "$line" | sed -n -e 's/^.*workspace \([0-9]*\)[ ,].*$/\1/p') + class_value=$(echo "$line" | sed -n -e 's/^.*class:\s*\(.*\)$/\1/p') + regex=$class_value + + if [ -n "$workspace_value" ] && [ -n "$class_value" ]; then + + # Compare the retrieved value with the active class of the window + if echo "$active_class" | grep -E "$regex"; then + #echo "The class matches the active class of the window. Workspace value to apply: $workspace_value" + hyprctl dispatch movetoworkspace "$workspace_value" + fi + fi +done +exit 1