Index: Events.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Events.c,v retrieving revision 1.5 diff -u -p -r1.5 Events.c --- Events.c 13 Jun 2005 00:09:23 -0000 1.5 +++ Events.c 16 Jun 2005 13:48:35 -0000 @@ -34,6 +34,7 @@ is" without express or implied warranty. #include "Screen.h" #include "XNWindow.h" #include "Events.h" +#include "Keyboard.h" #include "mipointer.h" CARD32 lastEventTime = 0; @@ -96,6 +97,16 @@ xnestCollectExposures() } void +xnestQueueKeyEvent(int type, unsigned int keycode) +{ + xEvent x; + x.u.u.type = type; + x.u.u.detail = keycode; + x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + mieqEnqueue(&x); +} + +void xnestCollectEvents() { XEvent X; @@ -105,17 +116,13 @@ xnestCollectEvents() while (XCheckIfEvent(xnestDisplay, &X, xnestNotExposurePredicate, NULL)) { switch (X.type) { case KeyPress: - x.u.u.type = KeyPress; - x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); - mieqEnqueue(&x); + xnestUpdateModifierState(X.xkey.state); + xnestQueueKeyEvent(KeyPress, X.xkey.keycode); break; case KeyRelease: - x.u.u.type = KeyRelease; - x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); - mieqEnqueue(&x); + xnestUpdateModifierState(X.xkey.state); + xnestQueueKeyEvent(KeyRelease, X.xkey.keycode); break; case ButtonPress: Index: Events.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Events.h,v retrieving revision 1.2 diff -u -p -r1.2 Events.h --- Events.h 23 Apr 2004 19:54:21 -0000 1.2 +++ Events.h 16 Jun 2005 13:48:35 -0000 @@ -26,5 +26,6 @@ extern CARD32 lastEventTime; void SetTimeSinceLastInputEvent(void); void xnestCollectExposures(void); void xnestCollectEvents(void); +void xnestQueueKeyEvent(int type, unsigned int keycode); #endif /* XNESTEVENTS_H */ Index: Init.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Init.c,v retrieving revision 1.5 diff -u -p -r1.5 Init.c --- Init.c 20 Apr 2005 12:25:41 -0000 1.5 +++ Init.c 16 Jun 2005 13:48:35 -0000 @@ -87,15 +87,13 @@ InitOutput(ScreenInfo *screenInfo, int a void InitInput(int argc, char *argv[]) { - pointer ptr, kbd; + xnestPointerDevice = AddInputDevice(xnestPointerProc, TRUE); + xnestKeyboardDevice = AddInputDevice(xnestKeyboardProc, TRUE); - ptr = AddInputDevice(xnestPointerProc, TRUE); - kbd = AddInputDevice(xnestKeyboardProc, TRUE); + RegisterPointerDevice(xnestPointerDevice); + RegisterKeyboardDevice(xnestKeyboardDevice); - RegisterPointerDevice(ptr); - RegisterKeyboardDevice(kbd); - - mieqInit(kbd, ptr); + mieqInit((DevicePtr)xnestKeyboardDevice, (DevicePtr)xnestPointerDevice); AddEnabledDevice(XConnectionNumber(xnestDisplay)); Index: Keyboard.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Keyboard.c,v retrieving revision 1.3 diff -u -p -r1.3 Keyboard.c --- Keyboard.c 20 Apr 2005 12:25:41 -0000 1.3 +++ Keyboard.c 16 Jun 2005 13:48:35 -0000 @@ -31,6 +31,7 @@ is" without express or implied warranty. #include "Screen.h" #include "Keyboard.h" #include "Args.h" +#include "Events.h" #ifdef XKB #include @@ -83,6 +84,8 @@ extern Status XkbGetControls( #endif +DeviceIntPtr xnestKeyboardDevice = NULL; + void xnestBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls) { @@ -282,3 +285,49 @@ LegalModifier(unsigned int key, DevicePt { return TRUE; } + +void +xnestUpdateModifierState(unsigned int state) +{ + DeviceIntPtr pDev = xnestKeyboardDevice; + KeyClassPtr keyc = pDev->key; + int i; + CARD8 mask; + + if (keyc->state == state) + return; + + for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { + int key; + + /* Modifier is down, but shouldn't be + */ + if ((keyc->state & mask) && !(state & mask)) { + int count = keyc->modifierKeyCount[i]; + + for (key = 0; key < MAP_LENGTH; key++) + if (keyc->modifierMap[key] & mask) { + int bit; + BYTE *kptr; + + kptr = &keyc->down[key >> 3]; + bit = 1 << (key & 7); + + if (*kptr & bit) + xnestQueueKeyEvent(KeyRelease, key); + + if (--count == 0) + break; + } + } + + /* Modifier shoud be down, but isn't + */ + if (!(keyc->state & mask) && (state & mask)) + for (key = 0; key < MAP_LENGTH; key++) + if (keyc->modifierMap[key] & mask) { + xnestQueueKeyEvent(KeyPress, key); + break; + } + } +} Index: Keyboard.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Keyboard.h,v retrieving revision 1.2 diff -u -p -r1.2 Keyboard.h --- Keyboard.h 23 Apr 2004 19:54:21 -0000 1.2 +++ Keyboard.h 16 Jun 2005 13:48:35 -0000 @@ -20,8 +20,11 @@ is" without express or implied warranty. #define XNEST_KEYBOARD_EVENT_MASK \ (KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask) +extern DeviceIntPtr xnestKeyboardDevice; + void xnestBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls); void xnestChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl); int xnestKeyboardProc(DeviceIntPtr pDev, int onoff); +void xnestUpdateModifierState(unsigned int state); #endif /* XNESTKEYBOARD_H */ Index: Pointer.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Pointer.c,v retrieving revision 1.3 diff -u -p -r1.3 Pointer.c --- Pointer.c 20 Apr 2005 12:25:41 -0000 1.3 +++ Pointer.c 16 Jun 2005 13:48:35 -0000 @@ -31,6 +31,8 @@ is" without express or implied warranty. #include "Pointer.h" #include "Args.h" +DeviceIntPtr xnestPointerDevice = NULL; + void xnestChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl) { Index: Pointer.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xnest/Pointer.h,v retrieving revision 1.2 diff -u -p -r1.2 Pointer.h --- Pointer.h 23 Apr 2004 19:54:21 -0000 1.2 +++ Pointer.h 16 Jun 2005 13:48:35 -0000 @@ -23,6 +23,8 @@ is" without express or implied warranty. (ButtonPressMask | ButtonReleaseMask | PointerMotionMask | \ EnterWindowMask | LeaveWindowMask) +extern DeviceIntPtr xnestPointerDevice; + void xnestChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl); int xnestPointerProc(DeviceIntPtr pDev, int onoff);