SDL_mouse_c.h File Reference
`#include "../SDL_internal.h"`
`#include "SDL_mouse.h"`
Include dependency graph for SDL_mouse_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | SDL_Cursor
struct | SDL_MouseClickState
struct | SDL_Mouse

## Typedefs

typedef Uint32 | SDL_MouseID

## Functions

int | SDL_MouseInit (void)
SDL_Mouse * | SDL_GetMouse (void)
void | SDL_SetDefaultCursor (SDL_Cursor *cursor)
void | SDL_SetMouseFocus (SDL_Window *window)
int | SDL_SendMouseMotion (SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
int | SDL_SendMouseButton (SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
int | SDL_SendMouseButtonClicks (SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int | SDL_SendMouseWheel (SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
void | SDL_MouseQuit (void)

## Typedef Documentation

## SDL_MouseID

typedef Uint32 SDL_MouseID

Definition at line 28 of file SDL_mouse_c.h.

## Function Documentation

## SDL_GetMouse()

SDL_Mouse* SDL_GetMouse | ( | void |  | ) |

Definition at line 178 of file SDL_mouse.c.

{
return &SDL_mouse;
}

References SDL_mouse.

Referenced by SDL_CaptureMouse(), SDL_CreateColorCursor(), SDL_CreateSystemCursor(), SDL_FreeCursor(), SDL_GetCursor(), SDL_GetDefaultCursor(), SDL_GetGlobalMouseState(), SDL_GetMouseFocus(), SDL_GetMouseState(), SDL_GetRelativeMouseMode(), SDL_GetRelativeMouseState(), SDL_MouseInit(), SDL_MouseQuit(), SDL_OnWindowFocusGained(), SDL_PrivateSendMouseButton(), SDL_PrivateSendMouseMotion(), SDL_SendMouseMotion(), SDL_SendMouseWheel(), SDL_SendTouch(), SDL_SendTouchMotion(), SDL_SetCursor(), SDL_SetDefaultCursor(), SDL_SetMouseFocus(), SDL_SetRelativeMouseMode(), SDL_ShowCursor(), SDL_UpdateMouseFocus(), SDL_UpdateWindowGrab(), SDL_WarpMouseGlobal(), and SDL_WarpMouseInWindow().

## SDL_MouseInit()

int SDL_MouseInit | ( | void |  | ) |

Definition at line 135 of file SDL_mouse.c.

{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_zerop(mouse);
SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
SDL_MouseDoubleClickTimeChanged, mouse);
SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
SDL_MouseDoubleClickRadiusChanged, mouse);
SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
SDL_MouseNormalSpeedScaleChanged, mouse);
SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
SDL_MouseRelativeSpeedScaleChanged, mouse);
SDL_AddHintCallback(SDL_HINT_TOUCH_MOUSE_EVENTS,
SDL_TouchMouseEventsChanged, mouse);
SDL_AddHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
SDL_MouseTouchEventsChanged, mouse);
mouse->was_touch_mouse_events = SDL_FALSE; /* no touch to mouse movement event pending */
mouse->cursor_shown = SDL_TRUE;
return (0);
}

References SDL_Mouse::cursor_shown, SDL_AddHintCallback, SDL_FALSE, SDL_GetMouse(), SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS, SDL_HINT_MOUSE_DOUBLE_CLICK_TIME, SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_HINT_MOUSE_TOUCH_EVENTS, SDL_HINT_TOUCH_MOUSE_EVENTS, SDL_MouseDoubleClickRadiusChanged(), SDL_MouseDoubleClickTimeChanged(), SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_MouseTouchEventsChanged(), SDL_TouchMouseEventsChanged(), SDL_TRUE, SDL_zerop, and SDL_Mouse::was_touch_mouse_events.

Referenced by SDL_VideoInit().

## SDL_MouseQuit()

void SDL_MouseQuit | ( | void |  | ) |

Definition at line 665 of file SDL_mouse.c.

{
SDL_Cursor *cursor, *next;
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->CaptureMouse) {
SDL_CaptureMouse(SDL_FALSE);
}
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_ShowCursor(1);
cursor = mouse->cursors;
while (cursor) {
next = cursor->next;
SDL_FreeCursor(cursor);
cursor = next;
}
mouse->cursors = NULL;
mouse->cur_cursor = NULL;
if (mouse->def_cursor && mouse->FreeCursor) {
mouse->FreeCursor(mouse->def_cursor);
mouse->def_cursor = NULL;
}
if (mouse->clickstate) {
SDL_free(mouse->clickstate);
mouse->clickstate = NULL;
}
SDL_DelHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
SDL_MouseNormalSpeedScaleChanged, mouse);
SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
SDL_MouseRelativeSpeedScaleChanged, mouse);
}

References SDL_Mouse::CaptureMouse, SDL_Mouse::clickstate, SDL_Mouse::cur_cursor, cursor, SDL_Mouse::cursors, SDL_Mouse::def_cursor, SDL_Mouse::FreeCursor, SDL_Cursor::next, NULL, SDL_CaptureMouse(), SDL_DelHintCallback, SDL_FALSE, SDL_free, SDL_FreeCursor(), SDL_GetMouse(), SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_SetRelativeMouseMode(), and SDL_ShowCursor().

