Sharing monitors between devices

It’s been a while I’ve been using a dual-monitor setup for my desktop computer at home running Ubuntu. Now due to the pandemics, I’ve been working from home sharing one of those monitors with a Windows 10 laptop issued to me by the company I work for.

Simply setting “Input Source” to “Auto” on the shared monitor wasn’t enough to make it work for me as the monitor’s auto selection seemingly had a strong opinion or found it would be funny to select precisely the input source I wanted to switch away from.

After a bit of research I found a command that would let me change these configurations from a terminal: xrandr.

To get a list of monitors connected to the host:

$ xrandr --listmonitors 
Monitors: 2
 0: +*DP-1 3840/597x2160/336+0+0  DP-1
 1: +HDMI-1 1920/509x1080/286+3840+0  HDMI-1


$ xrandr --output DP-1 --off

… to turn off the monitor connected to DP1.

$ xrandr --output DP-1 --auto --left-of HDMI-1

… turns it back on positioning it to the left of the monitor connected to the HDMI-1 in the virtual display.

While turning monitors on and off, GNOME automatically rearranges the desktop environment according to the new settings of the virtual desktop. That means moving UI elements such as desktop widgets, icons, etc.

More information xrandr‘s options most useful for multi-monitor setups can be found at ArchWiki.