如何只在一个工作区中显示Unity启动器?
我想保持启动器仅在主工作区中处于活动状态。 例如,我喜欢在没有启动器的情况下将Citrix窗口保持在完全显示模式(在工作区II中)。
像许多事情一样,据我所知它并不存在, 但是 ,它可以通过一点创造力和正确的工具来完成。
如何做到这一点
假设您在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
,与start_stop.py
脚本位于同一个文件夹中。 使它也可执行(!)。 现在,您可以使用命令切换自动隐藏function
/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..."])
启动或停止脚本的其他方法
还有其他几种方法可以方便地切换脚本:
将脚本添加到启动apoplications中
如果您永远想要在后台运行脚本:
- 打开“启动应用程序”并选择“添加”。
-
添加命令:
/path/to/autohide_launcher.py
-
给你一个喜欢的名字
设置键盘快捷键以切换脚本
- 打开系统设置,然后选择:“键盘”>“快捷方式”>“自定义快捷方式”。
-
使用以下命令创建您选择的新快捷方式:
/path/to/start_stop.py
现在,您可以使用组合键切换autohide-per-viewport。
发布在gist.gisthub上
介绍
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: 1047481448@qq.com # 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 "$@"