Skip to content

Commit 1fd56ef

Browse files
author
Chaoji Li
committed
Add bluetooth mouse support.
Due to the strangeness of iPadOS mouse support, this is not perfect solution. - No right click - Unable to capture mouse inside the screen After all this years, I totally can't and don't want to understand the original trackpad implementation, so I rewrote it completely, hopefully more clearly, to support external mouse.
1 parent ba70ab5 commit 1fd56ef

File tree

6 files changed

+333
-308
lines changed

6 files changed

+333
-308
lines changed

SDL/src/video/uikit/SDL_uikitview.h

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,81 +20,64 @@
2020
slouken@libsdl.org
2121
*/
2222

23+
//
24+
// This is a total rewrite of original implementation.
25+
//
26+
// We only support 1 mouse.
27+
//
28+
// The trackpad behavior:
29+
// - pan around is translated to mouse move
30+
// - tap is left click
31+
// - tap while another finger is down is right click
32+
//
33+
// Also: convert pointer move events (bluetooth mouse) to mouse events.
34+
//
35+
// By Chaoji Li, Aug 22, 2020
36+
//
2337
#import <UIKit/UIKit.h>
2438
#include "SDL_stdinc.h"
2539
#include "SDL_mouse.h"
2640
#include "SDL_mouse_c.h"
2741
#include "SDL_events.h"
2842

29-
#ifdef IPHONEOS
30-
#define MAX_SIMULTANEOUS_TOUCHES 2 /* Two fingers are enough */
31-
32-
/* Mouse hold status */
33-
#define MOUSE_HOLD_NO 0
34-
#define MOUSE_HOLD_WAIT 1
35-
#define MOUSE_HOLD_YES 2
36-
37-
#define POSITION_CHANGE_THRESHOLD 15 /* Cancel hold If finger pos move beyond this */
38-
#define MOUSE_HOLD_INTERVAL 1.5f /* mouse hold happens after 1s */
39-
#define TAP_THRESHOLD 0.3f /* Tap interval should be less than 0.3s */
4043

4144
typedef enum {
4245
MouseRightClickDefault,
4346
MouseRightClickWithDoubleTap
4447
} MouseRightClickMode;
4548

46-
typedef struct {
47-
CGPoint ptOrig;
48-
int leftHold;
49-
int mouseHold;
50-
NSTimeInterval timestamp;
51-
} ExtMice;
5249

5350
@protocol MouseHoldDelegate
5451

5552
-(void)onHold:(CGPoint)pt;
5653
-(void)cancelHold:(CGPoint)pt;
54+
-(void)onHoldMoved:(CGPoint)pt;
5755
- (MouseRightClickMode)currentRightClickMode;
5856

5957
@end
6058

61-
62-
#else
63-
#if SDL_IPHONE_MULTIPLE_MICE
64-
#define MAX_SIMULTANEOUS_TOUCHES 5
65-
#else
66-
#define MAX_SIMULTANEOUS_TOUCHES 1
67-
#endif
68-
#endif
69-
7059
/* *INDENT-OFF* */
7160
#if SDL_IPHONE_KEYBOARD
7261
@interface SDL_uikitview : UIView<UITextFieldDelegate> {
7362
#else
7463
@interface SDL_uikitview : UIView {
7564
#endif
7665

77-
SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
66+
SDL_Mouse mice;
7867

79-
#ifdef IPHONEOS
80-
ExtMice extmice[MAX_SIMULTANEOUS_TOUCHES];
8168
id<MouseHoldDelegate> mouseHoldDelegate;
82-
#endif
8369

8470
#if SDL_IPHONE_KEYBOARD
8571
UITextField *textField;
8672
BOOL keyboardVisible;
8773
#endif
8874

8975
}
90-
#ifdef IPHONEOS
9176
@property (nonatomic,assign) id<MouseHoldDelegate> mouseHoldDelegate;
9277

9378
- (void)sendMouseEvent:(int)index left:(BOOL)isLeft down:(BOOL)isDown;
94-
95-
#endif
96-
97-
79+
- (void)sendMouseMotion:(int)index x:(CGFloat)x y:(CGFloat)y;
80+
9881
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
9982
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
10083
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

0 commit comments

Comments
 (0)