如何按任务栏顺序循环窗口?

use*_*974 6 scripts window-manager shortcut-keys window

我想更改Alt+Tab行为,或者最好设置不同的热键组合以左右方式循环浏览所有窗口,其中 MRU,最近使用的不适用。

在搜索时,我找到了在 Windows 或compiz其他发行版中执行此操作的方法,但我无法在 Ubuntu 中使用。

Jac*_*ijm 5

从左到右循环切换窗口

(仅在当前视口上,或跨所有视口)

下面的脚本添加到快捷键中,将从左到右循环浏览您的窗口:

在此处输入图片说明

剧本

#!/usr/bin/env python3
import subprocess
from operator import itemgetter
import sys

this_ws = True if "oncurrent" in sys.argv[1:] else False
nxt = -1 if "backward" in sys.argv[1:] else 1

def get(command):
    try:
        return subprocess.check_output(command).decode("utf-8").strip()
    except subprocess.CalledProcessError:
        pass

def exclude(w_id):
    # exclude window types; you wouldn't want to incude the launcher or Dash
    exclude = ["_NET_WM_WINDOW_TYPE_DOCK", "_NET_WM_WINDOW_TYPE_DESKTOP"]
    wdata = get(["xprop", "-id", w_id])
    return any([tpe in wdata for tpe in exclude])

if this_ws:
    # if only windows on this viewport should be picked: get the viewport size
    resdata = get("xrandr").split(); index = resdata.index("current")
    res = [int(n.strip(",")) for n in [resdata[index+1], resdata[index+3]]]

# get the window list, geometry
valid = [w for w in sorted([[w[0], int(w[2]), int(w[3])] for w in [
    l.split() for l in get(["wmctrl", "-lG"]).splitlines()
    ]], key = itemgetter(1)) if not exclude(w[0])]

# exclude windows on other viewports (if set)
if this_ws:
    valid = [w[0] for w in valid if all([
        0 <= w[1] < res[0], 0 <= w[2] < res[1]
        ])]
else:
    valid = [w[0] for w in valid]

# get active window
front = [l.split()[-1] for l in get(["xprop", "-root"]).splitlines() if \
         "_NET_ACTIVE_WINDOW(WINDOW)" in l][0]

# convert xprop- format for window id to wmctrl format
current = front[:2]+((10-len(front))*"0")+front[2:]

# pick the next window
try:
    next_win = valid[valid.index(current)+nxt]
except IndexError:
    next_win = valid[0]

# raise next in row
subprocess.Popen(["wmctrl", "-ia", next_win])
Run Code Online (Sandbox Code Playgroud)

如何使用

  1. 脚本需要wmctrl

    sudo apt-get install wmctrl
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将脚本复制到一个空文件中,另存为 cyclewins.py

  3. 将脚本添加到快捷键:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并添加命令:

    python3 /path/to/cyclewins.py
    
    Run Code Online (Sandbox Code Playgroud)

就是这样

只在当前视口上循环浏览窗口?

如果您只想在当前视口上循环浏览窗口,请使用带有参数的脚本oncurrent

python3 /path/to/cyclewins.py oncurrent
Run Code Online (Sandbox Code Playgroud)

循环倒退?

如果您想从右向左循环,请使用参数运行脚本backward

python3 /path/to/cyclewins.py backward
Run Code Online (Sandbox Code Playgroud)

当然,两个参数的组合是可能的;

python3 /path/to/cyclewins.py backward oncurrent
Run Code Online (Sandbox Code Playgroud)

将在当前视口上的窗口中向后循环。