diff options
author | Patrick Spek <p.spek@tyil.nl> | 2023-09-21 11:44:10 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2023-09-21 11:44:10 +0200 |
commit | eaa86d44258ce72dbee5e9fa5304dfe002819036 (patch) | |
tree | 9adaaa2d1f3b7599db24ea18ce8f001ffd2f3e24 | |
parent | d65e96c938a259bdf4745fe06aeadeb7843bbdc1 (diff) |
Try out this hyprland script
-rw-r--r-- | .config/hypr/hyprland.conf | 18 | ||||
-rwxr-xr-x | .local/bin/hyprland-switch-tag | 161 |
2 files changed, 170 insertions, 9 deletions
diff --git a/.config/hypr/hyprland.conf b/.config/hypr/hyprland.conf index 109675d..5e75df6 100644 --- a/.config/hypr/hyprland.conf +++ b/.config/hypr/hyprland.conf @@ -99,15 +99,15 @@ bind=SUPER,SPACE,layoutmsg,orientationnext bind=SUPER_SHIFT,SPACE,layoutmsg,orientationprev bind=SUPER,M,fullscreen,1 -bind=SUPER,2,workspace,1 -bind=SUPER,3,workspace,2 -bind=SUPER,4,workspace,3 -bind=SUPER,5,workspace,4 -bind=SUPER,6,workspace,5 -bind=SUPER,7,workspace,6 -bind=SUPER,8,workspace,7 -bind=SUPER,9,workspace,8 -bind=SUPER,0,workspace,9 +bind=SUPER,2,exec,~/.local/bin/hyprland-switch-tag 1 +bind=SUPER,3,exec,~/.local/bin/hyprland-switch-tag 2 +bind=SUPER,4,exec,~/.local/bin/hyprland-switch-tag 3 +bind=SUPER,5,exec,~/.local/bin/hyprland-switch-tag 4 +bind=SUPER,6,exec,~/.local/bin/hyprland-switch-tag 5 +bind=SUPER,7,exec,~/.local/bin/hyprland-switch-tag 6 +bind=SUPER,8,exec,~/.local/bin/hyprland-switch-tag 7 +bind=SUPER,9,exec,~/.local/bin/hyprland-switch-tag 8 +bind=SUPER,0,exec,~/.local/bin/hyprland-switch-tag 9 bind=SUPER_SHIFT,2,movetoworkspacesilent,1 bind=SUPER_SHIFT,3,movetoworkspacesilent,2 diff --git a/.local/bin/hyprland-switch-tag b/.local/bin/hyprland-switch-tag new file mode 100755 index 0000000..06840c9 --- /dev/null +++ b/.local/bin/hyprland-switch-tag @@ -0,0 +1,161 @@ +#!/usr/bin/env bash + +# Pascal Jaeger <pascal.jaeger@leimstift.de> + +# utils +green="\033[0;32m" +red="\033[0;31m" +blue="\033[0;34m" +nocolor="\033[0m" + +#util functions +check() { + command -v "$1" 1>/dev/null +} + +ok() { + echo -e "[$green $nocolor] $*" +} + +err() { + echo -e "[$red $nocolor] $*" +} +optional() { + echo -e "[$blue $nocolor] $*" +} + +notify() { + # shellcheck disable=SC2015 + check notify-send && { + notify-send "$@" + } || { + echo "$@" + } +} + +checkUtils() { + # shellcheck disable=SC2015 + check grep && ok "grep" || err "grep" + # shellcheck disable=SC2015 + check grep && ok "cut" || err "cut" + # shellcheck disable=SC2015 + check notify-send && ok "notify-send (Optional)" || optional "notify-send (Optional)" + exit +} + +basicChecks() { + check hyprctl || { + notify "Seriously mate!!" "Start Hyprland before this script" + exit 1 + } + pgrep -x Hyprland &>/dev/null || { + notify "Make Sure Hyprland Session is running." + exit 1 + } +} + +help() { + cat <<EOF + This is a bash script to move arbitrary workspace to arbritrary monitor and to swap workspaces between + monitors if the desired workspace is already active on a monitor for Hyprland using hyprctl. + + flags: + -h: Displays This help menu + -c: Checks for all dependencies + + Usage: try_swap_workspace [WORKSPACE] + bind = ALT,1,exec, /path/to/try_swap_workspace/binary 1 + (where the last 1 is the workspace that should be shown on the currently active monitor) + +EOF +} + +getArgs() { + while [ "$#" -gt 0 ]; do + case "$1" in + -h | --help) + help + exit 0 + ;; + -c) + checkUtils + ;; + (*[!0-9]*) + # contains non-numbers + help + echo "" + echo "Wrong argument given" + exit 1 + ;; + *) + # only nubers left, so good + switch_or_swap "$1" + ;; + esac + shift + done +} + + +#variables +mon_wrkspcs=() + +get_active_mon() { + echo $(($(hyprctl monitors | grep 'focused' | grep -n 'yes' | cut -c1)-1)) +} + +get_workspaces_array() { + local workspaces + workspaces=$(hyprctl monitors | grep 'active workspace' | cut -f3 -d' ') + SAVEIFS=$IFS + IFS=$'\n' + mon_wrkspcs=($workspaces) + IFS=$SAVEIFS +} + +# first argument: workspace to switch to +# second argument: monitor to switch workspace on +switch_workspace() { + local target_wrkspc=$1 + local target_mon=$2 + hyprctl dispatch moveworkspacetomonitor "$target_wrkspc" "$target_mon" + hyprctl dispatch workspace "$target_wrkspc" +} +# first argument: monitor the workspace should go to +# second argument: monitor the workspace is currently displayed on +swap_workspace() { + local target_mon=$1 + local source_mon=$2 + hyprctl dispatch swapactiveworkspaces "$target_mon" "$source_mon" +} + +# first argument: workspace to switch to active monitor +switch_or_swap() { + target_mon=$(get_active_mon) + target_wrkspc=$1 + get_workspaces_array + # check if the workspace is currently displayed on another monitor + local currently_active_on_mon=-1 + for (( i=0; i<${#mon_wrkspcs[@]}; i++ )) + do + if [[ "$target_wrkspc" == "${mon_wrkspcs[$i]}" ]]; then + currently_active_on_mon=$i + fi + done + if [[ $currently_active_on_mon -lt 0 ]]; then + # workspace is not active on any monitor, do a normal switch + ok "switching workspace $target_wrkspc to monitor $target_mon" + switch_workspace "$target_wrkspc" "$target_mon" + else + # workspace is already active on other monitor, swap workspaces between monitor + ok "swapping workspaces between $target_mon to monitor $currently_active_on_mon" + swap_workspace "$target_mon" "$currently_active_on_mon" + fi +} + +main() { + basicChecks + getArgs "$@" +} + +main "$@" |