# HG changeset patch # User Eris Caffee # Date 1334645809 18000 # Node ID 1b73e60d53b4632140605f467cc414060201bf49 # Parent 008e28de2870f59717256f12d5cd7a5680dbedb5 Now with keyboard support diff -r 008e28de2870 -r 1b73e60d53b4 CMakeLists.txt --- a/CMakeLists.txt Mon Apr 16 10:32:59 2012 -0500 +++ b/CMakeLists.txt Tue Apr 17 01:56:49 2012 -0500 @@ -113,11 +113,11 @@ ################################################################################ # When using GCC turn on lots of warnings. # Some other options to consider: -# C++ -Weffc++ +# C++ -Weffc++ -std=c++0x or -std=gnu++0x # C -std=gnu99 -std=c99 if (CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-pedantic -Wall) + add_definitions(-pedantic -Wall -std=gnu++0x -Weffc++) endif () diff -r 008e28de2870 -r 1b73e60d53b4 include/App.h --- a/include/App.h Mon Apr 16 10:32:59 2012 -0500 +++ b/include/App.h Tue Apr 17 01:56:49 2012 -0500 @@ -77,6 +77,7 @@ Display * dpy; WindowMap windows; + long event_mask; Atom wm_delete_window; // Need this in contructor and run(). }; diff -r 008e28de2870 -r 1b73e60d53b4 src/App.cpp --- a/src/App.cpp Mon Apr 16 10:32:59 2012 -0500 +++ b/src/App.cpp Tue Apr 17 01:56:49 2012 -0500 @@ -5,6 +5,7 @@ #include #include + //////////////////////////////////////////////////////////////////////////////// App::App(const std::string & appname) { @@ -86,7 +87,8 @@ // Select the event types we want to receive. //Other interesting events include KeyReleaseMask and ButtonReleaseMask - XSelectInput(dpy, wd->win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); + event_mask = ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask ; + XSelectInput(dpy, wd->win, event_mask); @@ -182,29 +184,54 @@ void App::run(void) { XEvent e; + KeySym k; + char key_buffer[8]; + key_buffer[7] = 0; + XComposeStatus compose_status; + int done = 0; + while (!done) { - XNextEvent(dpy, &e); - switch (e.type) + while (XCheckIfEvent(dpy, &e, + // *sniff* My very first lambda function in C++ + [&](Display * d, XEvent * e, XPointer a)->Bool { return True; }, + NULL)) { - case Expose: - // We'll only redraw the entire window at a time, so unless this is - // the last contiguous expose, don't draw the window. - if (e.xexpose.count != 0) + switch (e.type) + { + case Expose: + // We'll only redraw the entire window at a time, so unless this is + // the last contiguous expose, don't draw the window. + if (e.xexpose.count != 0) + break; + // Draw the window contents here break; - // Draw the window contents here - break; - case ClientMessage: - if ((Atom)e.xclient.data.l[0] == wm_delete_window) - done = 1; - break; - case ButtonPress: - case KeyPress: - done = 1; - default: - break; + case ClientMessage: + if ((Atom)e.xclient.data.l[0] == wm_delete_window) + done = 1; + break; + case ButtonPress: + case KeyPress: + XLookupString(&(e.xkey), key_buffer, 7, &k, &compose_status); + switch (k) + { + case XK_Escape: + case XK_q: + std::cout << "Goodbye!" << std::endl; + done = 1; + break; + default: + std::cout << "You typed " << key_buffer << std::endl; + break; + } + default: + break; + } } + + // Do idle time things here + } }