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_SetDoubleClickTime (Uint32 interval)
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_SendMouseWheel (SDL_Window *window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
void | SDL_MouseQuit (void)

## Typedef Documentation

typedef Uint32 SDL_MouseID

Definition at line 28 of file SDL_mouse_c.h.

## Function Documentation

SDL_Mouse* SDL_GetMouse | ( | void |  | ) |

Definition at line 66 of file SDL_mouse.c.

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_PrivateSendMouseMotion(), SDL_ResetMouse(), SDL_SendMouseButton(), SDL_SendMouseMotion(), SDL_SendMouseWheel(), SDL_SetCursor(), SDL_SetDefaultCursor(), SDL_SetMouseFocus(), SDL_SetRelativeMouseMode(), SDL_ShowCursor(), SDL_UpdateMouseFocus(), SDL_UpdateWindowGrab(), SDL_WarpMouseGlobal(), and SDL_WarpMouseInWindow().

{
return &SDL_mouse;
}
SDL_mouse
static SDL_Mouse SDL_mouse
Definition: SDL_mouse.c:36

int SDL_MouseInit | ( | void |  | ) |

Definition at line 45 of file SDL_mouse.c.

References SDL_Mouse::cursor_shown, SDL_GetMouse(), and SDL_TRUE.

Referenced by SDL_VideoInit().

{
SDL_Mouse *mouse = SDL_GetMouse();
mouse->cursor_shown = SDL_TRUE;
return (0);
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_Mouse::cursor_shown
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:94
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_Mouse
Definition: SDL_mouse_c.h:43

void SDL_MouseQuit | ( | void |  | ) |

Definition at line 435 of file SDL_mouse.c.

References SDL_Mouse::CaptureMouse, SDL_Mouse::clickstate, cursor, SDL_Mouse::cursors, SDL_Mouse::def_cursor, SDL_Mouse::FreeCursor, SDL_Cursor::next, SDL_CaptureMouse(), SDL_FALSE, SDL_free(), SDL_FreeCursor(), SDL_GetMouse(), SDL_SetRelativeMouseMode(), SDL_ShowCursor(), and SDL_zerop.

Referenced by SDL_VideoQuit().

{
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;
}
if (mouse->def_cursor && mouse->FreeCursor) {
mouse->FreeCursor(mouse->def_cursor);
}
if (mouse->clickstate) {
SDL_free(mouse->clickstate);
}
SDL_zerop(mouse);
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_Mouse::clickstate
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:89
SDL_Cursor
Definition: SDL_mouse_c.h:30
SDL_ShowCursor
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:875
SDL_zerop
#define SDL_zerop(x)
Definition: SDL_stdinc.h:358
SDL_Mouse::cursors
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:91
SDL_CaptureMouse
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:628
SDL_Mouse::CaptureMouse
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
SDL_free
void SDL_free(void *mem)
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_Mouse::FreeCursor
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
SDL_Cursor::next
struct SDL_Cursor * next
Definition: SDL_mouse_c.h:32
SDL_SetRelativeMouseMode
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:571
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_Mouse
Definition: SDL_mouse_c.h:43
SDL_FreeCursor
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor().
Definition: SDL_mouse.c:841
SDL_Mouse::def_cursor
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92

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

Definition at line 326 of file SDL_mouse.c.

References button, SDL_Mouse::buttonstate, SDL_MouseClickState::click_count, SDL_Mouse::focus, GetMouseClickState(), SDL_Window::id, SDL_MouseClickState::last_timestamp, SDL_MouseClickState::last_x, SDL_MouseClickState::last_y, SDL_abs, SDL_BUTTON, SDL_double_click_radius, SDL_double_click_time, SDL_ENABLE, SDL_GetEventState, SDL_GetMouse(), SDL_GetTicks(), SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_PRESSED, SDL_PushEvent, SDL_RELEASED, SDL_TICKS_PASSED, SDL_UpdateMouseFocus(), state, SDL_Mouse::x, and SDL_Mouse::y.

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

{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
Uint32 type;
Uint32 buttonstate = mouse->buttonstate;
SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
Uint8 click_count;
/* Figure out which event to perform */
switch (state) {
case SDL_PRESSED:
type = SDL_MOUSEBUTTONDOWN;
buttonstate |= SDL_BUTTON(button);
break;
case SDL_RELEASED:
type = SDL_MOUSEBUTTONUP;
buttonstate &= ~SDL_BUTTON(button);
break;
default:
/* Invalid state -- bail */
return 0;
}
/* We do this after calculating buttonstate so button presses gain focus */
if (window && state == SDL_PRESSED) {
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
}
if (buttonstate == mouse->buttonstate) {
/* Ignore this event, no state change */
return 0;
}
mouse->buttonstate = buttonstate;
if (clickstate) {
if (state == SDL_PRESSED) {
Uint32 now = SDL_GetTicks();
if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
clickstate->click_count = 0;
}
clickstate->last_timestamp = now;
clickstate->last_x = mouse->x;
clickstate->last_y = mouse->y;
if (clickstate->click_count < 255) {
++clickstate->click_count;
}
}
click_count = clickstate->click_count;
} else {
click_count = 1;
}
/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(type) == SDL_ENABLE) {
SDL_Event event;
event.type = type;
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
event.button.which = mouseID;
event.button.state = state;
event.button.button = button;
event.button.clicks = click_count;
event.button.x = mouse->x;
event.button.y = mouse->y;
posted = (SDL_PushEvent(&event) > 0);
}
/* We do this after dispatching event so button releases can lose focus */
if (window && state == SDL_RELEASED) {
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
}
return posted;
}
SDL_abs
#define SDL_abs
Definition: SDL_dynapi_overrides.h:387
SDL_Mouse::y
int y
Definition: SDL_mouse_c.h:79
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
button
SDL_Texture * button
Definition: testgamecontroller.c:67
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_MOUSEBUTTONUP
Definition: SDL_events.h:104
SDL_MouseClickState::last_timestamp
Uint32 last_timestamp
Definition: SDL_mouse_c.h:39
SDL_Mouse::buttonstate
Uint32 buttonstate
Definition: SDL_mouse_c.h:83
SDL_Mouse::focus
SDL_Window * focus
Definition: SDL_mouse_c.h:77
state
struct xkb_state * state
Definition: SDL_waylandsym.h:97
SDL_MOUSEBUTTONDOWN
Definition: SDL_events.h:103
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_double_click_radius
static int SDL_double_click_radius
Definition: SDL_mouse.c:38
SDL_MouseClickState::click_count
Uint8 click_count
Definition: SDL_mouse_c.h:40
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1564
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
SDL_GetTicks
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_MouseClickState::last_x
int last_x
Definition: SDL_mouse_c.h:38
GetMouseClickState
static SDL_MouseClickState * GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
Definition: SDL_mouse.c:307
SDL_UpdateMouseFocus
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:140
SDL_Mouse::x
int x
Definition: SDL_mouse_c.h:78
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:74
SDL_BUTTON
#define SDL_BUTTON(X)
Definition: SDL_mouse.h:279
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_Mouse
Definition: SDL_mouse_c.h:43
SDL_MouseClickState::last_y
int last_y
Definition: SDL_mouse_c.h:38
SDL_MouseClickState
Definition: SDL_mouse_c.h:36
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_double_click_time
static Uint32 SDL_double_click_time
Definition: SDL_mouse.c:37
SDL_TICKS_PASSED
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
Definition: SDL_timer.h:56
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49

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

