Setup virtual display with xrandr

Hey there,
I have got a widescreen monitor and need to share may screen alot during meetings. I can usually share the whole screen or just one application. since I need to use multiple programs I usually have to share the whole screen. this creates two problems:

  • not everybody has a widescreen monitor, hence my shared screen has to fit their screens and it scales down
  • I don’t want them to see everything, because it is a distraction from the content and there is always secret stuff.

current solution: I use OBS Studio and share my screen via a virtual camera and define a small frame to share.
problem: modern laptops are incredible thin and incredible noisy under load. and it is just feels like a bad solution.

idea: I want to create a virtual monitor/screen/display that overlaps with 2/3 of the widescreen. during meetings I want to share that virtual screen.

what did I do: I tried to use xrandr to set up a monitor that overlaps with 2/3 of the widescreen:

xrandr --setmonitor hover1 2293/607x1440/381+0+0 none

I get the error message:

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  43 ()
  Value in failed request:  0x359
  Serial number of failed request:  41
  Current serial number in output stream:  42

is my solution even feasible? if so: how do I set up the virtual monitor?

I am using Manjaro KDE, I don’t hav a dedicated gpu, just intel graphics. the widescreen is connected via hdmi since it does not recognize the dp.

xrandr is used as a software solution to adjust the graphics output to a monitor, ex resolution, brightness, color correction, etc. It’s not a program for a virtual display.

Something like a VM will do the job; the window for a VM is the virtual display. But VM is more resource consuming than OBS for your case.

I know only Snowmix and OBS for live video streaming, with OBS the most popular one. So your best choice is to use OBS.

There are several laptop categories, like gaming laptop, content creator laptop, thin laptop, etc. And you have the wrong laptop spec; you probably have a thin laptop for simple everyday use.

Depending on the OEM website, you can search for a content creator (video editing, streaming, photography, graphic design, animation, or such similar terms) laptop. So this will be your lesson the next time you buy a laptop.

thx for the (rather unsatisfying) answer. in my defense: the laptop came first and the widescreen second and I might not have thought this through entirely.

there are people who split their monitor into two. effectively that means the first screen is resized and a second, virtual one is created. I want to do nearly the same thing except the first one is not resized, so the two overlap. what do I not understand?

Hmmm, I don’t know that xrandr can be used to spawn a virtual display. If you share xrandr --verbose, I can give a possible xrandr command for your use case.

Your laptop is connected to other widescreen monitor right? So xrandr should give 2 display outputs.

yes, the widescreen is connecte via hdmi, but it does say “DP1”, I dont know why

If my understanding is correct, you have to split the DP1 before you create a virtual monitor to show on it, so you reassign the adapter

xrandr --setmonitor DP1-1 1720/400x1440/330+0+0 DP1

and then you assign to it the virtual monitor to none but you will still see it on the widescreen you have

xrandr --setmonitor DP1-2 1720/400x1440/330+1720+0 none

and in both cases you have to give the width in pixels but also in mm as also the height in pixels and mm … plus you give the offset to the second virtual monitor … then you set or refresh the framebuffer to real resolution so you can see now both virtual monitors

 xrandr --fb 3440x1440

In principle all this could be done with one script, lets call it virtmon, placed in ~/.local/bin/ and set as executable, with this content in it:

#!/bin/sh
if [ -z "$(xrandr --listactivemonitors | grep 'DP1-1')"]; then
    xrandr --setmonitor DP1-1 1720/400x1440/330+0+0 DP1
    xrandr --setmonitor DP1-2 1720/400x1440/330+1720+0 none
    xrandr --fb 3440x1440
else
    xrandr --delmonitor DP1-1
    xrandr --delmonitor DP1-2
fi

So each time you run it, it will either set the dual virtual monitor, or remove them and get back to normal.

1 Like

I think what @nift.d wants is just to lower the resolution of the external widescreen display.

Your current DP1 resolution is:

3440x1440 (0x316) 159.870MHz +HSync -VSync *current

There are several modes with different resolution supported for your DP1 (below the 3440x1440 (0x316) 159.870MHz +HSync -VSync *current).

Since you just want to get a lower resolution on the widescreen monitor, maybe this is the easiest to configure and the closest to what you want:

# Change the DP1 screen resolution to 2560x1080.
xrandr --output DP1 --mode 2560x1080

thank you, it does work, but somehow the laptop screen goes black when I run the script again to deactivate the virtual monitor.

this is the script, virtual monitor takes 66% of the widescreen with no offset:

#!/bin/zsh
if [ -z "$(xrandr --listactivemonitors | grep 'DP1-1')"]; then
    xrandr --setmonitor DP1-1 3440/797x1440/333+0+0 DP1
    xrandr --setmonitor DP1-2 2293/531x1440/330+0+0 none
    xrandr --fb 3440x1440
else
    xrandr --delmonitor DP1-1
    xrandr --delmonitor DP1-2
fi

after trying to deactivate the virtual monitors, but actually activating the laptop screen I got:

 ~/.local/bin  sh virtmon                                                                                                             
virtmon: line 2: [: missing »]«

I ran, because the widescreen is connected via hdmi:

xrandr --output HDMI-1 --auto

it did not work, so I tried:

xrandr --output DP1 --auto

which did work, but messed up the screen resolution entirely.

Ok, so setting up the virtual monitor works, but deactivating it does not. I am quiet happy, but only half way there. can you help me with the rest please? I don’t see where a “]” could be missing. can this even be the reason for the deactivation not working?

You probably need to set the framebuffer size again, you may also need to reset the position of one or both monitors. I tried the method earlier and I had to do both (one screen was +13 in y instead of +0).

xrandr --fb 5360x1440  # I think that's right for your setup

