使用xlib在屏幕顶部绘制 [英] Draw on top of the screen using xlib

查看:179
本文介绍了使用xlib在屏幕顶部绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to draw some primitives on top of all windows on the screen. I've found some code in C and tried to port it to use python's 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)

但是屏幕上什么也没有出现(但是,分配了根窗口:工作后抓键盘)。

But nothing appears on the screen (however, the root window is assigned: grabbing keyboard after it works). How to do this correctly?

推荐答案

您可以在根窗口上绘制-您的代码可能有效,但根窗口可能被隐藏某种桌面窗口(nautilus,kde桌面等)。尝试在没有任何程序运行的情况下启动X会话,您会看到更新(可以使用Xephyr或Xnes​​t)

You can draw on root window - your code probably works, but root window may be obscured by some kind of desktop window (nautilus, kde desktop etc). Try to start X session without any programs running and you'll see updates (you can use Xephyr or Xnest for this)

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

Another approach would be to create transparent window, make it topmost and draw on it's surface. You'll need to propagate mouse events to underlying windows manually.

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

To actually draw on top of all windows you need to create simple composite manager or if there is already CM running use it's overlay window.

来自综合协议规范


协议的版本0.3添加了复合覆盖窗口,其中
为合成管理者提供了一个表面不受
的干扰进行抽奖。此窗口始终在普通窗口上方,并且始终在屏幕保护程序窗口下方
。这是一个InputOutput窗口,其宽度
和高度为屏幕尺寸。它的视觉效果是根视觉效果
,其边框宽度为零。使用
复合扩展名重定向它的尝试将被忽略。该窗口不会出现在QueryTree请求的
答复中。这也是一个覆盖重定向
窗口。这最后两个功能使窗口管理器
和其他X11客户端看不到它。访问此窗口
的XID的唯一方法是通过CompositeGetOverlayWindow请求。最初,复合
覆盖窗口未映射。

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返回复合覆盖
窗口的XID。如果窗口尚未映射,则此
请求将其映射。当所有调用此请求的客户都终止了
的X11连接时,该窗口将不被映射。

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.

这篇关于使用xlib在屏幕顶部绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