Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop Assignment Swaps Unexpectedly in Dual Monitor Setup #1491

Open
dongdongbh opened this issue Apr 19, 2024 · 19 comments
Open

Desktop Assignment Swaps Unexpectedly in Dual Monitor Setup #1491

dongdongbh opened this issue Apr 19, 2024 · 19 comments

Comments

@dongdongbh
Copy link

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.
@ortango
Copy link

ortango commented Apr 19, 2024

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
Copy link
Author

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
Copy link

ortango commented Apr 20, 2024

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
Copy link
Author

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
Copy link

ortango commented Apr 20, 2024

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
Copy link
Author

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
Copy link

ortango commented Apr 21, 2024

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
Copy link
Author

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
Copy link

ortango commented Apr 26, 2024

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

@dongdongbh
Copy link
Author

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
Copy link

ortango commented Apr 27, 2024

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
Copy link
Author

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

@ortango
Copy link

ortango commented Apr 27, 2024

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
Copy link
Author

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
Copy link

ortango commented Apr 27, 2024

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
Copy link
Author

dongdongbh commented Apr 27, 2024

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
Copy link

ortango commented Apr 27, 2024

01107f9 , 4b6f376 - 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
Copy link
Author

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

@ortango
Copy link

ortango commented Apr 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants