mirror of
https://github.com/encounter/SDL.git
synced 2025-12-16 08:27:05 +00:00
cocoa: Another attempt at synthesized mouse/touch events.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user