XNextEvent function in X11 makes my main app loop run again if there is an event on the X11 window

44 Views Asked by At

The XNextEvent function in X11 makes my main app loop run again if there is an event on the X11 window, here is my update function which runs in the main loop:

  XEvent event;
  XNextEvent(display_server->display,&event);
  if(event.type == ClientMessage)
    running = 0;

Here is the main loop:

  while(Engine::is_running()) {
    main->update();
    main->render();
  }

The code runs but the loop will only execute once if there is an X11 event on the window, such as moving the window around, clicking maximize, or closing.

I found this out by a counter which increments every frame, and it only got bigger when there was a X11 window event.

EDIT: I fixed it by using XNextEvent only if the display is pending with XPending(display).

if(XPending(display)) {
XNextEvent(display,&sussy_event);
}
0

There are 0 best solutions below