event loop and timers

Steven J Abner pheonix.sja at att.net
Sun Sep 1 13:30:22 UTC 2024


  Having an issue with using timers with 'beginner loop'. From scratch, 
created a window that handles events, with display port rectangles 
within the window. So basically one window with one main context or 
draw surface, and multiple 'dp rectangles' within. When resizing a 
window, these 'dp rectangles' adjust their size or 'configure'.
 A 'dp rectangle' can also have a grip for resizing. This can be better 
visualized as the window's context being a desktop background, and the 
'dp rectangle' as a window being resized on said desktop.
 When dragging the grip, the resizing can stutter or jump positions in 
a less than smooth fashion. The solution is a timer to fire off 
XCB_EXPOSE after an accumulation of invalid bounding areas rather than 
XCB_EXPOSE on every XCB_MOTION_NOTIFY.
 Using a timer with sigev_notify = SIGEV_THREAD works perfectly in this 
situation, but spams the heck out of creating a thread, and makes 
debugging almost useless because of reporting the million thread 
creations.
 Using a timer with sigev_signo = SIGALRM, or SIGUSR1 only partially 
works until crash caused xcb_send_request_with_fds64 locks, or forever 
wait.
 My question then becomes: can I parse 'event->response_type' > 0x7F to 
intercept signals or will this algorithm be a possible untested 
solution:

while (run_loop) {
  while ( !has_timers && (event = xcb_wait_for_event(connection)) ) {
parse_event:
  }
  while (has_timers) {
      /* run timers until event, run event return, until no timers */
    _timer_update()
    if ((event = xcb_poll_for_event(connection)) != NULL)
      goto parse_event;
  }
}

static void
_timer_update() {

  clock_gettime(CLOCK_MONOTONIC, &ts);
  if (elapsed) {
    call handler(); // may delete timer
    if (id)  update next firing
    else if (--timer_count == 0) has_timers = false;
  }
}

  Any insight would be greatly appreciated!
Steve





More information about the Xcb mailing list