Added documentation that the UIApplicationSupportsIndirectInputEvents key must be set to true in your application's Info.plist in order to get real Bluetooth mouse events.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/WhatsNew.txt b/WhatsNew.txt
index 08d82c0..7292712 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -8,6 +8,10 @@ This is a list of major changes in SDL's version history.
Android:
* Added support for audio output and capture using AAudio
+iOS:
+* Added documentation that the UIApplicationSupportsIndirectInputEvents key must be set to true in your application's Info.plist in order to get real Bluetooth mouse events.
+
+
---------------------------------------------------------------------------
2.0.16:
---------------------------------------------------------------------------
diff --git a/Xcode-iOS/Demos/Info.plist b/Xcode-iOS/Demos/Info.plist
index 7714fe8..aa7b5f6 100644
--- a/Xcode-iOS/Demos/Info.plist
+++ b/Xcode-iOS/Demos/Info.plist
@@ -30,5 +30,7 @@
<string>iOS Launch Screen</string>
<key>UISupportedInterfaceOrientations</key>
<array/>
+ <key>UIApplicationSupportsIndirectInputEvents</key>
+ <true/>
</dict>
</plist>
diff --git a/docs/README-ios.md b/docs/README-ios.md
index acb8bae..ee039de 100644
--- a/docs/README-ios.md
+++ b/docs/README-ios.md
@@ -191,6 +191,12 @@ SDL_bool SDL_IsTextInputActive()
-- returns whether or not text events are enabled (and the onscreen keyboard is visible)
+Notes -- Mouse
+==============================================================================
+
+iOS now supports Bluetooth mice on iPad, but by default will provide the mouse input as touch. In order for SDL to see the real mouse events, you should set the key UIApplicationSupportsIndirectInputEvents to true in your Info.plist
+
+
Notes -- Reading and Writing files
==============================================================================
diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 6d78685..82fde88 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -268,29 +268,37 @@ void SDL_InitGCMouse(void)
@autoreleasepool {
/* There is a bug where mouse accumulates duplicate deltas over time in iOS 14.0 */
if (@available(iOS 14.1, tvOS 14.1, *)) {
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
- mouse_connect_observer = [center addObserverForName:GCMouseDidConnectNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification *note) {
- GCMouse *mouse = note.object;
- OnGCMouseConnected(mouse);
- }];
+ /* iOS will not send the new pointer touch events if you don't have this key,
+ * and we need them to differentiate between mouse events and real touch events.
+ */
+ BOOL indirect_input_available = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UIApplicationSupportsIndirectInputEvents"] boolValue];
+ if (indirect_input_available) {
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ mouse_connect_observer = [center addObserverForName:GCMouseDidConnectNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *note) {
+ GCMouse *mouse = note.object;
+ OnGCMouseConnected(mouse);
+ }];
+
+ mouse_disconnect_observer = [center addObserverForName:GCMouseDidDisconnectNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *note) {
+ GCMouse *mouse = note.object;
+ OnGCMouseDisconnected(mouse);
+ }];
- mouse_disconnect_observer = [center addObserverForName:GCMouseDidDisconnectNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification *note) {
- GCMouse *mouse = note.object;
- OnGCMouseDisconnected(mouse);
- }];
+ for (GCMouse *mouse in [GCMouse mice]) {
+ OnGCMouseConnected(mouse);
+ }
- for (GCMouse *mouse in [GCMouse mice]) {
- OnGCMouseConnected(mouse);
+ SDL_GetMouse()->SetRelativeMouseMode = SetGCMouseRelativeMode;
+ } else {
+ NSLog(@"You need UIApplicationSupportsIndirectInputEvents in your Info.plist for mouse support");
}
-
- SDL_GetMouse()->SetRelativeMouseMode = SetGCMouseRelativeMode;
}
}
}