From d1e6f15abbf4c43af935587559e6ff124a0d00e1 Mon Sep 17 00:00:00 2001 From: Nulo Date: Wed, 9 Nov 2022 17:20:33 -0300 Subject: [PATCH] sway: Operar workspaces similar a GNOME --- .config/sway/config | 9 +++++++++ .local/bin/sway-compact_workspaces | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100755 .local/bin/sway-compact_workspaces diff --git a/.config/sway/config b/.config/sway/config index fdf14ed..1303a6d 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -119,6 +119,15 @@ input * { # bindsym $mod+Shift+8 move container to workspace "8: comms" # bindsym $mod+Shift+9 move container to workspace "9: media" # bindsym $mod+Shift+0 move container to workspace number 10 + # + # https://old.reddit.com/r/swaywm/comments/pe5ipl/workspace_next_or_new/ + set $next_or_new swaymsg -r -t get_workspaces | jq -r --arg OUTPUT $(swaymsg -t get_outputs -r | jq -r '.[] | select(.focused == true) | .name') '(. | (max_by(.num) | .num)) as $max | [.[] | select(.output == $OUTPUT)] | (max_by(.num) | .num) as $maxOutput | (.[] | select(.focused == true) | .num) as $current | if $maxOutput > $current then "next_on_output" else $max + 1 end' + set $prev_or_new swaymsg -r -t get_workspaces | jq -r --arg OUTPUT $(swaymsg -t get_outputs -r | jq -r '.[] | select(.focused == true) | .name') '(. | (max_by(.num) | .num)) as $max | [.[] | select(.output == $OUTPUT)] | (min_by(.num) | .num) as $minOutput | (.[] | select(.focused == true) | .num) as $current | if $minOutput < $current then "prev_on_output" else $current end' + + bindsym Mod4+Prior exec sway-compact_workspaces, exec swaymsg "workspace $($prev_or_new)" + bindsym Mod4+Next exec sway-compact_workspaces, exec swaymsg "workspace $($next_or_new)" + bindsym Mod4+Mod1+Prior exec sway-compact_workspaces, exec swaymsg "move container to workspace $($prev_or_new)" + bindsym Mod4+Mod1+Next exec sway-compact_workspaces, exec swaymsg "move container to workspace $($next_or_new)" # Layout stuff: bindsym $mod+a focus parent diff --git a/.local/bin/sway-compact_workspaces b/.local/bin/sway-compact_workspaces new file mode 100755 index 0000000..5969494 --- /dev/null +++ b/.local/bin/sway-compact_workspaces @@ -0,0 +1,6 @@ +#!/bin/bash +count=1 +for workspace in $(swaymsg -t get_workspaces -r | jq '. | sort_by(.num)[] | .name'); do + swaymsg rename workspace $workspace to $count + ((count+=1)) +done