Definition at line 188 of file SDL_mouse.c.

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

Referenced by SDL_BApp::_HandleMouseMove(), IsSDLWindowEventPending(), and SDL_WarpMouseInWindow().

{
if (window && !relative) {
SDL_Mouse *mouse = SDL_GetMouse();
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
return 0;
}
}
return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_PrivateSendMouseMotion
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:201
SDL_Mouse::buttonstate
Uint32 buttonstate
Definition: SDL_mouse_c.h:83
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
SDL_UpdateMouseFocus
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:140
SDL_Mouse
Definition: SDL_mouse_c.h:43

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

Definition at line 406 of file SDL_mouse.c.

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

Referenced by SDL_BApp::_HandleMouseWheel().

{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
if (window) {
SDL_SetMouseFocus(window);
}
if (!x && !y) {
return 0;
}
/* 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;
event.wheel.x = x;
event.wheel.y = y;
event.wheel.direction = (Uint32)direction;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
SDL_Mouse::focus
SDL_Window * focus
Definition: SDL_mouse_c.h:77
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_SetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:103
SDL_MOUSEWHEEL
Definition: SDL_events.h:105
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:74
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_Mouse
Definition: SDL_mouse_c.h:43

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

Definition at line 55 of file SDL_mouse.c.

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

{
SDL_Mouse *mouse = SDL_GetMouse();
mouse->def_cursor = cursor;
if (!mouse->cur_cursor) {
SDL_SetCursor(cursor);
}
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_SetCursor
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:779
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_Mouse
Definition: SDL_mouse_c.h:43
SDL_Mouse::cur_cursor
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:93
SDL_Mouse::def_cursor
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92

void SDL_SetDoubleClickTime | ( | Uint32 | interval | ) |

Definition at line 72 of file SDL_mouse.c.

References SDL_double_click_time.

{
SDL_double_click_time = interval;
}
SDL_double_click_time
static Uint32 SDL_double_click_time
Definition: SDL_mouse.c:37

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

Definition at line 103 of file SDL_mouse.c.

References SDL_Mouse::focus, NULL, SDL_GetMouse(), SDL_ResetMouse(), SDL_SendWindowEvent(), SDL_SetCursor(), SDL_WINDOWEVENT_ENTER, SDL_WINDOWEVENT_LEAVE, and window.

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

{
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;
if (mouse->focus) {
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
}
/* Update cursor visibility */
SDL_SetCursor(NULL);
}
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_Mouse::focus
SDL_Window * focus
Definition: SDL_mouse_c.h:77
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_SetCursor
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:779
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_ResetMouse
void SDL_ResetMouse(void)
Definition: SDL_mouse.c:86
SDL_WINDOWEVENT_LEAVE
Definition: SDL_video.h:154
NULL
#define NULL
Definition: begin_code.h:143
SDL_WINDOWEVENT_ENTER
Definition: SDL_video.h:153
SDL_Mouse
Definition: SDL_mouse_c.h:43