baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.81k stars 416 forks source link

Desktop Assignment Swaps Unexpectedly in Dual Monitor Setup #1491

Open dongdongbh opened 7 months ago

dongdongbh commented 7 months ago

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:

ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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?

ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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.

ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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.

ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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
ortango commented 7 months ago

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

dongdongbh commented 7 months ago

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
ortango commented 7 months ago

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
dongdongbh commented 7 months ago
bspc desktop primary:^1 -f
zsh: no matches found: primary:^1
bspc desktop DP-3:^1
zsh: no matches found: DP-3:^1
ortango commented 7 months ago

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"
dongdongbh commented 7 months ago

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
ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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'.
ortango commented 7 months ago

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.

dongdongbh commented 7 months ago

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

ortango commented 7 months ago

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