i3: Simulate monitor-independent workspaces
Often when I want to open a new workspace, I look at my bar to see which workspaces are still free. This does not work sometimes when having multiple monitors connected, as workspace numbers are unique between all outputs. Add a script that handles workspace switching/moving by prepending the index with the index of the current monitor.
This commit is contained in:
@@ -97,29 +97,17 @@ bindsym $mod+space focus mode_toggle
|
|||||||
# focus the parent container
|
# focus the parent container
|
||||||
bindsym $mod+a focus parent
|
bindsym $mod+a focus parent
|
||||||
|
|
||||||
# Set workspace names
|
|
||||||
set $ws1 "1"
|
|
||||||
set $ws2 "2"
|
|
||||||
set $ws3 "3"
|
|
||||||
set $ws4 "4"
|
|
||||||
set $ws5 "5"
|
|
||||||
set $ws6 "6"
|
|
||||||
set $ws7 "7"
|
|
||||||
set $ws8 "8"
|
|
||||||
set $ws9 "9"
|
|
||||||
set $ws10 "10"
|
|
||||||
|
|
||||||
# switch to workspace
|
# switch to workspace
|
||||||
bindsym $mod+1 workspace $ws1
|
bindsym $mod+1 exec ~/.config/i3/multi-monitor-workspaces.sh -s 1
|
||||||
bindsym $mod+2 workspace $ws2
|
bindsym $mod+2 exec ~/.config/i3/multi-monitor-workspaces.sh -s 2
|
||||||
bindsym $mod+3 workspace $ws3
|
bindsym $mod+3 exec ~/.config/i3/multi-monitor-workspaces.sh -s 3
|
||||||
bindsym $mod+4 workspace $ws4
|
bindsym $mod+4 exec ~/.config/i3/multi-monitor-workspaces.sh -s 4
|
||||||
bindsym $mod+5 workspace $ws5
|
bindsym $mod+5 exec ~/.config/i3/multi-monitor-workspaces.sh -s 5
|
||||||
bindsym $mod+6 workspace $ws6
|
bindsym $mod+6 exec ~/.config/i3/multi-monitor-workspaces.sh -s 6
|
||||||
bindsym $mod+7 workspace $ws7
|
bindsym $mod+7 exec ~/.config/i3/multi-monitor-workspaces.sh -s 7
|
||||||
bindsym $mod+8 workspace $ws8
|
bindsym $mod+8 exec ~/.config/i3/multi-monitor-workspaces.sh -s 8
|
||||||
bindsym $mod+9 workspace $ws9
|
bindsym $mod+9 exec ~/.config/i3/multi-monitor-workspaces.sh -s 9
|
||||||
bindsym $mod+0 workspace $ws10
|
bindsym $mod+0 exec ~/.config/i3/multi-monitor-workspaces.sh -s 0
|
||||||
|
|
||||||
# switch back to the previous workspace
|
# switch back to the previous workspace
|
||||||
workspace_auto_back_and_forth yes
|
workspace_auto_back_and_forth yes
|
||||||
@@ -134,28 +122,28 @@ bindsym $mod+Shift+Tab exec i3-msg workspace "$( \
|
|||||||
head -1)"
|
head -1)"
|
||||||
|
|
||||||
# move focused container to workspace
|
# move focused container to workspace
|
||||||
bindsym $mod+Shift+1 move container to workspace $ws1
|
bindsym $mod+Shift+1 exec ~/.config/i3/multi-monitor-workspaces.sh -m 1
|
||||||
bindsym $mod+Shift+2 move container to workspace $ws2
|
bindsym $mod+Shift+2 exec ~/.config/i3/multi-monitor-workspaces.sh -m 2
|
||||||
bindsym $mod+Shift+3 move container to workspace $ws3
|
bindsym $mod+Shift+3 exec ~/.config/i3/multi-monitor-workspaces.sh -m 3
|
||||||
bindsym $mod+Shift+4 move container to workspace $ws4
|
bindsym $mod+Shift+4 exec ~/.config/i3/multi-monitor-workspaces.sh -m 4
|
||||||
bindsym $mod+Shift+5 move container to workspace $ws5
|
bindsym $mod+Shift+5 exec ~/.config/i3/multi-monitor-workspaces.sh -m 5
|
||||||
bindsym $mod+Shift+6 move container to workspace $ws6
|
bindsym $mod+Shift+6 exec ~/.config/i3/multi-monitor-workspaces.sh -m 6
|
||||||
bindsym $mod+Shift+7 move container to workspace $ws7
|
bindsym $mod+Shift+7 exec ~/.config/i3/multi-monitor-workspaces.sh -m 7
|
||||||
bindsym $mod+Shift+8 move container to workspace $ws8
|
bindsym $mod+Shift+8 exec ~/.config/i3/multi-monitor-workspaces.sh -m 8
|
||||||
bindsym $mod+Shift+9 move container to workspace $ws9
|
bindsym $mod+Shift+9 exec ~/.config/i3/multi-monitor-workspaces.sh -m 9
|
||||||
bindsym $mod+Shift+0 move container to workspace $ws10
|
bindsym $mod+Shift+0 exec ~/.config/i3/multi-monitor-workspaces.sh -m 0
|
||||||
|
|
||||||
# move focused container and switch to workspace
|
# move focused container and switch to workspace
|
||||||
bindsym Mod1+Shift+1 move container to workspace $ws1; workspace $ws1
|
bindsym Mod1+Shift+1 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 1
|
||||||
bindsym Mod1+Shift+2 move container to workspace $ws2; workspace $ws2
|
bindsym Mod1+Shift+2 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 2
|
||||||
bindsym Mod1+Shift+3 move container to workspace $ws3; workspace $ws3
|
bindsym Mod1+Shift+3 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 3
|
||||||
bindsym Mod1+Shift+4 move container to workspace $ws4; workspace $ws4
|
bindsym Mod1+Shift+4 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 4
|
||||||
bindsym Mod1+Shift+5 move container to workspace $ws5; workspace $ws5
|
bindsym Mod1+Shift+5 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 5
|
||||||
bindsym Mod1+Shift+6 move container to workspace $ws6; workspace $ws6
|
bindsym Mod1+Shift+6 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 6
|
||||||
bindsym Mod1+Shift+7 move container to workspace $ws7; workspace $ws7
|
bindsym Mod1+Shift+7 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 7
|
||||||
bindsym Mod1+Shift+8 move container to workspace $ws8; workspace $ws8
|
bindsym Mod1+Shift+8 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 8
|
||||||
bindsym Mod1+Shift+9 move container to workspace $ws9; workspace $ws9
|
bindsym Mod1+Shift+9 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 9
|
||||||
bindsym Mod1+Shift+0 move container to workspace $ws10; workspace $ws10
|
bindsym Mod1+Shift+0 exec ~/.config/i3/multi-monitor-workspaces.sh -ms 0
|
||||||
|
|
||||||
# reload the configuration file
|
# reload the configuration file
|
||||||
bindsym $mod+Shift+c reload
|
bindsym $mod+Shift+c reload
|
||||||
|
|||||||
54
.config/i3/multi-monitor-workspaces.sh
Executable file
54
.config/i3/multi-monitor-workspaces.sh
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2025 Julian Prein
|
||||||
|
#
|
||||||
|
# Script to simulate output-independent workspaces. Can be used to switch and/or
|
||||||
|
# move a container to the workspace.
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
switch=
|
||||||
|
move=
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
printf >&2 "Usage: %s [-s] [-m] <index>\n" "$0"
|
||||||
|
exit "${1:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "sm" flag; do
|
||||||
|
case $flag in
|
||||||
|
s) switch=1;;
|
||||||
|
m) move=1;;
|
||||||
|
*) usage 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
[ $# -gt 0 ] || usage
|
||||||
|
|
||||||
|
outputs="$(i3-msg -t get_outputs | jq -r '.[] | select(.active).name')"
|
||||||
|
num_outs="$(printf "%s\n" "$outputs" | wc -l)"
|
||||||
|
|
||||||
|
if [ "$num_outs" -lt 2 ]; then
|
||||||
|
# only one monitor
|
||||||
|
workspace="$1"
|
||||||
|
else
|
||||||
|
name="$(i3-msg -t get_tree \
|
||||||
|
| jq -r '.. | objects | select(.focused).output')"
|
||||||
|
num="$(printf "%s\n" "$outputs" \
|
||||||
|
| grep -Fxn "$name" \
|
||||||
|
| cut -d: -f1)"
|
||||||
|
num="$((num - 1))"
|
||||||
|
|
||||||
|
# Omit the number on the first monitor
|
||||||
|
[ "$num" -gt 0 ] || num=
|
||||||
|
|
||||||
|
workspace="$num$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$switch" ] && [ -z "$move" ]; then
|
||||||
|
printf "%s\n" "$workspace"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$move" ] || i3-msg move container to workspace "$workspace"
|
||||||
|
[ -z "$switch" ] || i3-msg workspace "$workspace"
|
||||||
Reference in New Issue
Block a user