bspwm icon indicating copy to clipboard operation
bspwm copied to clipboard

Desktop Assignment Swaps Unexpectedly in Dual Monitor Setup

Open dongdongbh opened this issue 1 year ago • 19 comments

Issue Description:

I am encountering an issue with desktop assignments swapping between monitors in my dual-monitor setup using BSPWM. Initially, upon system start, desktops are correctly assigned with my main monitor (DP-3) hosting desktops 1 to 8 and my side monitor (HDMI-1), which is set up to the left of the main monitor, hosting desktops 9 and 10. However, after some period of use, the desktop assignment swaps - the side monitor starts showing desktops 1 and 2, and the main monitor shows desktops 3 to 10.

This issue seems to occur without any manual changes to the configuration or physical adjustments to the monitor setup. It appears as though BSPWM might be reordering the desktops based on the physical arrangement of the monitors (left to right) automatically in the background.

Steps to Reproduce:

  1. Start the system with the dual-monitor setup: Main monitor (DP-3) and side monitor (HDMI-1) to the left.
  2. Desktops are correctly assigned initially.
  3. Use the system normally for some time.
  4. After a while, without any system configuration changes or disconnecting/reconnecting monitors, the desktops swap as described.

Expected Behavior:

Desktops should remain on their originally assigned monitors unless manually reconfigured. The main monitor should consistently keep desktops 1 to 8, and the side monitor should keep desktops 9 and 10.

Actual Behavior: Desktops unexpectedly swap between the two monitors after some period of use, disrupting the workflow and desktop organization.

Setup Details:

Operating System: Ubuntu server 22.04 BSPWM Version: 0.9.10 sxhkd Version: 0.6.2 Relevant Configuration Files: my config files can be found here

Additional Information:

  • The xrandr configuration sets the side monitor (HDMI-1) to the left of the main monitor (DP-3).
  • No physical reconnections or configuration changes are made before the issue occurs.
  • Logs and monitoring indicate that no explicit reconfiguration commands are executed.

dongdongbh avatar Apr 19 '24 16:04 dongdongbh

since you are using bspc wm -O to arrange the monitors: my guess it that that reorder_monitors() is run from update_root() and resets this order back to xrandr's default geometry based order. there are a few paths to update_root() including update_monitors. if that function is responsible you should see monitor_geometry subscription events.

ortango avatar Apr 19 '24 23:04 ortango

since you are using bspc wm -O to arrange the monitors: my guess it that that reorder_monitors() is run from update_root() and resets this order back to xrandr's default geometry based order. there are a few paths to update_root() including update_monitors. if that function is responsible you should see monitor_geometry subscription events.

So I have to modify the bspwm source code and recompile it to make it work in my intended way?

dongdongbh avatar Apr 20 '24 03:04 dongdongbh

first, i would just confirm that is the problem you are having.

the way i would deal with it personally - set the desired order in xorg instead of bspwm. I have used dynamic multimonitor for years with bspwm and never have needed to deal with this issue.

alternatively, maybe this patch would work. I've not tested it - at least not recently.

ortango avatar Apr 20 '24 15:04 ortango

first, i would just confirm that is the problem you are having.

the way i would deal with it personally - set the desired order in xorg instead of bspwm. I have used dynamic multimonitor for years with bspwm and never have needed to deal with this issue.

alternatively, maybe this patch would work. I've not tested it - at least not recently.

I think maybe my setup is a bit strange, I want my HDMI-1 monitor to be physically on the left of DP-3, with DP-3 set as the primary monitor, but HDMI-1 hosting desktops 9 and 10 in BSPWM, not desktops 1 and 2 in BSPWM, that's why I set the desired order in bspwm.

dongdongbh avatar Apr 20 '24 18:04 dongdongbh

you can still get the desired behavior with sxhkd - can't say anything about polybar though. my setup is a little simpler in that i only use one desktop per secondary monitor - this makes keybinding simple using primary:^index and primary#next:^index to refer to desktops eg:

# focus specific desktop
super + {1-4}
    bspc desktop primary:^{1-4} -f
super + 0
    bspc desktop primary#next:focused -f || \
    bspc desktop primary:^5 -f

but you can also use a script to translate the indexes to desktop id's based on some hardcoded order. ran like: scriptname desktop ^7 -f

mapfile -t d < <( bspc query -D -m HDMI-A-0;
                  bspc query -D -m DisplayPort-2)
cmd=( "$@" )
for ind in "${!cmd[@]}"; do
    case "${cmd[$ind]}" in
        ^*)
            [[ -n "${d["${cmd[$ind]:1}"-1]}" ]] || exit
            cmd[$ind]="${d["${cmd[$ind]:1}"-1]}"
            ;;
    esac
done
bspc "${cmd[@]}"

or try that patch and see if it works out.

none of this is to say this isn't a valid bug - if the cause is an unwarranted reorder_monitors(), it has been reported previously.

