「WINDOWS-MANAGER」- 窗口管理器 | Window Manager

在图形用户界面中,Window Manager 用于控制窗口系统内窗口的位置和外观的系统软件。大多数窗口管理器旨在帮助提供一个桌面环境。简而言之,窗口管理器就是一个专门控制应用程序窗口在屏幕上如何放置、如何移动、如何改变大小、如何装饰以及如何切换的程序。

下图中标注的就是一个 Window Manager 的组成部分,但是图中 Window Content 的内容是由 Client 或软件绘制的,它不属于 Window Manager;

功能

类型:Compositing WM、Stacking WM、Tiling WM、Dynamic WM

创建应用程序窗口

DeepSeek / Window Manager 与 GTK 的关系

功能:窗口的装饰(边框、标题栏)、位置、大小、堆叠顺序、虚拟桌面、焦点策略、快捷键、……

当我们打开用 GTK 编写的应用(例如 gedit 文本编辑器)时:

GTK 的工作:gedit 程序内部的 GTK 库开始工作。它绘制出应用程序的内容区域:包括菜单栏、工具栏、文本编辑区、状态栏等。其决定“新建”按钮的样子,字体选择框的布局方式。

创建窗口:应用程序向显示服务器(如 X11 或 Wayland)请求,然后 Window Manager 介入,其截获该请求,并开始它的工作:

它为这个窗口加上一个边框和标题栏(这就是所谓的“装饰”)。其可能同样使用 GTK 来绘制组件,例如,按钮、图标、……

它决定把这个新窗口放在屏幕的什么位置(比如居中或放在鼠标位置)。

它管理这个窗口与其他窗口(比如我们的浏览器窗口)的关系(谁在上面,谁被遮挡)。

它负责响应我们对标题栏的拖动、最大化/最小化/关闭操作。

所以,我们最终看到的 gedit 窗口是两者合作的产物:窗口内部的UI(内容)由 GTK 绘制。包裹着内容的窗口框架(外壳)由 Window Manager 绘制和管理。

Compositing Window Manager

Wikipedia/Compositing window manager

Compositing window managers let all windows be created and drawn separately and then put together and displayed in various 2D and 3D environments. The most advanced compositing window managers allow for a great deal of variety in interface look and feel, and for the presence of advanced 2D and 3D visual effects.

第一次接触「合成窗口管理器」是因为 ScreenKey 这个工具的背景无法透明。ScreenKey 支持背景透明(Opacity),但是需要安装并运行“合成窗口管理器”(例如,compton、“unagi、xcompmgr、……)。

第二次接触“合乘窗口管理器”是因为 Kazma 截图时,桌面背景无法透明。自然而然的想到了它,然后运行 xcompmgr,然后 Kazma 截图时,桌面背景可以透明显示。

例如:“compton”、“unagi”、“xcompmgr”、Sway

Stacking Window Manager

All window managers that have overlapping windows and are not compositing window managers are stacking window managers, although it is possible that not all use the same methods. Stacking window managers allow windows to overlap by drawing background windows first, which is referred to as the painter’s algorithm. Changes sometimes require that all windows be re-stacked or repainted, which usually involves redrawing every window. However, to bring a background window to the front usually only requires that one window be redrawn, since background windows may have bits of other windows painted over them, effectively erasing the areas that are covered.

例如:the Weston, KWin, and Mutter compositing window managers(Mutter 是 GNOME 3 的窗口管理器)

Tiling Window Manager

Tiling Window Management and i3wm config additions

Tiling window managers paint all windows on-screen by placing them side by side or above and below each other, so that no window ever covers another. Microsoft Windows 1.0 used tiling, and a variety of tiling window managers for X are available.

例如:XMonad、i3wm、Sway

Dynamic window manager

Dynamic window managers can dynamically switch between tiling or floating window layout. A variety of dynamic window managers for X are available.

针对窗口的绘制:Stacking WM vs. Compositing WM

The window manager sends each window a message to repaint itself when needed. Windows may overlap. When a window in front is moved, it can reveal an area of a window behind that was previously concealed. Window managers are broadly categorised by their strategy for causing that newly revealed area to be displayed to the user.

In the “stacking” strategy, the window manager tells the back window to repaint itself.

In the “compositing” strategy, the window manager maintains an off-screen memory buffer containing the full appearance of each window, including the back window.

With a stacking manager, the repainting process can become corrupted when a program that is slow, unresponsive or buggy does not respond to messages in a timely manner. A malicious program can cause the system to appear unstable by simply neglecting to repaint its window.

With a compositing manager, if a window stops repainting itself when requested by the window manager, its last repaint will remain displayed and the window might be dimmed. Often, the title changes to reflect the status of the window as unresponsive. A program may prevent its window from being moved or unmapped, but generally will not cause repainting problems.

根据我们的理解,两者主要区别在与绘制窗口的时机。Stacking WM 是按需绘制,而 Compositing WM 则是更早的绘制并维护。

实现

PaperWM | Tiled scrollable window management for GNOME Shell

FVWM

Emacs X Window Manager

ch11ng/exwm: Emacs X Window Manager
EXWM – ArchWiki

for GNOME Desktop Environment

Metacity was the default window manager used by the GNOME 2 desktop environment.

Metacity was replaced by Mutter in GNOME 3. It is still used by GNOME Flashback.

GNOME Flashback 是为了在 GNOME 3 中提供类似 GNOME 2 用户体验。

Mutter

Compiz

https://en.wikipedia.org/wiki/Compiz

Compiz (/kɒmpɪz/) is a compositing window manager for the X Window System, using 3D graphics hardware to create fast compositing desktop effects for window management.