bool GLWindow::GetEvent(Event &event) { if (XPending(dpy)) { int keysyms_per_keycode_return; XEvent xev; // Keyboard Key Press (Keysym code available in /usr/include/X11/keysymdef.h) if (XCheckWindowEvent(dpy, glWin, KeyPressMask, &xev)) { event.type = TMGL_Press; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } // Keyboard Key Release (Keysym code available in /usr/include/X11/keysymdef.h) else if (XCheckWindowEvent(dpy, glWin, KeyReleaseMask, &xev)) { event.type = TMGL_Release; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } // Mouse Button Press else if (XCheckWindowEvent(dpy, glWin, ButtonPressMask, &xev)) { event.type = TMGL_Press; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Mouse Button Release else if (XCheckWindowEvent(dpy, glWin, ButtonReleaseMask, &xev)) { event.type = TMGL_Release; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Mouse Motion else if (XCheckWindowEvent(dpy, glWin, PointerMotionMask, &xev)) { event.type = TMGL_Motion; event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Window Exposure else if (XCheckWindowEvent(dpy, glWin, ExposureMask, &xev)) { XWindowAttributes gwa; event.type = TMGL_Expose; XGetWindowAttributes(dpy, glWin, &gwa); event.expose.width = gwa.width; event.expose.height = gwa.height; } // Quit button pressed else if (XCheckTypedEvent(dpy, ClientMessage, &xev)) { event.type = TMGL_Quit; } // Other Events else { return false; } return true; } return false; }
void GLWindow::GetEventBlocking(Event &event) { XEvent xev; int keysyms_per_keycode_return; XNextEvent(dpy, &xev); while (xev.type == ConfigureNotify || xev.type == MapNotify || xev.type == ReparentNotify) XNextEvent(dpy, &xev); if (xev.type == ClientMessage || xev.type == DestroyNotify || xev.type == UnmapNotify) { event.type = TMGL_Quit; } else if (xev.type == Expose) { XWindowAttributes gwa; event.type = TMGL_Expose; XGetWindowAttributes(dpy, glWin, &gwa); event.expose.width = gwa.width; event.expose.height = gwa.height; } else if (xev.type == KeyPress) { event.type = TMGL_Press; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } else if (xev.type == KeyRelease) { event.type = TMGL_Release; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } else if (xev.type == ButtonPress) { event.type = TMGL_Press; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } else if (xev.type == ButtonRelease) { event.type = TMGL_Release; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } else if (xev.type == MotionNotify) { event.type = TMGL_Motion; event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } else { printf("[GLWindow::GetEventBlocking] Warning: undefined event\n"); event.type = TMGL_None; SearchEventType(xev.type); } }
bool GetEvent(Event &event){ #ifdef LINUX if(XPending(dpy)){ XEvent xev; // Keyboard Key Press (Keysym code available in /usr/include/X11/keysymdef.h) if( XCheckWindowEvent(dpy, glWin, KeyPressMask, &xev) ) { event.type = TMGL_Press; KeySym ks = XKeycodeToKeysym(dpy, xev.xkey.keycode, 0); MapKey(ks, event.input); } // Keyboard Key Release (Keysym code available in /usr/include/X11/keysymdef.h) else if(XCheckWindowEvent(dpy, glWin, KeyReleaseMask, &xev)) { event.type = TMGL_Release; KeySym ks = XKeycodeToKeysym(dpy, xev.xkey.keycode, 0); MapKey(ks, event.input); } // Mouse Button Press else if(XCheckWindowEvent(dpy, glWin, ButtonPressMask, &xev)) { event.type = TMGL_Press; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xbutton.x; event.motion.y = xev.xbutton.y; } // Mouse Button Release else if(XCheckWindowEvent(dpy, glWin, ButtonReleaseMask, &xev)) { event.type = TMGL_Release; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xbutton.x; event.motion.y = xev.xbutton.y; } // Mouse Motion else if(XCheckWindowEvent(dpy, glWin, PointerMotionMask, &xev)) { event.type = TMGL_Motion; event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Window Exposure else if(XCheckWindowEvent(dpy, glWin, ExposureMask, &xev)) { XWindowAttributes gwa; event.type = TMGL_Expose; XGetWindowAttributes(dpy, glWin, &gwa); event.expose.width = gwa.width; event.expose.height = gwa.height; } // Other Events else { return false; } return true; } #endif // LINUX implementation return false; }