x-on-resize is a simple utility that detects when you connect/disconnect a monitor to your laptop and will run a script that you provide to it.
Since my X1E has a discrete Nvidia graphics card, this presented a problem of its own. Simply running x-on-resize didn’t work for me. The way it works with the 1050ti is the HDMI port is wired to Nvidia graphics as opposed to Intel. So there is a utility called
intel-virtual-output that connects the discrete output to intel’s gpu.
I managed to put together a script that works well with x-on-resize and haven’t had any issues with so far.
You can download it here: Monitor.sh
And the way I start
x-on-resize is run the command xinitrc