diff --git a/include/SDL3/SDL_pen.h b/include/SDL3/SDL_pen.h index 57744599f..9eab3c0ad 100644 --- a/include/SDL3/SDL_pen.h +++ b/include/SDL3/SDL_pen.h @@ -58,7 +58,7 @@ typedef Uint32 SDL_PenID; /**< SDL_PenIDs identify pens uniquely within a sessio #define SDL_PEN_INVALID ((SDL_PenID)0) /**< Reserved invalid ::SDL_PenID is valid */ -#define SDL_PEN_MOUSEID ((SDL_PenID)-2) /**< Device ID for mouse events triggered by pen events */ +#define SDL_PEN_MOUSEID ((SDL_MouseID)-2) /**< Device ID for mouse events triggered by pen events */ #define SDL_PEN_INFO_UNKNOWN (-1) /**< Marks unknown information when querying the pen */ diff --git a/src/core/haiku/SDL_BApp.h b/src/core/haiku/SDL_BApp.h index 2d5be1e2b..54f98b267 100644 --- a/src/core/haiku/SDL_BApp.h +++ b/src/core/haiku/SDL_BApp.h @@ -46,6 +46,9 @@ extern "C" { #include +#define BAPP_KEYBOARD_ID 1 +#define BAPP_MOUSE_ID 1 + /* Forward declarations */ class SDL_BLooper; class SDL_BWin; @@ -248,12 +251,12 @@ class SDL_BLooper : public BLooper SDL_GetWindowPosition(win, &winPosX, &winPosY); int dx = x - (winWidth / 2); int dy = y - (winHeight / 2); - SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, (float)dx, (float)dy); + SDL_SendMouseMotion(0, win, BAPP_MOUSE_ID, SDL_GetMouse()->relative_mode, (float)dx, (float)dy); set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2)); if (!be_app->IsCursorHidden()) be_app->HideCursor(); } else { - SDL_SendMouseMotion(0, win, 0, 0, (float)x, (float)y); + SDL_SendMouseMotion(0, win, BAPP_MOUSE_ID, SDL_FALSE, (float)x, (float)y); if (SDL_CursorVisible() && be_app->IsCursorHidden()) be_app->ShowCursor(); } @@ -271,7 +274,7 @@ class SDL_BLooper : public BLooper return; } win = GetSDLWindow(winID); - SDL_SendMouseButton(0, win, 0, state, button); + SDL_SendMouseButton(0, win, BAPP_MOUSE_ID, state, button); } void _HandleMouseWheel(BMessage *msg) @@ -286,7 +289,7 @@ class SDL_BLooper : public BLooper return; } win = GetSDLWindow(winID); - SDL_SendMouseWheel(0, win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, win, BAPP_MOUSE_ID, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL); } void _HandleKey(BMessage *msg) @@ -303,7 +306,7 @@ class SDL_BLooper : public BLooper return; } HAIKU_SetKeyState(scancode, state); - SDL_SendKeyboardKey(0, 0, state, HAIKU_GetScancodeFromBeKey(scancode)); + SDL_SendKeyboardKey(0, BAPP_KEYBOARD_ID, state, HAIKU_GetScancodeFromBeKey(scancode)); if (state == SDL_PRESSED && SDL_EventEnabled(SDL_EVENT_TEXT_INPUT)) { const int8 *keyUtf8; diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index 5a8c6e5e5..fa9b14131 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -605,11 +605,20 @@ static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode) return scancode; } +static int SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class) +{ + SDL_AddKeyboard((SDL_KeyboardID)item->fd, SDL_TRUE); + + return 0; +} + static int SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class) { int ret; struct input_absinfo abs_info; + SDL_AddMouse((SDL_MouseID)item->fd, SDL_TRUE); + ret = ioctl(item->fd, EVIOCGABS(ABS_X), &abs_info); if (ret < 0) { // no absolute mode info, continue @@ -922,6 +931,14 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) SDL_free(item); return ret; } + } else if (udev_class & SDL_UDEV_DEVICE_KEYBOARD) { + int ret = SDL_EVDEV_init_keyboard(item, udev_class); + if (ret < 0) { + close(item->fd); + SDL_free(item->path); + SDL_free(item); + return ret; + } } if (!_this->last) { diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c index 1cc361b76..541ad2cbe 100644 --- a/src/core/openbsd/SDL_wscons_kbd.c +++ b/src/core/openbsd/SDL_wscons_kbd.c @@ -33,6 +33,7 @@ #include #include "../../events/SDL_events_c.h" +#include "../../events/SDL_keyboard_c.h" #ifdef SDL_PLATFORM_NETBSD #define KS_GROUP_Ascii KS_GROUP_Plain @@ -388,6 +389,7 @@ static struct wscons_keycode_to_SDL typedef struct { int fd; + SDL_KeyboardID keyboardID; struct wskbd_map_data keymap; int ledstate; int origledstate; @@ -420,14 +422,19 @@ static SDL_WSCONS_input_data *SDL_WSCONS_Init_Keyboard(const char *dev) SDL_WSCONS_input_data *input = (SDL_WSCONS_input_data *)SDL_calloc(1, sizeof(SDL_WSCONS_input_data)); if (!input) { - return input; + return NULL; } + input->fd = open(dev, O_RDWR | O_NONBLOCK | O_CLOEXEC); if (input->fd == -1) { SDL_free(input); input = NULL; return NULL; } + + input->keyboardID = SDL_GetNextObjectID(); + SDL_AddKeyboard(input->keyboardID, SDL_FALSE); + input->keymap.map = SDL_calloc(sizeof(struct wscons_keymap), KS_NUMKEYCODES); if (!input->keymap.map) { SDL_free(input); @@ -553,22 +560,22 @@ static void Translate_to_keycode(SDL_WSCONS_input_data *input, int type, keysym_ switch (keyDesc.command) { case KS_Cmd_ScrollBack: { - SDL_SendKeyboardKey(0, 0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEUP); + SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEUP); return; } case KS_Cmd_ScrollFwd: { - SDL_SendKeyboardKey(0, 0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEDOWN); + SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEDOWN); return; } } for (i = 0; i < sizeof(conversion_table) / sizeof(struct wscons_keycode_to_SDL); i++) { if (conversion_table[i].sourcekey == group[0]) { - SDL_SendKeyboardKey(0, 0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, conversion_table[i].targetKey); + SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, conversion_table[i].targetKey); return; } } - SDL_SendKeyboardKey(0, 0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_UNKNOWN); + SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_UNKNOWN); } static void updateKeyboard(SDL_WSCONS_input_data *input) @@ -802,13 +809,13 @@ static void updateKeyboard(SDL_WSCONS_input_data *input) } break; case WSCONS_EVENT_ALL_KEYS_UP: for (i = 0; i < SDL_NUM_SCANCODES; i++) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, i); + SDL_SendKeyboardKey(0, input->keyboardID, SDL_RELEASED, i); } break; } if (input->type == WSKBD_TYPE_USB && events[i].value <= 0xE7) - SDL_SendKeyboardKey(0, 0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)events[i].value); + SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)events[i].value); else Translate_to_keycode(input, type, events[i].value); diff --git a/src/core/openbsd/SDL_wscons_mouse.c b/src/core/openbsd/SDL_wscons_mouse.c index 3d3de9557..435de1e09 100644 --- a/src/core/openbsd/SDL_wscons_mouse.c +++ b/src/core/openbsd/SDL_wscons_mouse.c @@ -32,6 +32,7 @@ typedef struct SDL_WSCONS_mouse_input_data { int fd; + SDL_MouseID mouseID; } SDL_WSCONS_mouse_input_data; SDL_WSCONS_mouse_input_data *SDL_WSCONS_Init_Mouse() @@ -39,32 +40,36 @@ SDL_WSCONS_mouse_input_data *SDL_WSCONS_Init_Mouse() #ifdef WSMOUSEIO_SETVERSION int version = WSMOUSE_EVENT_VERSION; #endif - SDL_WSCONS_mouse_input_data *mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data)); + SDL_WSCONS_mouse_input_data *input = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data)); - if (!mouseInputData) { + if (!input) { return NULL; } - mouseInputData->fd = open("/dev/wsmouse", O_RDWR | O_NONBLOCK | O_CLOEXEC); - if (mouseInputData->fd == -1) { - SDL_free(mouseInputData); + input->fd = open("/dev/wsmouse", O_RDWR | O_NONBLOCK | O_CLOEXEC); + if (input->fd == -1) { + SDL_free(input); return NULL; } + + input->mouseID = SDL_GetNextObjectID(); + SDL_AddMouse(input->mouseID, SDL_FALSE); + #ifdef WSMOUSEIO_SETMODE - ioctl(mouseInputData->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT); + ioctl(input->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT); #endif #ifdef WSMOUSEIO_SETVERSION - ioctl(mouseInputData->fd, WSMOUSEIO_SETVERSION, &version); + ioctl(input->fd, WSMOUSEIO_SETVERSION, &version); #endif - return mouseInputData; + return input; } -void updateMouse(SDL_WSCONS_mouse_input_data *inputData) +void updateMouse(SDL_WSCONS_mouse_input_data *input) { struct wscons_event events[64]; int n; SDL_Mouse *mouse = SDL_GetMouse(); - if ((n = read(inputData->fd, events, sizeof(events))) > 0) { + if ((n = read(input->fd, events, sizeof(events))) > 0) { int i; n /= sizeof(struct wscons_event); for (i = 0; i < n; i++) { @@ -74,13 +79,13 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData) { switch (events[i].value) { case 0: /* Left Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT); break; case 1: /* Middle Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE); break; case 2: /* Right Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT); break; } } break; @@ -88,34 +93,34 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData) { switch (events[i].value) { case 0: /* Left Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_RELEASED, SDL_BUTTON_LEFT); break; case 1: /* Middle Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE); break; case 2: /* Right Mouse Button. */ - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT); + SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT); break; } } break; case WSCONS_EVENT_MOUSE_DELTA_X: { - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, (float)events[i].value, 0.0f); + SDL_SendMouseMotion(0, mouse->focus, input->mouseID, 1, (float)events[i].value, 0.0f); break; } case WSCONS_EVENT_MOUSE_DELTA_Y: { - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, 0.0f, -(float)events[i].value); + SDL_SendMouseMotion(0, mouse->focus, input->mouseID, 1, 0.0f, -(float)events[i].value); break; } case WSCONS_EVENT_MOUSE_DELTA_W: { - SDL_SendMouseWheel(0, mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, mouse->focus, input->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL); break; } case WSCONS_EVENT_MOUSE_DELTA_Z: { - SDL_SendMouseWheel(0, mouse->focus, mouse->mouseID, 0, -events[i].value, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, mouse->focus, input->mouseID, 0, -events[i].value, SDL_MOUSEWHEEL_NORMAL); break; } } @@ -123,11 +128,11 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData) } } -void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data *inputData) +void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data *input) { - if (!inputData) { + if (!input) { return; } - close(inputData->fd); - SDL_free(inputData); + close(input->fd); + SDL_free(input); } diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index 9fddd3d10..0565d4f85 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -538,7 +538,7 @@ void SDL_WinRTApp::OnWindowActivated(CoreWindow ^ sender, WindowActivatedEventAr */ #if !SDL_WINAPI_FAMILY_PHONE || NTDDI_VERSION >= NTDDI_WINBLUE Point cursorPos = WINRT_TransformCursorPosition(window, sender->PointerPosition, TransformToSDLWindowSize); - SDL_SendMouseMotion(0, window, 0, 0, cursorPos.X, cursorPos.Y); + SDL_SendMouseMotion(0, window, 0, SDL_FALSE, cursorPos.X, cursorPos.Y); #endif /* TODO, WinRT: see if the Win32 bugfix from https://hg.libsdl.org/SDL/rev/d278747da408 needs to be applied (on window activation) */ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 63bd9842e..1e5eb02a0 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -691,7 +691,7 @@ SDL_bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys) return SDL_TRUE; } -void SDL_PrivateKeyboardAdded(SDL_KeyboardID keyboardID) +void SDL_AddKeyboard(SDL_KeyboardID keyboardID, SDL_bool send_event) { int keyboard_index = -1; @@ -717,14 +717,16 @@ void SDL_PrivateKeyboardAdded(SDL_KeyboardID keyboardID) SDL_keyboards = keyboards; ++SDL_keyboard_count; - SDL_Event event; - SDL_zero(event); - event.type = SDL_EVENT_KEYBOARD_ADDED; - event.kdevice.which = keyboardID; - SDL_PushEvent(&event); + if (send_event) { + SDL_Event event; + SDL_zero(event); + event.type = SDL_EVENT_KEYBOARD_ADDED; + event.kdevice.which = keyboardID; + SDL_PushEvent(&event); + } } -void SDL_PrivateKeyboardRemoved(SDL_KeyboardID keyboardID) +void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID) { int keyboard_index = -1; @@ -936,13 +938,6 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo Uint8 repeat = SDL_FALSE; const Uint8 source = flags & KEYBOARD_SOURCE_MASK; - if (keyboardID == 0) { - if (source == KEYBOARD_HARDWARE && SDL_keyboard_count > 0) { - /* Assume it's from the first keyboard */ - keyboardID = SDL_keyboards[0]; - } - } - if (scancode == SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { return 0; } diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index f32566df7..584951a94 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -30,10 +30,10 @@ extern int SDL_InitKeyboard(void); extern SDL_bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys); /* A keyboard has been added to the system */ -extern void SDL_PrivateKeyboardAdded(SDL_KeyboardID keyboardID); +extern void SDL_AddKeyboard(SDL_KeyboardID keyboardID, SDL_bool send_event); /* A keyboard has been removed from the system */ -extern void SDL_PrivateKeyboardRemoved(SDL_KeyboardID keyboardID); +extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID); /* Get the default keymap */ extern void SDL_GetDefaultKeymap(SDL_Keycode *keymap); diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 347227020..616115bf7 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -41,7 +41,7 @@ static SDL_MouseID *SDL_mice; /* for mapping mouse events to touch */ static SDL_bool track_mouse_down = SDL_FALSE; -static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y); +static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y); static void SDLCALL SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { @@ -235,7 +235,7 @@ SDL_bool SDL_IsMouse(Uint16 vendor, Uint16 product) return SDL_TRUE; } -void SDL_PrivateMouseAdded(SDL_MouseID mouseID) +void SDL_AddMouse(SDL_MouseID mouseID, SDL_bool send_event) { int mouse_index = -1; @@ -261,14 +261,16 @@ void SDL_PrivateMouseAdded(SDL_MouseID mouseID) SDL_mice = mice; ++SDL_mouse_count; - SDL_Event event; - SDL_zero(event); - event.type = SDL_EVENT_MOUSE_ADDED; - event.mdevice.which = mouseID; - SDL_PushEvent(&event); + if (send_event) { + SDL_Event event; + SDL_zero(event); + event.type = SDL_EVENT_MOUSE_ADDED; + event.mdevice.which = mouseID; + SDL_PushEvent(&event); + } } -void SDL_PrivateMouseRemoved(SDL_MouseID mouseID) +void SDL_RemoveMouse(SDL_MouseID mouseID) { int mouse_index = -1; @@ -469,7 +471,7 @@ void SDL_SetMouseFocus(SDL_Window *window) SDL_SetCursor(NULL); } -SDL_bool SDL_MousePositionInWindow(SDL_Window *window, SDL_MouseID mouseID, float x, float y) +SDL_bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y) { if (!window) { return SDL_FALSE; @@ -487,7 +489,7 @@ SDL_bool SDL_MousePositionInWindow(SDL_Window *window, SDL_MouseID mouseID, floa static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, float x, float y, Uint32 buttonstate, SDL_bool send_mouse_motion) { SDL_Mouse *mouse = SDL_GetMouse(); - SDL_bool inWindow = SDL_MousePositionInWindow(window, mouse->mouseID, x, y); + SDL_bool inWindow = SDL_MousePositionInWindow(window, x, y); if (!inWindow) { if (window == mouse->focus) { @@ -495,7 +497,7 @@ static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, float x, float y, Uint3 SDL_Log("Mouse left window, synthesizing move & focus lost event\n"); #endif if (send_mouse_motion) { - SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y); + SDL_PrivateSendMouseMotion(0, window, 0, SDL_FALSE, x, y); } SDL_SetMouseFocus(NULL); } @@ -508,13 +510,13 @@ static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, float x, float y, Uint3 #endif SDL_SetMouseFocus(window); if (send_mouse_motion) { - SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y); + SDL_PrivateSendMouseMotion(0, window, 0, SDL_FALSE, x, y); } } return SDL_TRUE; } -int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y) +int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y) { if (window && !relative) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -672,7 +674,7 @@ static void ConstrainMousePosition(SDL_Mouse *mouse, SDL_Window *window, float * } } -static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y) +static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -713,7 +715,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ if (mouse->WarpMouse) { mouse->WarpMouse(window, center_x, center_y); } else { - SDL_PrivateSendMouseMotion(timestamp, window, mouseID, 0, center_x, center_y); + SDL_PrivateSendMouseMotion(timestamp, window, mouseID, SDL_FALSE, center_x, center_y); } } } @@ -1186,7 +1188,7 @@ void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, SDL_bool (!mouse->relative_mode || mouse->relative_mode_warp)) { mouse->WarpMouse(window, x, y); } else { - SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y); + SDL_PrivateSendMouseMotion(0, window, 0, SDL_FALSE, x, y); } } diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 1b2ccbeac..ea700a30b 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -75,7 +75,6 @@ typedef struct Uint32 (*GetGlobalMouseState)(float *x, float *y); /* Data common to all mice */ - SDL_MouseID mouseID; SDL_Window *focus; float x; float y; @@ -132,10 +131,10 @@ extern void SDL_PostInitMouse(void); extern SDL_bool SDL_IsMouse(Uint16 vendor, Uint16 product); /* A mouse has been added to the system */ -extern void SDL_PrivateMouseAdded(SDL_MouseID mouseID); +extern void SDL_AddMouse(SDL_MouseID mouseID, SDL_bool send_event); /* A mouse has been removed from the system */ -extern void SDL_PrivateMouseRemoved(SDL_MouseID mouseID); +extern void SDL_RemoveMouse(SDL_MouseID mouseID); /* Get the mouse state structure */ extern SDL_Mouse *SDL_GetMouse(void); @@ -153,7 +152,7 @@ extern int SDL_UpdateMouseCapture(SDL_bool force_release); extern int SDL_SetMouseSystemScale(int num_values, const float *values); /* Send a mouse motion event */ -extern int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y); +extern int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y); /* Send a mouse button event */ extern int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button); @@ -173,7 +172,7 @@ extern void SDL_ResetMouse(void); #endif /* 0 */ /* Check if mouse position is within window or captured by window */ -extern SDL_bool SDL_MousePositionInWindow(SDL_Window *window, SDL_MouseID mouseID, float x, float y); +extern SDL_bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y); /* Shutdown the mouse subsystem */ extern void SDL_QuitMouse(void); diff --git a/src/events/SDL_pen.c b/src/events/SDL_pen.c index 43ec94921..e2eb4e10c 100644 --- a/src/events/SDL_pen.c +++ b/src/events/SDL_pen.c @@ -496,7 +496,6 @@ int SDL_SendPenMotion(Uint64 timestamp, SDL_bool window_relative, const SDL_PenStatusInfo *status) { - const SDL_Mouse *mouse = SDL_GetMouse(); int i; SDL_Pen *pen = SDL_GetPenPtr(instance_id); SDL_Event event; @@ -539,7 +538,7 @@ int SDL_SendPenMotion(Uint64 timestamp, send_mouse_update = (x != last_x) || (y != last_y); - if (!(SDL_MousePositionInWindow(window, mouse->mouseID, x, y))) { + if (!(SDL_MousePositionInWindow(window, x, y))) { return SDL_FALSE; } @@ -557,7 +556,7 @@ int SDL_SendPenMotion(Uint64 timestamp, if (send_mouse_update) { switch (pen_mouse_emulation_mode) { case PEN_MOUSE_EMULATE: - return (SDL_SendMouseMotion(0, window, SDL_PEN_MOUSEID, 0, x, y)) || posted; + return (SDL_SendMouseMotion(0, window, SDL_PEN_MOUSEID, SDL_FALSE, x, y)) || posted; case PEN_MOUSE_STATELESS: /* Report mouse event but don't update mouse state */ @@ -584,7 +583,6 @@ int SDL_SendPenMotion(Uint64 timestamp, int SDL_SendPenTipEvent(Uint64 timestamp, SDL_PenID instance_id, Uint8 state) { - SDL_Mouse *mouse = SDL_GetMouse(); SDL_Pen *pen = SDL_GetPenPtr(instance_id); SDL_Event event; SDL_bool posted = SDL_FALSE; @@ -597,7 +595,7 @@ int SDL_SendPenTipEvent(Uint64 timestamp, SDL_PenID instance_id, Uint8 state) } window = pen->header.window; - if ((state == SDL_PRESSED) && !(window && SDL_MousePositionInWindow(window, mouse->mouseID, last->x, last->y))) { + if ((state == SDL_PRESSED) && !(window && SDL_MousePositionInWindow(window, last->x, last->y))) { return SDL_FALSE; } @@ -663,7 +661,6 @@ int SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, Uint8 state, Uint8 button) { - SDL_Mouse *mouse = SDL_GetMouse(); SDL_Pen *pen = SDL_GetPenPtr(instance_id); SDL_Event event; SDL_bool posted = SDL_FALSE; @@ -676,7 +673,7 @@ int SDL_SendPenButton(Uint64 timestamp, } window = pen->header.window; - if ((state == SDL_PRESSED) && !(window && SDL_MousePositionInWindow(window, mouse->mouseID, last->x, last->y))) { + if ((state == SDL_PRESSED) && !(window && SDL_MousePositionInWindow(window, last->x, last->y))) { return SDL_FALSE; } diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index dcd855771..98975e9ca 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -279,7 +279,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W if (pos_y > (float)(window->h - 1)) { pos_y = (float)(window->h - 1); } - SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, SDL_FALSE, pos_x, pos_y); SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); } } else { @@ -403,7 +403,7 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, if (pos_y > (float)(window->h - 1)) { pos_y = (float)(window->h - 1); } - SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, SDL_FALSE, pos_x, pos_y); } } } diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index 3c5063bd3..cff44ed61 100644 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -330,12 +330,12 @@ static SDL_Scancode TranslateKeycode(int keycode) int Android_OnKeyDown(int keycode) { - return SDL_SendKeyboardKey(0, 0, SDL_PRESSED, TranslateKeycode(keycode)); + return SDL_SendKeyboardKey(0, Android_KeyboardID, SDL_PRESSED, TranslateKeycode(keycode)); } int Android_OnKeyUp(int keycode) { - return SDL_SendKeyboardKey(0, 0, SDL_RELEASED, TranslateKeycode(keycode)); + return SDL_SendKeyboardKey(0, Android_KeyboardID, SDL_RELEASED, TranslateKeycode(keycode)); } SDL_bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this) diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index 39dee434f..122fece95 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -221,25 +221,25 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y changes = state & ~last_state; button = TranslateButton(changes); last_state = state; - SDL_SendMouseMotion(0, window, 0, relative, x, y); - SDL_SendMouseButton(0, window, 0, SDL_PRESSED, button); + SDL_SendMouseMotion(0, window, Android_MouseID, relative, x, y); + SDL_SendMouseButton(0, window, Android_MouseID, SDL_PRESSED, button); break; case ACTION_UP: changes = last_state & ~state; button = TranslateButton(changes); last_state = state; - SDL_SendMouseMotion(0, window, 0, relative, x, y); - SDL_SendMouseButton(0, window, 0, SDL_RELEASED, button); + SDL_SendMouseMotion(0, window, Android_MouseID, relative, x, y); + SDL_SendMouseButton(0, window, Android_MouseID, SDL_RELEASED, button); break; case ACTION_MOVE: case ACTION_HOVER_MOVE: - SDL_SendMouseMotion(0, window, 0, relative, x, y); + SDL_SendMouseMotion(0, window, Android_MouseID, relative, x, y); break; case ACTION_SCROLL: - SDL_SendMouseWheel(0, window, 0, x, y, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, window, Android_MouseID, x, y, SDL_MOUSEWHEEL_NORMAL); break; default: diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 17f7e5704..3a0686ce8 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -67,6 +67,8 @@ SDL_Semaphore *Android_PauseSem = NULL; SDL_Semaphore *Android_ResumeSem = NULL; SDL_Mutex *Android_ActivityMutex = NULL; static SDL_SystemTheme Android_SystemTheme; +SDL_KeyboardID Android_KeyboardID = 0; +SDL_MouseID Android_MouseID = 0; static int Android_SuspendScreenSaver(SDL_VideoDevice *_this) { diff --git a/src/video/android/SDL_androidvideo.h b/src/video/android/SDL_androidvideo.h index f6dd54eb5..ebda0cc20 100644 --- a/src/video/android/SDL_androidvideo.h +++ b/src/video/android/SDL_androidvideo.h @@ -46,5 +46,7 @@ extern int Android_SurfaceHeight; extern float Android_ScreenDensity; extern SDL_Semaphore *Android_PauseSem, *Android_ResumeSem; extern SDL_Mutex *Android_ActivityMutex; +extern SDL_KeyboardID Android_KeyboardID; +extern SDL_MouseID Android_MouseID; #endif /* SDL_androidvideo_h_ */ diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 5c419cda3..99dfb9931 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -200,6 +200,7 @@ static bool IsModifierKeyPressed(unsigned int flags, static void HandleModifiers(SDL_VideoDevice *_this, SDL_Scancode code, unsigned int modifierFlags) { + SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata; bool pressed = false; if (code == SDL_SCANCODE_LSHIFT) { @@ -231,9 +232,9 @@ static void HandleModifiers(SDL_VideoDevice *_this, SDL_Scancode code, unsigned } if (pressed) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, code); + SDL_SendKeyboardKey(0, videodata.keyboardID, SDL_PRESSED, code); } else { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, code); + SDL_SendKeyboardKey(0, videodata.keyboardID, SDL_RELEASED, code); } } @@ -414,7 +415,7 @@ void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event) UpdateKeymap(data, SDL_TRUE); } - SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), 0, SDL_PRESSED, code); + SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), data ? data.keyboardID : 0, SDL_PRESSED, code); #ifdef DEBUG_SCANCODES if (code == SDL_SCANCODE_UNKNOWN) { SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list or to Christian Walther . Mac virtual key code is %d.\n", scancode); @@ -433,7 +434,7 @@ void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event) } break; case NSEventTypeKeyUp: - SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), 0, SDL_RELEASED, code); + SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), data ? data.keyboardID : 0, SDL_RELEASED, code); break; case NSEventTypeFlagsChanged: { // see if the new modifierFlags mean any existing keys should be pressed/released... diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 3be095b37..727912cae 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -302,7 +302,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y) SDL_SetMouseFocus(win); if (win) { SDL_assert(win == mouse->focus); - SDL_SendMouseMotion(0, win, mouse->mouseID, 0, x - win->x, y - win->y); + SDL_SendMouseMotion(0, win, 0, SDL_FALSE, x - win->x, y - win->y); } } @@ -450,9 +450,10 @@ static void Cocoa_HandleTitleButtonEvent(SDL_VideoDevice *_this, NSEvent *event) void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event) { + SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata; + SDL_MouseID mouseID = videodata.mouseID; SDL_Mouse *mouse; SDL_MouseData *driverdata; - SDL_MouseID mouseID; NSPoint location; CGFloat lastMoveX, lastMoveY; float deltaX, deltaY; @@ -490,7 +491,6 @@ void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event) return; /* can happen when returning from fullscreen Space on shutdown */ } - mouseID = mouse ? mouse->mouseID : 0; seenWarp = driverdata->seenWarp; driverdata->seenWarp = NO; @@ -524,20 +524,16 @@ void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event) DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY); } - SDL_SendMouseMotion(Cocoa_GetEventTimestamp([event timestamp]), mouse->focus, mouseID, 1, deltaX, deltaY); + SDL_SendMouseMotion(Cocoa_GetEventTimestamp([event timestamp]), mouse->focus, mouseID, SDL_TRUE, deltaX, deltaY); } void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) { - SDL_MouseID mouseID; + SDL_CocoaVideoData *videodata = ((__bridge SDL_CocoaWindowData *)window->driverdata).videodata; + SDL_MouseID mouseID = videodata.mouseID; SDL_MouseWheelDirection direction; CGFloat x, y; - SDL_Mouse *mouse = SDL_GetMouse(); - if (!mouse) { - return; - } - mouseID = mouse->mouseID; x = -[event deltaX]; y = [event deltaY]; direction = SDL_MOUSEWHEEL_NORMAL; diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h index 2929fe0ad..a35063a6a 100644 --- a/src/video/cocoa/SDL_cocoavideo.h +++ b/src/video/cocoa/SDL_cocoavideo.h @@ -101,6 +101,8 @@ DECLARE_ALERT_STYLE(Critical); @property(nonatomic) int trackpad_is_touch_only; @property(nonatomic) unsigned int modifierFlags; @property(nonatomic) void *key_layout; +@property(nonatomic) SDL_KeyboardID keyboardID; +@property(nonatomic) SDL_MouseID mouseID; @property(nonatomic) SDLTranslatorResponder *fieldEdit; @property(nonatomic) NSInteger clipboard_count; @property(nonatomic) IOPMAssertionID screensaver_assertion; diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 971892f11..20c46b5ca 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -33,6 +33,9 @@ #include "SDL_cocoamessagebox.h" #include "SDL_cocoashape.h" +#include "../../events/SDL_keyboard_c.h" +#include "../../events/SDL_mouse_c.h" + @implementation SDL_CocoaVideoData @end @@ -198,6 +201,13 @@ int Cocoa_VideoInit(SDL_VideoDevice *_this) return -1; } + // Assume we have a mouse and keyboard + // We could use GCMouse and GCKeyboard if we needed to, as is done in SDL_uikitevents.m + data.keyboardID = SDL_GetNextObjectID(); + SDL_AddKeyboard(data.keyboardID, SDL_FALSE); + data.mouseID = SDL_GetNextObjectID(); + SDL_AddMouse(data.mouseID, SDL_FALSE); + data.allow_spaces = SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE); data.trackpad_is_touch_only = SDL_GetHintBoolean(SDL_HINT_TRACKPAD_IS_TOUCH_ONLY, SDL_FALSE); diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 5b7c5aca6..0a43da32c 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -191,7 +191,6 @@ NSData *data; NSArray *array; NSPoint point; - SDL_Mouse *mouse; float x, y; if (desiredType == nil) { @@ -208,11 +207,10 @@ /* Code addon to update the mouse location */ point = [sender draggingLocation]; - mouse = SDL_GetMouse(); x = point.x; y = (sdlwindow->h - point.y); if (x >= 0.0f && x < (float)sdlwindow->w && y >= 0.0f && y < (float)sdlwindow->h) { - SDL_SendMouseMotion(0, sdlwindow, mouse->mouseID, 0, x, y); + SDL_SendMouseMotion(0, sdlwindow, 0, SDL_FALSE, x, y); } /* Code addon to update the mouse location */ @@ -1091,7 +1089,7 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) y = (window->h - point.y); if (x >= 0.0f && x < (float)window->w && y >= 0.0f && y < (float)window->h) { - SDL_SendMouseMotion(0, window, mouse->mouseID, 0, x, y); + SDL_SendMouseMotion(0, window, 0, SDL_FALSE, x, y); } } @@ -1378,11 +1376,13 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) /* Also note that SDL_SendKeyboardKey expects all capslock events to be keypresses; it won't toggle the mod state if you send a keyrelease. */ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata; const SDL_bool osenabled = ([theEvent modifierFlags] & NSEventModifierFlagCapsLock) ? SDL_TRUE : SDL_FALSE; const SDL_bool sdlenabled = (SDL_GetModState() & SDL_KMOD_CAPS) ? SDL_TRUE : SDL_FALSE; if (osenabled ^ sdlenabled) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, videodata.keyboardID, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, videodata.keyboardID, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); } } - (void)keyDown:(NSEvent *)theEvent @@ -1457,7 +1457,9 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button) { - const SDL_MouseID mouseID = mouse->mouseID; + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata; + SDL_MouseID mouseID = videodata.mouseID; const int clicks = (int)[theEvent clickCount]; SDL_Window *focus = SDL_GetKeyboardFocus(); int rc; @@ -1589,8 +1591,10 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ - (void)mouseMoved:(NSEvent *)theEvent { + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata; + SDL_MouseID mouseID = videodata.mouseID; SDL_Mouse *mouse = SDL_GetMouse(); - SDL_MouseID mouseID; NSPoint point; float x, y; SDL_Window *window; @@ -1599,7 +1603,6 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ return; } - mouseID = mouse->mouseID; window = _data.window; if (window->flags & SDL_WINDOW_TRANSPARENT) { @@ -1631,7 +1634,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ } } - SDL_SendMouseMotion(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, 0, x, y); + SDL_SendMouseMotion(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, SDL_FALSE, x, y); } - (void)mouseDragged:(NSEvent *)theEvent diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index d1e768dfd..e7f2c1d3f 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -614,7 +614,7 @@ static EM_BOOL Emscripten_HandlePointerLockChange(int eventType, const Emscripte static EM_BOOL Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { SDL_WindowData *window_data = userData; - const int isPointerLocked = window_data->has_pointer_lock; + const SDL_bool isPointerLocked = window_data->has_pointer_lock; float mx, my; /* rescale (in case canvas is being scaled)*/ @@ -631,7 +631,7 @@ static EM_BOOL Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEv my = (float)(mouseEvent->targetY * yscale); } - SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my); + SDL_SendMouseMotion(0, window_data->window, EMSCRIPTEN_MOUSE_ID, isPointerLocked, mx, my); return 0; } @@ -669,7 +669,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse sdl_event_type = SDL_EVENT_MOUSE_BUTTON_UP; prevent_default = SDL_EventEnabled(sdl_event_type); } - SDL_SendMouseButton(0, window_data->window, 0, sdl_button_state, sdl_button); + SDL_SendMouseButton(0, window_data->window, EMSCRIPTEN_MOUSE_ID, sdl_button_state, sdl_button); /* Do not consume the event if the mouse is outside of the canvas. */ emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h); @@ -685,7 +685,7 @@ static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseE { SDL_WindowData *window_data = userData; - const int isPointerLocked = window_data->has_pointer_lock; + const SDL_bool isPointerLocked = window_data->has_pointer_lock; if (!isPointerLocked) { /* rescale (in case canvas is being scaled)*/ @@ -695,7 +695,7 @@ static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseE mx = (float)(mouseEvent->targetX * (window_data->window->w / client_w)); my = (float)(mouseEvent->targetY * (window_data->window->h / client_h)); - SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my); + SDL_SendMouseMotion(0, window_data->window, EMSCRIPTEN_MOUSE_ID, isPointerLocked, mx, my); } SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL); @@ -720,7 +720,7 @@ static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent break; } - SDL_SendMouseWheel(0, window_data->window, 0, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, window_data->window, EMSCRIPTEN_MOUSE_ID, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL); return SDL_EventEnabled(SDL_EVENT_MOUSE_WHEEL); } @@ -811,7 +811,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent } if (scancode != SDL_SCANCODE_UNKNOWN) { - SDL_SendKeyboardKeyAndKeycode(0, 0, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode, keycode); + SDL_SendKeyboardKeyAndKeycode(0, EMSCRIPTEN_KEYBOARD_ID, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode, keycode); } /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index a7b9aa68e..67bf34075 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -136,6 +136,10 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this) Emscripten_InitMouse(); + /* Assume we have a mouse and keyboard */ + SDL_AddKeyboard(EMSCRIPTEN_KEYBOARD_ID, SDL_FALSE); + SDL_AddMouse(EMSCRIPTEN_MOUSE_ID, SDL_FALSE); + /* We're done! */ return 0; } diff --git a/src/video/emscripten/SDL_emscriptenvideo.h b/src/video/emscripten/SDL_emscriptenvideo.h index 441720585..094f9b150 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.h +++ b/src/video/emscripten/SDL_emscriptenvideo.h @@ -28,6 +28,9 @@ #include #include +#define EMSCRIPTEN_KEYBOARD_ID 1 +#define EMSCRIPTEN_MOUSE_ID 1 + struct SDL_WindowData { SDL_Window *window; diff --git a/src/video/haiku/SDL_BApp.h b/src/video/haiku/SDL_BApp.h deleted file mode 100644 index 2d5be1e2b..000000000 --- a/src/video/haiku/SDL_BApp.h +++ /dev/null @@ -1,425 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2024 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef SDL_BAPP_H -#define SDL_BAPP_H - -#include -#include -#include -#ifdef SDL_VIDEO_OPENGL -#include -#endif - -#include "../../video/haiku/SDL_bkeyboard.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "SDL_internal.h" - -/* Local includes */ -#include "../../events/SDL_events_c.h" -#include "../../video/haiku/SDL_bframebuffer.h" - -#ifdef __cplusplus -} -#endif - -#include - -/* Forward declarations */ -class SDL_BLooper; -class SDL_BWin; - -/* Message constants */ -enum ToSDL -{ - /* Intercepted by BWindow on its way to BView */ - BAPP_MOUSE_MOVED, - BAPP_MOUSE_BUTTON, - BAPP_MOUSE_WHEEL, - BAPP_KEY, - BAPP_REPAINT, /* from _UPDATE_ */ - /* From BWindow */ - BAPP_MAXIMIZE, /* from B_ZOOM */ - BAPP_MINIMIZE, - BAPP_RESTORE, /* TODO: IMPLEMENT! */ - BAPP_SHOW, - BAPP_HIDE, - BAPP_MOUSE_FOCUS, /* caused by MOUSE_MOVE */ - BAPP_KEYBOARD_FOCUS, /* from WINDOW_ACTIVATED */ - BAPP_WINDOW_CLOSE_REQUESTED, - BAPP_WINDOW_MOVED, - BAPP_WINDOW_RESIZED, - BAPP_SCREEN_CHANGED -}; - - -extern "C" SDL_BLooper *SDL_Looper; - - -/* Create a descendant of BLooper */ -class SDL_BLooper : public BLooper -{ - public: - SDL_BLooper(const char* name) : BLooper(name) - { -#ifdef SDL_VIDEO_OPENGL - _current_context = NULL; -#endif - } - - virtual ~SDL_BLooper() - { - } - - /* Event-handling functions */ - virtual void MessageReceived(BMessage *message) - { - /* Sort out SDL-related messages */ - switch (message->what) { - case BAPP_MOUSE_MOVED: - _HandleMouseMove(message); - break; - - case BAPP_MOUSE_BUTTON: - _HandleMouseButton(message); - break; - - case BAPP_MOUSE_WHEEL: - _HandleMouseWheel(message); - break; - - case BAPP_KEY: - _HandleKey(message); - break; - - case BAPP_REPAINT: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_EXPOSED); - break; - - case BAPP_MAXIMIZE: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_MAXIMIZED); - break; - - case BAPP_MINIMIZE: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_MINIMIZED); - break; - - case BAPP_SHOW: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_SHOWN); - break; - - case BAPP_HIDE: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_HIDDEN); - break; - - case BAPP_MOUSE_FOCUS: - _HandleMouseFocus(message); - break; - - case BAPP_KEYBOARD_FOCUS: - _HandleKeyboardFocus(message); - break; - - case BAPP_WINDOW_CLOSE_REQUESTED: - _HandleBasicWindowEvent(message, SDL_EVENT_WINDOW_CLOSE_REQUESTED); - break; - - case BAPP_WINDOW_MOVED: - _HandleWindowMoved(message); - break; - - case BAPP_WINDOW_RESIZED: - _HandleWindowResized(message); - break; - - case B_LOCALE_CHANGED: - SDL_SendLocaleChangedEvent(); - break; - - case BAPP_SCREEN_CHANGED: - /* TODO: Handle screen resize or workspace change */ - break; - - default: - BLooper::MessageReceived(message); - break; - } - } - - /* Window creation/destruction methods */ - int32 GetID(SDL_Window *win) - { - int32 i; - for (i = 0; i < _GetNumWindowSlots(); ++i) { - if (GetSDLWindow(i) == NULL) { - _SetSDLWindow(win, i); - return i; - } - } - - /* Expand the vector if all slots are full */ - if (i == _GetNumWindowSlots()) { - _PushBackWindow(win); - return i; - } - - /* TODO: error handling */ - return 0; - } - - /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is - there another way to do this? */ - void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ - - SDL_Window *GetSDLWindow(int32 winID) - { - return _window_map[winID]; - } - -#ifdef SDL_VIDEO_OPENGL - BGLView *GetCurrentContext() - { - return _current_context; - } - - void SetCurrentContext(BGLView *newContext) - { - if (_current_context) - _current_context->UnlockGL(); - _current_context = newContext; - if (_current_context) - _current_context->LockGL(); - } -#endif - - private: - /* Event management */ - void _HandleBasicWindowEvent(BMessage *msg, SDL_EventType sdlEventType) - { - SDL_Window *win; - int32 winID; - if ( - !_GetWinID(msg, &winID)) { - return; - } - win = GetSDLWindow(winID); - SDL_SendWindowEvent(win, sdlEventType, 0, 0); - } - - void _HandleMouseMove(BMessage *msg) - { - SDL_Window *win; - int32 winID; - int32 x = 0, y = 0; - if ( - !_GetWinID(msg, &winID) || - msg->FindInt32("x", &x) != B_OK || /* x movement */ - msg->FindInt32("y", &y) != B_OK /* y movement */ - ) { - return; - } - win = GetSDLWindow(winID); - - // Simple relative mode support for mouse. - if (SDL_GetMouse()->relative_mode) { - int winWidth, winHeight, winPosX, winPosY; - SDL_GetWindowSize(win, &winWidth, &winHeight); - SDL_GetWindowPosition(win, &winPosX, &winPosY); - int dx = x - (winWidth / 2); - int dy = y - (winHeight / 2); - SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, (float)dx, (float)dy); - set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2)); - if (!be_app->IsCursorHidden()) - be_app->HideCursor(); - } else { - SDL_SendMouseMotion(0, win, 0, 0, (float)x, (float)y); - if (SDL_CursorVisible() && be_app->IsCursorHidden()) - be_app->ShowCursor(); - } - } - - void _HandleMouseButton(BMessage *msg) - { - SDL_Window *win; - int32 winID; - int32 button, state; /* left/middle/right, pressed/released */ - if ( - !_GetWinID(msg, &winID) || - msg->FindInt32("button-id", &button) != B_OK || - msg->FindInt32("button-state", &state) != B_OK) { - return; - } - win = GetSDLWindow(winID); - SDL_SendMouseButton(0, win, 0, state, button); - } - - void _HandleMouseWheel(BMessage *msg) - { - SDL_Window *win; - int32 winID; - int32 xTicks, yTicks; - if ( - !_GetWinID(msg, &winID) || - msg->FindInt32("xticks", &xTicks) != B_OK || - msg->FindInt32("yticks", &yTicks) != B_OK) { - return; - } - win = GetSDLWindow(winID); - SDL_SendMouseWheel(0, win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL); - } - - void _HandleKey(BMessage *msg) - { - int32 scancode, state; /* scancode, pressed/released */ - if ( - msg->FindInt32("key-state", &state) != B_OK || - msg->FindInt32("key-scancode", &scancode) != B_OK) { - return; - } - - /* Make sure this isn't a repeated event (key pressed and held) */ - if (state == SDL_PRESSED && HAIKU_GetKeyState(scancode) == SDL_PRESSED) { - return; - } - HAIKU_SetKeyState(scancode, state); - SDL_SendKeyboardKey(0, 0, state, HAIKU_GetScancodeFromBeKey(scancode)); - - if (state == SDL_PRESSED && SDL_EventEnabled(SDL_EVENT_TEXT_INPUT)) { - const int8 *keyUtf8; - ssize_t count; - if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) { - char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; - SDL_zeroa(text); - SDL_memcpy(text, keyUtf8, count); - SDL_SendKeyboardText(text); - } - } - } - - void _HandleMouseFocus(BMessage *msg) - { - SDL_Window *win; - int32 winID; - bool bSetFocus; /* If false, lose focus */ - if ( - !_GetWinID(msg, &winID) || - msg->FindBool("focusGained", &bSetFocus) != B_OK) { - return; - } - win = GetSDLWindow(winID); - if (bSetFocus) { - SDL_SetMouseFocus(win); - } else if (SDL_GetMouseFocus() == win) { - /* Only lose all focus if this window was the current focus */ - SDL_SetMouseFocus(NULL); - } - } - - void _HandleKeyboardFocus(BMessage *msg) - { - SDL_Window *win; - int32 winID; - bool bSetFocus; /* If false, lose focus */ - if ( - !_GetWinID(msg, &winID) || - msg->FindBool("focusGained", &bSetFocus) != B_OK) { - return; - } - win = GetSDLWindow(winID); - if (bSetFocus) { - SDL_SetKeyboardFocus(win); - } else if (SDL_GetKeyboardFocus() == win) { - /* Only lose all focus if this window was the current focus */ - SDL_SetKeyboardFocus(NULL); - } - } - - void _HandleWindowMoved(BMessage *msg) - { - SDL_Window *win; - int32 winID; - int32 xPos, yPos; - /* Get the window id and new x/y position of the window */ - if ( - !_GetWinID(msg, &winID) || - msg->FindInt32("window-x", &xPos) != B_OK || - msg->FindInt32("window-y", &yPos) != B_OK) { - return; - } - win = GetSDLWindow(winID); - SDL_SendWindowEvent(win, SDL_EVENT_WINDOW_MOVED, xPos, yPos); - } - - void _HandleWindowResized(BMessage *msg) - { - SDL_Window *win; - int32 winID; - int32 w, h; - /* Get the window id ]and new x/y position of the window */ - if ( - !_GetWinID(msg, &winID) || - msg->FindInt32("window-w", &w) != B_OK || - msg->FindInt32("window-h", &h) != B_OK) { - return; - } - win = GetSDLWindow(winID); - SDL_SendWindowEvent(win, SDL_EVENT_WINDOW_RESIZED, w, h); - } - - bool _GetWinID(BMessage *msg, int32 *winID) - { - return msg->FindInt32("window-id", winID) == B_OK; - } - - /* Vector functions: Wraps vector stuff in case we need to change - implementation */ - void _SetSDLWindow(SDL_Window *win, int32 winID) - { - _window_map[winID] = win; - } - - int32 _GetNumWindowSlots() - { - return _window_map.size(); - } - - void _PopBackWindow() - { - _window_map.pop_back(); - } - - void _PushBackWindow(SDL_Window *win) - { - _window_map.push_back(win); - } - - /* Members */ - std::vector _window_map; /* Keeps track of SDL_Windows by index-id */ - -#ifdef SDL_VIDEO_OPENGL - BGLView *_current_context; -#endif -}; - -#endif diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index be246c42a..ea495af7a 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -40,6 +40,8 @@ extern "C" { #include "SDL_bframebuffer.h" #include "SDL_bevents.h" #include "SDL_bmessagebox.h" +#include "../../events/SDL_keyboard_c.h" +#include "../../events/SDL_mouse_c.h" static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { return (SDL_BWin *)(window->driverdata); @@ -279,6 +281,10 @@ int HAIKU_VideoInit(SDL_VideoDevice *_this) HAIKU_MouseInit(_this); + /* Assume we have a mouse and keyboard */ + SDL_AddKeyboard(BAPP_KEYBOARD_ID, SDL_FALSE); + SDL_AddMouse(BAPP_MOUSE_ID, SDL_FALSE); + #ifdef SDL_VIDEO_OPENGL /* testgl application doesn't load library, just tries to load symbols */ /* is it correct? if so we have to load library here */ diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index 1b3524b91..9270afb11 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -351,7 +351,7 @@ static int KMSDRM_WarpMouseGlobal(float x, float y) SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); /* Update internal mouse position. */ - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y); + SDL_SendMouseMotion(0, mouse->focus, 0, SDL_FALSE, x, y); /* And now update the cursor graphic position on screen. */ if (dispdata->cursor_bo) { diff --git a/src/video/ngage/SDL_ngageevents.cpp b/src/video/ngage/SDL_ngageevents.cpp index 091d6e968..4977516c7 100644 --- a/src/video/ngage/SDL_ngageevents.cpp +++ b/src/video/ngage/SDL_ngageevents.cpp @@ -44,15 +44,15 @@ int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent); void NGAGE_PumpEvents(SDL_VideoDevice *_this) { - SDL_VideoData *phdata = _this->driverdata; + SDL_VideoData *data = _this->driverdata; - while (phdata->NGAGE_WsEventStatus != KRequestPending) { - phdata->NGAGE_WsSession.GetEvent(phdata->NGAGE_WsEvent); + while (data->NGAGE_WsEventStatus != KRequestPending) { + data->NGAGE_WsSession.GetEvent(data->NGAGE_WsEvent); - HandleWsEvent(_this, phdata->NGAGE_WsEvent); + HandleWsEvent(_this, data->NGAGE_WsEvent); - phdata->NGAGE_WsEventStatus = KRequestPending; - phdata->NGAGE_WsSession.EventReady(&phdata->NGAGE_WsEventStatus); + data->NGAGE_WsEventStatus = KRequestPending; + data->NGAGE_WsSession.EventReady(&data->NGAGE_WsEventStatus); } } @@ -149,25 +149,25 @@ static SDL_Scancode ConvertScancode(SDL_VideoDevice *_this, int key) int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent) { - SDL_VideoData *phdata = _this->driverdata; + SDL_VideoData *data = _this->driverdata; int posted = 0; switch (aWsEvent.Type()) { case EEventKeyDown: /* Key events */ - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, ConvertScancode(_this, aWsEvent.Key()->iScanCode)); + SDL_SendKeyboardKey(0, data->keyboardID, SDL_PRESSED, ConvertScancode(_this, aWsEvent.Key()->iScanCode)); break; case EEventKeyUp: /* Key events */ - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, ConvertScancode(_this, aWsEvent.Key()->iScanCode)); + SDL_SendKeyboardKey(0, data->keyboardID, SDL_RELEASED, ConvertScancode(_this, aWsEvent.Key()->iScanCode)); break; case EEventFocusGained: /* SDL window got focus */ - phdata->NGAGE_IsWindowFocused = ETrue; + data->NGAGE_IsWindowFocused = ETrue; /* Draw window background and screen buffer */ DisableKeyBlocking(_this); RedrawWindowL(_this); break; case EEventFocusLost: /* SDL window lost focus */ { - phdata->NGAGE_IsWindowFocused = EFalse; + data->NGAGE_IsWindowFocused = EFalse; RWsSession s; s.Connect(); RWindowGroup g(s); @@ -175,7 +175,7 @@ int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent) g.EnableReceiptOfFocus(EFalse); RWindow w(s); w.Construct(g, TUint32(&w)); - w.SetExtent(TPoint(0, 0), phdata->NGAGE_WsWindow.Size()); + w.SetExtent(TPoint(0, 0), data->NGAGE_WsWindow.Size()); w.SetOrdinalPosition(0); w.Activate(); w.Close(); diff --git a/src/video/ngage/SDL_ngagevideo.h b/src/video/ngage/SDL_ngagevideo.h index 77252e144..d3e3a7cfd 100644 --- a/src/video/ngage/SDL_ngagevideo.h +++ b/src/video/ngage/SDL_ngagevideo.h @@ -61,6 +61,8 @@ struct SDL_VideoData CFbsBitGc::TGraphicsOrientation NGAGE_ScreenOrientation; + SDL_KeyboardID keyboardID; + SDL_MouseID mouseID; }; #endif /* SDL_ngagevideo_h */ diff --git a/src/video/qnx/SDL_qnx.h b/src/video/qnx/SDL_qnx.h index 368f84000..1a9826bb5 100644 --- a/src/video/qnx/SDL_qnx.h +++ b/src/video/qnx/SDL_qnx.h @@ -33,6 +33,9 @@ typedef struct EGLConfig conf; } window_impl_t; +#define QNX_KEYBOARD_ID 1 +#define QNX_MOUSE_ID 1 + extern void handleKeyboardEvent(screen_event_t event); extern int glGetConfig(EGLConfig *pconf, int *pformat); diff --git a/src/video/qnx/SDL_qnxkeyboard.c b/src/video/qnx/SDL_qnxkeyboard.c index bb9546887..453a02801 100644 --- a/src/video/qnx/SDL_qnxkeyboard.c +++ b/src/video/qnx/SDL_qnxkeyboard.c @@ -125,8 +125,8 @@ void handleKeyboardEvent(screen_event_t event) // FIXME: // Need to handle more key states (such as key combinations). if (val & KEY_DOWN) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, scancode); + SDL_SendKeyboardKey(0, QNX_KEYBOARD_ID, SDL_PRESSED, scancode); } else { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, scancode); + SDL_SendKeyboardKey(0, QNX_KEYBOARD_ID, SDL_RELEASED, scancode); } } diff --git a/src/video/qnx/SDL_qnxvideo.c b/src/video/qnx/SDL_qnxvideo.c index b3fee9093..b0cd9fd79 100644 --- a/src/video/qnx/SDL_qnxvideo.c +++ b/src/video/qnx/SDL_qnxvideo.c @@ -20,6 +20,8 @@ */ #include "../../SDL_internal.h" #include "../SDL_sysvideo.h" +#include "../../events/SDL_keyboard_c.h" +#include "../../events/SDL_mouse_c.h" #include "SDL_qnx.h" static screen_context_t context; @@ -50,7 +52,10 @@ static int videoInit(SDL_VideoDevice *_this) return -1; } - _this->num_displays = 1; + /* Assume we have a mouse and keyboard */ + SDL_AddKeyboard(QNX_KEYBOARD_ID, SDL_FALSE); + SDL_AddMouse(QNX_MOUSE_ID, SDL_FALSE); + return 0; } diff --git a/src/video/raspberry/SDL_rpimouse.c b/src/video/raspberry/SDL_rpimouse.c index 6999cdb91..c834037e5 100644 --- a/src/video/raspberry/SDL_rpimouse.c +++ b/src/video/raspberry/SDL_rpimouse.c @@ -276,7 +276,7 @@ static int RPI_WarpMouseGlobal(float x, float y) } /* Update internal mouse position. */ - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y); + SDL_SendMouseMotion(0, mouse->focus, 0, SDL_FALSE, x, y); return RPI_WarpMouseGlobalGraphically(x, y); } diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index ad4a72c9d..8c6403f5d 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -58,7 +58,7 @@ void RISCOS_PollKeyboard(SDL_VideoDevice *_this) for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { if (driverdata->key_pressed[i] != 255) { if ((_kernel_osbyte(129, driverdata->key_pressed[i] ^ 0xff, 0xff) & 0xff) != 255) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_RISCOS_translate_keycode(driverdata->key_pressed[i])); + SDL_SendKeyboardKey(0, driverdata->keyboardID, SDL_RELEASED, SDL_RISCOS_translate_keycode(driverdata->key_pressed[i])); driverdata->key_pressed[i] = 255; } } @@ -81,7 +81,7 @@ void RISCOS_PollKeyboard(SDL_VideoDevice *_this) break; default: - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_RISCOS_translate_keycode(key)); + SDL_SendKeyboardKey(0, driverdata->keyboardID, SDL_PRESSED, SDL_RISCOS_translate_keycode(key)); /* Record the press so we can detect release later. */ for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { @@ -126,12 +126,12 @@ void RISCOS_PollMouse(SDL_VideoDevice *_this) buttons = regs.r[2]; if (mouse->x != x || mouse->y != y) { - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, (float)x, (float)y); + SDL_SendMouseMotion(0, mouse->focus, driverdata->mouseID, 0, (float)x, (float)y); } if (driverdata->last_mouse_buttons != buttons) { for (i = 0; i < SDL_arraysize(mouse_button_map); i++) { - SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]); + SDL_SendMouseButton(0, mouse->focus, driverdata->mouseID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]); } driverdata->last_mouse_buttons = buttons; } diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index 035431807..02b0abbc4 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -25,6 +25,8 @@ #include "../SDL_sysvideo.h" #include "../SDL_pixels_c.h" #include "../../events/SDL_events_c.h" +#include "../../events/SDL_keyboard_c.h" +#include "../../events/SDL_mouse_c.h" #include "SDL_riscosvideo.h" #include "SDL_riscosevents_c.h" @@ -51,7 +53,7 @@ static void RISCOS_DeleteDevice(SDL_VideoDevice *device) static SDL_VideoDevice *RISCOS_CreateDevice(void) { SDL_VideoDevice *device; - SDL_VideoData *phdata; + SDL_VideoData *data; /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); @@ -60,13 +62,13 @@ static SDL_VideoDevice *RISCOS_CreateDevice(void) } /* Initialize internal data */ - phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); - if (!phdata) { + data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); + if (!data) { SDL_free(device); return NULL; } - device->driverdata = phdata; + device->driverdata = data; /* Set the function pointers */ device->VideoInit = RISCOS_VideoInit; @@ -96,6 +98,8 @@ VideoBootStrap RISCOS_bootstrap = { static int RISCOS_VideoInit(SDL_VideoDevice *_this) { + SDL_VideoData *data = _this->driverdata; + if (RISCOS_InitEvents(_this) < 0) { return -1; } @@ -104,6 +108,12 @@ static int RISCOS_VideoInit(SDL_VideoDevice *_this) return -1; } + /* Assume we have a mouse and keyboard */ + data->keyboardID = SDL_GetNextObjectID(); + SDL_AddKeyboard(data->keyboardID, SDL_FALSE); + data->mouseID = SDL_GetNextObjectID(); + SDL_AddMouse(data->mouseID, SDL_FALSE); + if (RISCOS_InitModes(_this) < 0) { return -1; } diff --git a/src/video/riscos/SDL_riscosvideo.h b/src/video/riscos/SDL_riscosvideo.h index 986bcc2ff..c05598d9c 100644 --- a/src/video/riscos/SDL_riscosvideo.h +++ b/src/video/riscos/SDL_riscosvideo.h @@ -29,6 +29,8 @@ struct SDL_VideoData { + SDL_KeyboardID keyboardID; + SDL_MouseID mouseID; int last_mouse_buttons; Uint8 key_pressed[RISCOS_MAX_KEYS_PRESSED]; }; diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index 7f640cf02..233216486 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -178,7 +178,7 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0 { SDL_KeyboardID keyboardID = (SDL_KeyboardID)(uintptr_t)keyboard; - SDL_PrivateKeyboardAdded(keyboardID); + SDL_AddKeyboard(keyboardID, SDL_TRUE); keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) { SDL_SendKeyboardKey(0, keyboardID, pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode); @@ -193,7 +193,7 @@ static void OnGCKeyboardDisconnected(GCKeyboard *keyboard) API_AVAILABLE(macos(1 { SDL_KeyboardID keyboardID = (SDL_KeyboardID)(uintptr_t)keyboard; - SDL_PrivateKeyboardRemoved(keyboardID); + SDL_RemoveKeyboard(keyboardID); keyboard.keyboardInput.keyChangedHandler = nil; } @@ -319,7 +319,7 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14 { SDL_MouseID mouseID = (SDL_MouseID)(uintptr_t)mouse; - SDL_PrivateMouseAdded(mouseID); + SDL_AddMouse(mouseID, SDL_TRUE); 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_PrivateMouseRemoved(mouseID); + SDL_RemoveMouse(mouseID); } void SDL_InitGCMouse(void) diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c index 64108b1e7..cb0ccc4e9 100644 --- a/src/video/vita/SDL_vitakeyboard.c +++ b/src/video/vita/SDL_vitakeyboard.c @@ -43,6 +43,10 @@ void VITA_InitKeyboard(void) sceSysmoduleLoadModule(SCE_SYSMODULE_IME); /** For PVR OSK Support **/ #endif sceHidKeyboardEnumerate(&keyboard_hid_handle, 1); + + if (keyboard_hid_handle > 0) { + SDL_AddKeyboard((SDL_KeyboardID)keyboard_hid_handle, SDL_FALSE); + } } void VITA_PollKeyboard(void) @@ -53,6 +57,7 @@ void VITA_PollKeyboard(void) } if (keyboard_hid_handle > 0) { + SDL_KeyboardID keyboardID = (SDL_KeyboardID)keyboard_hid_handle; int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport **)&k_reports, SCE_HID_MAX_REPORT); if (numReports < 0) { @@ -62,40 +67,40 @@ void VITA_PollKeyboard(void) // The k_report only reports the state of the LED if (k_reports[numReports - 1].modifiers[1] & 0x1) { if (!(locks & 0x1)) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); locks |= 0x1; } } else { if (locks & 0x1) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); locks &= ~0x1; } } if (k_reports[numReports - 1].modifiers[1] & 0x2) { if (!(locks & 0x2)) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); locks |= 0x2; } } else { if (locks & 0x2) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); locks &= ~0x2; } } if (k_reports[numReports - 1].modifiers[1] & 0x4) { if (!(locks & 0x4)) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_SCROLLLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_SCROLLLOCK); locks |= 0x4; } } else { if (locks & 0x4) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_SCROLLLOCK); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_SCROLLLOCK); locks &= ~0x4; } } @@ -105,58 +110,58 @@ void VITA_PollKeyboard(void) if (changed_modifiers & 0x01) { if (prev_modifiers & 0x01) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LCTRL); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_LCTRL); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_LCTRL); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_LCTRL); } } if (changed_modifiers & 0x02) { if (prev_modifiers & 0x02) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_LSHIFT); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_LSHIFT); } } if (changed_modifiers & 0x04) { if (prev_modifiers & 0x04) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LALT); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_LALT); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_LALT); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_LALT); } } if (changed_modifiers & 0x08) { if (prev_modifiers & 0x08) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LGUI); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_LGUI); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_LGUI); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_LGUI); } } if (changed_modifiers & 0x10) { if (prev_modifiers & 0x10) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RCTRL); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_RCTRL); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_RCTRL); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_RCTRL); } } if (changed_modifiers & 0x20) { if (prev_modifiers & 0x20) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RSHIFT); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_RSHIFT); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_RSHIFT); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_RSHIFT); } } if (changed_modifiers & 0x40) { if (prev_modifiers & 0x40) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RALT); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_RALT); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_RALT); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_RALT); } } if (changed_modifiers & 0x80) { if (prev_modifiers & 0x80) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RGUI); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, SDL_SCANCODE_RGUI); } else { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, SDL_SCANCODE_RGUI); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, SDL_SCANCODE_RGUI); } } } @@ -170,10 +175,10 @@ void VITA_PollKeyboard(void) if (keyCode != prev_keys[i]) { if (prev_keys[i]) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, prev_keys[i]); + SDL_SendKeyboardKey(0, keyboardID, SDL_RELEASED, prev_keys[i]); } if (keyCode) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, keyCode); + SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, keyCode); } prev_keys[i] = keyCode; } diff --git a/src/video/vita/SDL_vitamouse.c b/src/video/vita/SDL_vitamouse.c index 836d33ee4..46d736252 100644 --- a/src/video/vita/SDL_vitamouse.c +++ b/src/video/vita/SDL_vitamouse.c @@ -37,6 +37,10 @@ Uint8 prev_buttons = 0; void VITA_InitMouse(void) { sceHidMouseEnumerate(&mouse_hid_handle, 1); + + if (mouse_hid_handle > 0) { + SDL_AddMouse((SDL_MouseID)mouse_hid_handle, SDL_FALSE); + } } void VITA_PollMouse(void) @@ -47,6 +51,7 @@ void VITA_PollMouse(void) } if (mouse_hid_handle > 0) { + SDL_MouseID mouseID = (SDL_MouseID)mouse_hid_handle; int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport **)&m_reports, SCE_HID_MAX_REPORT); if (numReports > 0) { for (int i = 0; i <= numReports - 1; i++) { @@ -54,27 +59,27 @@ void VITA_PollMouse(void) if (changed_buttons & 0x1) { if (prev_buttons & 0x1) - SDL_SendMouseButton(0, Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_LEFT); else - SDL_SendMouseButton(0, Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_LEFT); } if (changed_buttons & 0x2) { if (prev_buttons & 0x2) - SDL_SendMouseButton(0, Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_RIGHT); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT); else - SDL_SendMouseButton(0, Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_RIGHT); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT); } if (changed_buttons & 0x4) { if (prev_buttons & 0x4) - SDL_SendMouseButton(0, Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_MIDDLE); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE); else - SDL_SendMouseButton(0, Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_MIDDLE); + SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE); } prev_buttons = m_reports[i].buttons; if (m_reports[i].rel_x || m_reports[i].rel_y) { - SDL_SendMouseMotion(0, Vita_Window, 0, 1, (float)m_reports[i].rel_x, (float)m_reports[i].rel_y); + SDL_SendMouseMotion(0, Vita_Window, mouseID, SDL_TRUE, (float)m_reports[i].rel_x, (float)m_reports[i].rel_y); } } } diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index b36c745ad..24dde270f 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -515,7 +515,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *pointer, if (input->pointer_focus) { float sx = (float)(wl_fixed_to_double(sx_w) * window_data->pointer_scale.x); float sy = (float)(wl_fixed_to_double(sy_w) * window_data->pointer_scale.y); - SDL_SendMouseMotion(Wayland_GetPointerTimestamp(input, time), window_data->sdlwindow, input->pointer_id, 0, sx, sy); + SDL_SendMouseMotion(Wayland_GetPointerTimestamp(input, time), window_data->sdlwindow, input->pointer_id, SDL_FALSE, sx, sy); } if (window && window->hit_test) { @@ -1715,7 +1715,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, wl_pointer_add_listener(input->pointer, &pointer_listener, input); input->pointer_id = SDL_GetNextObjectID(); - SDL_PrivateMouseAdded(input->pointer_id); + SDL_AddMouse(input->pointer_id, SDL_TRUE); } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) { if (input->cursor_shape) { wp_cursor_shape_device_v1_destroy(input->cursor_shape); @@ -1725,7 +1725,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, input->pointer = NULL; input->display->pointer = NULL; - SDL_PrivateMouseRemoved(input->pointer_id); + SDL_RemoveMouse(input->pointer_id); input->pointer_id = 0; } @@ -1748,12 +1748,12 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, input); input->keyboard_id = SDL_GetNextObjectID(); - SDL_PrivateKeyboardAdded(input->keyboard_id); + SDL_AddKeyboard(input->keyboard_id, SDL_TRUE); } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) { wl_keyboard_destroy(input->keyboard); input->keyboard = NULL; - SDL_PrivateKeyboardRemoved(input->keyboard_id); + SDL_RemoveKeyboard(input->keyboard_id); input->keyboard_id = 0; } @@ -2709,7 +2709,7 @@ static void tablet_tool_handle_motion(void *data, struct zwp_tablet_tool_v2 *too input->current_pen.update_window = window; } else { /* Plain mouse event */ - SDL_SendMouseMotion(0, window->sdlwindow, 0, 0, sx, sy); + SDL_SendMouseMotion(0, window->sdlwindow, 0, SDL_FALSE, sx, sy); } } } @@ -3178,7 +3178,7 @@ static void relative_pointer_handle_relative_motion(void *data, dy_unaccel = wl_fixed_to_double(dy_unaccel_w); if (input->pointer_focus && d->relative_mouse_mode) { - SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, 1, (float)dx_unaccel, (float)dy_unaccel); + SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, SDL_TRUE, (float)dx_unaccel, (float)dy_unaccel); } } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index efb63b922..f6d80544e 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -293,6 +293,7 @@ static void WIN_CheckRawMouseButtons(Uint64 timestamp, HANDLE hDevice, ULONG raw static void WIN_CheckAsyncMouseRelease(Uint64 timestamp, SDL_WindowData *data) { + SDL_MouseID mouseID = data->videodata->mouseID; Uint32 mouseFlags; SHORT keyState; SDL_bool swapButtons; @@ -305,23 +306,23 @@ static void WIN_CheckAsyncMouseRelease(Uint64 timestamp, SDL_WindowData *data) keyState = GetAsyncKeyState(VK_LBUTTON); if (!(keyState & 0x8000)) { - WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_LEFT, 0); + WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_LEFT, mouseID); } keyState = GetAsyncKeyState(VK_RBUTTON); if (!(keyState & 0x8000)) { - WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_RIGHT, 0); + WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_RIGHT, mouseID); } keyState = GetAsyncKeyState(VK_MBUTTON); if (!(keyState & 0x8000)) { - WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_MIDDLE, 0); + WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_MIDDLE, mouseID); } keyState = GetAsyncKeyState(VK_XBUTTON1); if (!(keyState & 0x8000)) { - WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_X1, 0); + WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_X1, mouseID); } keyState = GetAsyncKeyState(VK_XBUTTON2); if (!(keyState & 0x8000)) { - WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_X2, 0); + WIN_CheckWParamMouseButton(timestamp, SDL_FALSE, mouseFlags, swapButtons, data, SDL_BUTTON_X2, mouseID); } data->mouse_button_flags = (WPARAM)-1; } @@ -363,7 +364,7 @@ static void WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus) if (!SDL_GetMouse()->relative_mode) { GetCursorPos(&cursorPos); ScreenToClient(hwnd, &cursorPos); - SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, 0, 0, (float)cursorPos.x, (float)cursorPos.y); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, data->videodata->mouseID, SDL_FALSE, (float)cursorPos.x, (float)cursorPos.y); } WIN_CheckAsyncMouseRelease(WIN_GetEventTimestamp(), data); @@ -504,9 +505,9 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) } if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, scanCode); + SDL_SendKeyboardKey(0, data->keyboardID, SDL_PRESSED, scanCode); } else { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, scanCode); + SDL_SendKeyboardKey(0, data->keyboardID, SDL_RELEASED, scanCode); /* If the key was down prior to our hook being installed, allow the key up message to pass normally the first time. This ensures other @@ -534,7 +535,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_WindowData *data, HAND if ((rawmouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) { if (rawmouse->lLastX || rawmouse->lLastY) { - SDL_SendMouseMotion(timestamp, data->window, mouseID, 1, (float)rawmouse->lLastX, (float)rawmouse->lLastY); + SDL_SendMouseMotion(timestamp, data->window, mouseID, SDL_TRUE, (float)rawmouse->lLastX, (float)rawmouse->lLastY); } } else if (rawmouse->lLastX || rawmouse->lLastY) { /* This is absolute motion, either using a tablet or mouse over RDP @@ -591,7 +592,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_WindowData *data, HAND const int MAX_RELATIVE_MOTION = (h / 6); if (SDL_abs(relX) < MAX_RELATIVE_MOTION && SDL_abs(relY) < MAX_RELATIVE_MOTION) { - SDL_SendMouseMotion(timestamp, data->window, mouseID, 1, (float)relX, (float)relY); + SDL_SendMouseMotion(timestamp, data->window, mouseID, SDL_TRUE, (float)relX, (float)relY); } } } @@ -601,7 +602,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_WindowData *data, HAND SDL_abs(relY) > MAXIMUM_TABLET_RELATIVE_MOTION) { /* Ignore this motion, probably a pen lift and drop */ } else { - SDL_SendMouseMotion(timestamp, data->window, mouseID, 1, (float)relX, (float)relY); + SDL_SendMouseMotion(timestamp, data->window, mouseID, SDL_TRUE, (float)relX, (float)relY); } } @@ -719,8 +720,9 @@ static SDL_bool HasDeviceID(Uint32 deviceID, Uint32 *list, int count) return SDL_FALSE; } -void WIN_CheckKeyboardAndMouseHotplug(SDL_bool initial_check) +void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_check) { + SDL_VideoData *data = _this->driverdata; PRAWINPUTDEVICELIST raw_devices = NULL; UINT raw_device_count = 0; int old_keyboard_count = 0; @@ -731,6 +733,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_bool initial_check) SDL_MouseID *old_mice = NULL; int new_mouse_count = 0; SDL_MouseID *new_mice = NULL; + SDL_bool send_event = !initial_check; /* Check to see if anything has changed */ static Uint64 s_last_device_change; @@ -792,28 +795,38 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_bool initial_check) old_keyboards = SDL_GetKeyboards(&old_keyboard_count); for (int i = old_keyboard_count; i--;) { if (!HasDeviceID(old_keyboards[i], new_keyboards, new_keyboard_count)) { - SDL_PrivateKeyboardRemoved(old_keyboards[i]); + SDL_RemoveKeyboard(old_keyboards[i]); } } for (int i = 0; i < new_keyboard_count; ++i) { if (!HasDeviceID(new_keyboards[i], old_keyboards, old_keyboard_count)) { - SDL_PrivateKeyboardAdded(new_keyboards[i]); + SDL_AddKeyboard(new_keyboards[i], send_event); } } + if (new_keyboard_count > 0) { + data->keyboardID = new_keyboards[0]; + } else { + data->keyboardID = 0; + } SDL_free(new_keyboards); SDL_free(old_keyboards); old_mice = SDL_GetMice(&old_mouse_count); for (int i = old_mouse_count; i--;) { if (!HasDeviceID(old_mice[i], new_mice, new_mouse_count)) { - SDL_PrivateMouseRemoved(old_mice[i]); + SDL_RemoveMouse(old_mice[i]); } } for (int i = 0; i < new_mouse_count; ++i) { if (!HasDeviceID(new_mice[i], old_mice, old_mouse_count)) { - SDL_PrivateMouseAdded(new_mice[i]); + SDL_AddMouse(new_mice[i], send_event); } } + if (new_mouse_count > 0) { + data->mouseID = new_mice[0]; + } else { + data->mouseID = 0; + } SDL_free(new_mice); SDL_free(old_mice); } @@ -928,7 +941,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara /* Only generate mouse events for real mouse */ if (GetMouseMessageSource((ULONG)GetMessageExtraInfo()) != SDL_MOUSE_EVENT_SOURCE_TOUCH && lParam != data->last_pointer_update) { - SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam)); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, data->videodata->mouseID, SDL_FALSE, (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam)); } } } break; @@ -950,7 +963,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara if (!mouse->relative_mode || mouse->relative_mode_warp) { if (GetMouseMessageSource((ULONG)GetMessageExtraInfo()) != SDL_MOUSE_EVENT_SOURCE_TOUCH && lParam != data->last_pointer_update) { - WIN_CheckWParamMouseButtons(WIN_GetEventTimestamp(), wParam, data, 0); + WIN_CheckWParamMouseButtons(WIN_GetEventTimestamp(), wParam, data, data->videodata->mouseID); } } } break; @@ -988,9 +1001,9 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara short amount = GET_WHEEL_DELTA_WPARAM(wParam); float fAmount = (float)amount / WHEEL_DELTA; if (msg == WM_MOUSEWHEEL) { - SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, 0, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, data->videodata->mouseID, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL); } else { - SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, 0, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(WIN_GetEventTimestamp(), data->window, data->videodata->mouseID, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL); } } break; @@ -1003,13 +1016,13 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara ScreenToClient(hwnd, &cursorPos); mouse = SDL_GetMouse(); if (!mouse->was_touch_mouse_events) { /* we're not a touch handler causing a mouse leave? */ - SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)cursorPos.x, (float)cursorPos.y); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, data->videodata->mouseID, SDL_FALSE, (float)cursorPos.x, (float)cursorPos.y); } else { /* touch handling? */ mouse->was_touch_mouse_events = SDL_FALSE; /* not anymore */ if (mouse->touch_mouse_events) { /* convert touch to mouse events */ - SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, SDL_TOUCH_MOUSEID, 0, (float)cursorPos.x, (float)cursorPos.y); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, SDL_TOUCH_MOUSEID, SDL_FALSE, (float)cursorPos.x, (float)cursorPos.y); } else { /* normal handling */ - SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, (float)cursorPos.x, (float)cursorPos.y); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, data->videodata->mouseID, SDL_FALSE, (float)cursorPos.x, (float)cursorPos.y); } } } @@ -1042,7 +1055,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara } if (code != SDL_SCANCODE_UNKNOWN) { - SDL_SendKeyboardKey(WIN_GetEventTimestamp(), 0, SDL_PRESSED, code); + SDL_SendKeyboardKey(WIN_GetEventTimestamp(), data->videodata->keyboardID, SDL_PRESSED, code); } } @@ -1058,9 +1071,9 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara if (code != SDL_SCANCODE_UNKNOWN) { if (code == SDL_SCANCODE_PRINTSCREEN && keyboardState[code] == SDL_RELEASED) { - SDL_SendKeyboardKey(WIN_GetEventTimestamp(), 0, SDL_PRESSED, code); + SDL_SendKeyboardKey(WIN_GetEventTimestamp(), data->videodata->keyboardID, SDL_PRESSED, code); } - SDL_SendKeyboardKey(WIN_GetEventTimestamp(), 0, SDL_RELEASED, code); + SDL_SendKeyboardKey(WIN_GetEventTimestamp(), data->videodata->keyboardID, SDL_RELEASED, code); } } returnCode = 0; @@ -1777,9 +1790,9 @@ static void WIN_UpdateMouseCapture() if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) { SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0; - SDL_MouseID mouseID = SDL_GetMouse()->mouseID; + SDL_MouseID mouseID = data->videodata->mouseID; - SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 0, (float)cursorPos.x, (float)cursorPos.y); + SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, SDL_FALSE, (float)cursorPos.x, (float)cursorPos.y); SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT); SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, @@ -1927,10 +1940,10 @@ void WIN_PumpEvents(SDL_VideoDevice *_this) and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */ keystate = SDL_GetKeyboardState(NULL); if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); + SDL_SendKeyboardKey(0, _this->driverdata->keyboardID, SDL_RELEASED, SDL_SCANCODE_LSHIFT); } if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RSHIFT); + SDL_SendKeyboardKey(0, _this->driverdata->keyboardID, SDL_RELEASED, SDL_SCANCODE_RSHIFT); } /* The Windows key state gets lost when using Windows+Space or Windows+G shortcuts and @@ -1939,10 +1952,10 @@ void WIN_PumpEvents(SDL_VideoDevice *_this) focusWindow = SDL_GetKeyboardFocus(); if (!focusWindow || !(focusWindow->flags & SDL_WINDOW_KEYBOARD_GRABBED)) { if ((keystate[SDL_SCANCODE_LGUI] == SDL_PRESSED) && !(GetKeyState(VK_LWIN) & 0x8000)) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_LGUI); + SDL_SendKeyboardKey(0, _this->driverdata->keyboardID, SDL_RELEASED, SDL_SCANCODE_LGUI); } if ((keystate[SDL_SCANCODE_RGUI] == SDL_PRESSED) && !(GetKeyState(VK_RWIN) & 0x8000)) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, SDL_SCANCODE_RGUI); + SDL_SendKeyboardKey(0, _this->driverdata->keyboardID, SDL_RELEASED, SDL_SCANCODE_RGUI); } } @@ -1952,7 +1965,7 @@ void WIN_PumpEvents(SDL_VideoDevice *_this) /* Update mouse capture */ WIN_UpdateMouseCapture(); - WIN_CheckKeyboardAndMouseHotplug(SDL_FALSE); + WIN_CheckKeyboardAndMouseHotplug(_this, SDL_FALSE); #endif /*!defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)*/ diff --git a/src/video/windows/SDL_windowsevents.h b/src/video/windows/SDL_windowsevents.h index 30ab7c2ab..1b01ba4bd 100644 --- a/src/video/windows/SDL_windowsevents.h +++ b/src/video/windows/SDL_windowsevents.h @@ -31,7 +31,7 @@ extern LRESULT CALLBACK WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lP extern LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); extern void WIN_PollRawMouseInput(void); -extern void WIN_CheckKeyboardAndMouseHotplug(SDL_bool initial_check); +extern void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_check); extern void WIN_PumpEvents(SDL_VideoDevice *_this); extern void WIN_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window); extern int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS); diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 73032fcab..85e726366 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -493,7 +493,7 @@ static int WIN_WarpMouse(SDL_Window *window, float x, float y) WIN_SetCursorPos(pt.x, pt.y); /* Send the exact mouse motion associated with this warp */ - SDL_SendMouseMotion(0, window, SDL_GetMouse()->mouseID, 0, x, y); + SDL_SendMouseMotion(0, window, data->videodata->mouseID, SDL_FALSE, x, y); return 0; } diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 5b5af7572..710015983 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -457,7 +457,7 @@ int WIN_VideoInit(SDL_VideoDevice *_this) WIN_InitKeyboard(_this); WIN_InitMouse(_this); WIN_InitDeviceNotification(); - WIN_CheckKeyboardAndMouseHotplug(SDL_TRUE); + WIN_CheckKeyboardAndMouseHotplug(_this, SDL_TRUE); #endif SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL); diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 4b3d3c27a..b6113b520 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -373,6 +373,9 @@ struct SDL_VideoData { int render; + SDL_KeyboardID keyboardID; + SDL_MouseID mouseID; + DWORD clipboard_count; #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) /* Xbox doesn't support user32/shcore*/ diff --git a/src/video/winrt/SDL_winrtevents_c.h b/src/video/winrt/SDL_winrtevents_c.h index e77e37d90..cd6ce2e22 100644 --- a/src/video/winrt/SDL_winrtevents_c.h +++ b/src/video/winrt/SDL_winrtevents_c.h @@ -24,6 +24,9 @@ extern "C" { #include "../SDL_sysvideo.h" } +#define WINRT_KEYBOARD_ID 1 +#define WINRT_MOUSE_ID 1 + /* * Internal-use, C-style functions: */ diff --git a/src/video/winrt/SDL_winrtkeyboard.cpp b/src/video/winrt/SDL_winrtkeyboard.cpp index e6e4c3f98..ab320779d 100644 --- a/src/video/winrt/SDL_winrtkeyboard.cpp +++ b/src/video/winrt/SDL_winrtkeyboard.cpp @@ -77,7 +77,7 @@ void WINRT_ProcessAcceleratorKeyActivated(Windows::UI::Core::AcceleratorKeyEvent } code = WINRT_TranslateKeycode(args->VirtualKey, args->KeyStatus); - SDL_SendKeyboardKey(0, 0, state, code); + SDL_SendKeyboardKey(0, WINRT_KEYBOARD_ID, state, code); } void WINRT_ProcessCharacterReceivedEvent(SDL_Window *window, Windows::UI::Core::CharacterReceivedEventArgs ^ args) diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp index cca8ec017..1fa6abc28 100644 --- a/src/video/winrt/SDL_winrtpointerinput.cpp +++ b/src/video/winrt/SDL_winrtpointerinput.cpp @@ -220,7 +220,7 @@ void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::Po Uint8 button, pressed; WINRT_GetSDLButtonForPointerPoint(pointerPoint, &button, &pressed); SDL_assert(pressed == 1); - SDL_SendMouseButton(0, window, 0, SDL_PRESSED, button); + SDL_SendMouseButton(0, window, WINRT_MOUSE_ID, SDL_PRESSED, button); } else { Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne); Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize); @@ -249,10 +249,10 @@ void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::Poin /* For some odd reason Moved events are used for multiple mouse buttons */ Uint8 button, pressed; if (WINRT_GetSDLButtonForPointerPoint(pointerPoint, &button, &pressed)) { - SDL_SendMouseButton(0, window, 0, pressed, button); + SDL_SendMouseButton(0, window, WINRT_MOUSE_ID, pressed, button); } - SDL_SendMouseMotion(0, window, 0, 0, windowPoint.X, windowPoint.Y); + SDL_SendMouseMotion(0, window, WINRT_MOUSE_ID, SDL_FALSE, windowPoint.X, windowPoint.Y); } else { SDL_SendTouchMotion(0, WINRT_TouchID, @@ -274,7 +274,7 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P Uint8 button, pressed; WINRT_GetSDLButtonForPointerPoint(pointerPoint, &button, &pressed); SDL_assert(pressed == 0); - SDL_SendMouseButton(0, window, 0, SDL_RELEASED, button); + SDL_SendMouseButton(0, window, WINRT_MOUSE_ID, SDL_RELEASED, button); } else { Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne); @@ -318,7 +318,7 @@ void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Inpu } float motion = (float)pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA; - SDL_SendMouseWheel(0, window, 0, 0, (float)motion, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, window, WINRT_MOUSE_ID, 0.0f, motion, SDL_MOUSEWHEEL_NORMAL); } void WINRT_ProcessMouseMovedEvent(SDL_Window *window, Windows::Devices::Input::MouseEventArgs ^ args) @@ -383,12 +383,7 @@ void WINRT_ProcessMouseMovedEvent(SDL_Window *window, Windows::Devices::Input::M // const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y); const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize); - SDL_SendMouseMotion(0, - window, - 0, - 1, - mouseDeltaInSDLWindowCoords.X, - mouseDeltaInSDLWindowCoords.Y); + SDL_SendMouseMotion(0, window, WINRT_MOUSE_ID, SDL_TRUE, mouseDeltaInSDLWindowCoords.X, mouseDeltaInSDLWindowCoords.Y); } #endif // SDL_VIDEO_DRIVER_WINRT diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index c1313182a..dd39b9511 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -238,6 +238,11 @@ int WINRT_VideoInit(SDL_VideoDevice *_this) /* Initialize screensaver-disabling support */ driverdata->displayRequest = WINRT_CreateDisplayRequest(_this); } + + /* Assume we have a mouse and keyboard */ + SDL_AddKeyboard(WINRT_KEYBOARD_ID, SDL_FALSE); + SDL_AddMouse(WINRT_MOUSE_ID, SDL_FALSE); + return 0; } diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 30f520a3a..1a63f06f6 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -351,8 +351,8 @@ static void X11_HandleGenericEvent(SDL_VideoDevice *_this, XEvent *xev) static unsigned X11_GetNumLockModifierMask(SDL_VideoDevice *_this) { - SDL_VideoData *viddata = _this->driverdata; - Display *display = viddata->display; + SDL_VideoData *videodata = _this->driverdata; + Display *display = videodata->display; unsigned num_mask = 0; int i, j; XModifierKeymap *xmods; @@ -363,7 +363,7 @@ static unsigned X11_GetNumLockModifierMask(SDL_VideoDevice *_this) for (i = 3; i < 8; i++) { for (j = 0; j < n; j++) { KeyCode kc = xmods->modifiermap[i * n + j]; - if (viddata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) { + if (videodata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) { num_mask = 1 << i; break; } @@ -376,8 +376,8 @@ static unsigned X11_GetNumLockModifierMask(SDL_VideoDevice *_this) static unsigned X11_GetScrollLockModifierMask(SDL_VideoDevice *_this) { - SDL_VideoData *viddata = _this->driverdata; - Display *display = viddata->display; + SDL_VideoData *videodata = _this->driverdata; + Display *display = videodata->display; unsigned num_mask = 0; int i, j; XModifierKeymap *xmods; @@ -388,7 +388,7 @@ static unsigned X11_GetScrollLockModifierMask(SDL_VideoDevice *_this) for (i = 3; i < 8; i++) { for (j = 0; j < n; j++) { KeyCode kc = xmods->modifiermap[i * n + j]; - if (viddata->key_layout[kc] == SDL_SCANCODE_SCROLLLOCK) { + if (videodata->key_layout[kc] == SDL_SCANCODE_SCROLLLOCK) { num_mask = 1 << i; break; } @@ -401,8 +401,8 @@ static unsigned X11_GetScrollLockModifierMask(SDL_VideoDevice *_this) void X11_ReconcileKeyboardState(SDL_VideoDevice *_this) { - SDL_VideoData *viddata = _this->driverdata; - Display *display = viddata->display; + SDL_VideoData *videodata = _this->driverdata; + Display *display = videodata->display; char keys[32]; int keycode; Window junk_window; @@ -420,8 +420,8 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this) } keyboardState = SDL_GetKeyboardState(0); - for (keycode = 0; keycode < SDL_arraysize(viddata->key_layout); ++keycode) { - SDL_Scancode scancode = viddata->key_layout[keycode]; + for (keycode = 0; keycode < SDL_arraysize(videodata->key_layout); ++keycode) { + SDL_Scancode scancode = videodata->key_layout[keycode]; SDL_bool x11KeyPressed = (keys[keycode / 8] & (1 << (keycode % 8))) != 0; SDL_bool sdlKeyPressed = keyboardState[scancode] == SDL_PRESSED; @@ -437,13 +437,13 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this) case SDLK_LGUI: case SDLK_RGUI: case SDLK_MODE: - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, scancode); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_PRESSED, scancode); break; default: break; } } else if (!x11KeyPressed && sdlKeyPressed) { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, scancode); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_RELEASED, scancode); } } } @@ -508,9 +508,9 @@ static void X11_DispatchUnmapNotify(SDL_WindowData *data) static void DispatchWindowMove(SDL_VideoDevice *_this, const SDL_WindowData *data, const SDL_Point *point) { - SDL_VideoData *viddata = _this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_Window *window = data->window; - Display *display = viddata->display; + Display *display = videodata->display; XEvent evt; /* !!! FIXME: we need to regrab this if necessary when the drag is done. */ @@ -539,9 +539,9 @@ static void ScheduleWindowMove(SDL_VideoDevice *_this, SDL_WindowData *data, con static void InitiateWindowResize(SDL_VideoDevice *_this, const SDL_WindowData *data, const SDL_Point *point, int direction) { - SDL_VideoData *viddata = _this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_Window *window = data->window; - Display *display = viddata->display; + Display *display = videodata->display; XEvent evt; if (direction < _NET_WM_MOVERESIZE_SIZE_TOPLEFT || direction > _NET_WM_MOVERESIZE_SIZE_LEFT) { @@ -842,7 +842,7 @@ void X11_HandleButtonPress(SDL_VideoDevice *_this, SDL_WindowData *windowdata, i printf("window %p: ButtonPress (X11 button = %d)\n", window, button); #endif if (X11_IsWheelEvent(display, button, &xticks, &yticks)) { - SDL_SendMouseWheel(0, window, 0, (float)-xticks, (float)yticks, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(0, window, videodata->mouseID, (float)-xticks, (float)yticks, SDL_MOUSEWHEEL_NORMAL); } else { SDL_bool ignore_click = SDL_FALSE; if (button == Button1) { @@ -863,7 +863,7 @@ void X11_HandleButtonPress(SDL_VideoDevice *_this, SDL_WindowData *windowdata, i windowdata->last_focus_event_time = 0; } if (!ignore_click) { - SDL_SendMouseButton(0, window, 0, SDL_PRESSED, button); + SDL_SendMouseButton(0, window, videodata->mouseID, SDL_PRESSED, button); } } X11_UpdateUserTime(windowdata, time); @@ -884,7 +884,7 @@ void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata, /* see explanation at case ButtonPress */ button -= (8 - SDL_BUTTON_X1); } - SDL_SendMouseButton(0, window, 0, SDL_RELEASED, button); + SDL_SendMouseButton(0, window, videodata->mouseID, SDL_RELEASED, button); } } @@ -957,9 +957,9 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) videodata->filter_time = xevent->xkey.time; if (orig_event_type == KeyPress) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, scancode); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_PRESSED, scancode); } else { - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, scancode); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_RELEASED, scancode); } #endif } @@ -1106,7 +1106,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) #endif if (!mouse->relative_mode) { - SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y); + SDL_SendMouseMotion(0, data->window, videodata->mouseID, SDL_FALSE, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y); } /* We ungrab in LeaveNotify, so we may need to grab again here */ @@ -1130,7 +1130,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) } #endif if (!SDL_GetMouse()->relative_mode) { - SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y); + SDL_SendMouseMotion(0, data->window, videodata->mouseID, SDL_FALSE, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y); } if (xevent->xcrossing.mode != NotifyGrab && @@ -1262,7 +1262,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) if (xevent->type == KeyPress) { /* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */ if (xevent->xkey.keycode != videodata->filter_code || xevent->xkey.time != videodata->filter_time) { - SDL_SendKeyboardKey(0, 0, SDL_PRESSED, videodata->key_layout[keycode]); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_PRESSED, videodata->key_layout[keycode]); } if (*text) { SDL_SendKeyboardText(text); @@ -1272,7 +1272,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) /* We're about to get a repeated key down, ignore the key up */ break; } - SDL_SendKeyboardKey(0, 0, SDL_RELEASED, videodata->key_layout[keycode]); + SDL_SendKeyboardKey(0, videodata->keyboardID, SDL_RELEASED, videodata->key_layout[keycode]); } } @@ -1525,7 +1525,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) #endif X11_ProcessHitTest(_this, data, (float)xevent->xmotion.x, (float)xevent->xmotion.y, SDL_FALSE); - SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xmotion.x, (float)xevent->xmotion.y); + SDL_SendMouseMotion(0, data->window, videodata->mouseID, SDL_FALSE, (float)xevent->xmotion.x, (float)xevent->xmotion.y); } } break; diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index e199dd516..30780098c 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -110,6 +110,9 @@ struct SDL_VideoData SDL_Point global_mouse_position; Uint32 global_mouse_buttons; + SDL_KeyboardID keyboardID; + SDL_MouseID mouseID; + SDL_XInput2DeviceInfo *mouse_device_info; int xrandr_event_base; diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index f614f0441..2aa7025ad 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -348,7 +348,7 @@ int X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie) } } - SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, (float)processed_coords[0], (float)processed_coords[1]); + SDL_SendMouseMotion(0, mouse->focus, videodata->mouseID, SDL_TRUE, (float)processed_coords[0], (float)processed_coords[1]); devinfo->prev_coords[0] = coords[0]; devinfo->prev_coords[1] = coords[1]; return 1; @@ -468,7 +468,7 @@ int X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie) SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event); if (window) { X11_ProcessHitTest(_this, window->driverdata, (float)xev->event_x, (float)xev->event_y, SDL_FALSE); - SDL_SendMouseMotion(0, window, 0, 0, (float)xev->event_x, (float)xev->event_y); + SDL_SendMouseMotion(0, window, videodata->mouseID, SDL_FALSE, (float)xev->event_x, (float)xev->event_y); } } } diff --git a/test/testautomation_pen.c b/test/testautomation_pen.c index 67cdebb1a..7bbc5aa37 100644 --- a/test/testautomation_pen.c +++ b/test/testautomation_pen.c @@ -72,10 +72,10 @@ #define SDL_SetMouseFocus SDL_Mock_SetMouseFocus /* Mock mouse API */ -static int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y); +static int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y); static int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button); static SDL_Mouse *SDL_GetMouse(void); -static SDL_bool SDL_MousePositionInWindow(SDL_Window *window, SDL_MouseID mouseID, float x, float y); +static SDL_bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y); static void SDL_SetMouseFocus(SDL_Window *window); /* Import SUT code with macro-renamed function names */ @@ -88,7 +88,7 @@ static void SDL_SetMouseFocus(SDL_Window *window); /* Mock implementations of Pen -> Mouse calls */ /* Not thread-safe! */ -static SDL_bool SDL_MousePositionInWindow(SDL_Window *window, SDL_MouseID mouseID, float x, float y) +static SDL_bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y) { return SDL_TRUE; } @@ -98,7 +98,7 @@ static float _mouseemu_last_x = 0.0f; static float _mouseemu_last_y = 0.0f; static int _mouseemu_last_mouseid = 0; static int _mouseemu_last_button = 0; -static int _mouseemu_last_relative = 0; +static SDL_bool _mouseemu_last_relative = SDL_FALSE; static int _mouseemu_last_focus = -1; static int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button) @@ -111,7 +111,7 @@ static int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID return 1; } -static int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, float x, float y) +static int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, SDL_bool relative, float x, float y) { if (mouseID == SDL_PEN_MOUSEID) { _mouseemu_last_event = SDL_EVENT_MOUSE_MOTION; @@ -127,9 +127,6 @@ static SDL_Mouse *SDL_GetMouse(void) { static SDL_Mouse dummy_mouse; - dummy_mouse.focus = NULL; - dummy_mouse.mouseID = 0; - return &dummy_mouse; }