From 2dee6a2c37afdf901753c66ef10cc45ff528911d Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 23 May 2010 17:54:46 +0200 Subject: [PATCH] Fixed: #920 NeL - X11 Modifier Keys (Patch provided by rti) --- code/nel/include/nel/misc/events.h | 95 ++++++++++--------- .../src/3d/driver/opengl/driver_opengl.vcproj | 8 ++ .../3d/driver/opengl/unix_event_emitter.cpp | 62 ++++++++---- 3 files changed, 100 insertions(+), 65 deletions(-) diff --git a/code/nel/include/nel/misc/events.h b/code/nel/include/nel/misc/events.h index fe024ef50..3ef67770a 100644 --- a/code/nel/include/nel/misc/events.h +++ b/code/nel/include/nel/misc/events.h @@ -80,42 +80,43 @@ const CClassId EventIME (0x261f1ede, 0x1b0a6c3a); enum TKey { - Key0 ='0', - Key1 ='1', - Key2 ='2', - Key3 ='3', - Key4 ='4', - Key5 ='5', - Key6 ='6', - Key7 ='7', - Key8 ='8', - Key9 ='9', - KeyA ='A', - KeyB ='B', - KeyC ='C', - KeyD ='D', - KeyE ='E', - KeyF ='F', - KeyG ='G', - KeyH ='H', - KeyI ='I', - KeyJ ='J', - KeyK ='K', - KeyL ='L', - KeyM ='M', - KeyN ='N', - KeyO ='O', - KeyP ='P', - KeyQ ='Q', - KeyR ='R', - KeyS ='S', - KeyT ='T', - KeyU ='U', - KeyV ='V', - KeyW ='W', - KeyX ='X', - KeyY ='Y', - KeyZ ='Z', + KeyNOKEY =0x00, + Key0 ='0', + Key1 ='1', + Key2 ='2', + Key3 ='3', + Key4 ='4', + Key5 ='5', + Key6 ='6', + Key7 ='7', + Key8 ='8', + Key9 ='9', + KeyA ='A', + KeyB ='B', + KeyC ='C', + KeyD ='D', + KeyE ='E', + KeyF ='F', + KeyG ='G', + KeyH ='H', + KeyI ='I', + KeyJ ='J', + KeyK ='K', + KeyL ='L', + KeyM ='M', + KeyN ='N', + KeyO ='O', + KeyP ='P', + KeyQ ='Q', + KeyR ='R', + KeyS ='S', + KeyT ='T', + KeyU ='U', + KeyV ='V', + KeyW ='W', + KeyX ='X', + KeyY ='Y', + KeyZ ='Z', KeyLBUTTON =0x01, KeyRBUTTON =0x02, KeyCANCEL =0x03, @@ -209,18 +210,18 @@ enum TKey KeyLMENU =0xA4, KeyRMENU =0xA5, KeySEMICOLON =0xBA, - KeyEQUALS =0xBB, - KeyCOMMA =0xBC, - KeyDASH =0xBD, - KeyPERIOD =0xBE, - KeySLASH =0xBF, - KeyTILDE =0xC0, - KeyLBRACKET =0xDB, - KeyBACKSLASH =0xDC, - KeyRBRACKET =0xDD, + KeyEQUALS =0xBB, + KeyCOMMA =0xBC, + KeyDASH =0xBD, + KeyPERIOD =0xBE, + KeySLASH =0xBF, + KeyTILDE =0xC0, + KeyLBRACKET =0xDB, + KeyBACKSLASH =0xDC, + KeyRBRACKET =0xDD, KeyAPOSTROPHE =0xDE, - KeyPARAGRAPH =0xDF, - KeyOEM_102 =0xE2, + KeyPARAGRAPH =0xDF, + KeyOEM_102 =0xE2, KeyPROCESSKEY =0xE5, KeyATTN =0xF6, KeyCRSEL =0xF7, diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.vcproj b/code/nel/src/3d/driver/opengl/driver_opengl.vcproj index 42159b9d7..2802bdc8e 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.vcproj +++ b/code/nel/src/3d/driver/opengl/driver_opengl.vcproj @@ -503,6 +503,14 @@ RelativePath="stdopengl.h" > + + + + diff --git a/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp b/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp index 44e512d4a..03e4083aa 100644 --- a/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp +++ b/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp @@ -52,20 +52,37 @@ void CUnixEventEmitter::submitEvents(CEventServer & server, bool allWindows) } } +#ifndef AltMask +# ifdef NL_OS_MAC +# define AltMask (8192) +# else +# define AltMask (Mod1Mask) +# endif +#endif + TMouseButton getMouseButton (uint32 state) { - TMouseButton button=noButton; - if (state&ControlMask) (int&)button|=ctrlButton; - if (state&Button1Mask) (int&)button|=leftButton; - if (state&Button3Mask) (int&)button|=rightButton; - if (state&Button2Mask) (int&)button|=middleButton; - if (state&ShiftMask) (int&)button|=shiftButton; - // TODO manage ALT key - // if (GetAsyncKeyState(VK_MENU)&(1<<15)) - // (int&)button|=altButton; - return button; + uint32 button=noButton; + if (state&Button1Mask) button|=leftButton; + if (state&Button2Mask) button|=middleButton; + if (state&Button3Mask) button|=rightButton; + if (state&ControlMask) button|=ctrlButton; + if (state&ShiftMask) button|=shiftButton; + if (state&AltMask) button|=altButton; + + return (TMouseButton)button; } +TKeyButton getKeyButton (uint32 state) +{ + uint32 button=noKeyButton; + if (state&ControlMask) button|=ctrlKeyButton; + if (state&ShiftMask) button|=shiftKeyButton; + if (state&AltMask) button|=altKeyButton; + + return (TKeyButton)button; +} + TKey getKey (KeySym keysym) { switch (keysym) @@ -122,11 +139,16 @@ TKey getKey (KeySym keysym) case XK_Shift_R: return KeySHIFT; case XK_Control_L: return KeyCONTROL; case XK_Control_R: return KeyCONTROL; + case XK_Super_L: return KeyLWIN; + case XK_Super_R: return KeyRWIN; /// case XK_Caps_Lock: return Key; /// case XK_Meta_L: return Key; /// case XK_Meta_R: return Key; -/// case XK_Alt_L: return Key; -/// case XK_Alt_R: return Key; + case XK_Mode_switch: return KeyMENU; + case XK_ISO_Level3_Shift: return KeyMENU; + case XK_Menu: return KeyAPPS; + case XK_Alt_L: return KeyMENU; + case XK_Alt_R: return KeyMENU; case XK_space: return KeySPACE; // case XK_comma: return Key; // case XK_minus: return Key; @@ -199,9 +221,9 @@ TKey getKey (KeySym keysym) case XK_y: return KeyY; case XK_Z: case XK_z: return KeyZ; - default: nldebug ("0x%x %d '%c'", keysym, keysym, keysym); + default: //nldebug ("0x%x %d '%c'", keysym, keysym, keysym); } - return KeyNUMLOCK; + return KeyNOKEY; } @@ -282,9 +304,11 @@ void CUnixEventEmitter::processMessage (XEvent &event, CEventServer &server) int c; c = XLookupString(&event.xkey, Text, 1024-1, &k, NULL); - TKey key = getKey (k); + TKey key = getKey(XKeycodeToKeysym(_dpy, ((XKeyEvent*)&event)->keycode, 0)); + if(key == KeyNOKEY) + key = getKey(XKeycodeToKeysym(_dpy, ((XKeyEvent*)&event)->keycode, 1)); // TODO manage the bool (first time pressed) - server.postEvent (new CEventKeyDown (key, noKeyButton, true, this)); + server.postEvent (new CEventKeyDown (key, getKeyButton(event.xbutton.state), true, this)); Text[c] = '\0'; if(c>0) @@ -303,9 +327,11 @@ void CUnixEventEmitter::processMessage (XEvent &event, CEventServer &server) int c; c = XLookupString(&event.xkey, Text, 1024-1, &k, NULL); - TKey key = getKey (k); + TKey key = getKey(XKeycodeToKeysym(_dpy, ((XKeyEvent*)&event)->keycode, 0)); + if(key == KeyNOKEY) + key = getKey(XKeycodeToKeysym(_dpy, ((XKeyEvent*)&event)->keycode, 1)); // TODO manage the bool (first time pressed) - server.postEvent (new CEventKeyUp (key, noKeyButton, this)); + server.postEvent (new CEventKeyUp (key, getKeyButton(event.xbutton.state), this)); break; } Case(FocusIn)