mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 06:28:24 +02:00
Updated raw input events to match SDL style
Also added raw keyboard events, and implemented raw input events on iOS, OpenBSD console, Linux console, and X11
This commit is contained in:
@@ -62,6 +62,8 @@ SDL_EventCategory SDL_GetEventCategory(Uint32 type)
|
||||
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
case SDL_EVENT_KEY_UP:
|
||||
case SDL_EVENT_RAW_KEY_DOWN:
|
||||
case SDL_EVENT_RAW_KEY_UP:
|
||||
return SDL_EVENTCATEGORY_KEY;
|
||||
|
||||
case SDL_EVENT_TEXT_EDITING:
|
||||
@@ -78,13 +80,17 @@ SDL_EventCategory SDL_GetEventCategory(Uint32 type)
|
||||
return SDL_EVENTCATEGORY_EDIT_CANDIDATES;
|
||||
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
case SDL_EVENT_RAW_MOUSE_MOTION:
|
||||
return SDL_EVENTCATEGORY_MOTION;
|
||||
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
case SDL_EVENT_RAW_MOUSE_BUTTON_DOWN:
|
||||
case SDL_EVENT_RAW_MOUSE_BUTTON_UP:
|
||||
return SDL_EVENTCATEGORY_BUTTON;
|
||||
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
case SDL_EVENT_RAW_MOUSE_WHEEL:
|
||||
return SDL_EVENTCATEGORY_WHEEL;
|
||||
|
||||
case SDL_EVENT_MOUSE_ADDED:
|
||||
|
||||
@@ -390,7 +390,7 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||
// sensor/mouse/pen/finger motion are spammy, ignore these if they aren't demanded.
|
||||
if ((SDL_EventLoggingVerbosity < 2) &&
|
||||
((event->type == SDL_EVENT_MOUSE_MOTION) ||
|
||||
(event->type == SDL_EVENT_MOUSE_RAW_MOTION) ||
|
||||
(event->type == SDL_EVENT_RAW_MOUSE_MOTION) ||
|
||||
(event->type == SDL_EVENT_FINGER_MOTION) ||
|
||||
(event->type == SDL_EVENT_PEN_AXIS) ||
|
||||
(event->type == SDL_EVENT_PEN_MOTION) ||
|
||||
@@ -535,6 +535,19 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||
break;
|
||||
#undef PRINT_KEY_EVENT
|
||||
|
||||
#define PRINT_RAW_KEY_EVENT(event) \
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u state=%s scancode=%u)", \
|
||||
(uint)event->raw_key.timestamp, (uint)event->raw_key.which, \
|
||||
event->raw_key.down ? "pressed" : "released", \
|
||||
(uint)event->raw_key.scancode);
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_KEY_DOWN)
|
||||
PRINT_RAW_KEY_EVENT(event);
|
||||
break;
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_KEY_UP)
|
||||
PRINT_RAW_KEY_EVENT(event);
|
||||
break;
|
||||
#undef PRINT_RAW_KEY_EVENT
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_TEXT_EDITING)
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
|
||||
(uint)event->edit.timestamp, (uint)event->edit.windowID,
|
||||
@@ -568,11 +581,18 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||
event->motion.xrel, event->motion.yrel);
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_MOUSE_MOTION)
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u dx=%d dy=%d)",
|
||||
(uint)event->raw_motion.timestamp,
|
||||
(uint)event->raw_motion.which,
|
||||
(int)event->raw_motion.dx, (int)event->raw_motion.dy);
|
||||
break;
|
||||
|
||||
#define PRINT_MBUTTON_EVENT(event) \
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%g y=%g)", \
|
||||
(uint)event->button.timestamp, (uint)event->button.windowID, \
|
||||
(uint)event->button.which, (uint)event->button.button, \
|
||||
event->button.down ? "pressed" : "released", \
|
||||
event->button.down ? "pressed" : "released", \
|
||||
(uint)event->button.clicks, event->button.x, event->button.y)
|
||||
SDL_EVENT_CASE(SDL_EVENT_MOUSE_BUTTON_DOWN)
|
||||
PRINT_MBUTTON_EVENT(event);
|
||||
@@ -582,6 +602,19 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||
break;
|
||||
#undef PRINT_MBUTTON_EVENT
|
||||
|
||||
#define PRINT_RAW_MBUTTON_EVENT(event) \
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u button=%u state=%s)", \
|
||||
(uint)event->raw_button.timestamp, \
|
||||
(uint)event->raw_button.which, (uint)event->raw_button.button, \
|
||||
event->raw_button.down ? "pressed" : "released");
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_MOUSE_BUTTON_DOWN)
|
||||
PRINT_RAW_MBUTTON_EVENT(event);
|
||||
break;
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_MOUSE_BUTTON_UP)
|
||||
PRINT_RAW_MBUTTON_EVENT(event);
|
||||
break;
|
||||
#undef PRINT_RAW_MBUTTON_EVENT
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_MOUSE_WHEEL)
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%g y=%g direction=%s)",
|
||||
(uint)event->wheel.timestamp, (uint)event->wheel.windowID,
|
||||
@@ -589,6 +622,13 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||
event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_RAW_MOUSE_WHEEL)
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u dx=%d dy=%d)",
|
||||
(uint)event->raw_wheel.timestamp,
|
||||
(uint)event->raw_wheel.which,
|
||||
(int)event->raw_wheel.dx, (int)event->raw_wheel.dy);
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_AXIS_MOTION)
|
||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
|
||||
(uint)event->jaxis.timestamp, (int)event->jaxis.which,
|
||||
@@ -1890,12 +1930,6 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
|
||||
if (type == SDL_EVENT_DROP_FILE || type == SDL_EVENT_DROP_TEXT) {
|
||||
SDL_ToggleDragAndDropSupport();
|
||||
}
|
||||
|
||||
if (type == SDL_EVENT_MOUSE_RAW_MOTION ||
|
||||
type == SDL_EVENT_MOUSE_RAW_SCROLL ||
|
||||
type == SDL_EVENT_MOUSE_RAW_BUTTON) {
|
||||
SDL_UpdateRawMouseDataEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1984,9 +2018,6 @@ bool SDL_InitEvents(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_SetEventEnabled(SDL_EVENT_MOUSE_RAW_MOTION, false);
|
||||
SDL_SetEventEnabled(SDL_EVENT_MOUSE_RAW_SCROLL, false);
|
||||
SDL_SetEventEnabled(SDL_EVENT_MOUSE_RAW_BUTTON, false);
|
||||
SDL_InitQuit();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -690,6 +690,22 @@ bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
|
||||
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, true);
|
||||
}
|
||||
|
||||
void SDL_SendRawKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down)
|
||||
{
|
||||
const SDL_EventType type = down ? SDL_EVENT_RAW_KEY_DOWN : SDL_EVENT_RAW_KEY_UP;
|
||||
|
||||
if (SDL_EventEnabled(type)) {
|
||||
SDL_Event event;
|
||||
event.type = type;
|
||||
event.common.timestamp = timestamp;
|
||||
event.raw_key.which = keyboardID;
|
||||
event.raw_key.scancode = scancode;
|
||||
event.raw_key.raw = rawcode;
|
||||
event.raw_key.down = down;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_ReleaseAutoReleaseKeys(void)
|
||||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
|
||||
@@ -63,6 +63,9 @@ extern bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scanco
|
||||
Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */
|
||||
extern bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, bool down);
|
||||
|
||||
// Send a raw keyboard key event
|
||||
extern void SDL_SendRawKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
|
||||
|
||||
// Release all the autorelease keys
|
||||
extern void SDL_ReleaseAutoReleaseKeys(void);
|
||||
|
||||
|
||||
@@ -597,34 +597,6 @@ void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouse
|
||||
SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y);
|
||||
}
|
||||
|
||||
void SDL_SendRawMouseAxis(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float ux, float uy, SDL_EventType type)
|
||||
{
|
||||
if (SDL_EventEnabled(type)) {
|
||||
SDL_Event event;
|
||||
event.type = type;
|
||||
event.common.timestamp = timestamp;
|
||||
event.maxis.which = mouseID;
|
||||
event.maxis.dx = dx;
|
||||
event.maxis.dy = dy;
|
||||
event.maxis.ux = ux;
|
||||
event.maxis.uy = uy;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_SendRawMouseButton(Uint64 timestamp, SDL_MouseID mouseID, Uint8 state, Uint8 button)
|
||||
{
|
||||
if (SDL_EventEnabled(SDL_EVENT_MOUSE_RAW_BUTTON)) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_EVENT_MOUSE_RAW_BUTTON;
|
||||
event.common.timestamp = timestamp;
|
||||
event.mbutton.which = mouseID;
|
||||
event.mbutton.button = button;
|
||||
event.mbutton.state = state;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConstrainMousePosition(SDL_Mouse *mouse, SDL_Window *window, float *x, float *y)
|
||||
{
|
||||
/* make sure that the pointers find themselves inside the windows,
|
||||
@@ -998,6 +970,51 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_SendRawMouseMotion(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float scale_x, float scale_y)
|
||||
{
|
||||
if (SDL_EventEnabled(SDL_EVENT_RAW_MOUSE_MOTION)) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_EVENT_RAW_MOUSE_MOTION;
|
||||
event.common.timestamp = timestamp;
|
||||
event.raw_motion.which = mouseID;
|
||||
event.raw_motion.dx = dx;
|
||||
event.raw_motion.dy = dy;
|
||||
event.raw_motion.scale_x = scale_x;
|
||||
event.raw_motion.scale_y = scale_y;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_SendRawMouseButton(Uint64 timestamp, SDL_MouseID mouseID, Uint8 button, bool down)
|
||||
{
|
||||
const SDL_EventType type = down ? SDL_EVENT_RAW_MOUSE_BUTTON_DOWN : SDL_EVENT_RAW_MOUSE_BUTTON_UP;
|
||||
|
||||
if (SDL_EventEnabled(type)) {
|
||||
SDL_Event event;
|
||||
event.type = type;
|
||||
event.common.timestamp = timestamp;
|
||||
event.raw_button.which = mouseID;
|
||||
event.raw_button.button = button;
|
||||
event.raw_button.down = down;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_SendRawMouseWheel(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float scale_x, float scale_y)
|
||||
{
|
||||
if (SDL_EventEnabled(SDL_EVENT_RAW_MOUSE_WHEEL)) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_EVENT_RAW_MOUSE_WHEEL;
|
||||
event.common.timestamp = timestamp;
|
||||
event.raw_wheel.which = mouseID;
|
||||
event.raw_wheel.dx = dx;
|
||||
event.raw_wheel.dy = dy;
|
||||
event.raw_wheel.scale_x = scale_x;
|
||||
event.raw_wheel.scale_y = scale_y;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_QuitMouse(void)
|
||||
{
|
||||
SDL_Cursor *cursor, *next;
|
||||
|
||||
@@ -169,12 +169,6 @@ extern bool SDL_UpdateMouseCapture(bool force_release);
|
||||
// Send a mouse motion event
|
||||
extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y);
|
||||
|
||||
/* Send a raw mouse motion or scroll event */
|
||||
extern void SDL_SendRawMouseAxis(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float ux, float uy, SDL_EventType type);
|
||||
|
||||
/* Send a raw mouse button event */
|
||||
extern void SDL_SendRawMouseButton(Uint64 timestamp, SDL_MouseID mouseID, Uint8 state, Uint8 button);
|
||||
|
||||
// Send a mouse button event
|
||||
extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down);
|
||||
|
||||
@@ -184,6 +178,15 @@ extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_
|
||||
// Send a mouse wheel event
|
||||
extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
|
||||
|
||||
// Send raw mouse motion
|
||||
extern void SDL_SendRawMouseMotion(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float scale_x, float scale_y);
|
||||
|
||||
// Send a raw mouse button event
|
||||
extern void SDL_SendRawMouseButton(Uint64 timestamp, SDL_MouseID mouseID, Uint8 button, bool down);
|
||||
|
||||
// Send a raw mouse wheel event
|
||||
extern void SDL_SendRawMouseWheel(Uint64 timestamp, SDL_MouseID mouseID, int dx, int dy, float scale_x, float scale_y);
|
||||
|
||||
// Warp the mouse within the window, potentially overriding relative mode
|
||||
extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user