Skip to content

Commit

Permalink
Mac: fix bug mentioned in kmonad#48
Browse files Browse the repository at this point in the history
  • Loading branch information
thoelze1 committed Aug 18, 2020
1 parent 6e95a3f commit 7c1c565
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 6 additions & 1 deletion c_src/mac/keyio_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ void input_callback(void *context, IOReturn result, void *sender, IOHIDValueRef
uint16_t usage = IOHIDElementGetUsage(element);
e.type = !integer_value;
e.keycode = (usage_page << 16) | usage;
write(fd[1], &e, sizeof(struct KeyEvent));
// "error" and "reserved" key events are ignored
// See https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-421.6/IOHIDFamily/IOHIDUsageTables.h.auto.html
if ((usage > kHIDUsage_KeyboardErrorUndefined && usage < 0xA5) ||
(usage > 0xDF && usage < 0xE8)) {
write(fd[1], &e, sizeof(struct KeyEvent));
}
}

void open_matching_devices(char *product, io_iterator_t iter) {
Expand Down
9 changes: 1 addition & 8 deletions src/KMonad/Keyboard/IO/Mac/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,7 @@ fromMacKeyEvent (MacKeyEvent (s, c)) = case fromMacKeycode c of
-- See https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDFamily/AppleHIDUsageTables.h.auto.html
kcMap :: M.HashMap MacKeycode Keycode
kcMap = M.fromList $
[ (0x00070000, KeyError) -- There's no documentation on this error code, but
-- I've seen it sent when the rollover is exceeded on
-- my macbook internal keyboard
, (0x00070001, KeyError) -- kHIDUsage_KeyErrorRollOver
, (0x00070002, KeyError) -- kHIDUsage_KeyPOSTFail
, (0x00070003, KeyError) -- kHIDUsage_Undefined
, (0x00070004, KeyA)
[ (0x00070004, KeyA)
, (0x00070005, KeyB)
, (0x00070006, KeyC)
, (0x00070007, KeyD)
Expand Down Expand Up @@ -292,7 +286,6 @@ kcMap = M.fromList $
, (0x000700E6, KeyRightAlt)
, (0x000700E7, KeyRightMeta)
-- /* 0x000700E8-0x0007FFFF Reserved */
, (0x0007FFFF, KeyReserved)
, (0x000C00B5, KeyNextSong)
, (0x000C00B6, KeyPreviousSong)
, (0x000C00CD, KeyPlayPause)
Expand Down
1 change: 0 additions & 1 deletion src/KMonad/Keyboard/Keycode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ data Keycode
| KeyMissionCtrl
| KeyBacklightDown
| KeyBacklightUp
| KeyError
#endif
deriving (Eq, Show, Bounded, Enum, Ord, Generic, Hashable)

Expand Down

0 comments on commit 7c1c565

Please sign in to comment.