diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index 902f7e69aef9d..b25afe1ff0ad3 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -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) diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c index 5a71044f312b0..723283908b0b4 100644 --- a/src/core/openbsd/SDL_wscons_kbd.c +++ b/src/core/openbsd/SDL_wscons_kbd.c @@ -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) { diff --git a/src/core/openbsd/SDL_wscons_mouse.c b/src/core/openbsd/SDL_wscons_mouse.c index 51195f39f4265..e6d2ec0002a6f 100644 --- a/src/core/openbsd/SDL_wscons_mouse.c +++ b/src/core/openbsd/SDL_wscons_mouse.c @@ -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); diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index bb43206024802..59aba366707f9 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -44,12 +44,6 @@ #define KEYCODE_OPTION_LATIN_LETTERS 0x04 #define DEFAULT_KEYCODE_OPTIONS (KEYCODE_OPTION_FRENCH_NUMBERS | KEYCODE_OPTION_LATIN_LETTERS) -typedef struct SDL_KeyboardInstance -{ - SDL_KeyboardID instance_id; - char *name; -} SDL_KeyboardInstance; - typedef struct SDL_Keyboard { // Data common to all keyboards @@ -65,7 +59,9 @@ typedef struct SDL_Keyboard static SDL_Keyboard SDL_keyboard; static int SDL_keyboard_count; -static SDL_KeyboardInstance *SDL_keyboards; +static SDL_KeyboardID *SDL_keyboards; +static SDL_HashTable *SDL_keyboard_names; +static bool SDL_keyboard_quitting; static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { @@ -94,6 +90,9 @@ bool SDL_InitKeyboard(void) { SDL_AddHintCallback(SDL_HINT_KEYCODE_OPTIONS, SDL_KeycodeOptionsChanged, &SDL_keyboard); + + SDL_keyboard_names = SDL_CreateHashTable(0, true, SDL_HashID, SDL_KeyMatchID, SDL_DestroyHashValue, NULL); + return true; } @@ -111,14 +110,14 @@ bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys) static int SDL_GetKeyboardIndex(SDL_KeyboardID keyboardID) { for (int i = 0; i < SDL_keyboard_count; ++i) { - if (keyboardID == SDL_keyboards[i].instance_id) { + if (keyboardID == SDL_keyboards[i]) { return i; } } 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) { @@ -128,26 +127,27 @@ void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool send_even SDL_assert(keyboardID != 0); - SDL_KeyboardInstance *keyboards = (SDL_KeyboardInstance *)SDL_realloc(SDL_keyboards, (SDL_keyboard_count + 1) * sizeof(*keyboards)); + SDL_KeyboardID *keyboards = (SDL_KeyboardID *)SDL_realloc(SDL_keyboards, (SDL_keyboard_count + 1) * sizeof(*keyboards)); if (!keyboards) { return; } - SDL_KeyboardInstance *instance = &keyboards[SDL_keyboard_count]; - instance->instance_id = keyboardID; - instance->name = SDL_strdup(name ? name : ""); + keyboards[SDL_keyboard_count] = keyboardID; 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); + if (!name) { + name = "Keyboard"; } + SDL_InsertIntoHashTable(SDL_keyboard_names, (const void *)(uintptr_t)keyboardID, SDL_strdup(name), true); + + 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) { @@ -155,14 +155,12 @@ void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event) return; } - SDL_free(SDL_keyboards[keyboard_index].name); - if (keyboard_index != SDL_keyboard_count - 1) { SDL_memmove(&SDL_keyboards[keyboard_index], &SDL_keyboards[keyboard_index + 1], (SDL_keyboard_count - keyboard_index - 1) * sizeof(SDL_keyboards[keyboard_index])); } --SDL_keyboard_count; - if (send_event) { + if (!SDL_keyboard_quitting) { SDL_Event event; SDL_zero(event); event.type = SDL_EVENT_KEYBOARD_REMOVED; @@ -188,7 +186,7 @@ SDL_KeyboardID *SDL_GetKeyboards(int *count) } for (i = 0; i < SDL_keyboard_count; ++i) { - keyboards[i] = SDL_keyboards[i].instance_id; + keyboards[i] = SDL_keyboards[i]; } keyboards[i] = 0; } else { @@ -202,12 +200,17 @@ SDL_KeyboardID *SDL_GetKeyboards(int *count) const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id) { - int keyboard_index = SDL_GetKeyboardIndex(instance_id); - if (keyboard_index < 0) { + const char *name = NULL; + if (!SDL_FindInHashTable(SDL_keyboard_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) { SDL_SetError("Keyboard %" SDL_PRIu32 " not found", instance_id); return NULL; } - return SDL_GetPersistentString(SDL_keyboards[keyboard_index].name); + if (!name) { + // SDL_strdup() failed during insert + SDL_OutOfMemory(); + return NULL; + } + return name; } void SDL_ResetKeyboard(void) @@ -869,12 +872,17 @@ 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]); } SDL_free(SDL_keyboards); SDL_keyboards = NULL; + SDL_DestroyHashTable(SDL_keyboard_names); + SDL_keyboard_names = NULL; + if (SDL_keyboard.keymap && SDL_keyboard.keymap->auto_release) { SDL_DestroyKeymap(SDL_keyboard.keymap); SDL_keyboard.keymap = NULL; @@ -882,6 +890,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) diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index ddfb5c5747176..1e26a54c312f3 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -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); diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 170e4335b3696..23f8017449742 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -34,16 +34,12 @@ #define WARP_EMULATION_THRESHOLD_NS SDL_MS_TO_NS(30) -typedef struct SDL_MouseInstance -{ - SDL_MouseID instance_id; - char *name; -} SDL_MouseInstance; - // The mouse state static SDL_Mouse SDL_mouse; static int SDL_mouse_count; -static SDL_MouseInstance *SDL_mice; +static SDL_MouseID *SDL_mice; +static SDL_HashTable *SDL_mouse_names; +static bool SDL_mouse_quitting; // for mapping mouse events to touch static bool track_mouse_down = false; @@ -310,6 +306,8 @@ bool SDL_PreInitMouse(void) mouse->cursor_visible = true; + SDL_mouse_names = SDL_CreateHashTable(0, true, SDL_HashID, SDL_KeyMatchID, SDL_DestroyHashValue, NULL); + return true; } @@ -339,14 +337,14 @@ bool SDL_IsMouse(Uint16 vendor, Uint16 product) static int SDL_GetMouseIndex(SDL_MouseID mouseID) { for (int i = 0; i < SDL_mouse_count; ++i) { - if (mouseID == SDL_mice[i].instance_id) { + if (mouseID == SDL_mice[i]) { return i; } } 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) { @@ -356,26 +354,27 @@ void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event) SDL_assert(mouseID != 0); - SDL_MouseInstance *mice = (SDL_MouseInstance *)SDL_realloc(SDL_mice, (SDL_mouse_count + 1) * sizeof(*mice)); + SDL_MouseID *mice = (SDL_MouseID *)SDL_realloc(SDL_mice, (SDL_mouse_count + 1) * sizeof(*mice)); if (!mice) { return; } - SDL_MouseInstance *instance = &mice[SDL_mouse_count]; - instance->instance_id = mouseID; - instance->name = SDL_strdup(name ? name : ""); + mice[SDL_mouse_count] = mouseID; 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); + if (!name) { + name = "Mouse"; } + SDL_InsertIntoHashTable(SDL_mouse_names, (const void *)(uintptr_t)mouseID, SDL_strdup(name), true); + + 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) { @@ -383,8 +382,6 @@ void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event) return; } - SDL_free(SDL_mice[mouse_index].name); - if (mouse_index != SDL_mouse_count - 1) { SDL_memmove(&SDL_mice[mouse_index], &SDL_mice[mouse_index + 1], (SDL_mouse_count - mouse_index - 1) * sizeof(SDL_mice[mouse_index])); } @@ -404,7 +401,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; @@ -430,7 +427,7 @@ SDL_MouseID *SDL_GetMice(int *count) } for (i = 0; i < SDL_mouse_count; ++i) { - mice[i] = SDL_mice[i].instance_id; + mice[i] = SDL_mice[i]; } mice[i] = 0; } else { @@ -444,12 +441,17 @@ SDL_MouseID *SDL_GetMice(int *count) const char *SDL_GetMouseNameForID(SDL_MouseID instance_id) { - int mouse_index = SDL_GetMouseIndex(instance_id); - if (mouse_index < 0) { + const char *name = NULL; + if (!SDL_FindInHashTable(SDL_mouse_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) { SDL_SetError("Mouse %" SDL_PRIu32 " not found", instance_id); return NULL; } - return SDL_GetPersistentString(SDL_mice[mouse_index].name); + if (!name) { + // SDL_strdup() failed during insert + SDL_OutOfMemory(); + return NULL; + } + return name; } void SDL_SetDefaultCursor(SDL_Cursor *cursor) @@ -1078,6 +1080,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,16 +1168,21 @@ 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]); } SDL_free(SDL_mice); SDL_mice = NULL; + SDL_DestroyHashTable(SDL_mouse_names); + SDL_mouse_names = NULL; + if (mouse->internal) { SDL_free(mouse->internal); mouse->internal = NULL; } SDL_zerop(mouse); + + SDL_mouse_quitting = false; } bool SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata) diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index c25974ba8278e..0114f2da84ae3 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -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); diff --git a/src/joystick/hidapi/SDL_hidapi_gip.c b/src/joystick/hidapi/SDL_hidapi_gip.c index a61906d8227e5..68161181c73af 100644 --- a/src/joystick/hidapi/SDL_hidapi_gip.c +++ b/src/joystick/hidapi/SDL_hidapi_gip.c @@ -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); diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 5f1ab6b920f62..bffa61527c4df 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1733,12 +1733,12 @@ void SDLTest_PrintEvent(const SDL_Event *event) SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " HDR %s", event->window.windowID, event->window.data1 ? "enabled" : "disabled"); break; case SDL_EVENT_KEYBOARD_ADDED: - SDL_Log("SDL EVENT: Keyboard %" SDL_PRIu32 " attached", - event->kdevice.which); + SDL_Log("SDL EVENT: Keyboard %" SDL_PRIu32 " (%s) attached", + event->kdevice.which, SDL_GetKeyboardNameForID(event->kdevice.which)); break; case SDL_EVENT_KEYBOARD_REMOVED: - SDL_Log("SDL EVENT: Keyboard %" SDL_PRIu32 " removed", - event->kdevice.which); + SDL_Log("SDL EVENT: Keyboard %" SDL_PRIu32 " (%s) removed", + event->kdevice.which, SDL_GetKeyboardNameForID(event->kdevice.which)); break; case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: { @@ -1775,12 +1775,12 @@ void SDLTest_PrintEvent(const SDL_Event *event) SDL_Log("SDL EVENT: Keymap changed"); break; case SDL_EVENT_MOUSE_ADDED: - SDL_Log("SDL EVENT: Mouse %" SDL_PRIu32 " attached", - event->mdevice.which); + SDL_Log("SDL EVENT: Mouse %" SDL_PRIu32 " (%s) attached", + event->mdevice.which, SDL_GetMouseNameForID(event->mdevice.which)); break; case SDL_EVENT_MOUSE_REMOVED: - SDL_Log("SDL EVENT: Mouse %" SDL_PRIu32 " removed", - event->mdevice.which); + SDL_Log("SDL EVENT: Mouse %" SDL_PRIu32 " (%s) removed", + event->mdevice.which, SDL_GetMouseNameForID(event->mdevice.which)); break; case SDL_EVENT_MOUSE_MOTION: SDL_Log("SDL EVENT: Mouse: moved to %g,%g (%g,%g) in window %" SDL_PRIu32, diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 3738f9574d02a..d77080779d848 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -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); diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index d1f1a6963f9dc..aec067c4ef845 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -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); diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index d7f9e7c80e121..e287744d7fead 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -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 diff --git a/src/video/qnx/SDL_qnxvideo.c b/src/video/qnx/SDL_qnxvideo.c index 4192cdbc109b9..4b3c07fdbcbcc 100644 --- a/src/video/qnx/SDL_qnxvideo.c +++ b/src/video/qnx/SDL_qnxvideo.c @@ -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; } diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index 1f556d2304772..de995726df4fb 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -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; diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index 86224f7948b2a..3925339df3975 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -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) diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c index 99677566c5da7..51894fb492133 100644 --- a/src/video/vita/SDL_vitakeyboard.c +++ b/src/video/vita/SDL_vitakeyboard.c @@ -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); } } diff --git a/src/video/vita/SDL_vitamouse.c b/src/video/vita/SDL_vitamouse.c index 7181023dcbdab..6b4764ea05719 100644 --- a/src/video/vita/SDL_vitamouse.c +++ b/src/video/vita/SDL_vitamouse.c @@ -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); } } diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index c0bf4f03cc1ee..72cabeafc35fe 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -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); } diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 3286f8aec7bfc..4422faac7c94b 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -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); } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index bac6179c69a1e..d13eedea4253b 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -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: @@ -2589,7 +2588,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) { diff --git a/src/video/windows/SDL_windowsgameinput.cpp b/src/video/windows/SDL_windowsgameinput.cpp index 78c19a57f93f8..7036babb12ad8 100644 --- a/src/video/windows/SDL_windowsgameinput.cpp +++ b/src/video/windows/SDL_windowsgameinput.cpp @@ -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; } diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 67128c85b5e42..7731c30edbefc 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -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; } } diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index ce34f9e6e98b4..c16ec00f113af 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -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 diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 3e51408625870..b251d0e9cc255 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -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]); } } diff --git a/src/video/x11/SDL_x11xinput2.h b/src/video/x11/SDL_x11xinput2.h index 35f4bb8b8bcae..91c33aa65451a 100644 --- a/src/video/x11/SDL_x11xinput2.h +++ b/src/video/x11/SDL_x11xinput2.h @@ -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_