Send events for mice and keyboards detected during initialization

Fixes https://github.com/libsdl-org/SDL/issues/12815
This commit is contained in:
Sam Lantinga
2025-09-11 19:12:42 -07:00
parent 8d5b82be2e
commit 3ddc3f1146
24 changed files with 83 additions and 79 deletions

View File

@@ -612,14 +612,14 @@ static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
SDL_AddKeyboard((SDL_KeyboardID)item->fd, name, true);
SDL_AddKeyboard((SDL_KeyboardID)item->fd, name);
return true;
}
static void SDL_EVDEV_destroy_keyboard(SDL_evdevlist_item *item)
{
SDL_RemoveKeyboard((SDL_KeyboardID)item->fd, true);
SDL_RemoveKeyboard((SDL_KeyboardID)item->fd);
}
static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
@@ -631,7 +631,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
SDL_AddMouse((SDL_MouseID)item->fd, name, true);
SDL_AddMouse((SDL_MouseID)item->fd, name);
ret = ioctl(item->fd, EVIOCGABS(ABS_X), &abs_info);
if (ret < 0) {
@@ -656,7 +656,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
static void SDL_EVDEV_destroy_mouse(SDL_evdevlist_item *item)
{
SDL_RemoveMouse((SDL_MouseID)item->fd, true);
SDL_RemoveMouse((SDL_MouseID)item->fd);
}
static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)

View File

@@ -433,7 +433,7 @@ static SDL_WSCONS_input_data *SDL_WSCONS_Init_Keyboard(const char *dev)
}
input->keyboardID = SDL_GetNextObjectID();
SDL_AddKeyboard(input->keyboardID, NULL, false);
SDL_AddKeyboard(input->keyboardID, NULL);
input->keymap.map = SDL_calloc(KS_NUMKEYCODES, sizeof(struct wscons_keymap));
if (!input->keymap.map) {

View File

@@ -52,7 +52,7 @@ SDL_WSCONS_mouse_input_data *SDL_WSCONS_Init_Mouse(void)
}
input->mouseID = SDL_GetNextObjectID();
SDL_AddMouse(input->mouseID, NULL, false);
SDL_AddMouse(input->mouseID, NULL);
#ifdef WSMOUSEIO_SETMODE
ioctl(input->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT);

View File

@@ -66,6 +66,7 @@ typedef struct SDL_Keyboard
static SDL_Keyboard SDL_keyboard;
static int SDL_keyboard_count;
static SDL_KeyboardInstance *SDL_keyboards;
static bool SDL_keyboard_quitting;
static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
@@ -118,7 +119,7 @@ static int SDL_GetKeyboardIndex(SDL_KeyboardID keyboardID)
return -1;
}
void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool send_event)
void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name)
{
int keyboard_index = SDL_GetKeyboardIndex(keyboardID);
if (keyboard_index >= 0) {
@@ -138,16 +139,14 @@ void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool send_even
SDL_keyboards = keyboards;
++SDL_keyboard_count;
if (send_event) {
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_KEYBOARD_ADDED;
event.kdevice.which = keyboardID;
SDL_PushEvent(&event);
}
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_KEYBOARD_ADDED;
event.kdevice.which = keyboardID;
SDL_PushEvent(&event);
}
void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event)
void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID)
{
int keyboard_index = SDL_GetKeyboardIndex(keyboardID);
if (keyboard_index < 0) {
@@ -162,7 +161,7 @@ void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event)
}
--SDL_keyboard_count;
if (send_event) {
if (!SDL_keyboard_quitting) {
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_KEYBOARD_REMOVED;
@@ -869,8 +868,10 @@ void SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int se
void SDL_QuitKeyboard(void)
{
SDL_keyboard_quitting = true;
for (int i = SDL_keyboard_count; i--;) {
SDL_RemoveKeyboard(SDL_keyboards[i].instance_id, false);
SDL_RemoveKeyboard(SDL_keyboards[i].instance_id);
}
SDL_free(SDL_keyboards);
SDL_keyboards = NULL;
@@ -882,6 +883,8 @@ void SDL_QuitKeyboard(void)
SDL_RemoveHintCallback(SDL_HINT_KEYCODE_OPTIONS,
SDL_KeycodeOptionsChanged, &SDL_keyboard);
SDL_keyboard_quitting = false;
}
const bool *SDL_GetKeyboardState(int *numkeys)

View File

@@ -38,10 +38,10 @@ extern bool SDL_InitKeyboard(void);
extern bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys);
// A keyboard has been added to the system
extern void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool send_event);
extern void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name);
// A keyboard has been removed from the system
extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event);
extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID);
// Set the mapping of scancode to key codes
extern void SDL_SetKeymap(SDL_Keymap *keymap, bool send_event);

