cocoa: Another attempt at synthesized mouse/touch 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 79f7927..7c09272 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -103,11 +103,7 @@ SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldVal
if (hint && (*hint == '0' || SDL_strcasecmp(hint, "false") == 0)) {
mouse->touch_mouse_events = SDL_FALSE;
} else {
-#if defined(__MACOSX__) /* macOS synthesizes its own events for this. */
- mouse->touch_mouse_events = SDL_FALSE;
-#else
mouse->touch_mouse_events = SDL_TRUE;
-#endif
}
}
@@ -387,11 +383,13 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
mouse->has_position = SDL_TRUE;
}
+#ifndef __MACOSX__ /* all your trackpad input would lack relative motion when not dragging in this case. */
/* Ignore relative motion positioning the first touch */
if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
xrel = 0;
yrel = 0;
}
+#endif
/* Update internal mouse coordinates */
if (!mouse->relative_mode) {
diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c
index caf5e56..e70214d 100644
--- a/src/events/SDL_touch.c
+++ b/src/events/SDL_touch.c
@@ -32,9 +32,18 @@ static int SDL_num_touch = 0;
static SDL_Touch **SDL_touchDevices = NULL;
/* for mapping touch events to mice */
+
+#ifndef __MACOSX__ /* don't generate mouse events from touch on macOS, the OS handles that. */
+#define SYNTHESIZE_TOUCH_TO_MOUSE 1
+#else
+#define SYNTHESIZE_TOUCH_TO_MOUSE 0
+#endif
+
+#if SYNTHESIZE_TOUCH_TO_MOUSE
static SDL_bool finger_touching = SDL_FALSE;
static SDL_FingerID track_fingerid;
static SDL_TouchID track_touchid;
+#endif
/* Public functions */
int
@@ -245,6 +254,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
return -1;
}
+#if SYNTHESIZE_TOUCH_TO_MOUSE
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
{
SDL_Mouse *mouse = SDL_GetMouse();
@@ -284,6 +294,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
}
}
}
+#endif
finger = SDL_GetFinger(touch, fingerid);
if (down) {
@@ -349,6 +360,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
return -1;
}
+#if SYNTHESIZE_TOUCH_TO_MOUSE
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
{
SDL_Mouse *mouse = SDL_GetMouse();
@@ -369,6 +381,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
}
}
}
+#endif
finger = SDL_GetFinger(touch,fingerid);
if (!finger) {
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 6357871..4769944 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -375,6 +375,15 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
return; /* can happen when returning from fullscreen Space on shutdown */
}
+ SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
+ if ([event subtype] == NSEventSubtypeTouch) { /* this is a synthetic from the OS */
+ if (mouse->touch_mouse_events) {
+ mouseID = SDL_TOUCH_MOUSEID; /* Hint is set */
+ } else {
+ return; /* no hint set, drop this one. */
+ }
+ }
+
const SDL_bool seenWarp = driverdata->seenWarp;
driverdata->seenWarp = NO;
@@ -408,13 +417,21 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
}
- SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)deltaY);
+ SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
}
void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{
SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
+ if ([event subtype] == NSEventSubtypeTouch) { /* this is a synthetic from the OS */
+ if (mouse->touch_mouse_events) {
+ mouseID = SDL_TOUCH_MOUSEID; /* Hint is set */
+ } else {
+ return; /* no hint set, drop this one. */
+ }
+ }
CGFloat x = -[event deltaX];
CGFloat y = [event deltaY];
@@ -437,7 +454,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
y = SDL_floor(y);
}
- SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
+ SDL_SendMouseWheel(window, mouseID, x, y, direction);
}
void
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 75bd03f..f4911e3 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -893,9 +893,19 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseDown:(NSEvent *)theEvent
{
+ const SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
int button;
int clicks;
+ if ([theEvent subtype] == NSEventSubtypeTouch) { /* this is a synthetic from the OS */
+ if (mouse->touch_mouse_events) {
+ mouseID = SDL_TOUCH_MOUSEID; /* Hint is set */
+ } else {
+ return; /* no hint set, drop this one. */
+ }
+ }
+
/* Ignore events that aren't inside the client area (i.e. title bar.) */
if ([theEvent window]) {
NSRect windowRect = [[[theEvent window] contentView] frame];
@@ -933,8 +943,6 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
clicks = (int) [theEvent clickCount];
- const SDL_Mouse *mouse = SDL_GetMouse();
- const SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_PRESSED, button, clicks);
}
@@ -950,9 +958,19 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseUp:(NSEvent *)theEvent
{
+ const SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
int button;
int clicks;
+ if ([theEvent subtype] == NSEventSubtypeTouch) { /* this is a synthetic from the OS */
+ if (mouse->touch_mouse_events) {
+ mouseID = SDL_TOUCH_MOUSEID; /* Hint is set */
+ } else {
+ return; /* no hint set, drop this one. */
+ }
+ }
+
if ([self processHitTest:theEvent]) {
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
return; /* stopped dragging, drop event. */
@@ -980,8 +998,6 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
clicks = (int) [theEvent clickCount];
- const SDL_Mouse *mouse = SDL_GetMouse();
- const SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_RELEASED, button, clicks);
}
@@ -998,10 +1014,19 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseMoved:(NSEvent *)theEvent
{
SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
SDL_Window *window = _data->window;
NSPoint point;
int x, y;
+ if ([theEvent subtype] == NSEventSubtypeTouch) { /* this is a synthetic from the OS */
+ if (mouse->touch_mouse_events) {
+ mouseID = SDL_TOUCH_MOUSEID; /* Hint is set */
+ } else {
+ return; /* no hint set, drop this one. */
+ }
+ }
+
if ([self processHitTest:theEvent]) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
return; /* dragging, drop event. */
@@ -1046,7 +1071,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
}
- SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
+ SDL_SendMouseMotion(window, mouseID, 0, x, y);
}
- (void)mouseDragged:(NSEvent *)theEvent