2

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.

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.
  • Thanks. I think I might go with the polling approach. Keyboard shortcut probably won't work if I find myself in a lock screen. – Sridhar Ratnakumar Jul 1 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.