4

I use a script that runs xrandr to turn off laptop display, showing only the external monitor screen.

I have another script that basically "reverses" this (showing only laptop display) which I use every time I have to take my laptop to a coffee shop.

Sometimes, in a hurry, I don't do this and just unplug my laptop directly before putting it in the bag. Now when I reach the coffee shop and try to use it, I would only see a blank screen which is due to what I assume to be my video configuration still being in "external screen only" mode. Question: how do I go to "laptop screen only" mode here? Otherwise, is there a way I can avoid having this problem in the first place?

Without knowing this I simply force reboot my laptop, which sucks.

For the record I run NixOS on Thinkpad P71.

2 Answers 2

1

This answer suggests, no event is fired on a monitor connect/disconnect event. If it is really so, then it is a major bottleneck of the Linux/X11 GUI in my opinion.

That answer suggests polling as a workaround (xrandr --listmonitors shows the connected / disconnected monitors, executing a script periodically would be a solution).

However, polling is bad. A better option would be to bind a monitor fixer script to a keyboard shortcut. Write a script, which

  1. gets the a list of the connected/disconnected monitors
  2. turns off always the one what you want (depending on, which is connected)
  3. bind its execution to a keyboard shortcut.
1
  • Thanks. I think I might go with the polling approach. Keyboard shortcut probably won't work if I find myself in a lock screen. Commented Jul 1, 2019 at 17:29
1

As an short term fix to avoid reboot, unlock your screen, hit the keyboard shortcut to open terminal, and run xrandr --output eDP1 --auto to turn on your monitor again. You can do all of that 'blind' while your monitor is disabled.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .