Every once in a while, I connect my laptop to my TV at home and watch a movie on my hard drive. So I configured the external display in Xorg in my i3 configuration file and it works fine.
The problem is, the external display is enabled even if it’s not connected, so the mouse regularly “disappears” off the right of the laptop screen.
Worse, when I run Cinnamon in Xephyr (a windowed environment), the display spans the entire virtual display including the invisible external display, and I only see the left half of the windows in fullscreen mode.
So I needed some way to configure the external display as secondary display, but start it off, and then define a key binding to turn it on and off as needed.
Here are the relevant config file lines to achieve this, if you have the same need:
# Configure multimonitor layout. Start with the secondary display off
set $display1 eDP
set $display2 HDMI-A-0
exec_always --no-startup-id xrandr --output $display1 --auto --primary --output $display2 --off --right-of $display1
# Enable / disable the secondary display
bindsym $mod+Shift+d exec xrandr --output $display2 --`xrandr --listactivemonitors | grep -q $display2 && echo off || echo auto` --right-of $display1
Note that in my case, my laptop’s internal display is called eDP
and the external display is called HDMI-A-0
. Also, my TV is physically sitting at the right of the laptop. Define the display’s names and physical layout to suit your needs of course.
Also, I configured workspaces 1, 2 and 3 to be assigned to the laptop’s display, and 4, 5 and 6 to the external display with these lines:
# Workspace names
set $ws1 1
set $ws2 2
set $ws3 3
set $ws4 4
set $ws5 5
set $ws6 6
# Assign workspaces to specific displays
workspace $ws1 output $display1
workspace $ws2 output $display1
workspace $ws3 output $display1
workspace $ws4 output $display2
workspace $ws5 output $display2
workspace $ws6 output $display2
If the external display is disabled, workspaces 4, 5 and 6 fall back to the primary display (the laptop’s monitor). When the external display is re-enabled, they automatically move back there.
So you can have a movie going on display 4 for example, plug in the external monitor, hit Shift-Meta-D and hey-presto, your movie moves to the external monitor.
I hope this helps.