Try specifying the resolution instead of auto and it’s called DP1 even if it is connected by HDMI. :slight_smile:

EDIT:
I can’t see a missing ] either, but you’ve specified zsh and than ran it using sh. Try using bash, or sh as it was written.

1 Like

ok, thx for clearing that up. it is a little counter intuitive…

let’s do it over again.

  1. start
$ xrandr --listactivemonitors                                                                                           
Monitors: 2
 0: +*eDP1 1920/310x1080/170+5388+1534  eDP1
 1: +DP1 3440/800x1440/330+0+0  DP1
  1. after running the scrip:
$ sh virtmon                                                                                                            
output list DP1
add monitor DP1
output name DP1
xrandr: specified screen 5360x1440 not large enough for output eDP1 (1920x1080+5388+1534)

→ the laptop screen went black
3. auto adjusting eDP1:

$ xrandr --output eDP1 --auto

now everything is fine!

$ xrandr --listactivemonitors                                                                                           
Monitors: 3
 0: +*eDP1 1920/310x1080/170+5388+1534  eDP1
 1: DP1-1 3440/797x1440/333+0+0  DP1
 2: DP1-2 2293/531x1440/330+0+0 
  1. deactivating virtmon:
$ sh virtmon                                                                                                            
virtmon: line 2: [: missing »]«
$ xrandr --listactivemonitors                                                                                           
Monitors: 2
 0: +*eDP1 1920/310x1080/170+5388+1534  eDP1
 1: +DP1 3440/800x1440/330+0+0  DP1

conclusion:
running the script does effect the laptop screen.

so a dirty, but working script could look like that:

#!/bin/zsh
if [ -z "$(xrandr --listactivemonitors | grep 'DP1-1')"]; then
    xrandr --setmonitor DP1-1 3440/797x1440/333+0+0 DP1
    xrandr --setmonitor DP1-2 2293/531x1440/330+0+0 none
    xrandr --fb 5360x1440
    xrandr --output eDP1 --auto
else
    xrandr --delmonitor DP1-1
    xrandr --delmonitor DP1-2
fi

Does this work on your widescreen? No display anomalies? The height is 1440 px, the same as the widescreen native height. But the width here is 3440 + 2293 = 5733, which is larger than the widescreen native width 3440. This doesn’t seem right. If you want to split your screen width to 2:1 ratio, then it should be 2293 and 1147:

    xrandr --setmonitor DP1-1 2293/533x1440/330+0+0 DP1
    xrandr --setmonitor DP1-2 1147/267x1440/330+2293+0 none

Take xrandr --fb 5360x1440 for example, this will set the entire display to 5360x1440. Your laptop native resolution is 1920x1080, which is smaller than 5360x1440 and you will get blank screen. xrandr --output eDP1 --auto adjusts the proper settings including resolution for your laptop screen, so that’s why your laptop screen worked fine again.

But then again, do you really want to split your widescreen to 2:1 ratio? The 1/3 part 1147/267x1440/330 may not look nice. Maybe it’s better for you to extend your screen, not duplicating; so your personal work is on the widescreen and you can screen share your laptop screen with your work stuffs.

1 Like

this is my setup: the widescreen and the laptop screen and I am only sharing the the red frame DP1-2

what I don’t get is this:

does the “5360 x 1440” have to include DP1-1 and eDP1?

and I am not sure why I get the notification for the missing " ] " when running the script a second time.

There should be a space before it. I should’ve got that straight away.

Yes, imagine a bounding box around all monitors, that’s the framebuffer, +0+0 is the top left corner. Why do you want the monitors like that? They should be next to each other without spaces. Empty space still has to be moved through. You’ll be blocked from moving to the laptop screen at the top of the widescreen, and blocked from moving to the widescreen from the bottom of the laptop screen.

I’m not sure virtual screens are what you’re looking for, but I’ve only just starting playing with them.

if [ -z "$(xrandr --listactivemonitors | grep 'DP1-1')"]; then
    xrandr --output eDP1 --pos 3440x0
    xrandr --output DP1 --0x0
    xrandr --setmonitor DP1-1 3440/797x1440/333+0+0 DP1
    xrandr --setmonitor DP1-2 2293/531x1440/330+0+0 none
    xrandr --fb 5360x1440   # This should only need to be run once, since we're not changing fb size again
  
else
    xrandr --delmonitor DP1-1
    xrandr --delmonitor DP1-2
    xrandr --output eDP1 --pos 3440x0
    xrandr --output DP1 --0x0
fi

@JiaZhang

The framebuffer is for all monitors, therefore with a 3440x1440 and a 1920x1080 next to each other that makes 5360x1440.

The monitors are in odd places and therefore need more space (7308x2614), then the --auto adjusts to match.

What is needed is placing them in a sensible way. Admittedly they weren’t quite as bad until after the script was run.

1 Like

thx alot!
I changed the odd places of the monitors, but left the gap between them since in KDE windows cast a shadow and it looks strange when they appear on the other screen. I also adjusted the DP1-2 to exclude the task bar. my sharing experience is now terrific.

#!/bin/zsh
if [ -z "$(xrandr --listactivemonitors | grep 'DP1-1')" ]; then
    xrandr --setmonitor DP1-1 3440/797x1440/333+0+0 DP1
    xrandr --setmonitor DP1-2 2293/531x1382/320+0+0 none
    xrandr --fb 5475x1440
else
    xrandr --delmonitor DP1-1
    xrandr --delmonitor DP1-2
    xrandr --output eDP1 --pos 3550x360
    xrandr --output DP1 --pos 0x0
fi
1 Like

You’re welcome. :smile:

Ah makes sense now, you can disable the shadows if you want.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.