Ubuntu – How to put unity launcher on in different positions on different monitors

16.04launchermultiple-monitorsunity

I have two monitors:
One is a large 2560×1600 monitor, which I use as my main monitor and do most work on, and the other is a 1360×768 monitor set up vertically for use as an 'off' monitor – for things like my calendar and email, notification popups, or for a web browser while playing games, etc.

I currently have it configured so that the unity launcher is located only on the left edge of the main monitor.

I would like to be able to have a separate unity launcher for each monitor.
The advantage of doing this is that the applications on each monitor are then associated with only the launcher on that monitor, which helps with keeping the desktop organized.

Unfortunately, horizontal space is at a premium on the off monitor – I don't want to have to use an extra 48 pixels of horizontal space just for this.

A solution to this would be to change the launcher position setting (e.g. via the Unity Tweak Tool or similar) to the bottom. However, this setting would affect the position of the launcher on both screens, and I want to keep the launcher on the left edge of my main monitor.

How can I configure unity to use different launcher positions on different monitors?

An alternate solution would be to have the unity launcher on the off monitor auto-hide, but I want to keep the launcher bar static on my main monitor. If there is a way to configure the auto-hide behavior on a per-monitor basis this would also be an acceptable solution.

I would prefer to stick to the default unity desktop environment, but if there is another DE that handles multiple monitors really well I might be interested.

Best Answer

Automatically move the launcher, depending on the active screen

A possible solution is to automatically change the position of the launcher, depending on the current mouse-position:

  • if it is on the left screen, move the launcher to left
  • if it is on the right screen, move it to the bottom

In the test I ran, it worked surprisingly smooth, and windows adapt well to the change.

The script

#!/usr/bin/env python3
import subprocess
import time

scr_data = subprocess.check_output(["xrandr"]).decode("utf-8")
border = int([s.split("x")[0] for s in scr_data.split() if "+0+0" in s][0])
left_scr = [l.split()[0] for l in scr_data.splitlines() if "+0+0" in l][0]

key = "com.canonical.Unity.Launcher"
item = "launcher-position"

def catch_mouse():
    return int(subprocess.check_output([
        "xdotool", "getmouselocation"
        ]).decode("utf-8").split()[0].split(":")[1])

test1 = ""

while True:
    time.sleep(1)
    test2 = catch_mouse() <= border
    if test2 != test1:
        if test2 == True:
            cmd = ["gsettings", "set", key, item, "Left"]
        else:
            cmd = ["gsettings", "set", key, item, "Bottom"]
        subprocess.Popen(cmd)
    test1 = test2

How to use

  1. The script needs xdotool:

    sudo apt-get install xdotool
    
  2. Copy the script into an empty file, save it as move_launcher.py

  3. Test- run it by the command (from a terminal)

    python3 /path/to/move_launcher.py
    
  4. If all works fine, add to Startup Applications: Dash > Startup Applications > Add. Add tghe command:

    /binh/bash -c "sleep 15 && python3 && /path/to/move_launcher.py
    

EDIT

...Or more advanced, only a launcher on the active screen on an arbitrary position.

...a script that will set only one launcher (on the left screen, on the left side):

![enter image description here

...while you are working on the left screen. This will give you full size view on the right screen...

...and one launcher at the bottom of the second screen:

enter image description here

...If you move to the right screen, giving you the launcher you need on the desired position on the right screen.

As mentioned, in the test(s), the windows adapted smoothly without an error.

The script

#!/usr/bin/env python3
import subprocess
import time

scr_data = subprocess.check_output(["xrandr"]).decode("utf-8")
border = int([s.split("x")[0] for s in scr_data.split() if "+0+0" in s][0])
left_scr = [l.split()[0] for l in scr_data.splitlines() if "+0+0" in l][0]
right_scr = [l.split()[0] for l in scr_data.splitlines() if all([
    not "+0+0" in l, l.count("+") == 2])][0]

key = "com.canonical.Unity.Launcher"
item = "launcher-position"

subprocess.call(["dconf", "write",
        "/org/compiz/profiles/unity/plugins/unityshell/num-launchers", "1"])

def catch_mouse():
    return int(subprocess.check_output([
        "xdotool", "getmouselocation"
        ]).decode("utf-8").split()[0].split(":")[1])

test1 = ""

while True:
    time.sleep(1)
    test2 = catch_mouse() <= border
    if test2 != test1:
        if test2 == True:
            cmd1 = ["xrandr", "--output", left_scr, "--primary"]
            cmd2 = ["gsettings", "set", key, item, "Left"]
        else:
            cmd1 = ["xrandr", "--output", right_scr, "--primary"]
            cmd2 = ["gsettings", "set", key, item, "Bottom"]
        subprocess.Popen(cmd1)
        subprocess.call(cmd2)
    test1 = test2

To use

  • This version runs exactly like the first one.

Note

These are just two examples. Many things are possible.

Two launchers, at the same time on a different position per screen, is currently impossible however, untill someone creates the option...

Related Question