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];
69Cocoa_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];
191 [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
192 withObject:[driverdata->nswindow contentView]
200SDL_FindWindowAtPoint(
const int x,
const int y)
215Cocoa_WarpMouseGlobal(
int x,
int y)
220 if ([
data->listener isMoving]) {
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);
276 if ([
data->listener isMoving]) {
283 result = CGAssociateMouseAndMouseCursorPosition(NO);
285 DLog(
"Turning off.");
286 result = CGAssociateMouseAndMouseCursorPosition(YES);
288 if (
result != kCGErrorSuccess) {
289 return SDL_SetError(
"CGAssociateMouseAndMouseCursorPosition() failed");
312Cocoa_GetGlobalMouseState(
int *
x,
int *
y)
314 const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
315 const NSPoint cocoaLocation = [NSEvent mouseLocation];
318 *
x = (int) cocoaLocation.x;
319 *
y = (
int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.
y);
335 if (driverdata ==
NULL) {
354 const NSPoint
location = [NSEvent mouseLocation];
364 case NSEventTypeMouseMoved:
365 case NSEventTypeLeftMouseDragged:
366 case NSEventTypeRightMouseDragged:
367 case NSEventTypeOtherMouseDragged:
385 const NSPoint
location = [NSEvent mouseLocation];
386 const CGFloat lastMoveX = driverdata->
lastMoveX;
387 const CGFloat lastMoveY = driverdata->
lastMoveY;
399 NSRect windowRect = [[[event window] contentView] frame];
400 if (!NSMouseInRect([
event locationInWindow], windowRect, NO)) {
405 float deltaX = [event deltaX];
406 float deltaY = [event deltaY];
409 deltaX += (lastMoveX - driverdata->lastWarpX);
410 deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
412 DLog(
"Motion was (%g, %g), offset to (%g, %g)", [
event deltaX], [
event deltaY], deltaX, deltaY);
427 CGFloat
x = -[
event deltaX];
428 CGFloat
y = [event deltaY];
431 if ([
event respondsToSelector:
@selector(isDirectionInvertedFromDevice)]) {
432 if ([
event isDirectionInvertedFromDevice] == YES) {
462 DLog(
"(%g, %g)",
x,
y);
#define SDL_assert(condition)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
void Cocoa_QuitMouse(_THIS)
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
int Cocoa_InitMouse(_THIS)
void Cocoa_InitMouseEventTap(SDL_MouseData *driverdata)
void Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
#define SDL_GetMouseFocus
#define SDL_OutOfMemory()
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
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
void SDL_SetMouseFocus(SDL_Window *window)
SDL_Mouse * SDL_GetMouse(void)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
@ SDL_SYSTEM_CURSOR_SIZENS
@ SDL_SYSTEM_CURSOR_ARROW
@ SDL_SYSTEM_CURSOR_SIZENWSE
@ SDL_SYSTEM_CURSOR_SIZENESW
@ SDL_SYSTEM_CURSOR_IBEAM
@ SDL_SYSTEM_CURSOR_WAITARROW
@ SDL_SYSTEM_CURSOR_SIZEALL
@ SDL_SYSTEM_CURSOR_SIZEWE
@ SDL_SYSTEM_CURSOR_CROSSHAIR
SDL_MouseWheelDirection
Scroll direction types for the Scroll event.
#define SDL_BUTTON_X1MASK
#define SDL_BUTTON_X2MASK
GLint GLint GLint GLint GLint GLint y
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
GLuint GLuint GLsizei GLenum type
GLenum GLenum GLsizei const GLuint GLboolean enabled
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
Returns true if point resides inside a rectangle.
SDL_VideoDevice * SDL_GetVideoDevice(void)
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)
NSCursor * invisibleCursor()
EGLSurface EGLNativeWindowType * window
static SDL_AudioDeviceID device
int(* SetRelativeMouseMode)(SDL_bool enabled)
void(* WarpMouse)(SDL_Window *window, int x, int y)
void(* FreeCursor)(SDL_Cursor *cursor)
int(* ShowCursor)(SDL_Cursor *cursor)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
int(* WarpMouseGlobal)(int x, int y)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
Uint32(* GetGlobalMouseState)(int *x, int *y)
int(* CaptureMouse)(SDL_Window *window)
The structure that defines a point (integer)
A rectangle, with the origin at the upper left (integer).
A collection of pixels used in software blitting.
The type used to identify a window.