我最近看到了一个很好的问题的答案,我想知道,是否可以在具有GNOME 3.18和GDM的Ubuntu GNOME 15.10上以及在Compiz上解决该问题?
但是键盘快捷键对我而言并不那么重要,我只是真的希望能够将窗口拖动到角落,并让它们自动调整到那些角落,而不是在释放鼠标时在侧面调整大小。
在发布的副本的边缘这一个(但问题略有不同),下面的脚本做你的描述,如果你用的参数运行
python3 /path/to/script.py 2 2
但是,如果有四个以上的窗口(或者,如果使用的参数不是2 2
,则大于网格的单元格),脚本将仅在网格中放置四个最早的窗口。
打开四个窗口后,将其随机放置在屏幕上:
运行脚本会将它们排列在网格中:
#!/usr/bin/env python3
import subprocess
import sys
#--- set your preferences below: padding between windows, margin(s)
cols = int(sys.argv[1]); rows = int(sys.argv[2]); padding = 10; left_margin = 0; top_margin = 30
#---
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
def get_res():
xr = get("xrandr").split(); pos = xr.index("current")
return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )]
def check_window(w_id):
w_type = get("xprop -id "+w_id)
if " _NET_WM_WINDOW_TYPE_NORMAL" in w_type:
return True
else:
return False
# get resolution
res = get_res()
# define (calculate) the area to divide
area_h = res[0] - left_margin; area_v = res[1] - top_margin
# create a list of calculated coordinates
x_coords = [int(left_margin+area_h/cols*n) for n in range(cols)]
y_coords = [int(top_margin+area_v/rows*n) for n in range(rows)]
coords = sum([[(cx, cy) for cx in x_coords] for cy in y_coords], [])
# calculate the corresponding window size, given the padding, margins, columns and rows
w_size = [str(int(area_h/cols - padding)), str(int(area_v/rows - padding))]
# find windows of the application, identified by their pid
wlist = [w.split()[0] for w in get("wmctrl -lp").splitlines()]
w_list = [w for w in wlist if check_window(w) == True][:cols*rows]
print(w_list)
# remove possibly maximization, move the windows
for n, w in enumerate(w_list):
data = (",").join([str(item) for item in coords[n]])+","+(",").join(w_size)
cmd1 = "wmctrl -ir "+w+" -b remove,maximized_horz"
cmd2 = "wmctrl -ir "+w+" -b remove,maximized_vert"
cmd3 = "wmctrl -ir "+w+" -e 0,"+data
for cmd in [cmd1, cmd2, cmd3]:
subprocess.Popen(["/bin/bash", "-c", cmd])
该脚本同时需要xdotool
和wmctrl
:
sudo apt-get install xdotool wmctrl
将脚本复制到一个空文件中,另存为 twobytwo.py
通过打开四个窗口(至少一个终端窗口来运行命令)进行测试,然后运行命令:
python3 /path/to/twobytwo.py 2 2
窗口应移至4的网格中,如第二个图像中所示
如果一切正常,请将其添加到快捷键:选择:“系统设置”>“键盘”>“快捷方式”>“自定义快捷方式”。单击“ +”并添加命令:
python3 /path/to/twobytwo.py 2 2
在头部部分,有一个部分:
left_margin = 0
我将其设置为零,因为gnome在左侧没有启动器。对于Unity,此值(至少)应该为65
,具体取决于启动器的设置宽度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句