使用 XGrabServer 抓取 X 服务器
在嵌入式 Linux 系统中,我试图显示一个关闭通知,该通知在关闭时应覆盖任何其他窗口。 现在创建窗口不是问题,但可靠地显示窗口才是问题。 X 服务器或 WM 不知何故太忙而无法每次都绘制通知。 考虑到我们的 CPU 能力有限,这并不奇怪。
因此,我想通过使用 gdk_x11_grab_server() (在默认显示上调用 XGrabServer)抓取 X 服务器,可以让 WM/X 变得容易。 但是我什么时候应该调用grab函数呢? 如果我在构建窗口之前调用它,在窗口的暴露事件中显示窗口或事件之前,则不会在屏幕上绘制任何内容(即使在空载测试中)!
文档 说:
XGrabServer功能禁用 处理请求和关闭 在除该连接之外的所有其他连接上 此请求已到达。
我想这意味着只应处理来自我的应用程序的请求,但情况似乎并非如此,因为如果我的应用程序抓住 X,则不会绘制任何内容。
那么,应该如何以及何时使用 X 服务器来实现想要的结果,或者它完全是一个错误的工具,我误解了它的用途(或者尝试使用它的级别太高,以至于无法实现)真的工作)。
In an embedded Linux system, I'm trying to show a shutdown notification that should override any other windows when shutting down. Now creating the window isn't a problem, but showing the window reliably is. The X server or WM is somehow too busy to draw the notification every time. Considering the limited CPU power we have, its not surprising.
So, I figured I will make it easy to the WM/X by grabbing the X server using gdk_x11_grab_server() (which calls XGrabServer on default display). But when should I call the grab func? If I call it before building my window, prior showing my window or event in expose-event of my window, nothing is drawn to the screen (even in no-load test)!
The documentation says:
The XGrabServer function disables
processing of requests and close downs
on all other connections than the one
this request arrived on.
I suppose that would mean that only requests from my app should be processed, but it seems that is not the case, since nothing is drawn if X is grabbed by my app.
So, how and when should grabbing the X server be used to achieve wanted outcome, or is it totally a wrong tool and I've misunderstood the use (or trying to use it too high level for it to work really).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我猜想没有绘制任何内容,因为您正在打开一个普通的顶级窗口,在这种情况下,窗口管理器需要对其进行操作才能使其可见; 但是您已经通过调用 XGrabServer() 锁定了窗口管理器。
您可以尝试在窗口上设置 OverrideRedirect,它告诉 X 服务器窗口管理器根本不应该参与该窗口。 这还具有从窗口中删除任何装饰(标题栏、关闭按钮等)的效果,这很可能是您想要的关闭通知。
I'd guess that nothing is being drawn because you're opening a normal top level window, in which case the window manager needs to operate on it before it'll be visible; however you've locked out the window manager by calling XGrabServer().
You could try setting OverrideRedirect on the window, which tells the X server that the window manager shouldn't be involved with this window at all. This also has the effect of removing any decorations (title bar, close button, etc) from the window, which could well be what you want for a shutdown notification.
您可能需要使用 XSync/XFlush 来关注该调用。
You may need to follow the call with XSync/XFlush.
您是否应该继续调用
XUngrabServer
以便 X 服务器恢复处理请求? 所有其他连接都已关闭,因为您调用了XGrabServer
,但您显然需要请求处理才能恢复,因为您想在连接上发出请求。Shouldn't you follow up with a call to
XUngrabServer
so that the X server resumes processing requests? All other connections have already been closed because you calledXGrabServer
, but you obviously need request handling to resume because you want to make requests on your connection.对于 XGrabServer 的实际作用似乎有些令人困惑,而不仅仅是在这个问题上。 手册页对此的描述相当模糊。 我们可以轻松验证服务器确实仍在处理来自我们连接的请求:
如果我在 Xephyr 中运行上述程序(没有窗口管理器或复合管理器),则可能有窗口管理器或复合管理器阻止窗口显示,我可以看到一个白色窗口 2 秒,然后是黑屏 2 秒,之后所有其他窗口都重新绘制。
There seems to be some confusing as to what
XGrabServer
actually does precisely, and not just on this question. The man pages are pretty ambiguous about this. We can easily verify though that the server indeed still processes requests from our connection:There is probably a window manager or composite manager preventing the window from being displayed, if I run the above program in Xephyr (without a window manager or composite manager), I can see a white window for 2 seconds followed by a black screen for 2 seconds, after which all other windows are redrawn again.