Referenced by SDL_VideoQuit().

## SDL_SendMouseButton()

int SDL_SendMouseButton | ( | SDL_Window * | window,
|  | SDL_MouseID | mouseID,
|  | Uint8 | state,
|  | Uint8 | button
| ) |  |

Definition at line 605 of file SDL_mouse.c.

{
return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
}

References button, SDL_PrivateSendMouseButton(), and state.

Referenced by SDL_BApp::_HandleMouseButton(), and SDL_SendTouch().

## SDL_SendMouseButtonClicks()

int SDL_SendMouseButtonClicks | ( | SDL_Window * | window,
|  | SDL_MouseID | mouseID,
|  | Uint8 | state,
|  | Uint8 | button,
|  | int | clicks
| ) |  |

Definition at line 598 of file SDL_mouse.c.

{
clicks = SDL_max(clicks, 0);
return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
}

References button, SDL_max, SDL_PrivateSendMouseButton(), and state.

## SDL_SendMouseMotion()

int SDL_SendMouseMotion | ( | SDL_Window * | window,
|  | SDL_MouseID | mouseID,
|  | int | relative,
|  | int | x,
|  | int | y
| ) |  |

Definition at line 301 of file SDL_mouse.c.

{
if (window && !relative) {
SDL_Mouse *mouse = SDL_GetMouse();
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
return 0;
}
}
return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
}

References SDL_Mouse::buttonstate, SDL_FALSE, SDL_GetMouse(), SDL_PrivateSendMouseMotion(), SDL_TOUCH_MOUSEID, SDL_TRUE, and SDL_UpdateMouseFocus().

Referenced by SDL_BApp::_HandleMouseMove(), SDL_SendTouch(), SDL_SendTouchMotion(), and SDL_WarpMouseInWindow().

## SDL_SendMouseWheel()

int SDL_SendMouseWheel | ( | SDL_Window * | window,
|  | SDL_MouseID | mouseID,
|  | float | x,
|  | float | y,
|  | SDL_MouseWheelDirection | direction
| ) |  |

Definition at line 611 of file SDL_mouse.c.

{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
int integral_x, integral_y;
if (window) {
SDL_SetMouseFocus(window);
}
if (x == 0.0f && y == 0.0f) {
return 0;
}
mouse->accumulated_wheel_x += x;
if (mouse->accumulated_wheel_x > 0) {
integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
} else if (mouse->accumulated_wheel_x < 0) {
integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
} else {
integral_x = 0;
}
mouse->accumulated_wheel_x -= integral_x;
mouse->accumulated_wheel_y += y;
if (mouse->accumulated_wheel_y > 0) {
integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
} else if (mouse->accumulated_wheel_y < 0) {
integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
} else {
integral_y = 0;
}
mouse->accumulated_wheel_y -= integral_y;
/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_MOUSEWHEEL;
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
event.wheel.which = mouseID;
#if 0 /* Uncomment this when it goes in for SDL 2.1 */
event.wheel.preciseX = x;
event.wheel.preciseY = y;
#endif
event.wheel.x = integral_x;
event.wheel.y = integral_y;
event.wheel.direction = (Uint32)direction;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
}

References SDL_Mouse::accumulated_wheel_x, SDL_Mouse::accumulated_wheel_y, SDL_Mouse::focus, SDL_Window::id, SDL_ceil, SDL_ENABLE, SDL_floor, SDL_GetEventState, SDL_GetMouse(), SDL_MOUSEWHEEL, SDL_PushEvent, and SDL_SetMouseFocus().

Referenced by SDL_BApp::_HandleMouseWheel().

## SDL_SetDefaultCursor()

void SDL_SetDefaultCursor | ( | SDL_Cursor * | cursor | ) |

Definition at line 167 of file SDL_mouse.c.

{
SDL_Mouse *mouse = SDL_GetMouse();
mouse->def_cursor = cursor;
if (!mouse->cur_cursor) {
SDL_SetCursor(cursor);
}
}

References SDL_Mouse::cur_cursor, cursor, SDL_Mouse::def_cursor, SDL_GetMouse(), and SDL_SetCursor().

## SDL_SetMouseFocus()

void SDL_SetMouseFocus | ( | SDL_Window * | window | ) |

Definition at line 211 of file SDL_mouse.c.

{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus == window) {
return;
}
/* Actually, this ends up being a bad idea, because most operating
systems have an implicit grab when you press the mouse button down
so you can drag things out of the window and then get the mouse up
when it happens. So, #if 0...
*/
#if 0
if (mouse->focus && !window) {
/* We won't get anymore mouse messages, so reset mouse state */
SDL_ResetMouse();
}
#endif
/* See if the current window has lost focus */
if (mouse->focus) {
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
}
mouse->focus = window;
mouse->has_position = SDL_FALSE;
if (mouse->focus) {
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
}
/* Update cursor visibility */
SDL_SetCursor(NULL);
}

