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
The script needs xdotool
:
sudo apt-get install xdotool
Copy the script into an empty file, save it as move_launcher.py
Test- run it by the command (from a terminal)
python3 /path/to/move_launcher.py
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):
...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:
...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...