Question

I have a program that has a thread that generates Expose messages using XSendEvent. A second thread receives the Expose messages along with other messages (mainly input handling). The problem is that the sending thread sends the Expose messages at a constant rate (~60Hz) but the receiving thread may be rendering slower than that. The X11 queue will get bogged down with extra Expose messages, and any input handling messages will start fall way behind all those extra Expose messages.

In Windows, this is not a problem because Windows will automatically coalesce all WM_PAINT messages into a single message. Is there any way to do this in X11, or some other way to solve this problem?

Was it helpful?

Solution

You can very easily coalesce any kind of event yourself with XCheckTypedEvent() and friends.

OTHER TIPS

I was able to solve this problem as follows:

Block the rendering thread using XPeekEvent.

When an event comes in, read all events into a new queue data structure using a combination of XPending and XNextEvent, but only copy the first expose message.

Then run the event processing loop over the new queue data structure.

This fixed the problem for me, but I think a solution that uses XCheckTypedEvent (per n.m.'s answer here) is probably more elegant.

A few of thing you can do:

  • If you are doing complete redraw for each event, only action events with a count of 0, count > 1 is the redraw of a particular rectange
  • If you generate expose events for part of the window, this will reduce the amount of work each expose event does
  • The constant rate, means you could just process every nth event or keep a time since the last event and ignore events received within a given time
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top