Skip to content

Commit 983e3c7

Browse files
dkosmariDaniel K. O. (dkosmari)
authored andcommitted
Wii U: Add support for swkbd. (#100)
* Implemented swkbd on the Wii U. * Let clang format it. * - Cleaned up code. - No more replacement of global new/delete operators; use strings with custom allocators instead. - Don't rely on C locale API, let the user control the locale explicitly. - A few more customization functions. - Properly documented all functions. - Added enums. - Input feeding from VPAD and KPAD is now public. * - Added events to differentiate before and after all text is received. - Added function to manually disable the swkbd. * Don't reset swkbd window to null until it's fully hidden. * - Added `-lstdc++` as a dependency, because the swkbd API is C++. - Added missing include `<new>`. - Don't copy the user-supplied `nn::swkbd::AppearArg`. * Removed duplicated name. * Link libstdc++ before libwut. * Fixed inconsistent indentation. * Removed dependency on libstdc++. * Removed emacs local variables. * Renamed SDL_wiiu_swkbd.* to SDL_wiiuswkbd.* * Removed CreateArg and AppearArg API. * Clean up swkbd from WIIU_VideoQuit(). * Forgot to remove attribute. * The default swkbd layout works for all languages. --------- Co-authored-by: Daniel K. O. (dkosmari) <none@none>
1 parent 6eab476 commit 983e3c7

File tree

12 files changed

+1208
-35
lines changed

12 files changed

+1208
-35
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ BraceWrapping:
3434
AfterStruct: true
3535
AfterUnion: true
3636
AfterExternBlock: false
37+
BeforeCatch: true
3738
BeforeElse: false
3839
BeforeWhile: false
3940
IndentBraces: false
@@ -62,6 +63,8 @@ IndentGotoLabels: true
6263
IndentPPDirectives: None
6364
IndentExternBlock: NoIndent
6465

66+
NamespaceIndentation: All
67+
6568
PointerAlignment: Right
6669
SpaceAfterCStyleCast: false
6770
SpacesInCStyleCastParentheses: false

CMakeLists.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ endif()
243243
if(WIIU)
244244
# Prefer coreinit atomics on Wii U due to a hardware bug in load-exclusive and store-exclusive instructions
245245
set(OPT_DEF_GCC_ATOMICS OFF)
246+
# Needed for nn::swkbd API
247+
set(LINKER_LANGUAGE CXX)
248+
set (CMAKE_CXX_STANDARD 23)
246249
endif()
247250

248251
# Default option knobs
@@ -2987,14 +2990,14 @@ elseif(WIIU)
29872990
if(SDL_VIDEO)
29882991
set(SDL_VIDEO_DRIVER_WIIU 1)
29892992
set(SDL_VIDEO_RENDER_WIIU 1)
2990-
file(GLOB WIIU_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/wiiu/*.c)
2993+
file(GLOB WIIU_VIDEO_SOURCES
2994+
${SDL2_SOURCE_DIR}/src/video/wiiu/*.c
2995+
${SDL2_SOURCE_DIR}/src/video/wiiu/*.cpp)
29912996
set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_VIDEO_SOURCES})
29922997
set(HAVE_SDL_VIDEO TRUE)
29932998
endif()
2994-
2995-
list(APPEND EXTRA_LIBS
2996-
wut
2997-
)
2999+
list(APPEND EXTRA_CXXFLAGS "-fno-exceptions")
3000+
list(APPEND EXTRA_LIBS wut)
29983001
endif()
29993002

30003003
if(HAVE_VULKAN AND NOT SDL_LOADSO)
@@ -3130,8 +3133,13 @@ endif()
31303133
if(EXTRA_CFLAGS)
31313134
list(REMOVE_DUPLICATES EXTRA_CFLAGS)
31323135
endif()
3136+
if(EXTRA_CXXFLAGS)
3137+
list(REMOVE_DUPLICATES EXTRA_CXXFLAGS)
3138+
endif()
31333139
listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
31343140
set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
3141+
listtostr(EXTRA_CXXFLAGS _EXTRA_CXXFLAGS)
3142+
set(EXTRA_CXXFLAGS ${_EXTRA_CXXFLAGS})
31353143

31363144
if(USE_GCC OR USE_CLANG)
31373145
string(REGEX REPLACE "(^| )-I" "\\1 -isystem" EXTRA_CFLAGS "${EXTRA_CFLAGS}")
@@ -3384,10 +3392,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
33843392
message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
33853393
endif()
33863394
message(STATUS "")
3387-
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
3388-
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
3389-
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
3390-
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
3395+
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
3396+
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
3397+
message(STATUS " EXTRA_CXXFLAGS: ${EXTRA_CXXFLAGS}")
3398+
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
3399+
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
33913400
message(STATUS "")
33923401
message(STATUS " Build Shared Library: ${SDL_SHARED}")
33933402
message(STATUS " Build Static Library: ${SDL_STATIC}")
@@ -3422,6 +3431,8 @@ endif()
34223431

34233432
# Ensure that the extra cflags are used at compile time
34243433
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${EXTRA_CFLAGS_BUILD}")
3434+
# Same for cxxflags
3435+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} ${EXTRA_CXXFLAGS_BUILD}")
34253436

34263437
if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
34273438
# Build SDLmain

include/SDL_system.h

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,212 @@ extern DECLSPEC int SDLCALL SDL_GDKGetDefaultUser(XUserHandle * outUserHandle);
631631

632632
#endif
633633

634+
/* Platform specific functions for Wii U */
635+
#if defined(__WIIU__)
636+
typedef enum SDL_WiiUSysWMEventType {
637+
/** Sent before any text input event. */
638+
SDL_WIIU_SYSWM_SWKBD_OK_START_EVENT = 1,
639+
/** Sent after all text input events. */
640+
SDL_WIIU_SYSWM_SWKBD_OK_FINISH_EVENT,
641+
/** Sent after the swkbd was canceled. */
642+
SDL_WIIU_SYSWM_SWKBD_CANCEL_EVENT
643+
} SDL_WiiUSysWMEventType;
644+
645+
/**
646+
* Disable the swkbd.
647+
*
648+
* Use this function if you only want text input from a physical USB keyboard.
649+
*
650+
* \param enabled `SDL_FALSE` if you do not want the swkbd to show up after calling
651+
* `SDL_StartTextInput()`.
652+
*/
653+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDEnabled(SDL_bool enabled);
654+
655+
/**
656+
* Select the swkbd keyboard mode.
657+
*
658+
* \sa SDL_WiiUSetSWKBDKeyboardMode
659+
*/
660+
typedef enum SDL_WiiUSWKBDKeyboardMode {
661+
/** Full keyboard. */
662+
SDL_WIIU_SWKBD_KEYBOARD_MODE_FULL,
663+
/** Numeric keyboard. */
664+
SDL_WIIU_SWKBD_KEYBOARD_MODE_NUMPAD,
665+
/** Restricted keyboard (only letters, numbers and symbols.) */
666+
SDL_WIIU_SWKBD_KEYBOARD_MODE_RESTRICTED,
667+
/** NNID keyboard. */
668+
SDL_WIIU_SWKBD_KEYBOARD_MODE_NNID
669+
} SDL_WiiUSWKBDKeyboardMode;
670+
671+
/**
672+
* Sets the swkbd's keyboard mode.
673+
*
674+
* \param mode One of SDL_WiiUSWKBDKeyboardMode. The default is
675+
* `SDL_WIIU_SWKBD_KEYBOARD_MODE_FULL`.
676+
*
677+
* \note
678+
* This option is reset to the default value after the swkbd is shown.
679+
*/
680+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDKeyboardMode(SDL_WiiUSWKBDKeyboardMode mode);
681+
682+
/**
683+
* Sets the label for the swkbd's "OK" button.
684+
*
685+
* \param label String for the "OK" button, encoded in UTF-8, or `NULL` to use the
686+
* default.
687+
*
688+
* \note
689+
* This option is reset to the default value after the swkbd is shown.
690+
*/
691+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDOKLabel(const char * label);
692+
693+
/**
694+
* Sets the swkbd's word suggestions option.
695+
*
696+
* \param show `SDL_TRUE` to enable word suggestions. The default is `SDL_TRUE`.
697+
*
698+
* \note
699+
* This option is reset to the default value after the swkbd is shown.
700+
*/
701+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDShowWordSuggestions(SDL_bool show);
702+
703+
/**
704+
* Sets the swkbd's initial text.
705+
*
706+
* \param text String for the initial text, encoded in UTF-8, or `NULL` to use the
707+
* default (no initial text.)
708+
*
709+
* \note
710+
* This option is reset to the default value after the swkbd is shown.
711+
*/
712+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDInitialText(const char * text);
713+
714+
/**
715+
* Sets the swkbd's hint text.
716+
*
717+
* \param text String for the hint text, encoded in UTF-8, or `NULL` to use the default
718+
* (no hint.)
719+
*
720+
* \note
721+
* This option is reset to the default value after the swkbd is shown.
722+
*/
723+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDHintText(const char * text);
724+
725+
/**
726+
* Controls how to display passwwords in the swkbd when in password mode.
727+
*/
728+
typedef enum SDL_WiiUSWKBDPasswordMode {
729+
SDL_WIIU_SWKBD_PASSWORD_MODE_SHOW, /**< Show password. */
730+
SDL_WIIU_SWKBD_PASSWORD_MODE_HIDE, /**< Hide password. */
731+
SDL_WIIU_SWKBD_PASSWORD_MODE_FADE /**< Hide password after 1 second. */
732+
} SDL_WiiUSWKBDPasswordMode;
733+
734+
/**
735+
* Sets the swkbd's password mode.
736+
*
737+
* \param mode One of of the SDL_WiiUSWKBDPasswordMode values. The default is
738+
* `SDL_WIIU_SWKBD_PASSWORD_MODE_SHOW`.
739+
*
740+
* \note
741+
* This option is reset to the default value after the swkbd is shown.
742+
*
743+
* \sa SDL_WiiUSetSWKBDKeyboardMode
744+
*/
745+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDPasswordMode(SDL_WiiUSWKBDPasswordMode mode);
746+
747+
/**
748+
* Sets whether to highlight (select) the swkbd's initial text.
749+
*
750+
* \param highlight `SDL_TRUE` to highlight the initial text. The default is `SDL_FALSE`.
751+
752+
* \note
753+
* This option is reset to the default value after the swkbd is shown.
754+
*/
755+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDHighlightInitialText(SDL_bool highlight);
756+
757+
/**
758+
* Sets the swkbd's copy-paste button option.
759+
*
760+
* \param show `SDL_TRUE` to show copy-paste buttons. The default is `SDL_FALSE`.
761+
*
762+
* \note
763+
* This option is reset to the default value after the swkbd is shown.
764+
*/
765+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDShowCopyPasteButtons(SDL_bool show);
766+
767+
/**
768+
* Sets the swkbd's built-in rendering of the Wii remote pointer.
769+
*
770+
* \param draw `SDL_TRUE` to let the swkbd draw its own Wii remote pointer. The default is
771+
* `SDL_TRUE`.
772+
*
773+
* This option is reset to the default value after the swkbd is shown.
774+
*/
775+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDDrawWiiPointer(SDL_bool draw);
776+
777+
/**
778+
* Sets the swkbd's locale (region and language.)
779+
*
780+
* \param locale String representing the intended keyboard region and language, using
781+
* Unix-style locale format (e.g. `"en_US"`, `"fr_CA"`, `ja_JP`, `"en"`.) Set to `NULL` to
782+
* use the system region and language. The default is `NULL`.
783+
*
784+
* The recognized languages are:
785+
* - ja: Japanese
786+
* - en: English
787+
* - fr: French
788+
* - de: German
789+
* - it: Italian
790+
* - es: Spanish
791+
* - nl: Dutch
792+
* - pt: Portuguese
793+
* - ru: Russian
794+
*
795+
* The recognized regions are:
796+
* - US, CA, MX, BR: mapped to the "USA" console region.
797+
* - DE, ES, FR, GB, IT, NL, PT, RU: mapped to the "EUR" console region.
798+
* - JP: mapped to the "JPN" console region.
799+
*
800+
* When no country is specified, "jp" will map to the "JPN" region, "en" to "USA" region,
801+
* and everything else will map to "EUR" region.
802+
*
803+
* By default the locale is obtained from the system configuration (cafe.language). The
804+
* empty locale string is equivalent to the system configuration.
805+
*
806+
* \note
807+
* The swkbd will be re-initialized after calling this function.
808+
*/
809+
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDLocale(const char * locale);
810+
811+
/**
812+
* Sends VPAD input to the swkbd.
813+
*
814+
* Call this function at every frame if your application calls `VPADRead()` instead of
815+
* using the SDL game controller subsystem.
816+
*
817+
* \param vpad Pointer to a `VPADStatus` object.
818+
* \returns `SDL_TRUE` if the swkbd is visible and is going to use the input.
819+
*
820+
* \note
821+
* The touch point in `tpNormal` should contain a calibrated point, by calling
822+
* `VPADGetTPCalibratedPoint()`, prior to calling this function.
823+
*/
824+
extern DECLSPEC SDL_bool SDLCALL SDL_WiiUSetSWKBDVPAD(const void * vpad);
825+
826+
/**
827+
* Sends KPAD input to the swkbd.
828+
*
829+
* Call this function at every frame if you call `KPADRead()` or `KPADReadEx()` in your
830+
* application, instead of using the SDL game controller subsystem.
831+
*
832+
* \param channel Number of channel.
833+
* \param kpad Pointer to a `KPADStatus` object.
834+
* \returns `SDL_TRUE` if the swkbd is visible and is going to use the input.
835+
*/
836+
extern DECLSPEC SDL_bool SDLCALL SDL_WiiUSetSWKBDKPAD(int channel, const void * kpad);
837+
838+
#endif /* Wii U */
839+
634840
/* Ends C function definitions when using C++ */
635841
#ifdef __cplusplus
636842
}

include/SDL_syswm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ typedef enum SDL_SYSWM_TYPE
148148
SDL_SYSWM_OS2,
149149
SDL_SYSWM_HAIKU,
150150
SDL_SYSWM_KMSDRM,
151-
SDL_SYSWM_RISCOS
151+
SDL_SYSWM_RISCOS,
152+
SDL_SYSWM_WIIU
152153
} SDL_SYSWM_TYPE;
153154

