From c94f9f82849905d79b72e152526dd25448820899 Mon Sep 17 00:00:00 2001 From: Paper Date: Sun, 7 Apr 2024 22:19:32 -0400 Subject: [PATCH 1/5] ogc: add USB keyboard support --- src/main/wii/SDL_wii_main.c | 2 +- src/video/ogc/SDL_ogcevents.c | 2 + src/video/ogc/SDL_ogckeyboard.c | 71 +++++++++++++++++++++++++++++++++ src/video/ogc/SDL_ogckeyboard.h | 36 +++++++++++++++++ src/video/ogc/SDL_ogcvideo.c | 3 ++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/video/ogc/SDL_ogckeyboard.c create mode 100644 src/video/ogc/SDL_ogckeyboard.h diff --git a/src/main/wii/SDL_wii_main.c b/src/main/wii/SDL_wii_main.c index 9a42125aae401..47b8b207fe22e 100644 --- a/src/main/wii/SDL_wii_main.c +++ b/src/main/wii/SDL_wii_main.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) WPAD_SetVRes(WPAD_CHAN_ALL, 640, 480); MOUSE_Init(); - // TODO KEYBOARD_Init(NULL); + KEYBOARD_Init(NULL); fatInitDefault(); /* Call the user's main function. Make sure that argv contains at least one diff --git a/src/video/ogc/SDL_ogcevents.c b/src/video/ogc/SDL_ogcevents.c index a3ebc0d3d6e1a..99b1cd3fc475b 100644 --- a/src/video/ogc/SDL_ogcevents.c +++ b/src/video/ogc/SDL_ogcevents.c @@ -29,6 +29,7 @@ #include "SDL_ogcevents_c.h" #include "SDL_ogcmouse.h" #include "SDL_ogcvideo.h" +#include "SDL_ogckeyboard.h" #include #include @@ -99,6 +100,7 @@ void OGC_PumpEvents(_THIS) #ifdef __wii__ pump_ir_events(_this); + OGC_PumpKeyboardEvents(_this); #endif } diff --git a/src/video/ogc/SDL_ogckeyboard.c b/src/video/ogc/SDL_ogckeyboard.c new file mode 100644 index 0000000000000..40e645532c31c --- /dev/null +++ b/src/video/ogc/SDL_ogckeyboard.c @@ -0,0 +1,71 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2023 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. +*/ +#include "SDL_ogckeyboard.h" +#include "../../events/SDL_keyboard_c.h" + +#if defined(SDL_VIDEO_DRIVER_OGC) && defined(__wii__) +#include +#include + +static int send_text_input = 0; + +void OGC_PumpKeyboardEvents(_THIS) { + keyboard_event ke; + + s32 res = KEYBOARD_GetEvent(&ke); + if (res && (ke.type == KEYBOARD_RELEASED || ke.type == KEYBOARD_PRESSED)) { + SDL_SendKeyboardKey((ke.type == KEYBOARD_PRESSED) ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)ke.keycode); + + if (send_text_input && ke.type == KEYBOARD_PRESSED) { + const Uint16 symbol = ke.symbol; + char utf8[4] = {'\0'}; + + /* invalid characters */ + if ((c >= 0xD800 && c < 0xE000) || c == 0xFFFF) + return; + + /* convert UCS-2 to UTF-8 */ + if (symbol < 0x80) { + utf8[0] = symbol; + } else if (symbol < 0x800) { + utf8[0] = 0xC0 | (symbol >> 6); + utf8[1] = 0x80 | (symbol & 0x3F); + } else { + utf8[0] = 0xE0 | (symbol >> 12); + utf8[1] = 0x80 | ((symbol >> 6) & 0x3F); + utf8[2] = 0x80 | (symbol & 0x3F); + } + + SDL_SendKeyboardText(utf8); + } + } +} + +void OGC_StartTextInput(_THIS) +{ + send_text_input = 1; +} + +void OGC_StopTextInput(_THIS) +{ + send_text_input = 0; +} +#endif \ No newline at end of file diff --git a/src/video/ogc/SDL_ogckeyboard.h b/src/video/ogc/SDL_ogckeyboard.h new file mode 100644 index 0000000000000..46499afdabf71 --- /dev/null +++ b/src/video/ogc/SDL_ogckeyboard.h @@ -0,0 +1,36 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2023 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_OGC_keyboard_h_ +#define SDL_OGC_keyboard_h_ + +#include "../../SDL_internal.h" +#include "SDL_ogcvideo.h" + +#ifdef __wii__ +void OGC_PumpKeyboardEvents(_THIS); +void OGC_StartTextInput(_THIS); +void OGC_StopTextInput(_THIS); +#endif + +#endif /* SDL_OGC_keyboard_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ogc/SDL_ogcvideo.c b/src/video/ogc/SDL_ogcvideo.c index d62723c7a0062..77c28c7cf204c 100644 --- a/src/video/ogc/SDL_ogcvideo.c +++ b/src/video/ogc/SDL_ogcvideo.c @@ -33,6 +33,7 @@ #include "SDL_ogcframebuffer_c.h" #include "SDL_ogcgxcommon.h" #include "SDL_ogcmouse.h" +#include "SDL_ogckeyboard.h" #include "SDL_ogcvideo.h" #include @@ -240,6 +241,8 @@ static SDL_VideoDevice *OGC_CreateDevice(void) device->CreateWindowFramebuffer = SDL_OGC_CreateWindowFramebuffer; device->UpdateWindowFramebuffer = SDL_OGC_UpdateWindowFramebuffer; device->DestroyWindowFramebuffer = SDL_OGC_DestroyWindowFramebuffer; + device->StartTextInput = OGC_StartTextInput; + device->StopTextInput = OGC_StopTextInput; device->free = OGC_DeleteDevice; From 8c50dc6a68afb74c998184516b4dd9456b8be964 Mon Sep 17 00:00:00 2001 From: Paper Date: Sun, 7 Apr 2024 22:41:38 -0400 Subject: [PATCH 2/5] ogc: remove redundant text input functions SDL_SendKeyboardText checks for these anyway --- src/video/ogc/SDL_ogckeyboard.c | 16 ++-------------- src/video/ogc/SDL_ogckeyboard.h | 2 -- src/video/ogc/SDL_ogcvideo.c | 2 -- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/video/ogc/SDL_ogckeyboard.c b/src/video/ogc/SDL_ogckeyboard.c index 40e645532c31c..60ab75a7bb266 100644 --- a/src/video/ogc/SDL_ogckeyboard.c +++ b/src/video/ogc/SDL_ogckeyboard.c @@ -25,8 +25,6 @@ #include #include -static int send_text_input = 0; - void OGC_PumpKeyboardEvents(_THIS) { keyboard_event ke; @@ -34,12 +32,12 @@ void OGC_PumpKeyboardEvents(_THIS) { if (res && (ke.type == KEYBOARD_RELEASED || ke.type == KEYBOARD_PRESSED)) { SDL_SendKeyboardKey((ke.type == KEYBOARD_PRESSED) ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)ke.keycode); - if (send_text_input && ke.type == KEYBOARD_PRESSED) { + if (ke.type == KEYBOARD_PRESSED) { const Uint16 symbol = ke.symbol; char utf8[4] = {'\0'}; /* invalid characters */ - if ((c >= 0xD800 && c < 0xE000) || c == 0xFFFF) + if ((symbol >= 0xD800 && symbol < 0xE000) || symbol == 0xFFFF) return; /* convert UCS-2 to UTF-8 */ @@ -58,14 +56,4 @@ void OGC_PumpKeyboardEvents(_THIS) { } } } - -void OGC_StartTextInput(_THIS) -{ - send_text_input = 1; -} - -void OGC_StopTextInput(_THIS) -{ - send_text_input = 0; -} #endif \ No newline at end of file diff --git a/src/video/ogc/SDL_ogckeyboard.h b/src/video/ogc/SDL_ogckeyboard.h index 46499afdabf71..ca8c0464dfb65 100644 --- a/src/video/ogc/SDL_ogckeyboard.h +++ b/src/video/ogc/SDL_ogckeyboard.h @@ -27,8 +27,6 @@ #ifdef __wii__ void OGC_PumpKeyboardEvents(_THIS); -void OGC_StartTextInput(_THIS); -void OGC_StopTextInput(_THIS); #endif #endif /* SDL_OGC_keyboard_h_ */ diff --git a/src/video/ogc/SDL_ogcvideo.c b/src/video/ogc/SDL_ogcvideo.c index 77c28c7cf204c..9f4698c102a8e 100644 --- a/src/video/ogc/SDL_ogcvideo.c +++ b/src/video/ogc/SDL_ogcvideo.c @@ -241,8 +241,6 @@ static SDL_VideoDevice *OGC_CreateDevice(void) device->CreateWindowFramebuffer = SDL_OGC_CreateWindowFramebuffer; device->UpdateWindowFramebuffer = SDL_OGC_UpdateWindowFramebuffer; device->DestroyWindowFramebuffer = SDL_OGC_DestroyWindowFramebuffer; - device->StartTextInput = OGC_StartTextInput; - device->StopTextInput = OGC_StopTextInput; device->free = OGC_DeleteDevice; From 5bd59811142e0176c35f5a86ec255e06513eb384 Mon Sep 17 00:00:00 2001 From: Paper Date: Sun, 7 Apr 2024 22:56:01 -0400 Subject: [PATCH 3/5] cmake: hint linking to wiikeyboard --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dc928208c77d..56629f588c4e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2944,7 +2944,7 @@ elseif(OGC) endif() list(APPEND EXTRA_LDFLAGS "${OGC_ARCH_SETTINGS} ${OGC_LINKER_FLAGS}") if(NINTENDO_WII) - list(APPEND EXTRA_LIBS "wiiuse;bte") + list(APPEND EXTRA_LIBS "wiiuse;bte;wiikeyboard") endif() list(APPEND EXTRA_LIBS "ogc;m") endif() From 64e18af979dfbac1ba1f3b0772802237d7719f2a Mon Sep 17 00:00:00 2001 From: Paper <37962225+mrpapersonic@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:56:50 -0400 Subject: [PATCH 4/5] ogc: ignore special keys in text input --- src/video/ogc/SDL_ogckeyboard.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/ogc/SDL_ogckeyboard.c b/src/video/ogc/SDL_ogckeyboard.c index 60ab75a7bb266..1ebf0f8fc56d4 100644 --- a/src/video/ogc/SDL_ogckeyboard.c +++ b/src/video/ogc/SDL_ogckeyboard.c @@ -36,8 +36,8 @@ void OGC_PumpKeyboardEvents(_THIS) { const Uint16 symbol = ke.symbol; char utf8[4] = {'\0'}; - /* invalid characters */ - if ((symbol >= 0xD800 && symbol < 0xE000) || symbol == 0xFFFF) + /* ignore private symbols, used by wiikeyboard for special keys */ + if ((symbol >= 0xE000 && symbol <= 0xF8FF) || symbol == 0xFFFF) return; /* convert UCS-2 to UTF-8 */ @@ -56,4 +56,4 @@ void OGC_PumpKeyboardEvents(_THIS) { } } } -#endif \ No newline at end of file +#endif From 4971642c559a143be23e25b9621613dc7004d55a Mon Sep 17 00:00:00 2001 From: Paper Date: Fri, 12 Apr 2024 16:10:31 -0400 Subject: [PATCH 5/5] ogc: stylize header includes --- src/video/ogc/SDL_ogcevents.c | 2 +- src/video/ogc/SDL_ogcvideo.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/video/ogc/SDL_ogcevents.c b/src/video/ogc/SDL_ogcevents.c index 99b1cd3fc475b..6fb8ac4557e34 100644 --- a/src/video/ogc/SDL_ogcevents.c +++ b/src/video/ogc/SDL_ogcevents.c @@ -27,9 +27,9 @@ #include "../../events/SDL_events_c.h" #include "SDL_ogcevents_c.h" +#include "SDL_ogckeyboard.h" #include "SDL_ogcmouse.h" #include "SDL_ogcvideo.h" -#include "SDL_ogckeyboard.h" #include #include diff --git a/src/video/ogc/SDL_ogcvideo.c b/src/video/ogc/SDL_ogcvideo.c index 9f4698c102a8e..d62723c7a0062 100644 --- a/src/video/ogc/SDL_ogcvideo.c +++ b/src/video/ogc/SDL_ogcvideo.c @@ -33,7 +33,6 @@ #include "SDL_ogcframebuffer_c.h" #include "SDL_ogcgxcommon.h" #include "SDL_ogcmouse.h" -#include "SDL_ogckeyboard.h" #include "SDL_ogcvideo.h" #include