如何将要升高的窗口分组为一个?

Sim*_*ong 11 command-line scripts window-manager shortcut-keys window

我有两个窗口 A 和 B。是否有可能以某种方式将两个窗口链接在一起,这样切换到 A 也会引发 B,或者切换到 B 也会引发 A ?

我知道使用多个工作区是另一种选择,但想知道这是否也可能?

Ser*_*nyy 10

介绍

The following script allows selecting two windows, and while both windows are open, it will raise both windows when user focuses either one. For instance, if one links widows A and B , witching to either A or B will make both raise above other widows.

To stop the script you can use killall link_windows.py in terminal , or close and reopen one of the windows. You can also cancel execution by pressing close button X on either of the window-selection popup dialogs.

Potential tweaks:

  • multiple instances of the script can be used to group pairs of two windows. For example, if we have windows A,B,C,and D we can link A and B together, and link C and D together.
  • multiple windows can be grouped under one single window. For example, if I link window B to A, C to A, and D to A , that means if I always switch to A , I can raise all 4 windows at the same time.

Usage

Run the script as:

python link_windows.py
Run Code Online (Sandbox Code Playgroud)

The script is compatible with Python 3 , so it can also run as

python3 link_windows.py
Run Code Online (Sandbox Code Playgroud)

There are two command line options:

  • --quiet or -q , allows silencing down the GUI windows. With this option you can just click with mouse on any two windows , and the script will begin linking those.
  • --help or -h, prints the usage and description information.

The -h option produces the following information:

$ python3 link_windows.py  -h                                                                                            
usage: link_windows.py [-h] [--quiet]

Linker for two X11 windows.Allows raising two user selected windows together

optional arguments:
  -h, --help  show this help message and exit
  -q, --quiet  Blocks GUI dialogs.
Run Code Online (Sandbox Code Playgroud)

Additional technical information can be viewed via pydoc ./link_windows.py , where ./ signifies that you must be in the same directory as the script.

Simple usage process for two windows:

  1. A popup will appear asking you to select a window #1 , press OK or hit Enter. The mouse pointer will turn in to a cross. Click on one of the windows you want to link.

  2. A second popup will appear asking you to select window #2,press OK or hit Enter. Again, the mouse pointer will turn into a cross.Click on the other window you want to link. After that execution will begin.

  3. Whenever you focus either window, the script will raise the other window up, but return focus to the one originally selected ( note - with a quarter of a second delay for best performance ) , thus creating feel that windows are linked together.

If you select the same window both times, the script will quit. If at any moment you click close button of popup dialog , the script will quit.

Script source

也可作为GitHub Gist

python link_windows.py
Run Code Online (Sandbox Code Playgroud)

笔记?


Jac*_*ijm 7

将任意数量的窗口提升为一个

下面的解决方案将让你选择任意的两个,三个或多个窗口进行组合,并提出作为一个使用键盘快捷键组合。

该脚本使用三个参数完成其工作:

add
Run Code Online (Sandbox Code Playgroud)

将活动窗口添加到组

raise
Run Code Online (Sandbox Code Playgroud)

提高集合组

clear
Run Code Online (Sandbox Code Playgroud)

清除组,准备定义一个新组

剧本

add
Run Code Online (Sandbox Code Playgroud)

如何使用

  1. 脚本需要wmctrlxdotool

    sudo apt-get install wmctrl xdotool
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将上面的脚本复制到一个空文件中,另存为 groupwindows.py
  3. 测试运行脚本:打开两个终端窗口,运行命令:

    python3 /absolute/path/to/groupwindows.py add
    
    Run Code Online (Sandbox Code Playgroud)

    在他们两个。用其他窗口覆盖它们(或最小化它们)。打开第三个终端窗口,运行命令:

    python3 /absolute/path/to/groupwindows.py raise
    
    Run Code Online (Sandbox Code Playgroud)

    前两个窗口将作为一个窗口升高。

  4. 如果一切正常,创建三个自定义快捷键:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并将以下命令添加到三个单独的快捷方式中:

    在我的系统上,我使用了:

    Alt+ A,运行命令:

    python3 /absolute/path/to/groupwindows.py add
    
    Run Code Online (Sandbox Code Playgroud)

    ...向组添加一个窗口。

    Alt+ R,运行命令:

    python3 /absolute/path/to/groupwindows.py raise
    
    Run Code Online (Sandbox Code Playgroud)

    ...提高组。

    Alt+ C,运行命令:

    python3 /absolute/path/to/groupwindows.py clear
    
    Run Code Online (Sandbox Code Playgroud)

    ...清除组

解释

该脚本的工作原理非常简单:

  • 当使用参数运行时add,脚本将活动窗口的 window-id 存储/添加到隐藏文件中~/.windowlist
  • 使用参数运行时raise,脚本读取文件,使用以下命令在列表中显示窗口:

    wmctrl -ia <window_id>
    
    Run Code Online (Sandbox Code Playgroud)
  • 使用参数运行时clear,脚本会删除隐藏文件~/.windowlist

笔记

  • 该脚本也适用于最小化的窗口,它将取消最小化可能最小化的窗口
  • 如果窗口集在另一个视口上,脚本将切换到相应的视口
  • 该集合是灵活的,您可以随时将其他窗口添加到当前集合中。

更灵活?

如上所述,上面的脚本允许随时将窗口添加到分组窗口中。下面的版本还允许从分组列表中删除任何窗口(随时):

raise
Run Code Online (Sandbox Code Playgroud)

运行脚本的附加参数是delete,因此:

python3 /absolute/path/to/groupwindows.py delete
Run Code Online (Sandbox Code Playgroud)

从分组窗口中删除活动窗口。要运行此命令,在我的系统上,我将Alt+设置D为快捷方式。