Skip to content

Commit

Permalink
Indicate repeated keypresses in NSEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
LubosD committed Mar 1, 2021
1 parent eff8a62 commit 879571d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions AppKit/X11.backend/X11Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
int clickCount;
X11Cursor *_blankCursor, *_defaultCursor;
BOOL _cursorGrabbed;
KeySym _lastKeySym;
}

- (Display *) display;
Expand Down
25 changes: 24 additions & 1 deletion AppKit/X11.backend/X11Display.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static void socketCallback(CFSocketRef s, CFSocketCallBackType type,
#endif

_windowsByID = [NSMutableDictionary new];
[self _enableDetectableAutoRepeat];

lastFocusedWindow = nil;
lastClickTimeStamp = 0.0;
Expand Down Expand Up @@ -151,6 +152,19 @@ - (Display *) display {
return _display;
}

- (void) _enableDetectableAutoRepeat {
int major = XkbMajorVersion, minor = XkbMinorVersion;
XkbStateRec state;

if (!XkbLibraryVersion(&major, &minor))
return;
if (!XkbQueryExtension(_display, NULL, NULL, &major, &minor, NULL))
return;

Bool supported;
XkbSetDetectableAutoRepeat(_display, TRUE, &supported);
}

- (NSArray *) screens {
int eventBase, errorBase;

Expand Down Expand Up @@ -926,6 +940,15 @@ - (void) postXEvent: (XEvent *) ev {
// kVK_ANSI_A), this gives it a chance to work.
const int carbonKeyCode = x11ToCarbon[ev->xkey.keycode];

BOOL isARepeat = NO;

if (ev->type == KeyPress) {
isARepeat = _lastKeySym == keySym;
_lastKeySym = keySym;
} else {
_lastKeySym = 0;
}

id event = [NSEvent keyEventWithType: ev->type == KeyPress ? NSKeyDown
: NSKeyUp
location: pos
Expand All @@ -935,7 +958,7 @@ - (void) postXEvent: (XEvent *) ev {
context: nil
characters: str
charactersIgnoringModifiers: strIg
isARepeat: NO
isARepeat: isARepeat
keyCode: carbonKeyCode];

[self postEvent: event atStart: NO];
Expand Down

0 comments on commit 879571d

Please sign in to comment.