References SDL_Mouse::focus, SDL_Mouse::has_position, NULL, SDL_FALSE, SDL_GetMouse(), SDL_SendWindowEvent(), SDL_SetCursor(), SDL_WINDOWEVENT_ENTER, and SDL_WINDOWEVENT_LEAVE.

Referenced by SDL_BApp::_HandleMouseFocus(), SDL_DestroyWindow(), SDL_OnWindowFocusGained(), SDL_SendMouseWheel(), SDL_SetRelativeMouseMode(), and SDL_UpdateMouseFocus().

SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_Mouse::CaptureMouse
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
SDL_Mouse::buttonstate
Uint32 buttonstate
Definition: SDL_mouse_c.h:85
SDL_Cursor
Definition: SDL_mouse_c.h:30
SDL_HINT_TOUCH_MOUSE_EVENTS
#define SDL_HINT_TOUCH_MOUSE_EVENTS
A variable controlling whether touch events should generate synthetic mouse events.
Definition: SDL_hints.h:316
SDL_Mouse::cursors
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:103
SDL_ceil
#define SDL_ceil
Definition: SDL_dynapi_overrides.h:426
NULL
#define NULL
Definition: begin_code.h:167
SDL_TouchMouseEventsChanged
static void SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:99
SDL_PrivateSendMouseMotion
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:329
SDL_zerop
#define SDL_zerop(x)
Definition: SDL_stdinc.h:417
SDL_MouseDoubleClickTimeChanged
static void SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:47
SDL_WINDOWEVENT_ENTER
@ SDL_WINDOWEVENT_ENTER
Definition: SDL_video.h:163
SDL_MouseNormalSpeedScaleChanged
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:75
SDL_Mouse::accumulated_wheel_x
float accumulated_wheel_x
Definition: SDL_mouse_c.h:83
SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
A variable setting the double click radius, in pixels.
Definition: SDL_hints.h:273
SDL_SetCursor
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:1012
SDL_floor
#define SDL_floor
Definition: SDL_dynapi_overrides.h:431
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:759
SDL_SetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:211
SDL_ShowCursor
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1108
SDL_MouseTouchEventsChanged
static void SDL_MouseTouchEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:111
SDL_TOUCH_MOUSEID
#define SDL_TOUCH_MOUSEID
Definition: SDL_touch.h:61
SDL_Mouse::was_touch_mouse_events
SDL_bool was_touch_mouse_events
Definition: SDL_mouse_c.h:97
SDL_CaptureMouse
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:861
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_UpdateMouseFocus
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
Definition: SDL_mouse.c:249
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
f
GLfloat f
Definition: SDL_opengl_glext.h:1870
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_max
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
SDL_mouse
static SDL_Mouse SDL_mouse
Definition: SDL_mouse.c:38
SDL_Mouse::def_cursor
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:104
SDL_MOUSEWHEEL
@ SDL_MOUSEWHEEL
Definition: SDL_events.h:108
SDL_Cursor::next
struct SDL_Cursor * next
Definition: SDL_mouse_c.h:32
SDL_Mouse
Definition: SDL_mouse_c.h:43
SDL_MouseDoubleClickRadiusChanged
static void SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:63
SDL_Mouse::focus
SDL_Window * focus
Definition: SDL_mouse_c.h:77
SDL_Mouse::accumulated_wheel_y
float accumulated_wheel_y
Definition: SDL_mouse_c.h:84
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_SetRelativeMouseMode
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:799
SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
A variable setting the double click time, in milliseconds.
Definition: SDL_hints.h:268
SDL_MouseRelativeSpeedScaleChanged
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:87
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:192
SDL_Mouse::clickstate
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:101
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:76
SDL_HINT_MOUSE_TOUCH_EVENTS
#define SDL_HINT_MOUSE_TOUCH_EVENTS
A variable controlling whether mouse events should generate synthetic touch events.
Definition: SDL_hints.h:326
SDL_Mouse::has_position
SDL_bool has_position
Definition: SDL_mouse_c.h:86
SDL_Mouse::FreeCursor
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
SDL_HINT_MOUSE_NORMAL_SPEED_SCALE
#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE
A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in rela...
Definition: SDL_hints.h:278
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_FreeCursor
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:1074
SDL_Event
General event structure.
Definition: SDL_events.h:557
SDL_DelHintCallback
#define SDL_DelHintCallback
Definition: SDL_dynapi_overrides.h:193
state
struct xkb_state * state
Definition: SDL_waylandsym.h:113
button
SDL_Texture * button
Definition: testgamecontroller.c:67
SDL_Mouse::cur_cursor
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:105
SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode.
Definition: SDL_hints.h:283
SDL_WINDOWEVENT_LEAVE
@ SDL_WINDOWEVENT_LEAVE
Definition: SDL_video.h:164
SDL_Mouse::cursor_shown
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:106
SDL_PrivateSendMouseButton
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:494