21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_COCOA
30 #include "../../events/SDL_mouse_c.h"
34 #ifdef DEBUG_COCOAMOUSE
35 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
37 #define DLog(...) do { } while (0)
46 static unsigned char cursorBytes[] = {
47 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
49 0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
50 0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
51 0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
54 NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
55 length:sizeof(cursorBytes)
57 NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
68 Cocoa_CreateDefaultCursor()
74 nscursor = [NSCursor arrowCursor];
92 NSCursor *nscursor =
NULL;
97 nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
116 NSCursor *nscursor =
NULL;
121 nscursor = [NSCursor arrowCursor];
124 nscursor = [NSCursor IBeamCursor];
127 nscursor = [NSCursor arrowCursor];
130 nscursor = [NSCursor crosshairCursor];
133 nscursor = [NSCursor arrowCursor];
137 nscursor = [NSCursor closedHandCursor];
140 nscursor = [NSCursor resizeLeftRightCursor];
143 nscursor = [NSCursor resizeUpDownCursor];
146 nscursor = [NSCursor closedHandCursor];
149 nscursor = [NSCursor operationNotAllowedCursor];
152 nscursor = [NSCursor pointingHandCursor];
190 [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
191 withObject:[driverdata->nswindow contentView]
199 SDL_FindWindowAtPoint(
const int x,
const int y)
214 Cocoa_WarpMouseGlobal(
int x,
int y)
219 if ([
data->listener isMoving]) {
220 DLog(
"Postponing warp, window being moved.");
221 [data->listener setPendingMoveX:x Y:y];
225 const CGPoint point = CGPointMake((
float)
x, (
float)
y);
229 CGWarpMouseCursorPosition(point);
236 CGAssociateMouseAndMouseCursorPosition(YES);
275 if ([
data->listener isMoving]) {
282 result = CGAssociateMouseAndMouseCursorPosition(NO);
284 DLog(
"Turning off.");
285 result = CGAssociateMouseAndMouseCursorPosition(YES);
287 if (
result != kCGErrorSuccess) {
288 return SDL_SetError(
"CGAssociateMouseAndMouseCursorPosition() failed");
311 Cocoa_GetGlobalMouseState(
int *
x,
int *
y)
313 const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
314 const NSPoint cocoaLocation = [NSEvent mouseLocation];
317 *
x = (
int) cocoaLocation.x;
318 *
y = (
int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.
y);
334 if (driverdata ==
NULL) {
353 const NSPoint
location = [NSEvent mouseLocation];
363 case NSEventTypeMouseMoved:
364 case NSEventTypeLeftMouseDragged:
365 case NSEventTypeRightMouseDragged:
366 case NSEventTypeOtherMouseDragged:
384 const NSPoint
location = [NSEvent mouseLocation];
385 const CGFloat lastMoveX = driverdata->
lastMoveX;
386 const CGFloat lastMoveY = driverdata->
lastMoveY;
398 NSRect windowRect = [[[event window] contentView] frame];
399 if (!NSMouseInRect([
event locationInWindow], windowRect, NO)) {
404 float deltaX = [event deltaX];
405 float deltaY = [event deltaY];
408 deltaX += (lastMoveX - driverdata->lastWarpX);
409 deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
411 DLog(
"Motion was (%g, %g), offset to (%g, %g)", [
event deltaX], [
event deltaY], deltaX, deltaY);
426 CGFloat
x = -[
event deltaX];
427 CGFloat
y = [event deltaY];
430 if ([
event respondsToSelector:
@selector(isDirectionInvertedFromDevice)]) {
431 if ([
event isDirectionInvertedFromDevice] == YES) {
461 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
SDL_Mouse * SDL_GetMouse(void)
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
void SDL_SetMouseFocus(SDL_Window *window)
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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
int(* SetRelativeMouseMode)(SDL_bool enabled)
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
void(* FreeCursor)(SDL_Cursor *cursor)
int(* ShowCursor)(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
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.
typedef int(__stdcall *FARPROC)()