我以前使用过 Windows 10,虽然我已经开始使用(并接受)Ubuntu 的工作方式,但 Windows 10 仍有一些我喜欢的地方,这里要讨论的功能是,如果我将一个窗口捕捉到显示屏的最右侧,它会占据显示屏的右半部分(这在 ubuntu 中也类似),但后台的另一个应用程序会占据显示屏的左半部分,不需要手动执行此操作。
在这张图片中,如果我将浏览器窗口对齐到右侧,Nautilus 窗口将不会受到此操作的影响,但我希望它(nautilus 窗口)对齐到左侧
细节
- Ubuntu 17.04
- 侏儒风味
更新
fillscreen.py
脚本的结果
第一次尝试填屏通知来了(我无法捕捉到它)并且它将第二个窗口(右边的窗口)移动到一个框中,而第一个窗口根本没有受到影响。
在第二次尝试中,出现了这个偏移,但它确实起作用了(而且基本上起作用了)
答案1
重要的提示!
下面的脚本将完全按照你描述的方式执行两个最小的windows,也就是:最后创建的两个窗口。
剧本、行为
脚本作用于拖拽将两个“最新”窗口之一移动到屏幕上的两个区域之一,如图所示。
该区域是故意不是紧紧地靠在角落里,以确保它不会干扰“正常”的窗户卡入。
如果窗口被拖到任一区域上,脚本会等待 0.15 秒来查看鼠标是否仍在同一位置,以确保在用户“正在”前往屏幕角落进行正常窗口捕捉时不会采取行动。
随后,拖动的窗口将被捕捉到该区域所在的屏幕的一半,第二个窗口将被捕捉到屏幕的另一侧
1. 将窗口拖到区域
2. 窗户卡住,另一个窗户卡在对面
最后,作为确认,通知将显示三秒钟:
脚本和设置
设置涉及两项:
剧本:
#!/usr/bin/env python3 import sys import os import subprocess import time from operator import itemgetter from itertools import groupby import math #--- set your preferences below: padding between windows, margin(s) cols = 2; rows = 1; padding = 20; left_margin = 0; top_margin = 30 #--- fpath = os.path.dirname(os.path.abspath(__file__)) n_wins = cols*rows def get_spot(pos): # get the resolution scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2 res = [int(n) for n in scrdata[resindex].split("+")[0].split("x")] # list the corners, could be more elegant no doubt corners = [[0, res[1]], [res[0], res[1]]] diff = [int(math.sqrt(sum([(c[i]-pos[i])**2 for i, n in enumerate(res)])))\ for c in corners] return diff def get(cmd): try: return subprocess.check_output(cmd).decode("utf-8") except subprocess.CalledProcessError: pass def get_res(): xr = get("xrandr").split(); pos = xr.index("current") return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )] def get_pos(): return [int(s.split(":")[1]) for s in get(["xdotool", "getmouselocation"]).split()[:2]] 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 def confirm(): val = False mouseloc = get_spot(get_pos()) match = [mouseloc.index(n) for n in mouseloc if 50 < n < 400] if match: time.sleep(0.15) val = True if get_spot(get_pos()) == mouseloc else False return val, match def arrange_wins(active, side): # 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 active = hex(int(get(["xdotool", "getactivewindow"]))) active = active[:2]+(10-len(active))*"0"+active[2:] wlist = [w.split()[0] for w in get(["wmctrl", "-l"]).splitlines()] w_list = [w for w in wlist if check_window(w) == True][-n_wins:] try: w_list = w_list[::-1] if w_list.index(active) != side else w_list except ValueError: pass else: 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]) wins1 = [] while True: time.sleep(0.5) windata = get(["wmctrl", "-lG"]) if windata: wins2 = [[l[0], l[2]] for l in [ ln.split() for ln in windata.splitlines()] ] # combined window locations old/new, grouped to see if moved winlocs = sorted(wins1 + wins2, key = itemgetter(0)) test = [[item, [item[1] for item in list(occ)]] \ for item, occ in groupby(winlocs, itemgetter(0))] for item in test: # old loc, new loc of window locs = item[1] # window moves? if locs.count(locs[0]) != len(locs): args = confirm() if args[0]: arrange_wins(item[0], args[1][0]) subprocess.Popen([ "notify-send", "-i", os.path.join( fpath, "left.png"), "Fill screen" ]) time.sleep(3) subprocess.Popen(["pkill", "notify-osd"]) wins1 = wins2
通知中显示的图标
设置
- 安装
xdotool
wmctrl
- 将脚本复制到一个空文件中,并将其保存
fillscreen.py
在某个专用文件夹中。 - 右键点击上面的图标,另存为(准确)
left.png
与脚本位于同一文件夹中。 现在打开终端,运行命令:
python3 /path/to/fillscreen.py
请注意,此终端窗口是脚本将捕捉的两个窗口之一。将终端拖到左侧或右侧的任一区域。最近的两个窗口应该被捕捉。
如果一切正常,请将脚本添加到启动应用程序:Dash > 启动应用程序 > 添加。添加命令:
/bin/bash -c "sleep 10 && python3 /path/to/fillscreen.py"
笔记
由于该脚本仅对窗口移动起作用,因此所有后续操作都取决于具体情况,因此该脚本的功能非常有限。比我开始编写它时预期的要低得多。