154155
/**
@@ -211,6 +212,11 @@ struct SDL_SysWMmsg
211212
MPARAM mp1; /**< The first first message parameter */
212213
MPARAM mp2; /**< The second first message parameter */
213214
} os2;
215+
#endif
216+
#if defined(SDL_VIDEO_DRIVER_WIIU)
217+
struct {
218+
unsigned event;
219+
} wiiu;
214220
#endif
215221
/* Can't have an empty union */
216222
int dummy;

src/events/SDL_events_c.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#include "../SDL_internal.h"
2626

27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
2731
/* Useful functions and variables from SDL_events.c */
2832
#include "SDL_events.h"
2933
#include "SDL_thread.h"
@@ -58,6 +62,11 @@ extern void SDL_SendPendingSignalEvents(void);
5862
extern int SDL_QuitInit(void);
5963
extern void SDL_QuitQuit(void);
6064

65+
#ifdef __cplusplus
66+
}
67+
#endif
68+
69+
6170
#endif /* SDL_events_c_h_ */
6271

6372
/* vi: set ts=4 sw=4 expandtab: */

src/events/SDL_keyboard_c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "SDL_keycode.h"
2727
#include "SDL_events.h"
2828

29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
2933
/* Initialize the keyboard subsystem */
3034
extern int SDL_KeyboardInit(void);
3135

@@ -84,6 +88,10 @@ extern char *SDL_UCS4ToUTF8(Uint32 ch, char *dst);
8488
/* Toggle on or off pieces of the keyboard mod state. */
8589
extern void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle);
8690

91+
#ifdef __cplusplus
92+
}
93+
#endif
94+
8795
#endif /* SDL_keyboard_c_h_ */
8896

8997
/* vi: set ts=4 sw=4 expandtab: */

0 commit comments

Comments
 (0)