Use OS-provided click counts on macOS and iOS for mouse press and release 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
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 7793de8..d54519c 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -322,15 +322,13 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
return &mouse->clickstate[button];
}
-int
-SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
+static int
+SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
Uint32 type;
Uint32 buttonstate = mouse->buttonstate;
- SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
- Uint8 click_count;
/* Figure out which event to perform */
switch (state) {
@@ -358,7 +356,8 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
}
mouse->buttonstate = buttonstate;
- if (clickstate) {
+ if (clicks < 0) {
+ SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
if (state == SDL_PRESSED) {
Uint32 now = SDL_GetTicks();
@@ -374,9 +373,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
++clickstate->click_count;
}
}
- click_count = clickstate->click_count;
- } else {
- click_count = 1;
+ clicks = clickstate->click_count;
}
/* Post the event, if desired */
@@ -388,7 +385,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
event.button.which = mouseID;
event.button.state = state;
event.button.button = button;
- event.button.clicks = click_count;
+ event.button.clicks = (Uint8) SDL_min(clicks, 255);
event.button.x = mouse->x;
event.button.y = mouse->y;
posted = (SDL_PushEvent(&event) > 0);
@@ -398,11 +395,24 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
if (window && state == SDL_RELEASED) {
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
}
-
+
return posted;
}
int
+SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
+{
+ clicks = SDL_max(clicks, 0);
+ return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
+}
+
+int
+SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
+{
+ return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
+}
+
+int
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
{
SDL_Mouse *mouse = SDL_GetMouse();
diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h
index 03aca0a..06dc887 100644
--- a/src/events/SDL_mouse_c.h
+++ b/src/events/SDL_mouse_c.h
@@ -119,6 +119,9 @@ extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int rel
/* Send a mouse button event */
extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
+/* Send a mouse button event with a click count */
+extern int SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
+
/* Send a mouse wheel event */
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index a1f93a5..3c86236 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -823,6 +823,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseDown:(NSEvent *)theEvent
{
int button;
+ int clicks;
/* Ignore events that aren't inside the client area (i.e. title bar.) */
if ([theEvent window]) {
@@ -858,7 +859,9 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
button = (int) [theEvent buttonNumber] + 1;
break;
}
- SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
+
+ clicks = (int) [theEvent clickCount];
+ SDL_SendMouseButtonClicks(_data->window, 0, SDL_PRESSED, button, clicks);
}
- (void)rightMouseDown:(NSEvent *)theEvent
@@ -874,6 +877,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseUp:(NSEvent *)theEvent
{
int button;
+ int clicks;
if ([self processHitTest:theEvent]) {
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
@@ -899,7 +903,9 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
button = (int) [theEvent buttonNumber] + 1;
break;
}
- SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
+
+ clicks = (int) [theEvent clickCount];
+ SDL_SendMouseButtonClicks(_data->window, 0, SDL_RELEASED, button, clicks);
}
- (void)rightMouseUp:(NSEvent *)theEvent
@@ -1264,7 +1270,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
}
}
- [nswindow setContentView: contentView];
+ [nswindow setContentView:contentView];
[contentView release];
/* Allow files and folders to be dragged onto the window by users */
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index d15b7ef..c7d9f51 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -143,12 +143,13 @@
if (!firstFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
+ int clicks = (int) touch.tapCount;
/* send mouse moved event */
SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
/* send mouse down event */
- SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
+ SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT, clicks);
firstFingerDown = touch;
}
@@ -166,7 +167,8 @@
if (touch == firstFingerDown) {
/* send mouse up */
- SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
+ int clicks = (int) touch.tapCount;
+ SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT, clicks);
firstFingerDown = nil;
}