Is there an equivalent to windows+p hotkey (change between mirrored/extended monitor) in Ubuntu?

9,209

If you don't find a simple built-in shortcut, you can do what I do on Xubuntu and use xrandr to switch the display output. All of this might seem like a pain in the ass, but I've found it to be rock solid reliable over the years (especially compared to relying on display auto-switching).

$ sudo apt-get install xrandr

So on my setup, this command switches to mirrored output:

xrandr --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off \
--output DP1 --off --output eDP1 --mode 1920x1080 --pos 2040x0 --rotate normal \
--same-as HDMI1 --output VGA1 --off

And this one switches to extended desktop:

xrandr --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off \
--output DP1 --off --output eDP1 --mode 1920x1080 --pos 2040x0 --rotate normal \
--output VGA1 --off

Obviously, these commands are too long to be typing in, so I save them to scripts called display_TV_mirror.sh and display_TV_extend.sh, and then I bind a shortcut key to each script. In regular Ubuntu, I think you can set the shortcuts in System Settings -> Keyboard -> Shortcuts. I use to separate scripts with two separate shortcut keys, but you could easily combine them into one switch with some toggle logic.

Note: To find out the exact command you want to use for xrandr, it is probably easier to use arandr at first, which is basically a gui interface to xrandr.

$ sudo apt-get install arandr
$ arandr

Then you can set up your desired config, save it to a file somewhere, then look at that file to find out what xrandr command is needed to get the setup you want.

Share:
9,209

Related videos on Youtube

Doug T.
Author by

Doug T.

I work at Shopify in search and discovery to help every business be able to connect their products and ideas with customers. Blog @softwaredoug LinkedIn

Updated on September 18, 2022

Comments

  • Doug T.
    Doug T. over 1 year

    In Windows, Windows Key + P changes how an attached monitor is attached. I primarilly used it to swap between mirrored and extended views.

    Is there a similar hotkey in Ubuntu 14.04?

    To clarify, I'm often in the situation where my built-in display is blank after being plugged into HDMI and suspendend. I think it just needs to be told to switch to a different display mode. I can't do this with a command, as I can't see what I'm typing.

    I've googled, and my google fu doesn't appear to be working well

    • user26742873
      user26742873 about 3 years
      Now there is a Super+P at 20.04 LTS! Hurray!