我想让启动器仅在主工作区中处于活动状态。例如,我喜欢让 Citrix 窗口处于全屏显示模式,而不使用启动器(在工作区 II 中)。
答案1
就像许多事物一样,据我所知它并不存在,但,只需一点创造力和正确的工具就可以做到。
如何实现
假设您使用的是 14.04(带有 python3),您可以使用脚本在后台运行,该脚本跟踪您当前的视口并根据当前视口将启动器设置为自动隐藏或不自动隐藏。
您首先需要做的是安装
wmctrl
:sudo apt-get install wmctrl
我们需要
wmctrl
获取有关所有视口的总大小的信息,并能够读取有关我们所在当前部分的信息。完成后,将下面的脚本复制到一个空文件中,并将其保存为
autohide_launcher.py
(保留原名)并使其可执行(!)。在行中
hide_launcher
,决定要为哪些视口自动隐藏启动器(设置“True”),并使用与您的视口数量相对应的正确条目数。列表按视口行从左到右读取。
#!/usr/bin/env python3
import subprocess
import time
# set the hide-launcher values for your viewports; in rows/columns
hide_launcher = (False, True, True, True)
# don't change anything below (or it must be the time.sleep(2) interval)
key = " org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ "
pr_get = "gsettings get "; pr_set = "gsettings set "
check = pr_get+key+"launcher-hide-mode"
hide = pr_set+key+"launcher-hide-mode 1"
show = pr_set+key+"launcher-hide-mode 0"
def get_value(command):
return subprocess.check_output(
["/bin/bash", "-c", command]).decode('utf-8').strip()
# get screen resolution
output = get_value("xrandr").split(); idf = output.index("current")
screen_res = (int(output[idf+1]), int(output[idf+3].replace(",", "")))
while True:
# get total span size all viewports, position data
wsp_info = get_value("wmctrl -d").strip()
scr_data = [item.split("x") for item in wsp_info.split(" ") if "x" in item][0]
# get current position (viewport coordinates)
VP = eval(wsp_info[wsp_info.find("VP: "):].split(" ")[1])
# calculated viewports rows / columns
VP_hor = int(scr_data[0])/int(screen_res[0])
VP_vert = int(scr_data[1])/int(screen_res[1])
# calculated viewport positions
range_hor = [i*screen_res[0] for i in range(int(VP_hor))]
range_vert = [i*screen_res[1] for i in range(int(VP_vert))]
viewports = [(h, range_vert[i])for i in range(len(range_vert)) for h in range_hor]
current_viewport = viewports.index(VP); a_hide = get_value(check)
if (hide_launcher[current_viewport], a_hide == "0") == (True, True):
subprocess.Popen(["/bin/bash", "-c", hide])
elif (hide_launcher[current_viewport], a_hide == "0") == (False, False):
subprocess.Popen(["/bin/bash", "-c", show])
else:
pass
time.sleep(1)
您可以通过以下命令启动脚本:
/path/to/autohide_launcher.py
开启/关闭每个视口的自动隐藏
但是,使用下面的脚本通过一个命令来打开/关闭脚本会更方便。
将以下脚本复制到一个空文件中并将其保存为start_stop.py
,在同一个文件夹中作为autohide_launcher.py
脚本。使其可执行(!)。现在,您可以使用命令切换自动隐藏功能
/path/to/start_stop.py
启动/停止脚本:
#!/usr/bin/env python3
import os
import subprocess
script_dir = os.path.dirname(os.path.abspath(__file__))
cmd = "ps -ef | grep autohide_launcher.py"
run = subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").split("\n")
match = [line for line in run if script_dir+"/"+"autohide_launcher.py" in line]
if len(match) != 0:
subprocess.Popen(["kill", match[0].split()[1]])
subprocess.Popen(["notify-send", "autohide per viewport stopped..."])
else:
subprocess.Popen(["/bin/bash", "-c", script_dir+"/"+"autohide_launcher.py"])
subprocess.Popen(["notify-send", "autohide per viewport started..."])
启动或停止脚本的其他方法
还有其他几种方便的方式切换脚本:
将脚本添加到你的启动应用程序中
如果您想永久在后台运行该脚本:
- 打开启动应用程序并选择“添加”。
添加命令:
/path/to/autohide_launcher.py
给它起一个你喜欢的名字
设置键盘快捷键来切换脚本
- 打开系统设置并选择:“键盘”>“快捷键”>“自定义快捷键”。
使用以下命令创建您选择的新快捷方式:
/path/to/start_stop.py
现在您可以使用组合键切换每个视口的自动隐藏。
发表于gist.gisthub
答案2
介绍
Unity Launcher 和 Compiz 没有仅在特定视口上显示启动器的设置,但是可以使用hide launcher
设置来轮询视口的变化并相应地更改该设置。左上角的视口将是坐标0,0
,因此必须轮询我们是否在该视口上 - 否则取消设置启动器。
下面的脚本正是起到这个作用。
获取脚本
源代码可以直接从这里复制,也可以通过运行以下命令(显然在终端中)从我的 git 存储库下载:
sudo apt-get install git
cd /opt ; sudo git clone https://github.com/SergKolo/sergrep.git
sudo chmod -R +x sergrep
该文件名为toggle_unity_launcher.sh
脚本的工作原理
该脚本可以不带选项调用(仅在左上角视口中显示启动器)或带选项-x
调用-y
以设置特定视口,如下所示
toggle_unity_launcher.sh -x 1366 -y 0
该-h
标志将打印使用情况。
在登录时运行脚本
可以通过在启动应用程序中添加文件的完整路径(包括-x
和-y
选项)和参数来在登录时启动该脚本,如下所示
源代码
#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: [email protected]
# Date: April 8th , 2016
# Purpose: Set Unity launcher to show up only on
# specific viewport. By default - viewport 0,0
# Written for: http://askubuntu.com/q/349247/295286
# Tested on: Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#
# Permission to use, copy, modify, and distribute this software is hereby granted
# without fee, provided that the copyright notice above and this permission statement
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
ARGV0="$0"
ARGC=$#
print_usage()
{
cat << EOF
Copyright 2016 Serg Kolo
Usage: toggle_unity_launcher.sh [-x INT -y INT] [-h]
The script toggles Unity Launcher on user-defined viewport
By default - launcher appears only on 0, 0
-x and -y flags serve to set custom viewport
Use 'xprop -root -notype _NET_DESKTOP_VIEWPORT' to find
the exact coordinates of a viewport you want to set
EOF
}
get_viewport()
{
xprop -root -notype _NET_DESKTOP_VIEWPORT | awk -F '=' '{printf "%s",substr($2,2)}'
}
set_launcher_mode()
{
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode $1
}
poll_viewport_change()
{
while [ "$(get_viewport)" = "$VIEWPORT" ]
do
set_launcher_mode 0
sleep 0.25
done
}
parse_args()
{
local OPTIND opt
while getopts "x:y:h" opt
do
case ${opt} in
x) XPOS=${OPTARG}
;;
y) YPOS=${OPTARG}
;;
h) print_usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
}
main()
{
local XPOS=0
local YPOS=0
parse_args "$@"
local VIEWPORT=$(printf "%s, %s" "$XPOS" "$YPOS" )
while true
do
poll_viewport_change
set_launcher_mode 1 # happens only when
# previous function exits
sleep 0.25
done
}
main "$@"