View File

@@ -44,6 +44,7 @@ typedef struct SDL_MouseInstance
static SDL_Mouse SDL_mouse;
static int SDL_mouse_count;
static SDL_MouseInstance *SDL_mice;
static bool SDL_mouse_quitting;
// for mapping mouse events to touch
static bool track_mouse_down = false;
@@ -346,7 +347,7 @@ static int SDL_GetMouseIndex(SDL_MouseID mouseID)
return -1;
}
void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event)
void SDL_AddMouse(SDL_MouseID mouseID, const char *name)
{
int mouse_index = SDL_GetMouseIndex(mouseID);
if (mouse_index >= 0) {
@@ -366,16 +367,14 @@ void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event)
SDL_mice = mice;
++SDL_mouse_count;
if (send_event) {
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_MOUSE_ADDED;
event.mdevice.which = mouseID;
SDL_PushEvent(&event);
}
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_MOUSE_ADDED;
event.mdevice.which = mouseID;
SDL_PushEvent(&event);
}
void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event)
void SDL_RemoveMouse(SDL_MouseID mouseID)
{
int mouse_index = SDL_GetMouseIndex(mouseID);
if (mouse_index < 0) {
@@ -404,7 +403,7 @@ void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event)
}
}
if (send_event) {
if (!SDL_mouse_quitting) {
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_MOUSE_REMOVED;
@@ -1078,6 +1077,8 @@ void SDL_QuitMouse(void)
SDL_Cursor *cursor, *next;
SDL_Mouse *mouse = SDL_GetMouse();
SDL_mouse_quitting = true;
if (mouse->added_mouse_touch_device) {
SDL_DelTouch(SDL_MOUSE_TOUCHID);
mouse->added_mouse_touch_device = false;
@@ -1164,7 +1165,7 @@ void SDL_QuitMouse(void)
SDL_MouseIntegerModeChanged, mouse);
for (int i = SDL_mouse_count; i--; ) {
SDL_RemoveMouse(SDL_mice[i].instance_id, false);
SDL_RemoveMouse(SDL_mice[i].instance_id);
}
SDL_free(SDL_mice);
SDL_mice = NULL;
@@ -1174,6 +1175,8 @@ void SDL_QuitMouse(void)
mouse->internal = NULL;
}
SDL_zerop(mouse);
SDL_mouse_quitting = false;
}
bool SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata)

View File

@@ -164,10 +164,10 @@ extern void SDL_PostInitMouse(void);
extern bool SDL_IsMouse(Uint16 vendor, Uint16 product);
// A mouse has been added to the system
extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event);
extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name);
// A mouse has been removed from the system
extern void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event);
extern void SDL_RemoveMouse(SDL_MouseID mouseID);
// Get the mouse state structure
extern SDL_Mouse *SDL_GetMouse(void);

View File

@@ -1249,7 +1249,7 @@ static bool GIP_SendInitSequence(GIP_Attachment *attachment)
}
if (attachment->attachment_type == GIP_TYPE_CHATPAD && !attachment->keyboard) {
attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad", true);
SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
}
return true;
}
@@ -2335,7 +2335,7 @@ static bool GIP_HandleSystemMessage(
if (header->message_type == GIP_CMD_HID_REPORT && num_bytes == 8) {
if (!attachment->keyboard) {
attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad", true);
SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
}
attachment->attachment_type = GIP_TYPE_CHATPAD;
attachment->metadata.device.in_system_messages[0] |= (1u << GIP_CMD_HID_REPORT);
@@ -2931,7 +2931,7 @@ static void HIDAPI_DriverGIP_FreeDevice(SDL_HIDAPI_Device *device)
attachment->fragment_data = NULL;
}
if (attachment->keyboard) {
SDL_RemoveKeyboard(attachment->keyboard, true);
SDL_RemoveKeyboard(attachment->keyboard);
}
GIP_MetadataFree(&attachment->metadata);
SDL_free(attachment);

View File

@@ -211,8 +211,8 @@ static bool Cocoa_VideoInit(SDL_VideoDevice *_this)
// Assume we have a mouse and keyboard
// We could use GCMouse and GCKeyboard if we needed to, as is done in SDL_uikitevents.m
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
data.allow_spaces = SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, true);
data.trackpad_is_touch_only = SDL_GetHintBoolean(SDL_HINT_TRACKPAD_IS_TOUCH_ONLY, false);

