2

I run an asynchronous dual montior setup. My primary monitor is a 16:9 2560x1440 and my secondary is 10:16 1200x1920 setup. I use the primary for coding/gaming/videos and the secondary for browsing, and reference materials.I also prefer to keep the launcher on the secondary monitor as it is on the right hand side of my primary.

The problem is that some of my games seem to think that the monitor which the launcher is on is considered the primary monitor. Some games give me launch options where I can force it over to my preferred monitor but some I need to switch the launcher placement in the display settings.

I would like to script a solution that allows me to quickly toggle the settings rather than needing to go into the screen display ui every time. I found ~/.config/monitors.xml and have tried swapping the primary monitor and then killing unity-settings-daemon and restarting it but that seems like it's not without side effects. Does anyone know a better way?

4
  • 1
    There are two options for the launcher: on all screens, or just one. In the latter case, the one with the launcher is also the primary screen. Would any of the options be the one you'd like to toggle to? Dec 19, 2015 at 21:31
  • Yes. I only want the launcher on my secondary monitor, except in the instances I want to coerce a game to launch on my preferred monitor, then I want a script to be able to quickly toggle it to my other monitor. Dec 19, 2015 at 21:53
  • Yes I just got back from my weekend vacation, this suits my needs, thank you. Dec 21, 2015 at 17:19
  • Perfect, glad it works. Dec 21, 2015 at 17:52

1 Answer 1

3

Launcher positions

Launcher positions can be defined by two parameters:

1. Launcher on all screens, or just on one

is set by the commands:

dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 0

to show on all screens, or

dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 1

to show on a single screen

2. The screen where the Launcher is visible

In the latter case (launcher only on one screen), the launcher is only visible on the primary screen. In other words, we need to set (toggle) the primary screen. This can be done with the command:

xrandr --output <screen_name> --primary

What we need is a script to look up the currently set primary screen (from the output of the xrandr command), and choose "the other one", and so does the script below.

enter image description here enter image description here

The script:

#!/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] == True:
        subprocess.Popen(["xrandr", "--output", screen[0], "--primary"])

If you also need to make sure the launcher is set to show on a single screen, use:

#!/usr/bin/env python3
import subprocess

# just to make sure the launcher is set to only show on one screen:
subprocess.Popen(["/bin/bash", "-c", "dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 1"])

# 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] == True:
        subprocess.Popen(["xrandr", "--output", screen[0], "--primary"])

How to use

  1. Copy the script into an empty file, save it as toggle_launcher.py
  2. Test- run it by the command:

    python3 /path/to/toggle_launcher.py
    
  3. If all works fine, add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/toggle_launcher.py
    

    to a shortcut key combination of your choice.

You must log in to answer this question.

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