ortango avatar Apr 20 '24 21:04 ortango

you can still get the desired behavior with sxhkd - can't say anything about polybar though. my setup is a little simpler in that i only use one desktop per secondary monitor - this makes keybinding simple using primary:^index and primary#next:^index to refer to desktops eg:

# focus specific desktop
super + {1-4}
    bspc desktop primary:^{1-4} -f
super + 0
    bspc desktop primary#next:focused -f || \
    bspc desktop primary:^5 -f

but you can also use a script to translate the indexes to desktop id's based on some hardcoded order. ran like: scriptname desktop ^7 -f

mapfile -t d < <( bspc query -D -m HDMI-A-0;
                  bspc query -D -m DisplayPort-2)
cmd=( "$@" )
for ind in "${!cmd[@]}"; do
    case "${cmd[$ind]}" in
        ^*)
            [[ -n "${d["${cmd[$ind]:1}"-1]}" ]] || exit
            cmd[$ind]="${d["${cmd[$ind]:1}"-1]}"
            ;;
    esac
done
bspc "${cmd[@]}"

or try that patch and see if it works out.

none of this is to say this isn't a valid bug - if the cause is an unwarranted reorder_monitors(), it has been reported previously.

Thanks, currently I use sxhkd workaround, but the desktop number still changes, the first desktop will change to 2 after a while. The hard code one seems better since it didn't care about the desktop number.

dongdongbh avatar Apr 21 '24 02:04 dongdongbh

just a note:

Thanks, currently I use sxhkd workaround

https://github.com/dongdongbh/dotfiles/blob/master/sxhkd/.config/sxhkd/bspwm.sxhkdrc#L86-L92

the example i gave above is using primary (and primary#next) monitor as the reference - so, the desktop index is per monitor. it will not change if monitor order changes.

eg primary:^1 and primary#next:^1 refer to two different desktops.

ortango avatar Apr 21 '24 03:04 ortango

bspc desktop primary:^5 -f

I can not use primary keyword on my setting.

bspc desktop `primary`:^1 -f
zsh: no matches found: primary:^1

dongdongbh avatar Apr 26 '24 03:04 dongdongbh

ensure that you have set a primary monitor in X - even if you have only a single monitor connected.

ortango avatar Apr 26 '24 11:04 ortango

already set that, but doesn't work

xrandr --query | grep primary
DP-3 connected primary 3840x2160+2160+0 (normal left inverted right x axis y axis) 597mm x 336mm

dongdongbh avatar Apr 26 '24 23:04 dongdongbh

bspc desktop `primary`:^1 -f

are those backticks a visual artifact, or are they in the command? they should not be.

bspc desktop primary:^1 -f

other then that i have not a clue. but you can also use monitor names instead eg

bspc desktop DP-3:^1

ortango avatar Apr 27 '24 01:04 ortango

bspc desktop primary:^1 -f
zsh: no matches found: primary:^1
bspc desktop DP-3:^1
zsh: no matches found: DP-3:^1

dongdongbh avatar Apr 27 '24 02:04 dongdongbh

oh. it's a zsh error. if you have EXTENDED_GLOB on you need to either quote or \ escape the carat.

bspc desktop primary:\^1 -f
# or
bspc desktop "DP-3:^1"

ortango avatar Apr 27 '24 02:04 ortango

Now

bspc desktop primary:\^1 -f
# or
bspc desktop "DP-3:^1 -f"

works. But bspc desktop primary#next:\^1 -f not work, and bspc desktop "HDMI-1:^1" -f works.

bspc desktop primary#next:\^1 -f
zsh: no matches found: primary#next:^1

dongdongbh avatar Apr 27 '24 07:04 dongdongbh

zsh: no matches found: primary#next:^1

that is a zsh error again. with extended glob active you need to also escape hashes. for those types of errors you should check the shell's documentation.

ortango avatar Apr 27 '24 14:04 ortango

I disabled the glob, and it still does not work

➜ ~ setopt NO_EXTENDED_GLOB
➜ ~ bspc desktop primary#next:^1 -f
desktop: Invalid descriptor found in 'primary#next:^1'.
➜ ~ bspc desktop 'primary#next:^1' -f
desktop: Invalid descriptor found in 'primary#next:^1'.

dongdongbh avatar Apr 27 '24 15:04 dongdongbh

01107f9 , 4b6f3761b0094fd911de84b1b0ccd2f3721b7a19 - is newer then ver 0.9.10. i'd guess that is the issue. my apologies, i didn't realize that commit isn't in a release.

ortango avatar Apr 27 '24 15:04 ortango

Seems this repository hasn't update for a long time, it is not actively developing.

dongdongbh avatar Apr 28 '24 16:04 dongdongbh

there have been a decent amount of commits since last release, but yeah it's been a while.

ortango avatar Apr 28 '24 22:04 ortango