View File

@@ -387,8 +387,8 @@ bool Emscripten_VideoInit(SDL_VideoDevice *_this)
Emscripten_InitMouse();
// Assume we have a mouse and keyboard
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
Emscripten_RegisterGlobalEventHandlers(_this);

View File

@@ -286,8 +286,8 @@ bool HAIKU_VideoInit(SDL_VideoDevice *_this)
HAIKU_MouseInit(_this);
// Assume we have a mouse and keyboard
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
#ifdef SDL_VIDEO_OPENGL
// testgl application doesn't load library, just tries to load symbols

View File

@@ -53,8 +53,8 @@ static bool videoInit(SDL_VideoDevice *_this)
}
// Assume we have a mouse and keyboard
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
return true;
}

View File

@@ -111,8 +111,8 @@ static bool RISCOS_VideoInit(SDL_VideoDevice *_this)
}
// Assume we have a mouse and keyboard
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
if (!RISCOS_InitModes(_this)) {
return false;

View File

@@ -185,7 +185,7 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
{
SDL_KeyboardID keyboardID = (SDL_KeyboardID)(uintptr_t)keyboard;
SDL_AddKeyboard(keyboardID, NULL, true);
SDL_AddKeyboard(keyboardID, NULL);
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
Uint64 timestamp = SDL_GetTicksNS();
@@ -201,7 +201,7 @@ static void OnGCKeyboardDisconnected(GCKeyboard *keyboard) API_AVAILABLE(macos(1
{
SDL_KeyboardID keyboardID = (SDL_KeyboardID)(uintptr_t)keyboard;
SDL_RemoveKeyboard(keyboardID, true);
SDL_RemoveKeyboard(keyboardID);
keyboard.keyboardInput.keyChangedHandler = nil;
}
@@ -314,7 +314,7 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
{
SDL_MouseID mouseID = (SDL_MouseID)(uintptr_t)mouse;
SDL_AddMouse(mouseID, NULL, true);
SDL_AddMouse(mouseID, NULL);
mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
OnGCMouseButtonChanged(mouseID, SDL_BUTTON_LEFT, pressed);
@@ -385,7 +385,7 @@ static void OnGCMouseDisconnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios
UpdatePointerLock();
SDL_RemoveMouse(mouseID, true);
SDL_RemoveMouse(mouseID);
}
void SDL_InitGCMouse(void)

View File

@@ -45,7 +45,7 @@ void VITA_InitKeyboard(void)
sceHidKeyboardEnumerate(&keyboard_hid_handle, 1);
if (keyboard_hid_handle > 0) {
SDL_AddKeyboard((SDL_KeyboardID)keyboard_hid_handle, NULL, false);
SDL_AddKeyboard((SDL_KeyboardID)keyboard_hid_handle, NULL);
}
}

View File

@@ -39,7 +39,7 @@ void VITA_InitMouse(void)
sceHidMouseEnumerate(&mouse_hid_handle, 1);
if (mouse_hid_handle > 0) {
SDL_AddMouse((SDL_MouseID)mouse_hid_handle, NULL, false);
SDL_AddMouse((SDL_MouseID)mouse_hid_handle, NULL);
}
}

View File

@@ -2201,7 +2201,7 @@ static void Wayland_SeatDestroyPointer(SDL_WaylandSeat *seat, bool send_event)
pointer_handle_leave(seat, seat->pointer.wl_pointer, 0, seat->pointer.focus->surface);
}
SDL_RemoveMouse(seat->pointer.sdl_id, send_event);
SDL_RemoveMouse(seat->pointer.sdl_id);
if (seat->pointer.confined_pointer) {
zwp_confined_pointer_v1_destroy(seat->pointer.confined_pointer);
@@ -2253,7 +2253,7 @@ static void Wayland_SeatDestroyKeyboard(SDL_WaylandSeat *seat, bool send_event)
keyboard_handle_leave(seat, seat->keyboard.wl_keyboard, 0, seat->keyboard.focus->surface);
}
SDL_RemoveKeyboard(seat->keyboard.sdl_id, send_event);
SDL_RemoveKeyboard(seat->keyboard.sdl_id);
if (seat->keyboard.sdl_keymap) {
if (seat->keyboard.xkb.current_layout < seat->keyboard.xkb.num_layouts &&
@@ -2351,7 +2351,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum w
SDL_snprintf(name_fmt, sizeof(name_fmt), "%s %" SDL_PRIu32, WAYLAND_DEFAULT_POINTER_NAME, seat->pointer.sdl_id);
}
SDL_AddMouse(seat->pointer.sdl_id, name_fmt, !seat->display->initializing);
SDL_AddMouse(seat->pointer.sdl_id, name_fmt);
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER) && seat->pointer.wl_pointer) {
Wayland_SeatDestroyPointer(seat, true);
}
@@ -2385,7 +2385,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum w
SDL_snprintf(name_fmt, sizeof(name_fmt), "%s %" SDL_PRIu32, WAYLAND_DEFAULT_KEYBOARD_NAME, seat->keyboard.sdl_id);
}
SDL_AddKeyboard(seat->keyboard.sdl_id, name_fmt, !seat->display->initializing);
SDL_AddKeyboard(seat->keyboard.sdl_id, name_fmt);
} else if (!(capabilities & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard.wl_keyboard) {
Wayland_SeatDestroyKeyboard(seat, true);
}

View File

@@ -1373,10 +1373,10 @@ static void display_remove_global(void *data, struct wl_registry *registry, uint
{
if (seat->registry_id == id) {
if (seat->keyboard.wl_keyboard) {
SDL_RemoveKeyboard(seat->keyboard.sdl_id, true);
SDL_RemoveKeyboard(seat->keyboard.sdl_id);
}
if (seat->pointer.wl_pointer) {
SDL_RemoveMouse(seat->pointer.sdl_id, true);
SDL_RemoveMouse(seat->pointer.sdl_id);
}
Wayland_SeatDestroy(seat, true);
}

View File

@@ -970,7 +970,6 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
SDL_MouseID *old_mice = NULL;
int new_mouse_count = 0;
SDL_MouseID *new_mice = NULL;
bool send_event = !initial_check;
// Check to see if anything has changed
static Uint64 s_last_device_change;
@@ -1048,7 +1047,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
AddDeviceID(keyboardID, &new_keyboards, &new_keyboard_count);
if (!HasDeviceID(keyboardID, old_keyboards, old_keyboard_count)) {
name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, "Keyboard", hid_loaded);
SDL_AddKeyboard(keyboardID, name, send_event);
SDL_AddKeyboard(keyboardID, name);
SDL_free(name);
}
}
@@ -1059,7 +1058,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
AddDeviceID(mouseID, &new_mice, &new_mouse_count);
if (!HasDeviceID(mouseID, old_mice, old_mouse_count)) {
name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, "Mouse", hid_loaded);
SDL_AddMouse(mouseID, name, send_event);
SDL_AddMouse(mouseID, name);
SDL_free(name);
}
}
@@ -1074,13 +1073,13 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
for (int i = old_keyboard_count; i--;) {
if (!HasDeviceID(old_keyboards[i], new_keyboards, new_keyboard_count)) {
SDL_RemoveKeyboard(old_keyboards[i], send_event);
SDL_RemoveKeyboard(old_keyboards[i]);
}
}
for (int i = old_mouse_count; i--;) {
if (!HasDeviceID(old_mice[i], new_mice, new_mouse_count)) {
SDL_RemoveMouse(old_mice[i], send_event);
SDL_RemoveMouse(old_mice[i]);
}
}
@@ -1403,7 +1402,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, SDL_GLOBAL_MOUSE_ID, false, (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam));
}
}
} break;
case WM_LBUTTONUP:
@@ -2592,7 +2591,7 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
// and this coincidence might no longer
// be true in the future.
// Ergo this placement concordantly
// conveys its unconditionality
// conveys its unconditionality
// vis-a-vis the queuing of clipcursor.
}
if (refresh_clipcursor) {

View File

@@ -142,10 +142,10 @@ static bool GAMEINPUT_InternalRemoveByIndex(WIN_GameInputData *data, int idx)
if (device) {
if (device->registered) {
if (device->info->supportedInput & GameInputKindMouse) {
SDL_RemoveMouse(device->instance_id, true);
SDL_RemoveMouse(device->instance_id);
}
if (device->info->supportedInput & GameInputKindKeyboard) {
SDL_RemoveKeyboard(device->instance_id, true);
SDL_RemoveKeyboard(device->instance_id);
}
if (device->last_mouse_reading) {
device->last_mouse_reading->Release();
@@ -446,10 +446,10 @@ void WIN_UpdateGameInput(SDL_VideoDevice *_this)
if (!device->registered) {
if (device->info->supportedInput & GameInputKindMouse) {
SDL_AddMouse(device->instance_id, device->name, true);
SDL_AddMouse(device->instance_id, device->name);
}
if (device->info->supportedInput & GameInputKindKeyboard) {
SDL_AddKeyboard(device->instance_id, device->name, true);
SDL_AddKeyboard(device->instance_id, device->name);
}
device->registered = true;
}

View File

@@ -2337,7 +2337,7 @@ void X11_PumpEvents(SDL_VideoDevice *_this)
}
if (data->xinput_hierarchy_changed) {
X11_Xinput2UpdateDevices(_this, false);
X11_Xinput2UpdateDevices(_this);
data->xinput_hierarchy_changed = false;
}
}

View File

@@ -417,8 +417,8 @@ static bool X11_VideoInit(SDL_VideoDevice *_this)
if (!X11_InitXinput2(_this)) {
// Assume a mouse and keyboard are attached
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL);
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL);
}
#ifdef SDL_VIDEO_DRIVER_X11_XFIXES

