mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-22 21:09:34 -10:00
Raw input, DirectInput, Wayland, SDL3 and Android built their touches on the stack at each poll and the frontend copied them in, Wayland sixteen of them every poll whether or not any screen was touched. They write the places the frontend lends them now.
1159 lines
35 KiB
C
1159 lines
35 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
* Copyright (C) 2014-2015 - Higor Euripedes
|
|
* Copyright (C) 2026 - Rob Loach
|
|
*
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <boolean.h>
|
|
#include <string/stdstring.h>
|
|
#include <encodings/utf.h>
|
|
#include <libretro.h>
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include "../input_keymaps.h"
|
|
|
|
#include "../../configuration.h"
|
|
#include "../../retroarch.h"
|
|
|
|
#ifdef HAVE_MENU
|
|
#include "../../menu/menu_input.h"
|
|
#endif
|
|
|
|
#include "../../gfx/common/sdl3_common.h"
|
|
|
|
#ifdef WEBOS
|
|
#include <dlfcn.h>
|
|
#include "../../gfx/common/sdl3_common_webos.h"
|
|
#endif
|
|
|
|
/* OVERLAY_MAX_TOUCH */
|
|
#define SDL3_MAX_TOUCH 16
|
|
|
|
typedef struct sdl3_input
|
|
{
|
|
/* The keyboard state, provided by SDL_GetKeyboardState(). */
|
|
const bool *kb_state;
|
|
int kb_num_keys;
|
|
SDL_Scancode key_scancode_lut[RETROK_LAST];
|
|
/* RETROK of each scancode's unmodified key, for the key events */
|
|
uint16_t scancode_rk_lut[SDL_SCANCODE_COUNT];
|
|
/* Whole-pixel relative motion, x and y: VIDEO_POS_PACK. */
|
|
uint32_t mouse_delta;
|
|
/* Sub-pixel remainder carried into the next frame. */
|
|
float mouse_rel_x;
|
|
float mouse_rel_y;
|
|
/* Absolute position stays fractional; it's truncated at the API
|
|
* boundary, where nothing accumulates. */
|
|
float mouse_abs_x;
|
|
float mouse_abs_y;
|
|
/* Button states. */
|
|
bool mouse_l;
|
|
bool mouse_r;
|
|
bool mouse_m;
|
|
bool mouse_b4;
|
|
bool mouse_b5;
|
|
bool mouse_wu;
|
|
bool mouse_wd;
|
|
bool mouse_wl;
|
|
bool mouse_wr;
|
|
|
|
/* Number of connected touch devices. Saves having to query them
|
|
* every frame. */
|
|
int num_touch_devices;
|
|
unsigned touch_recheck;
|
|
/* Fingers were read once; they change only with finger events. */
|
|
bool touch_read;
|
|
/* The video driver's window last polled through, 0 for none */
|
|
SDL_WindowID window_id;
|
|
|
|
/* Number of active fingers across all touch devices. */
|
|
int num_touches;
|
|
struct
|
|
{
|
|
float x;
|
|
float y;
|
|
} touches[SDL3_MAX_TOUCH];
|
|
|
|
/* Pen/stylus state, handled through SDL_EVENT_PEN_*. */
|
|
bool pen_in_proximity;
|
|
bool pen_down;
|
|
/* Barrel buttons, ORed into the right/middle mouse buttons. */
|
|
bool pen_b1;
|
|
bool pen_b2;
|
|
/* Last reported position in window coordinates (points). */
|
|
float pen_raw_x;
|
|
float pen_raw_y;
|
|
/* Position in output pixels, matching mouse_abs_*. */
|
|
float pen_abs_x;
|
|
float pen_abs_y;
|
|
|
|
/* The SDL_Window input is read against. */
|
|
SDL_Window *window;
|
|
|
|
/* Sensors. Used if the SDL3 joypad driver isn't active. */
|
|
SDL_Sensor *accel;
|
|
SDL_Sensor *gyro;
|
|
bool sensors_init;
|
|
} sdl3_input_t;
|
|
|
|
#ifdef WEBOS
|
|
enum sdl_webos_special_key
|
|
{
|
|
sdl_webos_spkey_back,
|
|
sdl_webos_spkey_return,
|
|
sdl_webos_spkey_up,
|
|
sdl_webos_spkey_down,
|
|
sdl_webos_spkey_left,
|
|
sdl_webos_spkey_right,
|
|
sdl_webos_spkey_size,
|
|
};
|
|
|
|
static uint8_t sdl_webos_special_keymap[sdl_webos_spkey_size] = {0};
|
|
|
|
/* Set after a real typing key while the OSK/line editor is open. Magic
|
|
* Remote arrows/OK/digits must leave this false so the OSK grid stays
|
|
* under remote control. */
|
|
static bool sdl_webos_phys_kbd_typing = false;
|
|
|
|
/* One-shot sticky keys: webOS often delivers KEYDOWN+KEYUP in the same
|
|
* poll, so SDL_GetKeyboardState is already clear when the menu reads input. */
|
|
static bool sdl_webos_sticky_pressed(enum sdl_webos_special_key slot)
|
|
{
|
|
if (sdl_webos_special_keymap[slot])
|
|
{
|
|
sdl_webos_special_keymap[slot] = 0;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static bool sdl_webos_is_remote_nav_scancode(SDL_Scancode scancode)
|
|
{
|
|
switch ((int)scancode)
|
|
{
|
|
case SDL_SCANCODE_UP:
|
|
case SDL_SCANCODE_DOWN:
|
|
case SDL_SCANCODE_LEFT:
|
|
case SDL_SCANCODE_RIGHT:
|
|
case SDL_SCANCODE_RETURN:
|
|
case SDL_SCANCODE_ESCAPE:
|
|
case SDL_SCANCODE_PAGEUP:
|
|
case SDL_SCANCODE_PAGEDOWN:
|
|
case SDL_SCANCODE_WEBOS_BACK:
|
|
case SDL_SCANCODE_WEBOS_RED:
|
|
case SDL_SCANCODE_WEBOS_GREEN:
|
|
case SDL_SCANCODE_WEBOS_YELLOW:
|
|
case SDL_SCANCODE_WEBOS_BLUE:
|
|
case SDL_SCANCODE_WEBOS_EXIT:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* Keys that mean a physical BT keyboard is in use (not Magic Remote). */
|
|
static bool sdl_webos_scancode_enables_phys_kbd(SDL_Scancode scancode)
|
|
{
|
|
if (sdl_webos_is_remote_nav_scancode(scancode))
|
|
return false;
|
|
|
|
/* Remote digit row inserts text but must not switch to caret mode. */
|
|
if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
/* Rebuilt on SDL_EVENT_KEYMAP_CHANGED (e.g. system layout switch). */
|
|
static void sdl3_build_scancode_lut(sdl3_input_t *sdl)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < RETROK_LAST; i++)
|
|
sdl->key_scancode_lut[i] = rarch_keysym_lut[i]
|
|
? SDL_GetScancodeFromKey((SDL_Keycode)rarch_keysym_lut[i], NULL)
|
|
: SDL_SCANCODE_UNKNOWN;
|
|
|
|
sdl->scancode_rk_lut[SDL_SCANCODE_UNKNOWN] = 0;
|
|
for (i = SDL_SCANCODE_UNKNOWN + 1; i < SDL_SCANCODE_COUNT; i++)
|
|
sdl->scancode_rk_lut[i] = (uint16_t)input_keymaps_translate_keysym_to_rk(
|
|
SDL_GetKeyFromScancode((SDL_Scancode)i, SDL_KMOD_NONE, true));
|
|
}
|
|
|
|
/* The key an event is for, from its scancode. Falls back to the shared
|
|
* keycode table for anything the layout did not place. */
|
|
static unsigned sdl3_translate_scancode(sdl3_input_t *sdl,
|
|
SDL_Scancode scancode, SDL_Keycode key)
|
|
{
|
|
if ( scancode > SDL_SCANCODE_UNKNOWN
|
|
&& scancode < SDL_SCANCODE_COUNT
|
|
&& sdl->scancode_rk_lut[scancode])
|
|
return sdl->scancode_rk_lut[scancode];
|
|
return input_keymaps_translate_keysym_to_rk(key);
|
|
}
|
|
|
|
static void *sdl3_input_init(const char *joypad_driver)
|
|
{
|
|
sdl3_input_t *sdl = (sdl3_input_t*)calloc(1, sizeof(*sdl));
|
|
if (!sdl)
|
|
return NULL;
|
|
|
|
/* Set up the SDL event queue. */
|
|
if (!SDL_InitSubSystem(SDL_INIT_EVENTS))
|
|
{
|
|
free(sdl);
|
|
return NULL;
|
|
}
|
|
|
|
input_keymaps_init_keyboard_lut(rarch_key_map_sdl3);
|
|
|
|
sdl->kb_state = SDL_GetKeyboardState(&sdl->kb_num_keys);
|
|
sdl3_build_scancode_lut(sdl);
|
|
|
|
/* Prime the touch probe so a present touchscreen works from the
|
|
* first frame (see sdl3_poll_touch). */
|
|
{
|
|
SDL_TouchID *devices = SDL_GetTouchDevices(&sdl->num_touch_devices);
|
|
SDL_free(devices);
|
|
}
|
|
|
|
return sdl;
|
|
}
|
|
|
|
static bool sdl3_key_pressed(sdl3_input_t *sdl, int key)
|
|
{
|
|
SDL_Scancode sym = 0;
|
|
|
|
if (!key)
|
|
return false;
|
|
|
|
#ifdef WEBOS
|
|
if (key == RETROK_BACKSPACE
|
|
&& sdl_webos_sticky_pressed(sdl_webos_spkey_back))
|
|
return true;
|
|
/* Sticky pulse (Magic Remote) → OSK grid / OK. Held BT keys must not
|
|
* also report as menu joypad while the line editor owns them. */
|
|
if (key == RETROK_RETURN
|
|
|| key == RETROK_UP
|
|
|| key == RETROK_DOWN
|
|
|| key == RETROK_LEFT
|
|
|| key == RETROK_RIGHT)
|
|
{
|
|
enum sdl_webos_special_key slot = sdl_webos_spkey_return;
|
|
|
|
if (key == RETROK_UP)
|
|
slot = sdl_webos_spkey_up;
|
|
else if (key == RETROK_DOWN)
|
|
slot = sdl_webos_spkey_down;
|
|
else if (key == RETROK_LEFT)
|
|
slot = sdl_webos_spkey_left;
|
|
else if (key == RETROK_RIGHT)
|
|
slot = sdl_webos_spkey_right;
|
|
|
|
if (sdl_webos_sticky_pressed(slot))
|
|
return true;
|
|
|
|
if (input_driver_text_entry_active())
|
|
return false;
|
|
}
|
|
if (key == RETROK_F1 && sdl->kb_state[SDL_SCANCODE_WEBOS_EXIT])
|
|
return true;
|
|
if (key == RETROK_x && sdl->kb_state[SDL_SCANCODE_WEBOS_RED])
|
|
return true;
|
|
if (key == RETROK_z && sdl->kb_state[SDL_SCANCODE_WEBOS_GREEN])
|
|
return true;
|
|
if (key == RETROK_s && sdl->kb_state[SDL_SCANCODE_WEBOS_YELLOW])
|
|
return true;
|
|
if (key == RETROK_a && sdl->kb_state[SDL_SCANCODE_WEBOS_BLUE])
|
|
return true;
|
|
#endif
|
|
|
|
/* The keyboard state array is refreshed by SDL while pumping
|
|
* window events - it stays empty until a focused SDL3 window
|
|
* exists (i.e. the SDL3 video driver is running). */
|
|
sym = sdl->key_scancode_lut[key];
|
|
|
|
if ((int)sym >= sdl->kb_num_keys)
|
|
return false;
|
|
|
|
return sdl->kb_state[sym];
|
|
}
|
|
|
|
/* Which of @keys are down: bit n of @down for keys[n]. */
|
|
static void sdl3_keys_down(void *data, unsigned port,
|
|
const uint16_t *keys, const uint8_t *bind, unsigned count,
|
|
uint32_t *down)
|
|
{
|
|
unsigned i;
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
(void)port;
|
|
(void)bind;
|
|
for (i = 0; i < count; i++)
|
|
if (sdl3_key_pressed(sdl, keys[i]))
|
|
down[i >> 5] |= (1u << (i & 31));
|
|
}
|
|
|
|
static int16_t sdl3_input_state(
|
|
void *data,
|
|
const input_device_driver_t *joypad,
|
|
rarch_joypad_info_t *joypad_info,
|
|
const retro_keybind_set *binds,
|
|
unsigned port,
|
|
unsigned device,
|
|
unsigned idx,
|
|
unsigned id)
|
|
{
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
|
|
switch (device)
|
|
{
|
|
/* The RetroPad's buttons and the hotkeys, where they are bound to
|
|
* keys or mouse buttons, are the frontend's to answer: it asks
|
|
* sdl3_keys_down() for the keys once a poll. */
|
|
/* ... and a stick's axes, where they are bound to keys. */
|
|
case RETRO_DEVICE_KEYBOARD:
|
|
/* While a text box is open, Ctrl is the clipboard-paste
|
|
* modifier (see sdl3_paste_clipboard), so ignore acting
|
|
* on it here. */
|
|
if ((id == RETROK_LCTRL || id == RETROK_RCTRL) && input_driver_keyboard_line_enabled())
|
|
return 0;
|
|
return (id && id < RETROK_LAST) && sdl3_key_pressed(sdl, id);
|
|
/* ... and the lightgun's buttons, from what they are bound to. */
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Nothing here is the video driver's: the window is looked up at every
|
|
* poll, and the keyboard state SDL hands out is global. Kept only for
|
|
* another SDL3 window; any other has an input driver of its own. */
|
|
static bool sdl3_input_survives_video(void *data)
|
|
{
|
|
return data && sdl3_get_window() && sdl3_next_window_is_sdl3();
|
|
}
|
|
|
|
static void sdl3_input_free(void *data)
|
|
{
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
|
|
if (!sdl)
|
|
return;
|
|
|
|
/* Drop only the events this driver owns, matching what
|
|
* sdl3_input_poll consumes. Flushing SDL_EVENT_FIRST..LAST would
|
|
* also take the video driver's pending SDL_EVENT_QUIT and the
|
|
* joypad driver's hotplug events with it - harmless at shutdown,
|
|
* but input drivers are also torn down and recreated on a runtime
|
|
* driver switch, where that can swallow a window close the user
|
|
* already clicked. */
|
|
SDL_FlushEvents(SDL_EVENT_KEY_DOWN, SDL_EVENT_MOUSE_REMOVED);
|
|
SDL_FlushEvents(SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_CANCELED);
|
|
SDL_FlushEvents(SDL_EVENT_PEN_PROXIMITY_IN, SDL_EVENT_PEN_AXIS);
|
|
|
|
if (sdl->accel)
|
|
SDL_CloseSensor(sdl->accel);
|
|
if (sdl->gyro)
|
|
SDL_CloseSensor(sdl->gyro);
|
|
if (sdl->sensors_init)
|
|
SDL_QuitSubSystem(SDL_INIT_SENSOR);
|
|
|
|
/* Nothing polls after this point, so the flags would stay raised
|
|
* across a runtime driver switch. */
|
|
input_driver_set_native_keyboard_shown(false);
|
|
input_driver_set_native_keyboard_available(false);
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
|
free(sdl);
|
|
}
|
|
|
|
/* Opens the first sensor of the given type. */
|
|
static SDL_Sensor *sdl3_open_sensor(SDL_SensorType type)
|
|
{
|
|
int i;
|
|
int num_sensors = 0;
|
|
SDL_Sensor *sensor = NULL;
|
|
SDL_SensorID *sensors = SDL_GetSensors(&num_sensors);
|
|
|
|
if (!sensors)
|
|
return NULL;
|
|
|
|
for (i = 0; i < num_sensors; i++)
|
|
{
|
|
if (SDL_GetSensorTypeForID(sensors[i]) == type)
|
|
{
|
|
sensor = SDL_OpenSensor(sensors[i]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
SDL_free(sensors);
|
|
return sensor;
|
|
}
|
|
|
|
/* Enables the accelerometer/gyroscope. */
|
|
static bool sdl3_set_sensor_state(void *data, unsigned port,
|
|
enum retro_sensor_action action, unsigned rate)
|
|
{
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
|
|
/* The host device's sensors only ever map to port 0. */
|
|
if (port != 0)
|
|
return false;
|
|
|
|
switch (action)
|
|
{
|
|
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
|
|
case RETRO_SENSOR_GYROSCOPE_ENABLE:
|
|
{
|
|
bool accelerometer = action == RETRO_SENSOR_ACCELEROMETER_ENABLE;
|
|
SDL_Sensor **sensor = accelerometer ? &sdl->accel : &sdl->gyro;
|
|
|
|
if (*sensor)
|
|
return true;
|
|
|
|
/* Make sure the Sensor subsystem is available. */
|
|
if (!sdl->sensors_init)
|
|
{
|
|
if (!SDL_InitSubSystem(SDL_INIT_SENSOR))
|
|
return false;
|
|
sdl->sensors_init = true;
|
|
}
|
|
|
|
return (*sensor = sdl3_open_sensor(accelerometer ? SDL_SENSOR_ACCEL : SDL_SENSOR_GYRO)) != NULL;
|
|
}
|
|
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
|
|
case RETRO_SENSOR_GYROSCOPE_DISABLE:
|
|
{
|
|
SDL_Sensor **sensor = action == RETRO_SENSOR_ACCELEROMETER_DISABLE
|
|
? &sdl->accel : &sdl->gyro;
|
|
|
|
if (*sensor)
|
|
{
|
|
SDL_CloseSensor(*sensor);
|
|
*sensor = NULL;
|
|
}
|
|
return true;
|
|
}
|
|
case RETRO_SENSOR_ILLUMINANCE_DISABLE:
|
|
/* Disabling an unsupported sensor shouldn't fail. */
|
|
return true;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/* SDL reports mouse and pen coordinates in window coordinates,
|
|
* while the video driver's viewport metrics are in output
|
|
* pixels. */
|
|
static float sdl3_window_pixel_density(sdl3_input_t *sdl)
|
|
{
|
|
if (sdl->window)
|
|
{
|
|
float density = SDL_GetWindowPixelDensity(sdl->window);
|
|
if (density > 0.0f)
|
|
return density;
|
|
}
|
|
|
|
return 1.0f;
|
|
}
|
|
|
|
|
|
static float sdl3_get_sensor_input(void *data, unsigned port, unsigned id)
|
|
{
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
float v[3];
|
|
|
|
/* The host device's sensors only ever map to port 0. */
|
|
if (port != 0)
|
|
return 0.0f;
|
|
|
|
/* Acceleration is m/s^2, though libretro expects gravity. The
|
|
* gyroscope uses radians per second. */
|
|
if (id <= RETRO_SENSOR_ACCELEROMETER_Z)
|
|
{
|
|
if (sdl->accel && SDL_GetSensorData(sdl->accel, v, 3))
|
|
return v[id - RETRO_SENSOR_ACCELEROMETER_X] / SDL_STANDARD_GRAVITY;
|
|
}
|
|
else if (id >= RETRO_SENSOR_GYROSCOPE_X && id <= RETRO_SENSOR_GYROSCOPE_Z)
|
|
{
|
|
if (sdl->gyro && SDL_GetSensorData(sdl->gyro, v, 3))
|
|
return v[id - RETRO_SENSOR_GYROSCOPE_X];
|
|
}
|
|
|
|
return 0.0f;
|
|
}
|
|
|
|
static void sdl3_poll_mouse(sdl3_input_t *sdl)
|
|
{
|
|
float density;
|
|
float dx = 0.0f;
|
|
float dy = 0.0f;
|
|
SDL_MouseButtonFlags btn = SDL_GetMouseState(&sdl->mouse_abs_x, &sdl->mouse_abs_y);
|
|
SDL_GetRelativeMouseState(&dx, &dy);
|
|
|
|
sdl->mouse_rel_x += dx;
|
|
sdl->mouse_rel_y += dy;
|
|
|
|
/* Converting a float outside int16_t's range is undefined behaviour
|
|
* rather than a wrap, so clamp before the cast. Only reachable if
|
|
* the frontend stops polling for a long stretch while the mouse
|
|
* keeps moving. */
|
|
sdl->mouse_rel_x = MIN(MAX(sdl->mouse_rel_x, -32767.0f), 32767.0f);
|
|
sdl->mouse_rel_y = MIN(MAX(sdl->mouse_rel_y, -32767.0f), 32767.0f);
|
|
|
|
sdl->mouse_delta = VIDEO_POS_PACK((int16_t)sdl->mouse_rel_x,
|
|
(int16_t)sdl->mouse_rel_y);
|
|
|
|
sdl->mouse_rel_x -= (float)VIDEO_POS_X(sdl->mouse_delta);
|
|
sdl->mouse_rel_y -= (float)VIDEO_POS_Y(sdl->mouse_delta);
|
|
|
|
density = sdl3_window_pixel_density(sdl);
|
|
sdl->mouse_abs_x *= density;
|
|
sdl->mouse_abs_y *= density;
|
|
|
|
sdl->mouse_l = (SDL_BUTTON_MASK(SDL_BUTTON_LEFT) & btn) != 0;
|
|
sdl->mouse_r = (SDL_BUTTON_MASK(SDL_BUTTON_RIGHT) & btn) != 0;
|
|
sdl->mouse_m = (SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE) & btn) != 0;
|
|
sdl->mouse_b4 = (SDL_BUTTON_MASK(SDL_BUTTON_X1) & btn) != 0;
|
|
sdl->mouse_b5 = (SDL_BUTTON_MASK(SDL_BUTTON_X2) & btn) != 0;
|
|
}
|
|
|
|
/* Snapshot the active fingers across all touchscreens. Polling
|
|
* SDL_GetTouchFingers avoids tracking finger-id lifetimes through
|
|
* SDL_EVENT_FINGER_* events by hand. */
|
|
static void sdl3_poll_touch(sdl3_input_t *sdl)
|
|
{
|
|
int i;
|
|
int num_devices = 0;
|
|
int num_direct = 0;
|
|
SDL_TouchID *devices = NULL;
|
|
|
|
/* Without finger events the fingers last read still hold, so the
|
|
* lists SDL allocates are only asked for when one moves. */
|
|
if ( sdl->num_touch_devices
|
|
&& sdl->touch_read
|
|
&& !SDL_HasEvents(SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_CANCELED))
|
|
return;
|
|
|
|
sdl->num_touches = 0;
|
|
|
|
/* Skip the per-frame device query on touch-less setups; re-probe
|
|
* every ~10s since SDL3 has no touch hotplug event. */
|
|
if (sdl->num_touch_devices == 0)
|
|
{
|
|
if (++sdl->touch_recheck < 600)
|
|
return;
|
|
sdl->touch_recheck = 0;
|
|
}
|
|
|
|
devices = SDL_GetTouchDevices(&num_devices);
|
|
if (!devices)
|
|
{
|
|
sdl->num_touch_devices = 0;
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < num_devices; i++)
|
|
{
|
|
int j, num_fingers = 0;
|
|
SDL_Finger **fingers;
|
|
|
|
/* Pen events are read elsewhere. */
|
|
if (devices[i] == SDL_PEN_TOUCHID)
|
|
continue;
|
|
|
|
/* Only SDL_TOUCH_DEVICE_DIRECT is a touchscreen. The two indirect
|
|
* types are trackpads, whose fingers are device or cursor-relative. */
|
|
if (SDL_GetTouchDeviceType(devices[i]) != SDL_TOUCH_DEVICE_DIRECT)
|
|
continue;
|
|
|
|
num_direct++;
|
|
|
|
if (sdl->num_touches >= SDL3_MAX_TOUCH)
|
|
continue;
|
|
|
|
if (!(fingers = SDL_GetTouchFingers(devices[i], &num_fingers)))
|
|
continue;
|
|
|
|
for (j = 0; j < num_fingers && sdl->num_touches < SDL3_MAX_TOUCH; j++)
|
|
{
|
|
sdl->touches[sdl->num_touches].x = fingers[j]->x;
|
|
sdl->touches[sdl->num_touches].y = fingers[j]->y;
|
|
sdl->num_touches++;
|
|
}
|
|
|
|
SDL_free(fingers);
|
|
}
|
|
|
|
SDL_free(devices);
|
|
sdl->touch_read = true;
|
|
|
|
/* Count touchscreens only, so a machine whose sole touch device is
|
|
* a trackpad still takes the cheap early-out above. */
|
|
sdl->num_touch_devices = num_direct;
|
|
}
|
|
|
|
/* Polls the pen events. */
|
|
static void sdl3_poll_pen(sdl3_input_t *sdl)
|
|
{
|
|
SDL_Event event;
|
|
float density;
|
|
|
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT,
|
|
SDL_EVENT_PEN_PROXIMITY_IN, SDL_EVENT_PEN_AXIS) > 0)
|
|
{
|
|
switch (event.type)
|
|
{
|
|
case SDL_EVENT_PEN_PROXIMITY_IN:
|
|
sdl->pen_in_proximity = true;
|
|
break;
|
|
case SDL_EVENT_PEN_PROXIMITY_OUT:
|
|
sdl->pen_in_proximity = false;
|
|
sdl->pen_down = false;
|
|
sdl->pen_b1 = false;
|
|
sdl->pen_b2 = false;
|
|
break;
|
|
case SDL_EVENT_PEN_DOWN:
|
|
case SDL_EVENT_PEN_UP:
|
|
sdl->pen_in_proximity = true;
|
|
sdl->pen_raw_x = event.ptouch.x;
|
|
sdl->pen_raw_y = event.ptouch.y;
|
|
sdl->pen_down = event.ptouch.down;
|
|
break;
|
|
case SDL_EVENT_PEN_MOTION:
|
|
sdl->pen_in_proximity = true;
|
|
sdl->pen_raw_x = event.pmotion.x;
|
|
sdl->pen_raw_y = event.pmotion.y;
|
|
break;
|
|
case SDL_EVENT_PEN_BUTTON_DOWN:
|
|
case SDL_EVENT_PEN_BUTTON_UP:
|
|
sdl->pen_in_proximity = true;
|
|
if (event.pbutton.button == 1)
|
|
sdl->pen_b1 = event.pbutton.down;
|
|
else if (event.pbutton.button == 2)
|
|
sdl->pen_b2 = event.pbutton.down;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Barrel buttons act as the right/middle mouse buttons (the
|
|
* usual OS mapping). sdl3_poll_mouse has already run, so this
|
|
* ORs on top of the polled state. */
|
|
sdl->mouse_r |= sdl->pen_b1;
|
|
sdl->mouse_m |= sdl->pen_b2;
|
|
|
|
/* If the pen isn't in proximity, skip calculating its position. */
|
|
if (!sdl->pen_in_proximity)
|
|
return;
|
|
|
|
density = sdl3_window_pixel_density(sdl);
|
|
sdl->pen_abs_x = sdl->pen_raw_x * density;
|
|
sdl->pen_abs_y = sdl->pen_raw_y * density;
|
|
}
|
|
|
|
/* Translates an SDL_Keymod to a RETROKMOD. */
|
|
static uint16_t sdl3_translate_mod(SDL_Keymod smod)
|
|
{
|
|
uint16_t mod = 0;
|
|
|
|
if (smod & SDL_KMOD_SHIFT)
|
|
mod |= RETROKMOD_SHIFT;
|
|
if (smod & SDL_KMOD_CTRL)
|
|
mod |= RETROKMOD_CTRL;
|
|
if (smod & SDL_KMOD_ALT)
|
|
mod |= RETROKMOD_ALT;
|
|
if (smod & SDL_KMOD_GUI)
|
|
mod |= RETROKMOD_META;
|
|
if (smod & SDL_KMOD_NUM)
|
|
mod |= RETROKMOD_NUMLOCK;
|
|
if (smod & SDL_KMOD_CAPS)
|
|
mod |= RETROKMOD_CAPSLOCK;
|
|
if (smod & SDL_KMOD_SCROLL)
|
|
mod |= RETROKMOD_SCROLLOCK;
|
|
|
|
return mod;
|
|
}
|
|
|
|
/* On devices where SDL_StartTextInput() brings up the system
|
|
* keyboard, hold it back until a menu dialog actually wants text and
|
|
* the user has opted in. On desktop, text input stays quietly enabled
|
|
* in the background, ensuring normal keyboard controls work.
|
|
*
|
|
* Also publishes INP_FLAG_NATIVE_KB_SHOWN for the frontend: this runs
|
|
* once per poll on the main thread, so consumers on the video thread
|
|
* (gfx_display_draw_keyboard) read a plain flag instead of calling
|
|
* into SDL from a thread SDL does not expect. */
|
|
static void sdl3_manage_text_input(void)
|
|
{
|
|
bool want = false;
|
|
bool shown = false;
|
|
SDL_Window *win;
|
|
|
|
if (!sdl3_uses_screen_keyboard() || !(win = sdl3_get_window()))
|
|
{
|
|
#ifndef WEBOS
|
|
/* A keyboard attached since: text events come from text input. */
|
|
if ((win = sdl3_get_window()) && !SDL_TextInputActive(win))
|
|
SDL_StartTextInput(win);
|
|
#endif
|
|
input_driver_set_native_keyboard_shown(false);
|
|
input_driver_set_native_keyboard_available(false);
|
|
return;
|
|
}
|
|
|
|
input_driver_set_native_keyboard_available(true);
|
|
|
|
want = input_driver_keyboard_line_enabled()
|
|
&& input_config_get_sdl3_system_keyboard();
|
|
|
|
if (want == SDL_TextInputActive(win))
|
|
goto publish;
|
|
|
|
if (want)
|
|
{
|
|
int w, h;
|
|
SDL_Rect area;
|
|
SDL_TextInputType type = SDL_TEXTINPUT_TYPE_TEXT;
|
|
SDL_PropertiesID props = SDL_CreateProperties();
|
|
|
|
switch (input_driver_text_entry_type())
|
|
{
|
|
case INPUT_TEXT_TYPE_PASSWORD:
|
|
type = SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN;
|
|
break;
|
|
case INPUT_TEXT_TYPE_NUMBER:
|
|
type = SDL_TEXTINPUT_TYPE_NUMBER;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* Menu drivers draw the dialog's entry field in the top half of
|
|
* the screen, so keep the system keyboard/IME from covering it.
|
|
* Uses window coordinates, not pixels. */
|
|
SDL_GetWindowSize(win, &w, &h);
|
|
area.x = 0;
|
|
area.y = 0;
|
|
area.w = w;
|
|
area.h = h / 2;
|
|
SDL_SetTextInputArea(win, &area, 0);
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTINPUT_TYPE_NUMBER, type);
|
|
SDL_StartTextInputWithProperties(win, props);
|
|
SDL_DestroyProperties(props);
|
|
}
|
|
else
|
|
SDL_StopTextInput(win);
|
|
|
|
publish:
|
|
/* SDL_StartTextInput() only asks; the panel can take a frame to
|
|
* appear and the user can dismiss it behind our back. Report what
|
|
* is actually on screen. */
|
|
shown = SDL_ScreenKeyboardShown(win);
|
|
input_driver_set_native_keyboard_shown(shown);
|
|
}
|
|
|
|
/* Translates control/modifier keys into their ASCII character counterpart. */
|
|
static uint32_t sdl3_translate_control_key(unsigned code, uint16_t mod)
|
|
{
|
|
switch (code)
|
|
{
|
|
case RETROK_BACKSPACE:
|
|
case RETROK_TAB:
|
|
case RETROK_RETURN:
|
|
case RETROK_ESCAPE:
|
|
case RETROK_DELETE:
|
|
case RETROK_KP_ENTER:
|
|
return input_keymaps_translate_rk_to_ascii((enum retro_key)code, (enum retro_mod)mod);
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Grabs text from the clipboard, and passes it as keyboard input. */
|
|
static void sdl3_paste_clipboard(void)
|
|
{
|
|
char *text = SDL_GetClipboardText();
|
|
const char *ptr = text;
|
|
|
|
if (!text)
|
|
return;
|
|
|
|
while (*ptr)
|
|
{
|
|
uint32_t c = utf8_walk(&ptr);
|
|
|
|
/* Skip newline and backspace characters, since those would
|
|
* negatively affect the input. */
|
|
if (c >= 0x20 && c != 0x7f)
|
|
input_keyboard_event(true, RETROK_UNKNOWN, c, 0, RETRO_DEVICE_KEYBOARD);
|
|
}
|
|
|
|
SDL_free(text);
|
|
}
|
|
|
|
#ifdef WEBOS
|
|
bool SDL_webOSCursorVisibility(bool visible)
|
|
{
|
|
static bool (*fn)(bool visible) = NULL;
|
|
static bool dlsym_called = false;
|
|
if (!dlsym_called)
|
|
{
|
|
fn = dlsym(RTLD_NEXT, "SDL_webOSCursorVisibility");
|
|
dlsym_called = true;
|
|
}
|
|
if (!fn)
|
|
{
|
|
SDL_ShowCursor();
|
|
return true;
|
|
}
|
|
return fn(visible);
|
|
}
|
|
#endif
|
|
|
|
/* The mouse's frame, the touches and the pen, handed to the frontend,
|
|
* which answers for the mouse, the pointer and the lightgun's aim. The
|
|
* mouse is the port's whose Mouse Index is 0; the pointer and the
|
|
* lightgun are every port's. Fingers are read before the pen, the pen
|
|
* before the mouse, which stands for one touch: its left button. A pen
|
|
* in the air is a pointer that is not pressed. */
|
|
static void sdl3_publish_pointers(sdl3_input_t *sdl)
|
|
{
|
|
input_pointer_frame_t *frame = input_driver_pointers_lend();
|
|
uint32_t *touch_pos = input_driver_touches_lend();
|
|
unsigned touches = 0;
|
|
unsigned present = 0;
|
|
unsigned down = 0;
|
|
unsigned buttons = 0;
|
|
|
|
if (sdl->mouse_l)
|
|
buttons |= INPUT_POINTER_LEFT;
|
|
if (sdl->mouse_r)
|
|
buttons |= INPUT_POINTER_RIGHT;
|
|
if (sdl->mouse_m)
|
|
buttons |= INPUT_POINTER_MIDDLE;
|
|
if (sdl->mouse_b4)
|
|
buttons |= INPUT_POINTER_BUTTON_4;
|
|
if (sdl->mouse_b5)
|
|
buttons |= INPUT_POINTER_BUTTON_5;
|
|
#ifdef WEBOS
|
|
/* Note: webOS wheel is reversed */
|
|
if (sdl->mouse_wd)
|
|
buttons |= INPUT_POINTER_WHEEL_UP;
|
|
if (sdl->mouse_wu)
|
|
buttons |= INPUT_POINTER_WHEEL_DOWN;
|
|
#else
|
|
if (sdl->mouse_wu)
|
|
buttons |= INPUT_POINTER_WHEEL_UP;
|
|
if (sdl->mouse_wd)
|
|
buttons |= INPUT_POINTER_WHEEL_DOWN;
|
|
#endif
|
|
if (sdl->mouse_wr)
|
|
buttons |= INPUT_POINTER_HWHEEL_UP;
|
|
if (sdl->mouse_wl)
|
|
buttons |= INPUT_POINTER_HWHEEL_DOWN;
|
|
frame->pos = VIDEO_POS_PACK((int)sdl->mouse_abs_x, (int)sdl->mouse_abs_y);
|
|
frame->rel = sdl->mouse_delta;
|
|
frame->buttons = (uint16_t)buttons;
|
|
|
|
if (sdl->num_touches > 0)
|
|
{
|
|
/* a finger's place is a fraction of the output */
|
|
video_viewport_t vp = {0};
|
|
if (input_driver_poll_viewport(&vp))
|
|
{
|
|
float w = (float)VIDEO_SCALE_W(vp.full_dims);
|
|
float h = (float)VIDEO_SCALE_H(vp.full_dims);
|
|
for (; touches < (unsigned)sdl->num_touches; touches++)
|
|
touch_pos[touches] = VIDEO_POS_PACK(
|
|
(int)(sdl->touches[touches].x * w),
|
|
(int)(sdl->touches[touches].y * h));
|
|
/* each finger listed is there, and down */
|
|
present = (1u << touches) - 1;
|
|
down = present;
|
|
}
|
|
}
|
|
else if (sdl->pen_in_proximity)
|
|
{
|
|
touch_pos[0] = VIDEO_POS_PACK((int)sdl->pen_abs_x, (int)sdl->pen_abs_y);
|
|
touches = 1;
|
|
/* in the air it is there, and not down */
|
|
present = 1;
|
|
down = sdl->pen_down ? 1 : 0;
|
|
}
|
|
|
|
input_driver_publish_pointers(frame, 1,
|
|
INPUT_POINTERS_BY_MOUSE_INDEX | INPUT_POINTERS_AIM_EVERY_PORT
|
|
| INPUT_POINTERS_GUN_BUTTONS_BOUND
|
|
| INPUT_POINTERS_GUN_BUTTONS_EVERY_PORT
|
|
| INPUT_POINTERS_POINTER_OFFSCREEN | INPUT_POINTERS_TOUCH_ALONE);
|
|
input_driver_publish_touches(touch_pos, touches, present, down);
|
|
}
|
|
|
|
static void sdl3_input_poll(void *data)
|
|
{
|
|
SDL_Event event;
|
|
sdl3_input_t *sdl = (sdl3_input_t*)data;
|
|
bool pumped;
|
|
|
|
/* SDL only emits keyboard/mouse-wheel events for a window that owns
|
|
* the input focus. Without an SDL3 video driver to create and pump
|
|
* that window, this queue drains nothing and key/wheel state below
|
|
* never updates. */
|
|
pumped = sdl3_pump_input_events();
|
|
|
|
/* Find the SDL window, so that window coordinates can be calculated
|
|
* properly. */
|
|
sdl->window = sdl3_get_window();
|
|
{
|
|
/* Kept across a video restart: what was read through the window
|
|
* before went with it. */
|
|
SDL_WindowID id = sdl->window ? SDL_GetWindowID(sdl->window) : 0;
|
|
if (id != sdl->window_id)
|
|
{
|
|
sdl->window_id = id;
|
|
sdl->touch_read = false;
|
|
sdl->num_touches = 0;
|
|
sdl->pen_in_proximity = false;
|
|
sdl->pen_down = false;
|
|
}
|
|
}
|
|
if (!sdl->window)
|
|
sdl->window = SDL_GetMouseFocus();
|
|
|
|
sdl3_manage_text_input();
|
|
|
|
sdl3_poll_mouse(sdl);
|
|
sdl3_poll_touch(sdl);
|
|
|
|
/* SDL_UpdateSensors works without a focused window. */
|
|
if ((sdl->accel || sdl->gyro) && !pumped)
|
|
SDL_UpdateSensors();
|
|
|
|
sdl->mouse_wu = false;
|
|
sdl->mouse_wd = false;
|
|
sdl->mouse_wl = false;
|
|
sdl->mouse_wr = false;
|
|
|
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENT_KEY_DOWN, SDL_EVENT_MOUSE_REMOVED) > 0)
|
|
{
|
|
if ( event.type == SDL_EVENT_KEY_DOWN
|
|
|| event.type == SDL_EVENT_KEY_UP)
|
|
{
|
|
uint16_t mod = sdl3_translate_mod(event.key.mod);
|
|
unsigned code = sdl3_translate_scancode(sdl,
|
|
event.key.scancode, event.key.key);
|
|
uint32_t character = 0;
|
|
|
|
#ifdef WEBOS
|
|
bool osk_active = input_driver_text_entry_active();
|
|
|
|
if (!osk_active)
|
|
sdl_webos_phys_kbd_typing = false;
|
|
|
|
switch ((int) event.key.scancode)
|
|
{
|
|
case SDL_SCANCODE_WEBOS_BACK:
|
|
/* Because webOS is sending DOWN/UP at the same time,
|
|
we save this flag for later */
|
|
sdl_webos_special_keymap[sdl_webos_spkey_back] |= event.type == SDL_EVENT_KEY_DOWN;
|
|
code = RETROK_BACKSPACE;
|
|
break;
|
|
case SDL_SCANCODE_WEBOS_RED:
|
|
code = RETROK_x;
|
|
break;
|
|
case SDL_SCANCODE_WEBOS_GREEN:
|
|
code = RETROK_z;
|
|
break;
|
|
case SDL_SCANCODE_WEBOS_YELLOW:
|
|
code = RETROK_s;
|
|
break;
|
|
case SDL_SCANCODE_WEBOS_BLUE:
|
|
code = RETROK_a;
|
|
break;
|
|
case SDL_SCANCODE_WEBOS_EXIT:
|
|
code = RETROK_F1;
|
|
break;
|
|
case SDL_SCANCODE_UP:
|
|
case SDL_SCANCODE_DOWN:
|
|
case SDL_SCANCODE_LEFT:
|
|
case SDL_SCANCODE_RIGHT:
|
|
/* Default: Magic Remote → OSK grid. After BT typing keys,
|
|
* ←/→ move the caret and ↑/↓ act as home/end. */
|
|
if (osk_active && !sdl_webos_phys_kbd_typing)
|
|
{
|
|
if (event.type == SDL_EVENT_KEY_DOWN)
|
|
{
|
|
if (event.key.scancode == SDL_SCANCODE_UP)
|
|
sdl_webos_special_keymap[sdl_webos_spkey_up] = 1;
|
|
else if (event.key.scancode == SDL_SCANCODE_DOWN)
|
|
sdl_webos_special_keymap[sdl_webos_spkey_down] = 1;
|
|
else if (event.key.scancode == SDL_SCANCODE_LEFT)
|
|
sdl_webos_special_keymap[sdl_webos_spkey_left] = 1;
|
|
else
|
|
sdl_webos_special_keymap[sdl_webos_spkey_right] = 1;
|
|
}
|
|
continue;
|
|
}
|
|
break;
|
|
case SDL_SCANCODE_RETURN:
|
|
/* Default: remote OK → OSK select. After BT typing → save. */
|
|
if (osk_active && !sdl_webos_phys_kbd_typing)
|
|
{
|
|
if (event.type == SDL_EVENT_KEY_DOWN)
|
|
sdl_webos_special_keymap[sdl_webos_spkey_return] = 1;
|
|
continue;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* Letters / numpad / backspace / punctuation ⇒ BT keyboard session.
|
|
* Remote digit row is excluded (see sdl_webos_scancode_enables_phys_kbd). */
|
|
if (osk_active
|
|
&& event.type == SDL_EVENT_KEY_DOWN
|
|
&& sdl_webos_scancode_enables_phys_kbd(event.key.scancode))
|
|
sdl_webos_phys_kbd_typing = true;
|
|
|
|
/* Disable cursor when using the buttons */
|
|
if (code && code != RETROK_RETURN)
|
|
SDL_webOSCursorVisibility(false);
|
|
|
|
#endif
|
|
/* Allow pasting the clipboard. */
|
|
if ( event.type == SDL_EVENT_KEY_DOWN
|
|
&& event.key.key == SDLK_V
|
|
&& (event.key.mod & SDL_KMOD_CTRL)
|
|
&& input_driver_keyboard_line_enabled())
|
|
{
|
|
sdl3_paste_clipboard();
|
|
continue;
|
|
}
|
|
|
|
character = sdl3_translate_control_key(code, mod);
|
|
#ifdef WEBOS
|
|
if (code == RETROK_RETURN || code == RETROK_KP_ENTER)
|
|
character = '\r';
|
|
|
|
/* Numpad Enter is never sent by the Magic Remote; always save. */
|
|
if (code == RETROK_KP_ENTER)
|
|
sdl_webos_phys_kbd_typing = true;
|
|
#endif
|
|
|
|
input_keyboard_event(event.type == SDL_EVENT_KEY_DOWN,
|
|
code, character, mod,
|
|
RETRO_DEVICE_KEYBOARD);
|
|
}
|
|
else if (event.type == SDL_EVENT_TEXT_INPUT)
|
|
{
|
|
const char *text = event.text.text;
|
|
uint16_t mod = sdl3_translate_mod(SDL_GetModState());
|
|
|
|
while (text && *text)
|
|
input_keyboard_event(true, RETROK_UNKNOWN,
|
|
utf8_walk(&text), mod, RETRO_DEVICE_KEYBOARD);
|
|
}
|
|
else if (event.type == SDL_EVENT_MOUSE_WHEEL)
|
|
{
|
|
#if SDL_VERSION_ATLEAST(3, 2, 12)
|
|
/* Whole ticks, so a smooth wheel's fractions don't each
|
|
* count as one. */
|
|
float wx = (float)event.wheel.integer_x;
|
|
float wy = (float)event.wheel.integer_y;
|
|
#else
|
|
float wx = event.wheel.x;
|
|
float wy = event.wheel.y;
|
|
#endif
|
|
|
|
/* FLIPPED = "natural" scrolling: SDL delivers inverted
|
|
* signs and expects the caller to negate them. */
|
|
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED)
|
|
{
|
|
wx = -wx;
|
|
wy = -wy;
|
|
}
|
|
sdl->mouse_wu |= wy > 0;
|
|
sdl->mouse_wd |= wy < 0;
|
|
sdl->mouse_wl |= wx < 0;
|
|
sdl->mouse_wr |= wx > 0;
|
|
}
|
|
else if (event.type == SDL_EVENT_KEYMAP_CHANGED)
|
|
sdl3_build_scancode_lut(sdl);
|
|
}
|
|
|
|
/* Fingers are reported as pointer input from polled state
|
|
* (sdl3_poll_touch / SDL_GetTouchFingers), rather than these
|
|
* events, so flush the finger events. */
|
|
SDL_FlushEvents(SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_CANCELED);
|
|
|
|
sdl3_poll_pen(sdl);
|
|
|
|
/* Sensor updates arrive at device rate and are read by polling
|
|
* above (SDL_GetSensorData), so flush the events. */
|
|
if (sdl->sensors_init)
|
|
SDL_FlushEvent(SDL_EVENT_SENSOR_UPDATE);
|
|
|
|
sdl3_publish_pointers(sdl);
|
|
}
|
|
|
|
static void sdl3_grab_mouse(void *data, bool state)
|
|
{
|
|
SDL_Window *win = sdl3_get_window();
|
|
|
|
if (win)
|
|
{
|
|
SDL_SetWindowMouseGrab(win, state);
|
|
/* Relative mouse mode matches the game-focus behaviour of
|
|
* the other desktop input drivers (winraw/x11/udev). */
|
|
SDL_SetWindowRelativeMouseMode(win, state);
|
|
}
|
|
}
|
|
|
|
static uint64_t sdl3_get_capabilities(void *data)
|
|
{
|
|
return (1 << RETRO_DEVICE_JOYPAD)
|
|
| (1 << RETRO_DEVICE_MOUSE)
|
|
| (1 << RETRO_DEVICE_KEYBOARD)
|
|
| (1 << RETRO_DEVICE_LIGHTGUN)
|
|
| (1 << RETRO_DEVICE_POINTER)
|
|
| (1 << RETRO_DEVICE_ANALOG);
|
|
}
|
|
|
|
input_driver_t input_sdl3 = {
|
|
sdl3_input_init,
|
|
sdl3_input_poll,
|
|
sdl3_input_state,
|
|
sdl3_input_free,
|
|
sdl3_set_sensor_state,
|
|
sdl3_get_sensor_input,
|
|
sdl3_get_capabilities,
|
|
"sdl3",
|
|
sdl3_grab_mouse,
|
|
NULL, /* grab_stdin */
|
|
NULL, /* keypress_vibrate */
|
|
sdl3_input_survives_video,
|
|
sdl3_keys_down
|
|
};
|