Skip to content

Commit

Permalink
Use a high priority dispatch queue for GCKeyboard and GCMouse events …
Browse files Browse the repository at this point in the history
…for the lowest latency possible

This appears to reduce latency between 1-4 ms on an iPad Pro.
  • Loading branch information
slouken committed Oct 15, 2020
1 parent a3a0ef7 commit bdc5129
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video/uikit/SDL_uikitevents.m
Expand Up @@ -90,6 +90,10 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
{
SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode);
};

dispatch_queue_t queue = dispatch_queue_create( "org.libsdl.input.keyboard", DISPATCH_QUEUE_SERIAL );
dispatch_set_target_queue( queue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
keyboard.handlerQueue = queue;
}

static void OnGCKeyboardDisconnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
Expand Down Expand Up @@ -221,6 +225,10 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, SDL_TRUE, (int)deltaX, -(int)deltaY);
};

dispatch_queue_t queue = dispatch_queue_create( "org.libsdl.input.mouse", DISPATCH_QUEUE_SERIAL );
dispatch_set_target_queue( queue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
mouse.handlerQueue = queue;

++mice_connected;
}

Expand Down Expand Up @@ -279,7 +287,7 @@ SDL_bool SDL_HasGCMouse(void)
void SDL_QuitGCMouse(void)
{
@autoreleasepool {
if (@available(iOS 14.0, tvOS 14.0, *)) {
if (@available(iOS 14.1, tvOS 14.1, *)) {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

if (mouse_connect_observer) {
Expand Down

0 comments on commit bdc5129

Please sign in to comment.