From: José Fonseca Date: Sat, 13 Oct 2012 08:33:04 +0000 (+0100) Subject: retrace: Exit when Escape key is pressed on X. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=e9392864d660f2d4e2c325e9b01ff7121786d92c;p=apitrace retrace: Exit when Escape key is pressed on X. Match Windows behavior. --- diff --git a/retrace/glws_glx.cpp b/retrace/glws_glx.cpp index 1573bb9..575776e 100644 --- a/retrace/glws_glx.cpp +++ b/retrace/glws_glx.cpp @@ -60,7 +60,8 @@ public: }; -static void describeEvent(const XEvent &event) { +static void +processEvent(XEvent &event) { if (0) { switch (event.type) { case ConfigureNotify: @@ -83,6 +84,19 @@ static void describeEvent(const XEvent &event) { } std::cerr << " " << event.xany.window << "\n"; } + + switch (event.type) { + case KeyPress: + { + char buffer[32]; + KeySym keysym; + XLookupString(&event.xkey, buffer, sizeof buffer - 1, &keysym, NULL); + if (keysym == XK_Escape) { + exit(0); + } + } + break; + } } class GlxDrawable : public Drawable @@ -102,7 +116,7 @@ public: attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask; + attr.event_mask = StructureNotifyMask | KeyPressMask; unsigned long mask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; @@ -135,11 +149,18 @@ public: glXWaitX(); } + void processKeys(void) { + XEvent event; + while (XCheckWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event)) { + processEvent(event); + } + } + void waitForEvent(int type) { XEvent event; do { - XWindowEvent(display, window, StructureNotifyMask, &event); - describeEvent(event); + XWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event); + processEvent(event); } while (event.type != type); } @@ -194,6 +215,8 @@ public: void swapBuffers(void) { glXSwapBuffers(display, window); + + processKeys(); } }; @@ -368,7 +391,7 @@ processEvents(void) { while (XPending(display) > 0) { XEvent event; XNextEvent(display, &event); - describeEvent(event); + processEvent(event); } return true; }