From: Ian Osgood Date: Tue, 21 Mar 2006 16:21:18 +0000 (-0800) Subject: Detect Alt-Q to quit using xcb_keysyms.h library. X-Git-Tag: 0.1~21 X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6db1b7e5de1abfc6315038aadc763ecfbb4213d0;p=free-sw%2Fxcb%2Fdemo Detect Alt-Q to quit using xcb_keysyms.h library. --- diff --git a/neko/Makefile b/neko/Makefile index de7ac0b..089f915 100644 --- a/neko/Makefile +++ b/neko/Makefile @@ -1,5 +1,5 @@ CFLAGS = -g -Wall -Wpointer-arith -Wstrict-prototypes -LIBS = -lxcb -lXCBAux -lXCBICCCM -lXCBAtom +LIBS = -lxcb -lXCBAux -lXCBICCCM -lXCBAtom -lXCBKeysyms xcbneko: xcbneko.c $(CC) $(CFLAGS) xcbneko.c $(LIBS) -o xcbneko diff --git a/neko/README b/neko/README index a0d2e37..1902013 100644 --- a/neko/README +++ b/neko/README @@ -9,7 +9,6 @@ XCB TODO * DEBUG not supported * -geometry not supported * WM hints, -iconic not supported (don't like the util interfaces) -* quit on Alt-Q not supported (XLookupString) XCB ENHANCEMENTS ---------------- diff --git a/neko/xcbneko.c b/neko/xcbneko.c index a10b9e1..bd7b706 100644 --- a/neko/xcbneko.c +++ b/neko/xcbneko.c @@ -27,6 +27,7 @@ #include /* XCBAuxGetScreen */ #include #include /* STRING atom */ +#include typedef enum { False, True } Bool; @@ -148,6 +149,7 @@ unsigned long theBlackPixel; unsigned long theWhitePixel; XCBWINDOW theWindow; XCBCURSOR theCursor; +XCBKeySymbols *theKeySyms; static unsigned int WindowWidth; static unsigned int WindowHeight; @@ -509,7 +511,6 @@ void InitBitmapAndGCs(void) { /* later: XCBFreePixmap( c, bitmap ); */ /* later: XCBFreeGC( c, gc ); */ - XCBFlush( xc ); } void @@ -698,6 +699,12 @@ InitScreen( char *DisplayName, char *theGeometry, char *theTitle, Bool iconicSta InitBitmapAndGCs(); XCBFlush(xc); + + /* latency: ask for keysyms now, and receive them later */ + theKeySyms = XCBKeySymbolsAlloc( xc ); + + /* later: XCBKeySymbolsFree( keysyms ); */ + /* later: XCBRefreshKeyboardMapping ( keysyms, mappingEvent ); */ } @@ -1076,36 +1083,17 @@ void DisplayCharacters() { Bool ProcessKeyPress( XCBKeyPressEvent *theKeyEvent ) { -#if TODO Bool ReturnState = True; - int Length; - char theKeyBuffer[ AVAIL_KEYBUF + 1 ]; - int theKeyBufferMaxLen = AVAIL_KEYBUF; - KeySym theKeySym; - XComposeStatus theComposeStatus; - - Length = XLookupString( theKeyEvent, - theKeyBuffer, theKeyBufferMaxLen, - &theKeySym, &theComposeStatus ); - - if ( Length > 0 ) { - switch ( theKeyBuffer[ 0 ] ) { - case 'q': - case 'Q': - if ( theKeyEvent->state & XCBModMask1 ) { /* META (Alt) %-!< */ - ReturnState = False; - } - break; - default: - break; - } - } -#else - /* quit on any key */ - Bool ReturnState = False; -#endif + /* quit on Meta-Q (Alt-Q) */ + XCBKEYSYM theKeySym; + + /* last param is "int col". What? add enumeration to xcb_keysyms.h */ + theKeySym = XCBKeyPressLookupKeysym( theKeySyms, theKeyEvent, 1 ); + /* KeySym XK_Q == 'Q' */ + if (theKeySym.id == 'Q' && (theKeyEvent->state & XCBModMask1)) + ReturnState = False; #ifdef DEBUG if ( EventState == DEBUG_MOVE ) {