Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
cde0d1bc
Commit
cde0d1bc
authored
Feb 28, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented mouse relative mode on Mac OS X.
parent
9959455a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
22 deletions
+53
-22
SDL_mouse.c
src/events/SDL_mouse.c
+15
-2
SDL_mouse_c.h
src/events/SDL_mouse_c.h
+3
-0
SDL_cocoamouse.m
src/video/cocoa/SDL_cocoamouse.m
+26
-2
SDL_cocoawindow.m
src/video/cocoa/SDL_cocoawindow.m
+2
-17
common.c
test/common.c
+7
-1
No files found.
src/events/SDL_mouse.c
View file @
cde0d1bc
...
@@ -308,8 +308,18 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
...
@@ -308,8 +308,18 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
{
{
SDL_Mouse
*
mouse
=
SDL_GetMouse
();
SDL_Mouse
*
mouse
=
SDL_GetMouse
();
/* Flush pending mouse motion */
if
(
enabled
==
mouse
->
relative_mode
)
{
SDL_FlushEvent
(
SDL_MOUSEMOTION
);
return
0
;
}
if
(
!
mouse
->
SetRelativeMouseMode
)
{
SDL_Unsupported
();
return
-
1
;
}
if
(
mouse
->
SetRelativeMouseMode
(
enabled
)
<
0
)
{
return
-
1
;
}
/* Set the relative mode */
/* Set the relative mode */
mouse
->
relative_mode
=
enabled
;
mouse
->
relative_mode
=
enabled
;
...
@@ -319,6 +329,9 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
...
@@ -319,6 +329,9 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
SDL_WarpMouseInWindow
(
mouse
->
focus
,
mouse
->
x
,
mouse
->
y
);
SDL_WarpMouseInWindow
(
mouse
->
focus
,
mouse
->
x
,
mouse
->
y
);
}
}
/* Flush pending mouse motion */
SDL_FlushEvent
(
SDL_MOUSEMOTION
);
/* Update cursor visibility */
/* Update cursor visibility */
SDL_SetCursor
(
NULL
);
SDL_SetCursor
(
NULL
);
...
...
src/events/SDL_mouse_c.h
View file @
cde0d1bc
...
@@ -49,6 +49,9 @@ typedef struct
...
@@ -49,6 +49,9 @@ typedef struct
/* Warp the mouse to (x,y) */
/* Warp the mouse to (x,y) */
void
(
*
WarpMouse
)
(
SDL_Window
*
window
,
int
x
,
int
y
);
void
(
*
WarpMouse
)
(
SDL_Window
*
window
,
int
x
,
int
y
);
/* Set relative mode */
int
(
*
SetRelativeMouseMode
)
(
SDL_bool
enabled
);
/* Data common to all mice */
/* Data common to all mice */
SDL_Window
*
focus
;
SDL_Window
*
focus
;
int
x
;
int
x
;
...
...
src/video/cocoa/SDL_cocoamouse.m
View file @
cde0d1bc
...
@@ -116,6 +116,23 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
...
@@ -116,6 +116,23 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
CGWarpMouseCursorPosition
(
point
)
;
CGWarpMouseCursorPosition
(
point
)
;
}
}
static
int
Cocoa
_
SetRelativeMouseMode
(
SDL
_
bool
enabled
)
{
CGError
result
;
if
(
enabled
)
{
result
=
CGAssociateMouseAndMouseCursorPosition
(
NO
)
;
}
else
{
result
=
CGAssociateMouseAndMouseCursorPosition
(
YES
)
;
}
if
(
result
!=
kCGErrorSuccess
)
{
SDL
_
SetError
(
"CGAssociateMouseAndMouseCursorPosition() failed"
)
;
return
-
1
;
}
return
0
;
}
void
void
Cocoa
_
InitMouse
(
_
THIS
)
Cocoa
_
InitMouse
(
_
THIS
)
{
{
...
@@ -123,8 +140,9 @@ Cocoa_InitMouse(_THIS)
...
@@ -123,8 +140,9 @@ Cocoa_InitMouse(_THIS)
mouse
->
CreateCursor
=
Cocoa
_
CreateCursor
;
mouse
->
CreateCursor
=
Cocoa
_
CreateCursor
;
mouse
->
ShowCursor
=
Cocoa
_
ShowCursor
;
mouse
->
ShowCursor
=
Cocoa
_
ShowCursor
;
mouse
->
WarpMouse
=
Cocoa
_
WarpMouse
;
mouse
->
FreeCursor
=
Cocoa
_
FreeCursor
;
mouse
->
FreeCursor
=
Cocoa
_
FreeCursor
;
mouse
->
WarpMouse
=
Cocoa
_
WarpMouse
;
mouse
->
SetRelativeMouseMode
=
Cocoa
_
SetRelativeMouseMode
;
SDL
_
SetDefaultCursor
(
Cocoa
_
CreateDefaultCursor
())
;
SDL
_
SetDefaultCursor
(
Cocoa
_
CreateDefaultCursor
())
;
}
}
...
@@ -147,7 +165,13 @@ ConvertMouseButtonToSDL(int button)
...
@@ -147,7 +165,13 @@ ConvertMouseButtonToSDL(int button)
void
void
Cocoa
_
HandleMouseEvent
(
_
THIS
,
NSEvent
*
event
)
Cocoa
_
HandleMouseEvent
(
_
THIS
,
NSEvent
*
event
)
{
{
/*
We
'
re
correctly
using
views
even
in
fullscreen
mode
now
*/
SDL
_
Mouse
*
mouse
=
SDL
_
GetMouse
()
;
if
(
mouse
->
relative
_
mode
&&
[
event
type
]
==
NSMouseMoved
)
{
float
x
=
[
event
deltaX
]
;
float
y
=
[
event
deltaY
]
;
SDL
_
SendMouseMotion
(
mouse
->
focus
,
1
,
(
int
)
x
,
(
int
)
y
)
;
}
}
}
void
void
...
...
src/video/cocoa/SDL_cocoawindow.m
View file @
cde0d1bc
...
@@ -302,15 +302,14 @@ static __inline__ void ConvertNSRect(NSRect *r)
...
@@ -302,15 +302,14 @@ static __inline__ void ConvertNSRect(NSRect *r)
-
(
void
)
mouseMoved
:
(
NSEvent
*
)
theEvent
-
(
void
)
mouseMoved
:
(
NSEvent
*
)
theEvent
{
{
SDL_Mouse
*
mouse
=
SDL_GetMouse
();
SDL_Window
*
window
=
_data
->
window
;
SDL_Window
*
window
=
_data
->
window
;
NSPoint
point
;
NSPoint
point
;
int
x
,
y
;
int
x
,
y
;
#ifdef RELATIVE_MOTION
if
(
mouse
->
relative_mode
)
{
if
(
window
->
flags
&
SDL_WINDOW_INPUT_GRABBED
)
{
return
;
return
;
}
}
#endif
point
=
[
theEvent
locationInWindow
];
point
=
[
theEvent
locationInWindow
];
x
=
(
int
)
point
.
x
;
x
=
(
int
)
point
.
x
;
...
@@ -861,19 +860,6 @@ NSPoint origin;
...
@@ -861,19 +860,6 @@ NSPoint origin;
void
void
Cocoa_SetWindowGrab
(
_THIS
,
SDL_Window
*
window
)
Cocoa_SetWindowGrab
(
_THIS
,
SDL_Window
*
window
)
{
{
#ifdef RELATIVE_MOTION
/* FIXME: work in progress
You set relative mode by using the following code in conjunction with
CGDisplayHideCursor(kCGDirectMainDisplay) and
CGDisplayShowCursor(kCGDirectMainDisplay)
*/
if
((
window
->
flags
&
SDL_WINDOW_INPUT_GRABBED
)
&&
(
window
->
flags
&
SDL_WINDOW_INPUT_FOCUS
))
{
CGAssociateMouseAndMouseCursorPosition
(
NO
);
}
else
{
CGAssociateMouseAndMouseCursorPosition
(
YES
);
}
#else
/* Move the cursor to the nearest point in the window */
/* Move the cursor to the nearest point in the window */
if
((
window
->
flags
&
SDL_WINDOW_INPUT_GRABBED
)
&&
if
((
window
->
flags
&
SDL_WINDOW_INPUT_GRABBED
)
&&
(
window
->
flags
&
SDL_WINDOW_INPUT_FOCUS
))
{
(
window
->
flags
&
SDL_WINDOW_INPUT_FOCUS
))
{
...
@@ -885,7 +871,6 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
...
@@ -885,7 +871,6 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
cgpoint
.
y
=
window
->
y
+
y
;
cgpoint
.
y
=
window
->
y
+
y
;
CGDisplayMoveCursorToPoint
(
kCGDirectMainDisplay
,
cgpoint
);
CGDisplayMoveCursorToPoint
(
kCGDirectMainDisplay
,
cgpoint
);
}
}
#endif
}
}
void
void
...
...
test/common.c
View file @
cde0d1bc
...
@@ -812,7 +812,7 @@ PrintEvent(SDL_Event * event)
...
@@ -812,7 +812,7 @@ PrintEvent(SDL_Event * event)
{
{
if
(
event
->
type
==
SDL_MOUSEMOTION
)
{
if
(
event
->
type
==
SDL_MOUSEMOTION
)
{
/* Mouse motion is really spammy */
/* Mouse motion is really spammy */
return
;
//
return;
}
}
fprintf
(
stderr
,
"SDL EVENT: "
);
fprintf
(
stderr
,
"SDL EVENT: "
);
...
@@ -1044,6 +1044,12 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
...
@@ -1044,6 +1044,12 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
}
}
}
}
break
;
break
;
case
SDLK_r
:
if
(
event
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
{
/* Ctrl-R toggle mouse relative mode */
SDL_SetRelativeMouseMode
(
!
SDL_GetRelativeMouseMode
());
}
break
;
case
SDLK_z
:
case
SDLK_z
:
if
(
event
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
{
if
(
event
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
{
/* Ctrl-Z minimize */
/* Ctrl-Z minimize */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment