启动器放置双显示器
我有两台显示器。 我有多个工作区。 我希望我的启动器(设置>显示中的“launcer placement”)出现在一个工作区的两个监视器上,但在另一个工作区中只有一个启动器(在主监视器上)。 这是因为我想在两台显示器上拉伸Tweetdeck,而启动器会阻挡它。 这可能吗?
工作区1(好):
工作区2(不好):
工作区2(好):
如何定义发射器的位置?
Launcher的位置由以下几个方面定义:
-
该值设置在
/org/compiz/profiles/unity/plugins/unityshell/num-launchers
。 您可以通过以下命令阅读它:dconf read /org/compiz/profiles/unity/plugins/unityshell/num-launchers
它将输出
1
(一个屏幕上的启动器)或0
(所有屏幕上的启动器)。要在所有屏幕上将启动器设置为可见,可以通过以下命令完成:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 0
-
如果值为
1
(仅在一个屏幕上可见),我们可以通过使用xrandr
命令将目标屏幕设置为主屏幕来设置启动器出现在哪个屏幕上:xrandr --output
--primary
这些正是下面脚本使用的命令。
SCRIPT1; 手动将启动器设置为仅在左侧或两个屏幕上(使用快捷键)
根据您运行脚本的参数,它可以使用以下命令将启动器设置为在所有屏幕上显示:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 0
或只有一个:
dconf write /org/compiz/profiles/unity/plugins/unityshell/num-launchers 1
在后一种情况下,它还将左侧屏幕设置为主屏幕。
剧本
#!/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"])
如何使用
- 将脚本复制到空文件中,将其另存为
launcher_pos.py
-
使用这两个命令(从终端窗口)测试脚本:
python3 /path/to/launcher_pos.py left
和
python3 /path/to/launcher_pos.py all
-
如果一切正常,请将命令添加到两个快捷键组合中:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并将两个命令添加到可用的快捷方式。
脚本2; 自动版
下面的脚本会自动跟踪当前工作空间(无论您拥有多少工作空间和配置)。
此脚本与工作区一起运行, 您只希望左侧的启动器作为参数。 一个例子:
如果使用以下命令运行脚本:
python3 /path/to/launcher_pos.py 2 3
结果是:
剧本
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
如何使用
-
该脚本需要
wmctrl
sudo apt-get install wmctrl
-
将脚本复制到空文件中,将其另存为
launcher_pos.py
-
通过命令测试运行它:
python3 /path/to/launcher_pos.py 1 3
在工作区1和3上,启动器现在应仅出现在左侧
-
如果一切正常,请将其添加到启动应用程序:Dash> Startup Applications> Add。 添加命令:
/bin/bash -c "sleep 15 && python3 /path/to/launcher_pos.py 1 3"
(如果工作区1和3是您只想要左侧启动器的工作区)