Skip to content

Commit 609dd2e

Browse files
dkosmariDaniel K. O. (dkosmari)
andauthored
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 6c8aa83 commit 609dd2e

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
@@ -240,6 +240,9 @@ endif()
240240
if(WIIU)
241241
# Prefer coreinit atomics on Wii U due to a hardware bug in load-exclusive and store-exclusive instructions
242242
set(OPT_DEF_GCC_ATOMICS OFF)
243+
# Needed for nn::swkbd API
244+
set(LINKER_LANGUAGE CXX)
245+
set (CMAKE_CXX_STANDARD 23)
243246
endif()
244247

245248
# Default option knobs
@@ -2920,14 +2923,14 @@ elseif(WIIU)
29202923
if(SDL_VIDEO)
29212924
set(SDL_VIDEO_DRIVER_WIIU 1)
29222925
set(SDL_VIDEO_RENDER_WIIU 1)
2923-
file(GLOB WIIU_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/wiiu/*.c)
2926+
file(GLOB WIIU_VIDEO_SOURCES
2927+
${SDL2_SOURCE_DIR}/src/video/wiiu/*.c
2928+
${SDL2_SOURCE_DIR}/src/video/wiiu/*.cpp)
29242929
set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_VIDEO_SOURCES})
29252930
set(HAVE_SDL_VIDEO TRUE)
29262931
endif()
2927-
2928-
list(APPEND EXTRA_LIBS
2929-
wut
2930-
)
2932+
list(APPEND EXTRA_CXXFLAGS "-fno-exceptions")
2933+
list(APPEND EXTRA_LIBS wut)
29312934
endif()
29322935

29332936
if(HAVE_VULKAN AND NOT SDL_LOADSO)
@@ -3063,8 +3066,13 @@ endif()
30633066
if(EXTRA_CFLAGS)
30643067
list(REMOVE_DUPLICATES EXTRA_CFLAGS)
30653068
endif()
3069+
if(EXTRA_CXXFLAGS)
3070+
list(REMOVE_DUPLICATES EXTRA_CXXFLAGS)
3071+
endif()
30663072
listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
30673073
set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
3074+
listtostr(EXTRA_CXXFLAGS _EXTRA_CXXFLAGS)
3075+
set(EXTRA_CXXFLAGS ${_EXTRA_CXXFLAGS})
30683076

30693077
# Compat helpers for the configuration files
30703078

@@ -3309,10 +3317,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
33093317
message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
33103318
endif()
33113319
message(STATUS "")
3312-
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
3313-
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
3314-
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
3315-
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
3320+
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
3321+
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
3322+
message(STATUS " EXTRA_CXXFLAGS: ${EXTRA_CXXFLAGS}")
3323+
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
3324+
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
33163325
message(STATUS "")
33173326
message(STATUS " Build Shared Library: ${SDL_SHARED}")
33183327
message(STATUS " Build Static Library: ${SDL_STATIC}")
@@ -3347,6 +3356,8 @@ endif()
33473356

33483357
# Ensure that the extra cflags are used at compile time
33493358
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${EXTRA_CFLAGS_BUILD}")
3359+
# Same for cxxflags
3360+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} ${EXTRA_CXXFLAGS_BUILD}")
33503361

33513362
if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
33523363
# Build SDLmain

include/SDL_system.h

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,212 @@ extern DECLSPEC int SDLCALL SDL_GDKGetTaskQueue(XTaskQueueHandle * outTaskQueue)
612612

613613
#endif
614614

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

include/SDL_syswm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ typedef enum
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)