XLIB C - 通过 PID 获取 window

XLIB C - get window by PID

我从 xlib 开始,我想知道是否可以使用 C 中的 xlib 到 "catch" 一个 window 及其 PID 以便能够移动 window,调整大小...?

例如询问我的程序Firefox的宽度和高度window。不知道我的问题有没有更清楚

谢谢

我猜你是指拥有 window.

的(Linux 或 POSIX)客户端的进程 ID

但是您的问题没有实际意义:X 客户端可能位于某些没有进程 ID 的操作系统上,或者可能 运行 在 远程 机器上(不同于 运行 X11 服务器),例如使用 ssh -X (然后你不能用那个 pid 做太多)。请务必了解更多关于 X Window System(以及客户端、服务器、window 管理器的角色)的信息。

但是,你可以学习(带着痛苦和小心)X11 Window protocols and architecture (include X11 core protocol), the EWMH specifications (and also ICCCM). Look into _NET_WM_PID & XGetWMClientMachine

(Xlib 和所有 X protocols are really complex; you would need to read thousands of pages to understand all of them; in 2017 that effort might be obsolete, e.g. because of Wayland; it is preferable to use some higher-level toolkit like Qt or GTK)。

如果你想写一些 X window manager(它们是复杂的野兽,因为与 X 相关的约定已经变得非常复杂),请考虑研究一些现有的源代码并根据你的需要进行调整。 ..

您可以iterate through all windows and search for the program that you want by it's name. Afterwards you could use XMoveResizeWindow随意移动和调整大小。