View File

@@ -327,7 +327,7 @@ bool X11_InitXinput2(SDL_VideoDevice *_this)
XISetMask(mask, XI_HierarchyChanged);
X11_XISelectEvents(data->display, DefaultRootWindow(data->display), &eventmask, 1);
X11_Xinput2UpdateDevices(_this, true);
X11_Xinput2UpdateDevices(_this);
return true;
#else
@@ -896,7 +896,7 @@ static bool HasDeviceID64(Uint64 deviceID, const Uint64 *list, int count)
#endif // SDL_VIDEO_DRIVER_X11_XINPUT2
void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check)
void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this)
{
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2
SDL_VideoData *data = _this->internal;
@@ -914,7 +914,6 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check)
Uint64 *old_touch_devices = NULL;
int new_touch_count = 0;
Uint64 *new_touch_devices = NULL;
bool send_event = !initial_check;
SDL_assert(X11_Xinput2IsInitialized());
@@ -944,7 +943,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check)
SDL_KeyboardID keyboardID = (SDL_KeyboardID)dev->deviceid;
AddDeviceID(keyboardID, &new_keyboards, &new_keyboard_count);
if (!HasDeviceID(keyboardID, old_keyboards, old_keyboard_count)) {
SDL_AddKeyboard(keyboardID, dev->name, send_event);
SDL_AddKeyboard(keyboardID, dev->name);
}
}
break;
@@ -956,7 +955,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check)
SDL_MouseID mouseID = (SDL_MouseID)dev->deviceid;
AddDeviceID(mouseID, &new_mice, &new_mouse_count);
if (!HasDeviceID(mouseID, old_mice, old_mouse_count)) {
SDL_AddMouse(mouseID, dev->name, send_event);
SDL_AddMouse(mouseID, dev->name);
}
}
break;
@@ -1040,13 +1039,13 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check)
for (int i = old_keyboard_count; i--;) {
if (!HasDeviceID(old_keyboards[i], new_keyboards, new_keyboard_count)) {
SDL_RemoveKeyboard(old_keyboards[i], send_event);
SDL_RemoveKeyboard(old_keyboards[i]);
}
}
for (int i = old_mouse_count; i--;) {
if (!HasDeviceID(old_mice[i], new_mice, new_mouse_count)) {
SDL_RemoveMouse(old_mice[i], send_event);
SDL_RemoveMouse(old_mice[i]);
}
}

View File

@@ -39,6 +39,6 @@ extern void X11_Xinput2Select(SDL_VideoDevice *_this, SDL_Window *window);
extern void X11_Xinput2GrabTouch(SDL_VideoDevice *_this, SDL_Window *window);
extern void X11_Xinput2UngrabTouch(SDL_VideoDevice *_this, SDL_Window *window);
extern bool X11_Xinput2SelectMouseAndKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
extern void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, bool initial_check);
extern void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this);
#endif // SDL_x11xinput2_h_