简体   繁体   English

使用X11 / Xlib确定队列中是否有事件

[英]Determining if there are events in the queue with X11/Xlib

I'm working on an X11 application and I'm trying to write a function that will process any events currently in the queue and then return without blocking. 我正在使用X11应用程序,正在尝试编写一个函数,该函数将处理队列中当前存在的所有事件,然后返回而不会阻塞。

All of the Xlib tutorials that I've found use XNextEvent in a perpetual loop which blocks on each XNextEvent call until an event is ready. 我发现的所有Xlib教程都在永久循环中使用XNextEvent,该循环会阻塞每个XNextEvent调用,直到事件准备就绪为止。

I have looked at XEventsQueued with QueuedAlready, which seems like it should return the number of events ready to be processed, but it always returns 0 even when I know there are events that can be retrieved with XNextEvent. 我已经看过带有QueuedAlready的XEventsQueued,它似乎应该返回准备处理的事件数,但是即使我知道有些事件可以用XNextEvent检索,它也总是返回0。

Am I missing something here, or is there another way to determine if there are events available in the queue? 我是否在这里缺少任何东西,或者还有另一种方法来确定队列中是否有可用事件?

Well it looks like if you just call XEventsQueued with QueuedAlready that the events are never read from the connection and put into the queue. 好吧,好像您仅使用QueuedAlready调用XEventsQueued一样,就永远不会从连接中读取事件并将其放入队列中。 Calling XEventsQueued with QueuedAfterFlush will flush the output buffer and then read any events available on the connection into the event queue. 使用QueuedAfterFlush调用XEventsQueued将刷新输出缓冲区,然后将连接上可用的任何事件读入事件队列。 XPending does the same thing. XPending也做同样的事情。 QueuedAfterFlush or XPending is what I needed. 我需要QueuedAfterFlush或XPending。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM