From f8a6e84aa9b9229a1b527dcd1c662c1068759dd8 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Thu, 3 Apr 2025 21:41:26 +1100 Subject: toggles: refactor to have config Config is in $XDG_CONFIG_HOME/caelestia/scripts.json Selector is a jq selector using hyprland client data Spawn is a command passed to uwsm app Action is either spawn, move, or both Extra cond is an extra shell command to check whether to do action (for easy disabling just put false or empty action) --- toggles/util.fish | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'toggles/util.fish') diff --git a/toggles/util.fish b/toggles/util.fish index 4d7df2c..f02dc73 100644 --- a/toggles/util.fish +++ b/toggles/util.fish @@ -1,4 +1,6 @@ -function move-client -a selector -a workspace +. (dirname (status filename))/../util.fish + +function move-client -a selector workspace if hyprctl -j clients | jq -e 'first(.[] | select('$selector')).workspace.name != "special:'$workspace'"' > /dev/null # Window not in correct workspace set -l window_addr (hyprctl -j clients | jq -r 'first(.[] | select('$selector')).address') @@ -6,16 +8,35 @@ function move-client -a selector -a workspace end end -function spawn-client -a selector +function spawn-client -a selector spawn # Spawn if doesn't exist hyprctl -j clients | jq -e "first(.[] | select($selector))" > /dev/null set -l stat $status if test $stat != 0 - uwsm app -- $argv[2..] & disown + eval "uwsm app -- $spawn & disown" end test $stat != 0 # Exit 1 if already exists end -function spawn-or-move -a selector -a workspace - spawn-client $selector $argv[3..] || move-client $selector $workspace +function jq-var -a op json + jq -rn --argjson json "$json" "\$json | $op" +end + +function toggle-workspace -a workspace + set -l apps (get-config "toggles.$workspace.apps") + + for i in (seq 0 (math (jq-var 'length' "$apps") - 1)) + set -l app (jq-var ".[$i]" "$apps") + set -l action (jq-var '.action' "$app") + set -l selector (jq-var '.selector' "$app") + set -l extra_cond (jq-var '.extraCond' "$app") + + test $extra_cond = null && set -l extra_cond true + if eval $extra_cond + string match -qe -- 'spawn' $action && spawn-client $selector (jq-var '.spawn' "$app") + string match -qe -- 'move' $action && move-client $selector $workspace + end + end + + hyprctl dispatch togglespecialworkspace $workspace end -- cgit v1.2.3-freya