toggle: refactor with proper flags
Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
parent
661ee80da0
commit
bddacf341c
1 changed files with 47 additions and 16 deletions
|
@ -1,27 +1,58 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
# Toggle tagged window, launch if needed
|
||||
#?? toggle TAG WORKSPACE [COMMAND]
|
||||
# TODO: Use proper flags
|
||||
# TODO: Support floating groups
|
||||
set -x
|
||||
|
||||
if (("$#" >= 3)); then
|
||||
# Launch if tag does not exist yet
|
||||
if ! hyprctl -j clients | jq -r '.[].tags[]' | grep "$1"; then
|
||||
hyprctl dispatch exec -- "${@:3}"
|
||||
# Toggle pinned window, launch if needed
|
||||
#?? toggle --type TYPE --expression EXPRESSION --workspace WORKSPACE [COMMAND]
|
||||
#!! Regex may need to be double-escaped
|
||||
# https://jqlang.github.io/jq/manual/#regular-expressions
|
||||
|
||||
focus=false
|
||||
|
||||
while (("$#" > 0)); do
|
||||
case "$1" in
|
||||
-e | --expression)
|
||||
shift
|
||||
expression="$1"
|
||||
;;
|
||||
-f | --focus)
|
||||
focus=true
|
||||
;;
|
||||
-t | --type)
|
||||
shift
|
||||
type="$1"
|
||||
;;
|
||||
-w | --workspace)
|
||||
shift
|
||||
workspace="$1"
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
command="${*}"
|
||||
|
||||
if [[ "$command" ]]; then
|
||||
if ! hyprctl -j clients | jq -re "any(.[].$type | test(\"$expression\"); . == true)"; then
|
||||
hyprctl dispatch exec -- "$command" # Launch window
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
# Dispatchers do not currently support matching by tag, so select address
|
||||
window="address:$(hyprctl -j clients | jq -r "first(.[] | select(.tags[] | startswith(\"$1\")).address)")"
|
||||
current_workspace="$(hyprctl -j clients | jq -r "first(.[] | select(.$type | test(\"$expression\")).workspace.name)")"
|
||||
|
||||
workspace="$(hyprctl -j clients | jq -r "first(.[] | select(.tags[] | startswith(\"$1\")).workspace.name)")"
|
||||
if [[ "$current_workspace" == "$workspace" ]]; then
|
||||
hyprctl dispatch movetoworkspacesilent "0,$type:$expression" # Move to current workspace first, otherwise some windows freeze
|
||||
hyprctl dispatch pin "$type:$expression" # Pin
|
||||
|
||||
if [[ "$workspace" == "$2" ]]; then
|
||||
hyprctl dispatch pin "$window" # Pin
|
||||
(("$#" >= 3)) && hyprctl dispatch focuswindow "$window" # Focus if third argument
|
||||
if "$focus"; then
|
||||
hyprctl dispatch focuswindow "$type:$expression" # Focus
|
||||
fi
|
||||
else
|
||||
hyprctl dispatch pin "$window" # Unpin
|
||||
hyprctl dispatch movetoworkspacesilent "$2,$window"
|
||||
hyprctl dispatch pin "$type:$expression" # Unpin
|
||||
hyprctl dispatch movetoworkspacesilent "$workspace,$type:$expression" # Move to workspace
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue