Skip to content

Conversation

@ilshatvm
Copy link
Contributor

The special feature of xrandr --listactivemonitors is that the first monitor in the list will be the primary monitor. This is very convenient because the rest of the script uses the first monitor in the list as the primary monitor. This allows you to set the primary monitor once using xrandr --output HDMI-0 --primary in the terminal or a third-party application like nvidia-settings.

output the primary monitor first in the list
@ilshatvm
Copy link
Contributor Author

Well, I jumped to conclusions.
If you use nvidia-settings and save the priority in the /etc/x11/xorg.conf file, one command will be enough.

As for the xrandr --output HDMI-0 --primary command, it will have to be added to the bspwmrc file, before the MonitorSetup function

@gh0stzk
Copy link
Owner

gh0stzk commented Nov 23, 2025

Hello, i dont understand, what need to be fixed?

@ilshatvm
Copy link
Contributor Author

The code currently uses the xrandr command to list monitors, which always returns the same list. The first monitor in this list will always be the primary monitor, even if I want the second monitor to be the primary monitor.

If I use xrandr --listmonitors or xrandr --listactivemonitors the primary monitor will always be the first in the list.

Shot-2025-11-23-185638

@ilshatvm
Copy link
Contributor Author

ilshatvm commented Nov 23, 2025

xrandr output is static, regardless of which monitor is the primary one.

@gh0stzk
Copy link
Owner

gh0stzk commented Nov 23, 2025

Is there a solution where the user doesn't have to edit another file like bspwmrc or interact with it to find and set their primary monitor?

@ilshatvm
Copy link
Contributor Author

Yes, this is possible. Instead of editing the bspwmrc file, you can use programs to edit the xorg.conf file. In my case, nvidia-settings helped. There may be other ways. In general, any working method for changing the monitor priority will work.

@ilshatvm
Copy link
Contributor Author

ilshatvm commented Nov 27, 2025

Currently, the MonitorSetup script works something like this:

XRANDR_OUTPUT does not change depending on the primary monitor Shot-2025-11-27-115117
In my case, the first element of NUM_MONITORS will always be VGA-0, even if HDMI-0 was set as the primary one Shot-2025-11-27-115801

NUM_MONITORS=[ VGA-0, HDMI-0 ]

  $monitor_1=VGA-0
  $monitor_2=HDMI-0   # primary
the first one in the NUM_MONITORS list will always be set as the primary (VGA-0) Shot-2025-11-27-123212

The main problem is that the script does not give priority to the primary monitor and resets it to the first monitor in the list, which may not be the primary one, even if we set it earlier

The simplest solution is to get a NUM_MONITORS list in which the first element will be the primary monitor

@gh0stzk
Copy link
Owner

gh0stzk commented Nov 27, 2025

I've made the changes you suggested locally; well, it's just the xrandr command with the flag to list active monitors.
It works, yes, but I find two drawbacks.
With the change you suggest, if you have the second monitor connected from the moment you turn on the PC it works correctly, assigning workspaces properly, etc... although for me it still showed EDP as the primary, not HDMI.
However, if you start your PC with only one monitor, for example, on a laptop, and then connect the second monitor, restarting bspwm or running MonitorSetup in a terminal won't work and won't configure the new monitor because --listactivemonitors, only shows the monitors that are configured and in use/active.
However, xrandr alone, without flags, will show the newly connected monitor even if it's not yet in use. Therefore, restarting bspwm or running MonitorSetup in the terminal will activate and configure the new connected monitor sucessfully. At least, that's what happened to me in the tests I ran a few minutes ago.

@gh0stzk
Copy link
Owner

gh0stzk commented Nov 27, 2025

I did it that way because at my job I'm constantly connecting and disconnecting the external/secondary monitor; it's never permanently connected. This works for me because i only connect it and press Super + Alt + R to restart bspwm, the monitor activates and configures itself. But of course, I overlooked the fact that some people need to configure their monitors specifically.

@ilshatvm
Copy link
Contributor Author

The main idea is to sort the list so that the primary monitor is first in the list. This is necessary because the remaining code uses the first monitor in the list as the primary.

You can also use xrandr standard output.

# Get connected monitors using POSIX-compliant method
set -- $(echo "$XRANDR_OUTPUT" | awk ' $2 == "connected" ' | sort -k 3 -r | awk '{ print $1 }'

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

Successfully merging this pull request may close these issues.

2 participants