|
41 | 41 | #include <ApplicationServices/ApplicationServices.h> |
42 | 42 | #endif |
43 | 43 |
|
| 44 | +/* For NX_DEVICE*KEYMASK - the device-specific L/R modifier-key bits that |
| 45 | + * ride in NSEvent.modifierFlags alongside the coalesced high-order bits. */ |
| 46 | +#include <IOKit/hidsystem/IOLLEvent.h> |
| 47 | + |
44 | 48 | #if defined(HAVE_COCOA_METAL) |
45 | 49 | #include "../../gfx/common/metal_common.h" |
46 | 50 | #endif |
@@ -456,9 +460,26 @@ - (void)sendEvent:(NSEvent *)event { |
456 | 460 | break; |
457 | 461 | case NSEventTypeFlagsChanged: |
458 | 462 | { |
| 463 | + /* Bits we treat as modifier-key transitions: the eight device- |
| 464 | + * specific L/R masks from IOKit plus CapsLock (which has no |
| 465 | + * device-specific bit). Everything else in modifierFlags is |
| 466 | + * metadata - notably kCGEventFlagMaskNonCoalesced (0x100) - and |
| 467 | + * must not be interpreted as a key press, or we end up |
| 468 | + * synthesising phantom events (a toggle of 0x100 with kc=0 used |
| 469 | + * to translate to MAC_NATIVE_TO_HID[0]==KEY_A, stuck forever). */ |
| 470 | + static const NSUInteger mod_mask = |
| 471 | + NX_DEVICELCTLKEYMASK |
| 472 | + | NX_DEVICELSHIFTKEYMASK |
| 473 | + | NX_DEVICERSHIFTKEYMASK |
| 474 | + | NX_DEVICELCMDKEYMASK |
| 475 | + | NX_DEVICERCMDKEYMASK |
| 476 | + | NX_DEVICELALTKEYMASK |
| 477 | + | NX_DEVICERALTKEYMASK |
| 478 | + | NX_DEVICERCTLKEYMASK |
| 479 | + | NSEventModifierFlagCapsLock; |
459 | 480 | static NSUInteger old_flags = 0; |
460 | 481 | NSUInteger new_flags = [event modifierFlags]; |
461 | | - NSUInteger changed_flags = new_flags ^ old_flags; |
| 482 | + NSUInteger changed_flags = (new_flags ^ old_flags) & mod_mask; |
462 | 483 | uint16_t keycode = [event keyCode]; |
463 | 484 | bool down = false; |
464 | 485 |
|
|
0 commit comments