How is the launcher's placement defined?
The Launcher's placement is defined by a few things:
The value, set in /org/compiz/profiles/unity/plugins/unityshell/num-launchers
. You can read it by the command:
dconf read /org/compiz/profiles/unity/plugins/unityshell/num-launchers
which will output either 1
(launcher on one screen) or 0
(launcher on all screens).
To set the launcher to visible on all screens can be done by the command:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 0
If the value is 1
(visible on only one screen), we can set on which screen the launcher appears, by setting the targeted screen as primary screen, with an xrandr
command:
xrandr --output <screen_name> --primary
Those are exactly the commands the script(s) below use(s).
Script1; manually set the launcher to only left or on both screens (with a key shortcut)
Depending on the argument you run the script with, it either sets the launcher to show on all screens with the command:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 0
or on only one:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 1
In the latter case, it also sets the left screen as the primary one.
The script
#!/usr/bin/env python3
import subprocess
import sys
key = "dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers "
arg = sys.argv[1]
if arg == "left":
# the launcher is set to show on all screens
subprocess.Popen(["/bin/bash", "-c", key+"1"])
elif arg == "all":
# the launcher is set to show only on the left screen
subprocess.Popen(["/bin/bash", "-c", key+"0"])
# make sure the left screen is the primary one
scr_data = subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()
left = [l.split()[0] for l in scr_data if "+0+0" in l][0]
subprocess.Popen(["xrandr", "--output", left, "--primary"])
How to use
- Copy the script into an empty file, save it as
launcher_pos.py
Test the script with both the commands (from a terminal window):
python3 /path/to/launcher_pos.py left
and
python3 /path/to/launcher_pos.py all
if all works fine, add the commands to two shortcut key combinations: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add both commands to available shortcuts.
Script 2; automatic version
The script below automatically keeps track of which is the current workspace (no matter how many workspaces you have and in what configuration).
This script is run with the workspaces, where you want the launcher only on the left, as an argument. An example:
If you run the script with the command:
python3 /path/to/launcher_pos.py 2 3
The result is:
The script
import subprocess
import sys
import time
wspace = sys.argv[1:]
key = "dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers "
def get_res():
# get resolution
xr = subprocess.check_output(["xrandr"]).decode("utf-8").split()
pos = xr.index("current")
return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )]
res = get_res()
def get_dt():
# get the current viewport
vp_data = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").split()
dt = [int(n) for n in vp_data[3].split("x")]
cols = int(dt[0]/res[0])
curr_vpdata = [int(n) for n in vp_data[5].split(",")]
curr_col = int(curr_vpdata[0]/res[0])+1; curr_row = int(curr_vpdata[1]/res[1])
return str(curr_col+curr_row*cols)
def set_launcher(arg):
if arg == "left":
# the launcher is set to show on all screens
subprocess.Popen(["/bin/bash", "-c", key+"1"])
elif arg == "all":
# the launcher is set to show only on the left screen
subprocess.Popen(["/bin/bash", "-c", key+"0"])
# make sure the left screen is the primary one
scr_data = subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()
left = [l.split()[0] for l in scr_data if "+0+0" in l][0]
subprocess.Popen(["xrandr", "--output", left, "--primary"])
curr_ws1 = get_dt()
while True:
time.sleep(1)
curr_ws2 = get_dt()
if curr_ws2 != curr_ws1:
if curr_ws2 in wspace:
arg = "left"
else:
arg = "all"
set_launcher(arg)
curr_ws1 = curr_ws2
How to use
The script needs wmctrl
sudo apt-get install wmctrl
Copy the script into an empty file, save it as launcher_pos.py
Test run it by the command:
python3 /path/to/launcher_pos.py 1 3
On workspace 1 and 3, the launcher now should appear only on the left
If all works fine, add it to your Startup Applications: Dash > Startup Applications > Add. Add the command:
/bin/bash -c "sleep 15 && python3 /path/to/launcher_pos.py 1 3"
(If workspace 1 and 3 are the ones you only want the launcher on the left)