我在左上角有一个热角,用于显示所有窗口,在右下角有一个热角,用于显示工作区。玩游戏时这些热角不断激活很烦人。有没有办法设置 Compiz 在全屏窗口时忽略热角?
答案1
下面有两个选项;一个脚本用于在活动窗口最大化时禁用所有热角(暂时),另一个脚本用于仅禁用您在问题中提到的特定热角和操作。
这两个脚本都非常轻量,不会给您的系统添加任何明显的负担。
1. 禁用全部如果活动窗口是全屏的,则显示热角
下面的背景补丁将禁用全部如果(并且只要)活动窗口最大化(全屏),则热角。
剧本
#!/usr/bin/env python3
import subprocess
import time
import ast
import os
edgedata = os.path.join(os.environ["HOME"], ".stored_edges")
key = "/org/compiz/profiles/unity/plugins/"
corners = [
"|TopRight", "|TopLeft", "|BottomLeft", "|Right",
"|Left", "|Top", "|Bottom", "|BottomRight",
]
def get(cmd):
# just a helper function
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass
def setval(cmd):
# just another helper function
subprocess.Popen(cmd)
def check_win():
# see if the active window is maximized
# get the active window, convert the id to wmctrl format
windata = get(["wmctrl", "-lG"])
if windata:
w = hex(int(get(["xdotool", "getactivewindow"])))
front = w[:2]+((10-len(w))*"0")+w[2:]
# look up the window size
match = [l for l in windata.splitlines() if front in l][0].split()[4:6]
# and compare them, if equal -> window is maximized
return match == res
def get_res():
# look up screen resolution
scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2
return [n for n in scrdata[resindex].split("+")[0].split("x")]
def get_edges():
# get data from dump, remember
data = get(["dconf", "dump", key]).split()
for s in data:
if s.startswith("["):
k = s.replace("[", "").replace("]", "/")
elif any([[c in s][0] for c in corners]):
currval = s.split("=")
stored = ["dconf", "write", key+k+currval[0], currval[1]]
tempval = ["dconf", "write", key+k+currval[0], "''"]
open(edgedata, "a+").write(str(stored)+"\n")
setval(tempval)
def set_stored():
# set the stored values
try:
prev = open(edgedata).readlines()
except FileNotFoundError:
pass
else:
for l in [l.strip() for l in open(edgedata).readlines()]:
toset = ast.literal_eval(l)
setval(toset)
os.remove(edgedata)
res = get_res()
state1 = None
while True:
time.sleep(1)
state2 = check_win()
if state2 != None:
if state2 != state1:
get_edges() if state2 else set_stored()
state1 = state2
如何使用
该脚本需要
xdotool
和wmctrl
:sudo apt-get install wmctrl xdotool
- 将脚本复制到一个空文件中,并将其保存为
disable_corners.py
使用以下命令从终端运行脚本:
python3 /path/to/disable_corners.py
如果一切正常,请将其添加到启动应用程序:Dash > 启动应用程序 > 添加。添加命令:
/bin/bash -c "sleep 10 && python3 /path/to/disable_corners.py"
2. 如果活动窗口为全屏,则仅禁用特定边缘
如果活动窗口最大化,下面的(背景)脚本将禁用您提到的两个角落操作。
剧本
#!/usr/bin/env python3
import subprocess
import time
key = "/org/compiz/profiles/unity/plugins"
active1 = "'|BottomRight'"; active2 = "'|TopLeft'"
def get(cmd):
# just a helper function
try:
return subprocess.check_output(cmd).decode("utf-8")
except subprocess.CalledProcessError:
pass
def setval(cmd):
# just another helper function
subprocess.Popen(cmd)
def check_win():
# see if the active window is maximized
# get the active window, convert the id to wmctrl format
windata = get(["wmctrl", "-lG"])
if windata:
w = hex(int(get(["xdotool", "getactivewindow"])))
front = w[:2]+((10-len(w))*"0")+w[2:]
# look up the window size
match = [l for l in windata.splitlines() if front in l][0].split()[4:6]
# and compare them, if equal -> window is maximized
return match == res
def get_res():
# look up screen resolution
scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2
return [n for n in scrdata[resindex].split("+")[0].split("x")]
res = get_res()
state1 = None
while True:
time.sleep(1)
state2 = check_win()
if state2 != None:
if state2 != state1:
newws = "''" if state2 else active1
# below the specific edges to take care of
setval(["dconf", "write", key+"/expo/expo-edge", newws])
newspread = "''" if state2 else active2
setval(["dconf", "write", key+"/scale/initiate-edge", newspread])
state1 = state2
如何使用
使用和设置与选项 1 完全相同。
解释
- 在脚本启动时,脚本会检查屏幕的分辨率。
- 该脚本每秒检查一次活动窗口的大小,并将其与屏幕的分辨率进行比较。
- 如果窗口大小和分辨率相等,则窗口显然最大化。
如果有改变在情况(最大化/非最大化)下,脚本使用以下命令设置/取消设置热角:
dconf write /org/compiz/profiles/unity/plugins/expo/expo-edge "''" dconf write /org/compiz/profiles/unity/plugins/scale/initiate-edge "''"
禁用,或
dconf write /org/compiz/profiles/unity/plugins "'|BottomRight'" dconf write /org/compiz/profiles/unity/plugins "'|TopLeft'"
启用。