Unable to get external HDMI monitor working on bspwm with xrandr

I am having problems setting up a second monitor to my laptop. I am running bspwm.

I have never user xrandr before, so I am not entirely sure what to do or whether my system is working properly.

Before connecting my HDMI cable, the output of xrandr-q shows DP-1 as disconnected. Once I connect the cable, xrandr -q says DP-1 is connected and it displays all the available resolutions and rates. So far, so good?

Now, when executing xrandr --output DP-1 --mode 1920x1080 --rate 60 --right-of eDP-1, my laptop screen goes black for a second, then returns, and that is it. My HDMI monitor remains black (it is on BTW!) It looks like I can move the mouse off the right edge of the screen, but nothing is shown on the HDMI display.

I find arandr (a basic gui) really handy to get the right options for xrandr. When you save a configuration with it, it is just a shell script with xrandr commands.

That may not be your entire issue, but it is likely to assist.

I think arandr just executes xrandr commands in the background. Anyway, I have tried it, and I get the same results. When I apply the new layout, my laptop display goes black for a second, but nothing is displayed on my HDMI monitor.

  • What’s the output of xrandr after trying to enable the monitor?
  • Have you tried the preferred mode advertised by the monitor (–auto instead of --mode + --rate)?
  • Have you tried a lower refresh rate and/or resolution?
  • Is it a DP-to-HDMI cable you’re using? Do you have another one to test?

disconnected

Yes, I have.

Yes, both.

It is a USBC-to-HDMI dongle (Framework laptop module), and I have tried a couple of different cables, which work just fine connected to another source.

Do you get any kernel messages or (unlikely) something in the x-server log?

No. No messages either place.

OK. Discovered something quite by accident. If I switch to a TTY screen, all of a sudden my display is mirrored on my HDMI monitor. If I then switch back to X, now the HDMI monitor is doing what I specified in the last xrandr statement I ran.

So, I played with this a bit and found that if I disconnect the HDMI cable, then reconnect it, I have to switch to a TTY then back to X to get the external display working.

What do you think is going on?

Very good. Something we can work with.

Just one quick check, have you tried specifying the complete layout at once?:
xrandr --output eDP-1 --auto --output DP-1 --auto --right-of eDP-1

Anyway. After the tty switch, when your monitor is working in X, do a xrandr --verbose and take notes of the crtc ids for eDP-1 and DP-1 (every active output has line CRTC: $id). Now, you should be able to reproduce the configuration by specifying the crtc id in the xrandr call.

$ xrandr \
    --output eDP-1 --auto --crtc $edp_crtc_id_from_xrandr_verbose \
    --output DP-1 --auto --crtc $dp_crtc_id_from_xrandr_verbose --right-of eDP-1

If that’s still not working, post the xrandr --verbose output before and after the tty switch, please.

Yup.

Tried with the CRTC: $id, and still no go.

Here are the results of xrandr --verbose:

After cable connected

After xrandr command

After TTY switch

Outputs are active and the screen/root is resized accordingly.

Hmm, is it just that the root window is black and no cursor is defined? Does anything happen if you

  • change the root window background: nix run nixpkgs#xorg.xsetroot -- -solid pink
  • or drag a window to the monitor?

No, it’s not that, because after the TTY switch trick, the display turns on and see the proper background image. Before that, if I try to move a window to the external monitor, it remains black. In fact, the monitor goes into standby, as if there is no signal at all. It is only after the TTY trick that the display recognizes a signal.