MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / event_loop

Function event_loop

demos/glthreadsint.c:384–488  ·  view source on GitHub ↗

* The main process thread runs this loop. * Single display connection for all threads. */

Source from the content-addressed store, hash-verified

382 * Single display connection for all threads.
383 */
384static void
385event_loop(Display *dpy)
386{
387 XEvent event;
388 int i;
389
390 assert(!MultiDisplays);
391
392 while (!ExitFlag) {
393
394 while (1) {
395 int k;
396 LOCK(dpy);
397 k = XPending(dpy);
398 if (k) {
399 XNextEvent(dpy, &event);
400 UNLOCK(dpy);
401 break;
402 }
403 UNLOCK(dpy);
404 usleep(5000);
405 }
406
407 switch (event.type) {
408 case ConfigureNotify:
409 /* Find winthread for this event's window */
410 for (i = 0; i < NumWinThreads; i++) {
411 struct winthread *wt = &WinThreads[i];
412 if (event.xconfigure.window == wt->Win) {
413 resize(wt, event.xconfigure.width,
414 event.xconfigure.height);
415 pthread_mutex_unlock(&wt->Ready);
416 break;
417 }
418 }
419 break;
420 case MotionNotify:
421 /* Find winthread for this event's window */
422 for (i = 0; i < NumWinThreads; i++) {
423 struct winthread *wt = &WinThreads[i];
424 if (event.xmotion.window == wt->Win) {
425 if (event.xmotion.state & Button1Mask ||
426 event.xmotion.state & Button2Mask ||
427 event.xmotion.state & Button3Mask ||
428 event.xmotion.state & Button4Mask ||
429 event.xmotion.state & Button5Mask) {
430 wt->AngleX += (float) (event.xmotion.x -
431 wt->MotionStartX) /
432 (float) wt->WinWidth * 180.;
433 wt->AngleY += (float) (event.xmotion.y -
434 wt->MotionStartY) /
435 (float) wt->WinHeight * 180.;
436 wt->MotionStartX = event.xmotion.x;
437 wt->MotionStartY = event.xmotion.y;
438 }
439 pthread_mutex_unlock(&wt->Ready);
440 break;
441 }

Callers 1

mainFunction · 0.70

Calls 3

XNextEventFunction · 0.85
resizeFunction · 0.70
keypressFunction · 0.70

Tested by

no test coverage detected