21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_COCOA 31 #include "../../events/SDL_mouse_c.h" 35 #ifdef DEBUG_COCOAMOUSE 36 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) 38 #define DLog(...) do { } while (0) 47 static unsigned char cursorBytes[] = {
48 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
50 0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
51 0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
52 0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
55 NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
56 length:sizeof(cursorBytes)
58 NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
69 Cocoa_CreateDefaultCursor()
75 nscursor = [NSCursor arrowCursor];
93 NSCursor *nscursor =
NULL;
98 nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
117 NSCursor *nscursor =
NULL;
122 nscursor = [NSCursor arrowCursor];
125 nscursor = [NSCursor IBeamCursor];
128 nscursor = [NSCursor arrowCursor];
131 nscursor = [NSCursor crosshairCursor];
134 nscursor = [NSCursor arrowCursor];
138 nscursor = [NSCursor closedHandCursor];
141 nscursor = [NSCursor resizeLeftRightCursor];
144 nscursor = [NSCursor resizeUpDownCursor];
147 nscursor = [NSCursor closedHandCursor];
150 nscursor = [NSCursor operationNotAllowedCursor];
153 nscursor = [NSCursor pointingHandCursor];
176 NSCursor *nscursor = (NSCursor *)cursor->
driverdata;
188 for (; window !=
NULL; window = window->
next) {
191 [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
192 withObject:[driverdata->nswindow contentView]
200 SDL_FindWindowAtPoint(
const int x,
const int y)
215 Cocoa_WarpMouseGlobal(
int x,
int y)
221 DLog(
"Postponing warp, window being moved.");
222 [data->listener setPendingMoveX:x Y:y];
226 const CGPoint point = CGPointMake((
float)x, (
float)y);
230 CGWarpMouseCursorPosition(point);
237 CGAssociateMouseAndMouseCursorPosition(YES);
244 SDL_Window *win = SDL_FindWindowAtPoint(x, y);
256 Cocoa_WarpMouse(
SDL_Window * window,
int x,
int y)
258 Cocoa_WarpMouseGlobal(x + window->
x, y + window->
y);
283 result = CGAssociateMouseAndMouseCursorPosition(NO);
285 DLog(
"Turning off.");
286 result = CGAssociateMouseAndMouseCursorPosition(YES);
288 if (result != kCGErrorSuccess) {
289 return SDL_SetError(
"CGAssociateMouseAndMouseCursorPosition() failed");
312 Cocoa_GetGlobalMouseState(
int *x,
int *y)
314 const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
315 const NSPoint cocoaLocation = [NSEvent mouseLocation];
318 for (NSScreen *
screen in [NSScreen screens]) {
319 NSRect
frame = [screen frame];
320 if (NSMouseInRect(cocoaLocation, frame, NO)) {
321 *x = (int) cocoaLocation.x;
322 *y = (
int) ((frame.origin.y + frame.
size.
height) - cocoaLocation.y);
358 const NSPoint
location = [NSEvent mouseLocation];
366 switch ([event
type]) {
367 case NSEventTypeMouseMoved:
368 case NSEventTypeLeftMouseDragged:
369 case NSEventTypeRightMouseDragged:
370 case NSEventTypeOtherMouseDragged:
387 const NSPoint
location = [NSEvent mouseLocation];
388 const CGFloat lastMoveX = driverdata->
lastMoveX;
389 const CGFloat lastMoveY = driverdata->
lastMoveY;
392 DLog(
"Last seen mouse: (%g, %g)", location.x, location.y);
400 if ([event window]) {
401 NSRect windowRect = [[[event window] contentView] frame];
402 if (!NSMouseInRect([event locationInWindow], windowRect, NO)) {
407 float deltaX = [event deltaX];
408 float deltaY = [event deltaY];
411 deltaX += (lastMoveX - driverdata->lastWarpX);
412 deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
414 DLog(
"Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
425 CGFloat x = -[event deltaX];
426 CGFloat y = [event deltaY];
429 if ([event respondsToSelector:
@selector(isDirectionInvertedFromDevice)]) {
430 if ([event isDirectionInvertedFromDevice] == YES) {
449 DLog(
"(%g, %g)", x, y);
void Cocoa_InitMouse(_THIS)
GLdouble GLdouble GLdouble r
SDL_Mouse * SDL_GetMouse(void)
int(* ShowCursor)(SDL_Cursor *cursor)
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
#define SDL_BUTTON_X2MASK
The structure that defines a point.
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Uint32(* GetGlobalMouseState)(int *x, int *y)
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
Returns true if point resides inside a rectangle.
void SDL_SetMouseFocus(SDL_Window *window)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
static SDL_AudioDeviceID device
int(* CaptureMouse)(SDL_Window *window)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
void Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
void Cocoa_QuitMouse(_THIS)
Cocoa_WindowListener * listener
#define SDL_BUTTON_X1MASK
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
NSCursor * invisibleCursor()
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
GLint GLint GLint GLint GLint GLint y
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_assert(condition)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
#define SDL_GetMouseFocus
GLint GLint GLsizei GLsizei height
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
SDL_MouseWheelDirection
Scroll direction types for the Scroll event.
void Cocoa_InitMouseEventTap(SDL_MouseData *driverdata)
A rectangle, with the origin at the upper left.
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x