Skip to content

Commit

Permalink
Fix for stuck modifier keys, attempt 2!
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Byer authored and Jeremy Huddleston committed Nov 19, 2007
1 parent 9e9633c commit ef29020
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
44 changes: 37 additions & 7 deletions hw/darwin/darwinEvents.c
Expand Up @@ -41,7 +41,6 @@ in this Software without prior written authorization from The Open Group.
#include "mi.h"
#include "scrnintstr.h"
#include "mipointer.h"

#include "darwin.h"
#include "darwinKeyboard.h"

Expand Down Expand Up @@ -72,7 +71,8 @@ typedef struct _EventQueue {
} EventQueueRec, *EventQueuePtr;

static EventQueueRec darwinEventQueue;

extern KeyClassPtr darwinKeyc;
#define KeyPressed(k) (darwinKeyc->down[k >> 3] & (1 << (k & 7)))

/*
* DarwinPressModifierMask
Expand Down Expand Up @@ -150,8 +150,37 @@ static void DarwinUpdateModifiers(
* are held down during a "context" switch -- otherwise, we would miss the KeyUp.
*/
static void DarwinReleaseModifiers(void) {
xEvent e;
DarwinUpdateModifiers(&e, KeyRelease, COMMAND_MASK(-1) | CONTROL_MASK(-1) | ALTERNATE_MASK(-1) | SHIFT_MASK(-1));
KeySym *map = NULL;
xEvent ke;
int i = 0, j = 0, nevents = 0;

map = darwinKeyc->curKeySyms.map;

for (i = darwinKeyc->curKeySyms.minKeyCode, map = darwinKeyc->curKeySyms.map;
i < darwinKeyc->curKeySyms.maxKeyCode;
i++, map += darwinKeyc->curKeySyms.mapWidth) {
if (KeyPressed(i)) {
switch (*map) {
/* Don't release the lock keys */
case XK_Caps_Lock:
case XK_Shift_Lock:
case XK_Num_Lock:
case XK_Scroll_Lock:
case XK_Kana_Lock:
break;
default:
ke.u.keyButtonPointer.time = GetTimeInMillis();
ke.u.keyButtonPointer.rootX = 0;
ke.u.keyButtonPointer.rootY = 0;
ke.u.u.type = KeyRelease;
ke.u.u.detail = i;
(*darwinEventQueue.pKbd->processInputProc)(&ke,
(DeviceIntPtr)darwinEventQueue.pKbd, 1);
break;
}
}
}
ProcessInputEvents();
}

/*
Expand Down Expand Up @@ -477,9 +506,10 @@ void ProcessInputEvents(void)
break;
}

case kXDarwinDeactivate:
DarwinReleaseModifiers();
// fall through
case kXDarwinDeactivate:
DarwinReleaseModifiers();
old_flags=0;
// fall through
default:
// Check for mode specific event
DarwinModeProcessEvent(&xe);
Expand Down
2 changes: 2 additions & 0 deletions hw/darwin/darwinKeyboard.c
Expand Up @@ -220,6 +220,7 @@ static void DarwinChangeKeyboardControl( DeviceIntPtr device, KeybdCtrl *ctrl )
static darwinKeyboardInfo keyInfo;
static FILE *fref = NULL;
static char *inBuffer = NULL;
KeyClassPtr darwinKeyc = NULL;

//-----------------------------------------------------------------------------
// Data Stream Object
Expand Down Expand Up @@ -835,6 +836,7 @@ InitModMap(register KeyClassPtr keyc)
CARD8 keysPerModifier[8];
CARD8 mask;

darwinKeyc = keyc;
if (keyc->modifierKeyMap != NULL)
xfree (keyc->modifierKeyMap);

Expand Down

0 comments on commit ef29020

Please sign in to comment.