在compiz中自动调整窗口大小

这个答案没有回答我的问题: 。

我想自动调整两个或多个窗口的大小,以便它们并排占据整个屏幕的一部分。 也就是说,2个占据1/2的窗口,3个占据1/3的窗口,依此类推。

我现在可以手动完成,但仅使用键盘单独调整窗口是非常耗时的。 例如,每个窗口的ctrl + Super +箭头和左/右/上/下。 然而,这会迫使我逐窗口调整它们。

在这个答案中 ,问题是如何(重新)将特定于应用程序的窗口安排到网格中,下面的编辑版本将所有“正常”窗口重新排列为网格:

#!/usr/bin/env python3 import subprocess import getpass 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 = 70; 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]) 

如何使用

  • 确保安装了wmctrl:

     sudo apt-get install wmctrl 
  • 将脚本复制到空文件中,将其另存为rearrange_windows.py

  • 在脚本的head部分,如果您愿意,可以设置您喜欢的填充:

     #--- set your preferences below: padding between windows, margin(s) cols = 3; rows = 2; padding = 10; left_margin = 70; top_margin = 30 #--- 

    由于使用(组合)Unity / wmctrl一些错误,我会留下left_margin = 70; top_margin = 30 left_margin = 70; top_margin = 30原样。

  • 通过命令运行它:

     python3 /path/to/rearrange_windows.py   

    例如:

     python3 /path/to/rearrange_windows.py 3 2 

    设置3个collums / 2行窗口的网格。

如果一切正常,请将其添加到快捷键:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并添加命令:

  python3 /path/to/rearrange_windows.py   

如果您想使用不同的网格(cols / rows),只需创建几个具有不同网格的快捷方式即可。

注意

如果窗口数超过网格中(可能的)窗口的数量,则脚本将对四个“最旧”的窗口进行网格化。

例子

 python3 /path/to/rearrange_windows.py 3 2 

在此处输入图像描述

 python3 /path/to/rearrange_windows.py 2 3 

在此处输入图像描述