gpt4 book ai didi

python - 使用 xlib 在屏幕顶部绘制

转载 作者:太空狗 更新时间:2023-10-30 01:23:20 24 4
gpt4 key购买 nike

我想在屏幕上所有窗口的顶部绘制一些图元。我在 C 中找到了一些代码并尝试将其移植以使用 python 的 xlib:

from Xlib.display import Display
from Xlib import X
from Xlib import protocol

display = Display(':0')
root = display.screen().root
gc = root.create_gc()
root.fill_rectangle(gc, 100, 100, 500, 500)

但屏幕上什么也没有出现(但是,分配了根窗口:工作后抓取键盘)。如何正确执行此操作?

最佳答案

您可以在根窗口上绘制 - 您的代码可能有效,但根窗口可能会被某种桌面窗口(nautilus、kde 桌面等)遮挡。尝试在没有任何程序运行的情况下启动 X session ,您将看到更新(为此您可以使用 Xephyr 或 Xnest)

另一种方法是创建 transparent window ,将其置于最顶部并在其表面绘制。您需要手动将鼠标事件传播到底层窗口。

要真正在所有窗口之上绘制,您需要创建简单的 composite manager,或者如果已经有 CM 在运行,则使用它的覆盖窗口。

来自 composite protocol spec :

Version 0.3 of the protocol adds the Composite Overlay Window, which provides compositing managers with a surface on which to draw without interference. This window is always above normal windows and is always below the screen saver window. It is an InputOutput window whose width and height are the screen dimensions. Its visual is the root visual and its border width is zero. Attempts to redirect it using the composite extension are ignored. This window does not appear in the reply of the QueryTree request. It is also an override redirect window. These last two features make it invisible to window managers and other X11 clients. The only way to access the XID of this window is via the CompositeGetOverlayWindow request. Initially, the Composite Overlay Window is unmapped.

CompositeGetOverlayWindow returns the XID of the Composite Overlay Window. If the window has not yet been mapped, it is mapped by this request. When all clients who have called this request have terminated their X11 connections the window is unmapped.

Composite managers may render directly to the Composite Overlay Window, or they may reparent other windows to be children of this window and render to these. Multiple clients may render to the Composite Overlay Window, create child windows of it, reshape it, and redefine its input region, but the specific arbitration rules followed by these clients is not defined by this specification; these policies should be defined by the clients themselves.

关于python - 使用 xlib 在屏幕顶部绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14200512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com