From c3a1612b0f06a53a5db1b015e2a3bc144d787460 Mon Sep 17 00:00:00 2001 From: thek4n Date: Fri, 23 May 2025 11:04:29 +0300 Subject: [PATCH] i3 bind swap workspaces --- TARGETS.sh | 2 +- home/user/.config/i3/config | 1 + home/user/.local/bin/i3_swap_workspaces | 26 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 home/user/.local/bin/i3_swap_workspaces diff --git a/TARGETS.sh b/TARGETS.sh index f57026e..1089159 100644 --- a/TARGETS.sh +++ b/TARGETS.sh @@ -11,7 +11,7 @@ ssh: git:.config/git ranger:.config/ranger gpg: -i3:.xinitrc .xprofile .Xresources .config/i3 .config/i3status .local/bin/i3status_wrapper .config/rofi .config/picom .local/bin/slm .local/bin/slm_rofi.sh .local/bin/power_rofi.sh .local/bin/i3_switch_workspace.sh .config/mimeapps.list .local/bin/screenshot +i3:.xinitrc .xprofile .Xresources .config/i3 .config/i3status .local/bin/i3status_wrapper .config/rofi .config/picom .local/bin/slm .local/bin/slm_rofi.sh .local/bin/power_rofi.sh .local/bin/i3_switch_workspace.sh .config/mimeapps.list .local/bin/screenshot .local/bin/i3_swap_workspaces bat:.config/bat font: termux:.termux diff --git a/home/user/.config/i3/config b/home/user/.config/i3/config index 7fba644..9559f8e 100644 --- a/home/user/.config/i3/config +++ b/home/user/.config/i3/config @@ -232,6 +232,7 @@ bindsym Shift+Print exec --no-startup-id screenshot select save bindsym Shift+$mod+Print exec --no-startup-id screenshot window save bindsym Shift+Ctrl+Print exec --no-startup-id screenshot entire save +bindsym $mod+s exec --no-startup-id i3_swap_workspaces # default workspaces for monitors in setup workspace $ws1 output primary diff --git a/home/user/.local/bin/i3_swap_workspaces b/home/user/.local/bin/i3_swap_workspaces new file mode 100755 index 0000000..252d229 --- /dev/null +++ b/home/user/.local/bin/i3_swap_workspaces @@ -0,0 +1,26 @@ +#!/bin/bash + + +set -eu + + +current_monitor=$(i3-msg -t get_workspaces | jq '.[] | select(.focused).output' | tr -d '"') +other_monitor=$(i3-msg -t get_outputs | jq -r ".[] | select(.active and .name != \"${current_monitor}\").name" | head -n 1) + +if [ -z "${other_monitor}" ]; then + echo "No other active monitor found." + exit 1 +fi + +current_workspace=$(i3-msg -t get_workspaces | jq '.[] | select(.focused).name' | tr -d '"') +other_workspace=$(i3-msg -t get_workspaces | jq -r ".[] | select(.visible and .output == \"${other_monitor}\").name" | head -n 1) + +if [ -n "${other_workspace}" ]; then + # Swap workspaces + i3-msg "workspace ${other_workspace}; move workspace to output ${current_monitor}" + i3-msg "workspace ${current_workspace}; move workspace to output ${other_monitor}" + i3-msg "workspace ${other_workspace}" +else + # Just move current workspace if target is empty + i3-msg "move workspace to output ${other_monitor}" +fi