Fixed: #920 NeL - X11 Modifier Keys (Patch provided by rti)

This commit is contained in:
kervala 2010-05-23 17:54:46 +02:00
parent 61a8c90b04
commit abe0f8d9a3
3 changed files with 100 additions and 65 deletions

View file

@ -80,6 +80,7 @@ const CClassId EventIME (0x261f1ede, 0x1b0a6c3a);
enum TKey enum TKey
{ {
KeyNOKEY =0x00,
Key0 ='0', Key0 ='0',
Key1 ='1', Key1 ='1',
Key2 ='2', Key2 ='2',

View file

@ -503,6 +503,14 @@
RelativePath="stdopengl.h" RelativePath="stdopengl.h"
> >
</File> </File>
<File
RelativePath=".\unix_event_emitter.cpp"
>
</File>
<File
RelativePath=".\unix_event_emitter.h"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View file

@ -52,18 +52,35 @@ 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 getMouseButton (uint32 state)
{ {
TMouseButton button=noButton; uint32 button=noButton;
if (state&ControlMask) (int&)button|=ctrlButton; if (state&Button1Mask) button|=leftButton;
if (state&Button1Mask) (int&)button|=leftButton; if (state&Button2Mask) button|=middleButton;
if (state&Button3Mask) (int&)button|=rightButton; if (state&Button3Mask) button|=rightButton;
if (state&Button2Mask) (int&)button|=middleButton; if (state&ControlMask) button|=ctrlButton;
if (state&ShiftMask) (int&)button|=shiftButton; if (state&ShiftMask) button|=shiftButton;
// TODO manage ALT key if (state&AltMask) button|=altButton;
// if (GetAsyncKeyState(VK_MENU)&(1<<15))
// (int&)button|=altButton; return (TMouseButton)button;
return 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) TKey getKey (KeySym keysym)
@ -122,11 +139,16 @@ TKey getKey (KeySym keysym)
case XK_Shift_R: return KeySHIFT; case XK_Shift_R: return KeySHIFT;
case XK_Control_L: return KeyCONTROL; case XK_Control_L: return KeyCONTROL;
case XK_Control_R: 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_Caps_Lock: return Key;
/// case XK_Meta_L: return Key; /// case XK_Meta_L: return Key;
/// case XK_Meta_R: return Key; /// case XK_Meta_R: return Key;
/// case XK_Alt_L: return Key; case XK_Mode_switch: return KeyMENU;
/// case XK_Alt_R: return Key; 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_space: return KeySPACE;
// case XK_comma: return Key; // case XK_comma: return Key;
// case XK_minus: return Key; // case XK_minus: return Key;
@ -199,9 +221,9 @@ TKey getKey (KeySym keysym)
case XK_y: return KeyY; case XK_y: return KeyY;
case XK_Z: case XK_Z:
case XK_z: return KeyZ; 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; int c;
c = XLookupString(&event.xkey, Text, 1024-1, &k, NULL); 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) // 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'; Text[c] = '\0';
if(c>0) if(c>0)
@ -303,9 +327,11 @@ void CUnixEventEmitter::processMessage (XEvent &event, CEventServer &server)
int c; int c;
c = XLookupString(&event.xkey, Text, 1024-1, &k, NULL); 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) // 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; break;
} }
Case(FocusIn) Case(FocusIn)