3

I wish to have a shortcut which switches the priority (i.e. primary, secondary) of the displays (laptop + external).

PS: I am aware that there's a dedicated button/shortcut to do this but, at least mine, cycles through all configurations (i.e. different resolutions). I want to cycle between two configurations only.

5
  • why? there should be one on your keyboard. probably Fn F8
    – Rinzwind
    Nov 11, 2016 at 18:49
  • @Rinzwind Actually I have two but they cycle through all possible configurations (with different resolutions).
    – user10853
    Nov 11, 2016 at 18:56
  • What is exactly the purpose? A screen being primary does not mean that much on Ubuntu, mostly for launcher presence, if set to only on primary. The order is set separately. Nov 11, 2016 at 19:00
  • @JacobVlijm I am using Ubuntu Gnome so switching the priority changes the location of the top bar, launcher & dash.
    – user10853
    Nov 11, 2016 at 19:15
  • @JacobVlijm Absolutely. Can wait. All the best
    – user10853
    Nov 11, 2016 at 19:57

1 Answer 1

2

It turned out I already wrote it, as part of this question. Since it is another question, below an outtake of that one:

#!/usr/bin/env python3
import subprocess

# Look up the currently set primary screen, set it to the other one
scr_data = subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()
scrs = [[l.split()[0], "primary" in l] for l in scr_data if " connected" in l]
for screen in scrs:
    if not screen[1]:
        subprocess.Popen(["xrandr", "--output", screen[0], "--primary"])

It toggles (switches between the two) the primary screen.

To use:

  • copy the script into an empty file, save it as toggle_primary.py

  • Add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

      python3 /path/to/toggle_primary.py
    
2
  • @user10853 you're welcom! Glad to help :) Nov 12, 2016 at 18:53
  • +1 because this script and shortcut hotkey feels very similar to what I'd like to do (toggle between 2 resolutions). @JacobVlijm I'd really love your thoughts at askubuntu.com/q/1378237/48214
    – Ryan
    Nov 29, 2021 at 18:08

You must log in to answer this question.

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