i3 / i3

A tiling window manager for X11
https://i3wm.org/
BSD 3-Clause "New" or "Revised" License
9.4k stars 774 forks source link

Plugging in a new display will create a workspace with a number that already exists #3314

Closed Gigahawk closed 6 years ago

Gigahawk commented 6 years ago

I'm submitting a…

[x] Bug
[ ] Feature Request
[ ] Documentation Request
[ ] Other (Please describe in detail)

Current Behavior

I have scripts that monitor the currently active window and will rename the current workspace (I've switched all the related bindings in my config to use workspace number).

When I plug in a monitor (or move the last workspace), a new workspace is created on that display with a number that already exists.

For example, if LVDS1 has a single workspace named 1 (Firefox Logo), plugging in a display to VGA1 and setting it to extend will create a workspace called 1, which renders one of the workspaces unusable.

Expected Behavior

i3 should recognize that workspace 1 already exists and create a workspace with a different number or move an existing one over.

Reproduction Instructions

Plug in and a new display and set it to extend while having a custom named workspace

Environment

Output of i3 --moreversion 2>&-:

Binary i3 version:  4.15.0.1 (03-13-2018) © 2009 Michael Stapelberg and contributors
(Getting version from running i3, press ctrl-c to abort…)
Running i3 version: 4.15.0.1 (03-13-2018) (pid 1100)
Loaded i3 config: /home/jasper/.config/i3/config (Last modified: Sat 23 Jun 2018 03:16:20 AM PDT, 182762 seconds ago)

The i3 binary you just called: /usr/bin/i3
The i3 binary you are running: i3

# vim: filetype=i3

bar {
    status_command i3blocks
    position top
    mode dock
    font Hack
    font pango:Font Awesome 5 Free
    font pango:Font Awesome 5 Brands 10

}

# Control focus with navkeys or clicks (fixes weird zathura/mupdf thing)
focus_follows_mouse no
font pango:mono 9
set $mod Mod4
set $term urxvt
set $video --no-startup-id bash ~/.config/Scripts/video.sh
set $stoprec --no-startup-id killall ffmpeg & killall screenkey
set $flash --no-startup-id bash ~/.config/Scripts/flash_win.sh

###---Starting External Scripts---###
# Start script to update icons on workspaces
exec_always --no-startup-id update_workspaces
# Start xbindkeys for tablet buttons
exec_always --no-startup-id xbindkeys

#Start autolocker
exec_always --no-startup-id xautolock -time 60 -locker "/home/jasper/.config/i3/lock.sh"
#Start f.lux
exec_always --no-startup-id xflux -l 49.179311327838334 -k 2400
#Start Transmission
exec --no-startup-id transmission-daemon
#Start syncthing
exec_always --no-startup-id killall -q syncthing
exec_always --no-startup-id syncthing -no-browser
exec_always --no-startup-id killall -q syncthing-inotify
exec_always --no-startup-id syncthing-inotify
#Start CopyQ
exec_always --no-startup-id copyq
#Set wacom configuration things
exec_always --no-startup-id ~/.config/Scripts/set-wacom.sh
#Automount USB drives:
#exec_always --no-startup-id ~/.config/i3/lock.sh
exec_always --no-startup-id devmon
#Music player daemon (sleep is needed to wait for sd card to mount):
exec --no-startup-id sleep 10 && mpd
#Torrent daemon:
#exec --no-startup-id transmission-daemon
#Wifi applet:
exec --no-startup-id nm-applet
#Bluetooth applet:
exec --no-startup-id blueman-applet
#Mount other drives:
#exec --no-startup-id sudo mount -a
#Composite manager:
exec --no-startup-id compton -b --xrender-sync-fence
#Refresh bash/ranger shortcuts:
#exec --no-startup-id python ~/.config/Scripts/shortcuts.py
#Try to load VGA screen if available:
#exec --no-startup-id ~/.config/Scripts/screen.sh v
#Launch Polybar where appropriate:
#exec_always --no-startup-id ~/.config/polybar/launch.sh
#Start the offlineimap daemon;
exec --no-startup-id killall python ~/.config/Scripts/offlineimap-daemon.py
#exec --no-startup-id python ~/.config/Scripts/offlineimap-daemon.py >/dev/null
exec --no-startup-id python ~/.config/Scripts/offlineimap-daemon.py
#Add wallpaper:
exec --no-startup-id feh --bg-scale ~/.config/wall.png
#exec_always --no-startup-id wal -c -i ~/.config/wall.png
#Remaps the caps lock button to escape and uses the US international keyboard with dead keys
exec_always --no-startup-id setxkbmap -option caps:escape
#exec_always --no-startup-id setxkbmap -layout us -variant altgr-intl -option caps:escape
#Remap Menu button to Super:
#exec_always --no-startup-id xmodmap -e 'keycode 135 = Super_R'
bindsym Menu    exec --no-startup-id xmodmap -e 'keycode 135 = Super_R'
#Unclutter makes the mouse invisible after a brief period
exec --no-startup-id unclutter
#Disables touchpad; you might like like this one! (I only use the ThinkPad trackpoint).
#exec --no-startup-id exec synclient TouchpadOff=1

###---Audio and Music Definitions---###
##For spotify
#set $music spotify
#set $pause dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
#set $trupause dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause
#set $play dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play
#set $next dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
#set $prev dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
#set $lilfor dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek
#set $bigfor dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek(

##For mpc:
set $music urxvt -e ncmpcpp
set $pause --no-startup-id mpc toggle
set $trupause --no-startup-id mpc pause
set $next --no-startup-id mpc next
set $prev --no-startup-id mpc prev
set $lilfor --no-startup-id mpc seek +10
set $bigfor --no-startup-id mpc seek +120
set $lilbak --no-startup-id mpc seek -10
set $bigbak --no-startup-id mpc seek -120
set $beg --no-startup-id mpc seek 0%

##For moc:
#set $music urxvt -e mocp
#set $pause --no-startup-id mocp -G
#set $truepause --no-startup-id mocp -P
#set $next --no-startup-id mocp -f
#set $prev --no-startup-id mocp -r
#set $lilfor --no-startup-id mocp -k 10
#set $bigfor --no-startup-id mocp -k 120
#set $lilbak --no-startup-id mocp -k -10
#set $bigbak --no-startup-id mocp -k -120
#set $beg --no-startup-id mocp -j 0%

##For cmus:
#set $music urxvt -e cmus
#set $pause --no-startup-id cmus-remote -u
#set $next --no-startup-id cmus-remote -n
#set $prev --no-startup-id cmus-remote -r
#set $lilfor --no-startup-id cmus-remote -k +10
#set $bigfor --no-startup-id cmus-remote -k +120
#set $lilbak --no-startup-id cmus-remote -k -10
#set $bigbak --no-startup-id cmus-remote -k -120
#set $beg --no-startup-id cmus-remote -k 00:00:00

#FOR ALSA/AMIXER
#set $inc --no-startup-id amixer sset Master 2%+
#set $biginc --no-startup-id amixer sset Master 5%+
#set $dec --no-startup-id amixer sset Master 2%-
#set $bigdec --no-startup-id amixer sset Master 5%-
#set $mute --no-startup-id amixer sset Master toggle
#set $truemute --no-startup-id amixer sset Master mute
#set $screencast  --no-startup-id bash ~/.config/Scripts/screencast_alsa.sh
#set $audio --no-startup-id bash ~/.config/Scripts/audio_alsa.sh

#For PULSEAUDIO/PAMIXER
set $inc --no-startup-id pamixer --allow-boost -i 5
set $biginc --no-startup-id pamixer --allow-boost -i 15
set $dec --no-startup-id pamixer --allow-boost -d 5
set $bigdec --no-startup-id pamixer --allow-boost -d 15
set $mute --no-startup-id pamixer --allow-boost -t
set $micmute --no-startup-id pamixer --allow-boost -t
set $truemute --no-startup-id pamixer -m
set $screencast  --no-startup-id bash ~/.config/Scripts/screencast_pulse.sh
set $audio --no-startup-id bash ~/.config/Scripts/audio_pulse.sh

###---Dropdown/Scratchpad Windows---###
#First I have a tmux window used for background scripts.
#I'll later bind this to mod+u.
for_window [instance="dropdown"] floating enable
for_window [instance="dropdown"] resize set 625 400
for_window [instance="dropdown"] move position center
for_window [instance="dropdown"] move scratchpad
exec --no-startup-id $term -name dropdown -e tmux

#Then I have a window running R I use for basic arithmetic
#I'll later bind this to mod+a.
for_window [instance="math"] floating enable
for_window [instance="math"] resize set 800 300
for_window [instance="math"] move position center
for_window [instance="math"] move scratchpad
exec --no-startup-id $term -fn "xft:mono:pixelsize=24" -name math -e R -q

##Set up Cisco's shitty anyconnect thing to be floating
#for_window [instance="vpnui"] floating enable
#for_window [instance="vpnui"] resize set 100 100
#for_window [instance="vpnui"] move position center
#for_window [instance="vpnui"] move scratchpad
#exec --no-startup-id /opt/cisco/anyconnect/bin/vpnui

###---Basic Bindings---###
bindsym $mod+Return         exec $term
bindsym $mod+Shift+Return   exec $term -e tmux

bindsym $mod+Shift+space    floating toggle
bindsym $mod+space      focus mode_toggle

bindsym $mod+Escape     workspace prev

bindsym $mod+BackSpace      exec $flash

bindsym $mod+grave      exec $flash
#bindsym $mod+asciitilde
#STOP/HIDE EVERYTHING:
bindsym $mod+Shift+Delete   exec $truemute ; exec $truepause ; workspace lmao ; exec $term -e htop ; exec $term -e ranger

###---Screenshot bindings---###
bindsym $mod+Shift+F4       exec --no-startup-id ~/.config/Scripts/snipper.sh
bindsym $mod+Shift+F5       exec --no-startup-id ~/.config/Scripts/windowsnipper.sh

###---Letter Key Bindings---###
bindsym $mod+q          kill
bindsym $mod+Shift+q        kill

bindsym $mod+w          exec --no-startup-id $term -e w3m http://lukesmith.xyz
bindsym $mod+Shift+w        exec --no-startup-id $BROWSER

bindsym $mod+e          exec dmenu_emoji_picker
#bindsym $mod+e         exec $term -e neomutt
#bindsym $mod+Shift+e

bindsym $mod+r          exec $term -e ranger

bindsym $mod+t          split toggle
bindsym $mod+Shift+t        gaps inner current set 15; gaps outer current set 15

bindsym $mod+y          exec $term -e calcurse
bindsym $mod+Shift+y        resize shrink width 10 px or 10ppt

bindsym $mod+u          [instance="dropdown"] scratchpad show; move position center
bindsym $mod+Shift+u        resize shrink height 10 px or 10 ppt

bindsym $mod+i          exec $term -e htop
bindsym $mod+Shift+i        resize grow height 10 px or 10 ppt

#bindsym $mod+o         exec --no-startup-id $beg
bindsym $mod+Shift+o        resize grow width 10 px or 10 ppt

bindsym $mod+p  exec dmenu_power
bindsym $mod+Shift+p            exec $pause

bindsym $mod+a          [instance="math"] scratchpad show; move position center
bindsym $mod+Shift+a        exec pavucontrol
#bindsym $mod+Shift+a       exec $term -e ncpamixer

bindsym $mod+s          gaps inner current plus 5
bindsym $mod+Shift+s        gaps inner current minus 5
bindsym $mod+d          exec dmenu_run_all
bindsym $mod+Shift+d        gaps inner current set 0; gaps outer current set 0

bindsym $mod+f          fullscreen toggle
#bindsym $mod+Shift+f

bindsym $mod+g          workspace prev

bindsym $mod+h          focus left
bindsym $mod+Shift+h        move left 30

bindsym $mod+j          focus down
bindsym $mod+Shift+j        move down 30

bindsym $mod+k          focus up
bindsym $mod+Shift+k        move up 30

bindsym $mod+l          focus right
bindsym $mod+Shift+l        move right 30

bindsym $mod+z          gaps outer current plus 5
bindsym $mod+Shift+z        gaps outer current minus 5

bindsym $mod+x          exec --no-startup-id ~/.config/i3/lock.sh
bindsym $mod+Shift+x        exec sudo shutdown -h now

bindsym $mod+c          exec $term -e weechat
#bindsym $mod+Shift+c

#bindsym $mod+v         exec urxvt -e vis
#bindsym $mod+v         [instance="vpnui"] scratchpad show; move position center
bindsym $mod+Shift+v        exec projectM-pulseaudio

bindsym $mod+n          exec $term -e newsboat
#bindsym $mod+Shift+n       exec $term -e newsboat

bindsym $mod+m          exec $music
bindsym $mod+Shift+m        exec $mute

###---Workspace Bindings---###
bindsym $mod+Home       workspace number $ws1
bindsym $mod+Shift+Home     move container to workspace number $ws1
bindsym $mod+End        workspace $ws10
bindsym $mod+Shift+End      move container to workspace number $ws10
bindsym $mod+Prior      workspace prev
bindsym $mod+Shift+Prior    move container to workspace prev
bindsym $mod+Next       workspace next
bindsym $mod+Shift+Next     move container to workspace next
bindsym $mod+Tab        workspace back_and_forth
bindsym $mod+XF86Back       workspace prev
#bindsym $mod+Shift+XF86Back
bindsym $mod+XF86Forward    workspace next
#bindsym $mod+Shift+XF86Forward
bindsym $mod+semicolon      workspace next
bindsym $mod+apostrophe     split horizontal ;; exec $term
bindsym $mod+slash      split vertical ;; exec $term
bindsym $mod+Shift+slash    kill
bindsym $mod+backslash      workspace back_and_forth

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
bindsym $mod+1      workspace number $ws1
bindsym $mod+2      workspace number $ws2
bindsym $mod+3      workspace number $ws3
bindsym $mod+4      workspace number $ws4
bindsym $mod+5      workspace number $ws5
bindsym $mod+6      workspace number $ws6
bindsym $mod+7      workspace number $ws7
bindsym $mod+8      workspace number $ws8
bindsym $mod+9      workspace number $ws9
bindsym $mod+0      workspace number $ws10

# move focused container to workspace
bindsym $mod+Shift+1    move container to workspace number $ws1
bindsym $mod+Shift+2    move container to workspace number $ws2
bindsym $mod+Shift+3    move container to workspace number $ws3
bindsym $mod+Shift+4    move container to workspace number $ws4
bindsym $mod+Shift+5    move container to workspace number $ws5
bindsym $mod+Shift+6    move container to workspace number $ws6
bindsym $mod+Shift+7    move container to workspace number $ws7
bindsym $mod+Shift+8    move container to workspace number $ws8
bindsym $mod+Shift+9    move container to workspace number $ws9
bindsym $mod+Shift+0    move container to workspace number $ws10

# move focused workspace to next adjacent display
bindsym $mod+Control+h move workspace to output left
bindsym $mod+Control+j move workspace to output down
bindsym $mod+Control+k move workspace to output up
bindsym $mod+Control+l move workspace to output right

workspace $ws6 gaps inner 0
workspace $ws6 gaps outer 0
workspace $ws5 gaps inner 0
workspace $ws5 gaps outer 0
workspace $ws8 gaps inner 0
workspace $ws8 gaps outer 0

###---Function Buttons---###
bindsym $mod+F1     exec --no-startup-id mupdf ~/.config/i3/i3_guide.md.pdf
bindsym $mod+F2     exec --no-startup-id python ~/.config/Scripts/shortcuts.py
bindsym $mod+F3     exec --no-startup-id arandr
bindsym $mod+F4     exec --no-startup-id sudo zzz
bindsym $mod+F5     exec --no-startup-id sudo systemctl restart NetworkManager
bindsym $mod+F6     exec --no-startup-id urxvt -e transmission-remote-cli
bindsym $mod+F7     exec transset -a --dec .15
bindsym $mod+F8     exec transset -a --inc .15
bindsym $mod+F9     exec --no-startup-id dmenu_mount
bindsym $mod+F10    exec --no-startup-id dmenu_screen
Logfile URL:
- Linux Distribution & Version: Void Linux
- Are you using a compositor (e.g., xcompmgr or compton): compton

update_workspaces:

#!/bin/bash

stdbuf -oL xtitle -s |
  while IFS= read -r line; do
    echo $line | update_workspace
  done

update_workspace:

#!/bin/bash

set -- "${1:-$(</dev/stdin)}" "${@:2}"
focus="$1"
if [ -z focus ]; then
  focus=$(get_focus)
fi

num=$(get_workspace)
icon=$(echo "$focus" | get_icon)

if [ -z "$icon" ]; then
  i3-msg "rename workspace to $num"
else
  i3-msg "rename workspace to \"$num $icon\""
fi
Airblader commented 6 years ago

Does this also happen if you (I know this will sound silly) don't have any workspace number 1 binding of any sort in the config?

I think the issue here is that we extract workspaces from bindings also for "workspace number" bindings, but later on only check that the entire name doesn't yet exist. We should probably only extract "workspace" but not "workspace number" bindings and/or compare only the numbers rather than the name.

Of course this is ultimately subject to usage in a sense – we explicitly don't forbid using the same workspace number several times, so it's not exactly "broken". However, I'd make the argument that in the vast majority of cases people do not use the same number multiple times.

Gigahawk commented 6 years ago

Actually, it looks like the issue was coming from the fact that I was running an older version of my config before I got around to switching all my workspace bindings to workspace number. Using the config as described above seems to work as expected.