X11: How to delay repainting until all events are processed?

前端 未结 2 1884
误落风尘
误落风尘 2020-12-12 01:15

I\'m writing a program that has an X11/Xlib interface, and my event processing loop looks like this:

while (XNextEvent(display, &ev) >= 0) {
    switc         


        
2条回答
  •  死守一世寂寞
    2020-12-12 01:40

    Try something like the following (not actually tested):

    while (TRUE) {
      if (XPending(display) || !pendingRedraws) {
        // if an event is pending, fetch it and process it
        // otherwise, we have neither events nor pending redraws, so we can
        // safely block on the event queue
        XNextEvent (display, &ev);
        if (isExposeEvent(&ev)) {
          pendingRedraws = TRUE;
        }
        else {
          processEvent(&ev);
        }
      }
      else {
        // we must have a pending redraw
        redraw();
        pendingRedraws = FALSE;
      }
    }
    

    It could be beneficial to wait for 10 ms or so before doing the redraw. Unfortunately the raw Xlib has no interface for timers. You need a higher-level toolkit for that (all toolkits including Xt have some kind of timer interface), or work directly with the underlying socket of the X11 connection.

提交回复
热议问题