Skip to content

Wii U: Add support for swkbd. #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: wiiu-sdl2-2.28
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BraceWrapping:
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: false
BeforeWhile: false
IndentBraces: false
Expand Down Expand Up @@ -62,6 +63,8 @@ IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: NoIndent

NamespaceIndentation: All

PointerAlignment: Right
SpaceAfterCStyleCast: false
SpacesInCStyleCastParentheses: false
Expand Down
29 changes: 20 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ endif()
if(WIIU)
# Prefer coreinit atomics on Wii U due to a hardware bug in load-exclusive and store-exclusive instructions
set(OPT_DEF_GCC_ATOMICS OFF)
# Needed for nn::swkbd API
set(LINKER_LANGUAGE CXX)
set (CMAKE_CXX_STANDARD 23)
endif()

# Default option knobs
Expand Down Expand Up @@ -2920,14 +2923,14 @@ elseif(WIIU)
if(SDL_VIDEO)
set(SDL_VIDEO_DRIVER_WIIU 1)
set(SDL_VIDEO_RENDER_WIIU 1)
file(GLOB WIIU_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/wiiu/*.c)
file(GLOB WIIU_VIDEO_SOURCES
${SDL2_SOURCE_DIR}/src/video/wiiu/*.c
${SDL2_SOURCE_DIR}/src/video/wiiu/*.cpp)
set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_VIDEO_SOURCES})
set(HAVE_SDL_VIDEO TRUE)
endif()

list(APPEND EXTRA_LIBS
wut
)
list(APPEND EXTRA_CXXFLAGS "-fno-exceptions")
list(APPEND EXTRA_LIBS wut)
endif()

if(HAVE_VULKAN AND NOT SDL_LOADSO)
Expand Down Expand Up @@ -3063,8 +3066,13 @@ endif()
if(EXTRA_CFLAGS)
list(REMOVE_DUPLICATES EXTRA_CFLAGS)
endif()
if(EXTRA_CXXFLAGS)
list(REMOVE_DUPLICATES EXTRA_CXXFLAGS)
endif()
listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
listtostr(EXTRA_CXXFLAGS _EXTRA_CXXFLAGS)
set(EXTRA_CXXFLAGS ${_EXTRA_CXXFLAGS})

# Compat helpers for the configuration files

Expand Down Expand Up @@ -3309,10 +3317,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
endif()
message(STATUS "")
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
message(STATUS " EXTRA_CXXFLAGS: ${EXTRA_CXXFLAGS}")
message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
message(STATUS "")
message(STATUS " Build Shared Library: ${SDL_SHARED}")
message(STATUS " Build Static Library: ${SDL_STATIC}")
Expand Down Expand Up @@ -3347,6 +3356,8 @@ endif()

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

if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
# Build SDLmain
Expand Down
256 changes: 256 additions & 0 deletions include/SDL_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,262 @@ extern DECLSPEC int SDLCALL SDL_GDKGetTaskQueue(XTaskQueueHandle * outTaskQueue)

#endif

/* Platform specific functions for Wii U */
#if defined(__WIIU__)
typedef enum SDL_WiiUSysWMEventType {
/** Sent before any text input event. */
SDL_WIIU_SYSWM_SWKBD_OK_START_EVENT = 1,
/** Sent after all text input events. */
SDL_WIIU_SYSWM_SWKBD_OK_FINISH_EVENT,
/** Sent after the swkbd was canceled. */
SDL_WIIU_SYSWM_SWKBD_CANCEL_EVENT
} SDL_WiiUSysWMEventType;

/**
* Disable the swkbd.
*
* Use this function if you only want text input from a physical USB keyboard.
*
* \param enabled `SDL_FALSE` if you do not want the swkbd to show up after calling
* `SDL_StartTextInput()`.
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDEnabled(SDL_bool enabled);

/**
* Sets a `nn::swkbd::CreateArg` object that will be used to create the swkbd.
*
* You don't need to set `arg->fsClient` nor `arg->workMemory`, these will be
* allocated if they are `NULL`, when the swkbd is first shown.
*
* \param arg Pointer to a persistent `nn::swkbd::CreateArg` object, or `NULL` to use the
* default.
*
* \note
* The swkbd will be re-initialized after calling this function.
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDCreateArg(void * arg);

/**
* Sets a `nn::swkbd::AppearArg` object that will be used every time the swkbd is shown.
* You don't have to call this function again if you update the argument's content.
*
* \param arg Pointer to a persistent `nn::swkbd::AppearArg` object, or `NULL` to use the
* default.
*
* \note
* When a `nn::swkbd::AppearArg` argument is used, all related customization options
* are ignored.
*
* \sa SDL_WiiUSetSWKBDHighlightInitialText
* \sa SDL_WiiUSetSWKBDHintText
* \sa SDL_WiiUSetSWKBDInitialText
* \sa SDL_WiiUSetSWKBDKeyboardMode
* \sa SDL_WiiUSetSWKBDOKLabel
* \sa SDL_WiiUSetSWKBDPasswordMode
* \sa SDL_WiiUSetSWKBDShowCopyPasteButtons
* \sa SDL_WiiUSetSWKBDShowWordSuggestions
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDAppearArg(const void * arg);

/**
* Select the swkbd keyboard mode.
*
* \sa SDL_WiiUSetSWKBDKeyboardMode
*/
typedef enum SDL_WiiUSWKBDKeyboardMode {
/** Full keyboard. */
SDL_WIIU_SWKBD_KEYBOARD_MODE_FULL,
/** Numeric keyboard. */
SDL_WIIU_SWKBD_KEYBOARD_MODE_NUMPAD,
/** Restricted keyboard (only letters, numbers and symbols.) */
SDL_WIIU_SWKBD_KEYBOARD_MODE_RESTRICTED,
/** NNID keyboard. */
SDL_WIIU_SWKBD_KEYBOARD_MODE_NNID
} SDL_WiiUSWKBDKeyboardMode;

/**
* Sets the swkbd's keyboard mode.
*
* \param mode One of SDL_WiiUSWKBDKeyboardMode. The default is
* `SDL_WIIU_SWKBD_KEYBOARD_MODE_FULL`.
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDKeyboardMode(SDL_WiiUSWKBDKeyboardMode mode);

/**
* Sets the label for the swkbd's "OK" button.
*
* \param label String for the "OK" button, encoded in UTF-8, or `NULL` to use the
* default.
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDOKLabel(const char * label);

/**
* Sets the swkbd's word suggestions option.
*
* \param show `SDL_TRUE` to enable word suggestions. The default is `SDL_TRUE`.
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDShowWordSuggestions(SDL_bool show);

/**
* Sets the swkbd's initial text.
*
* \param text String for the initial text, encoded in UTF-8, or `NULL` to use the
* default (no initial text.)
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDInitialText(const char * text);

/**
* Sets the swkbd's hint text.
*
* \param text String for the hint text, encoded in UTF-8, or `NULL` to use the default
* (no hint.)
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDHintText(const char * text);

/**
* Controls how to display passwwords in the swkbd when in password mode.
*/
typedef enum SDL_WiiUSWKBDPasswordMode {
SDL_WIIU_SWKBD_PASSWORD_MODE_SHOW, /**< Show password. */
SDL_WIIU_SWKBD_PASSWORD_MODE_HIDE, /**< Hide password. */
SDL_WIIU_SWKBD_PASSWORD_MODE_FADE /**< Hide password after 1 second. */
} SDL_WiiUSWKBDPasswordMode;

/**
* Sets the swkbd's password mode.
*
* \param mode One of of the SDL_WiiUSWKBDPasswordMode values. The default is
* `SDL_WIIU_SWKBD_PASSWORD_MODE_SHOW`.
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
* \sa SDL_WiiUSetSWKBDKeyboardMode
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDPasswordMode(SDL_WiiUSWKBDPasswordMode mode);

/**
* Sets whether to highlight (select) the swkbd's initial text.
*
* \param highlight `SDL_TRUE` to highlight the initial text. The default is `SDL_FALSE`.

* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDHighlightInitialText(SDL_bool highlight);

/**
* Sets the swkbd's copy-paste button option.
*
* \param show `SDL_TRUE` to show copy-paste buttons. The default is `SDL_FALSE`.
*
* \note
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDShowCopyPasteButtons(SDL_bool show);

/**
* Sets the swkbd's built-in rendering of the Wii remote pointer.
*
* \param draw `SDL_TRUE` to let the swkbd draw its own Wii remote pointer. The default is
* `SDL_TRUE`.
*
* This option is reset to the default value after the swkbd is shown, and is ignored if
* you use SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument.
*
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDDrawWiiPointer(SDL_bool draw);

/**
* Sets the swkbd's locale (region and language.)
*
* \param locale String representing the intended keyboard region and language, using
* Unix-style locale format (e.g. `"en_US"`, `"fr_CA"`, `ja_JP`, `"en"`.) Set to `NULL` to
* use the system region and language. The default is `NULL`.
*
* \note
* The swkbd will be re-initialized after calling this function.
*
* \note
* Calling SDL_WiiUSetSWKBDCreateArg with a non-`NULL` argument will override the region.
*
* \note
* Calling SDL_WiiUSetSWKBDAppearArg with a non-`NULL` argument will override the
* language.
*
* \sa SDL_WiiUSetSWKBDCreateArg
* \sa SDL_WiiUSetSWKBDAppearArg
*/
extern DECLSPEC void SDLCALL SDL_WiiUSetSWKBDLocale(const char * locale);

/**
* Sends VPAD input to the swkbd.
*
* Call this function at every frame if your application calls `VPADRead()` instead of
* using the SDL game controller subsystem.
*
* \param vpad Pointer to a `VPADStatus` object.
* \returns `SDL_TRUE` if the swkbd is visible and is going to use the input.
*
* \note
* The touch point in `tpNormal` should contain calibrated point, by calling
* `VPADGetTPCalibratedPoint()`, prior to calling this function.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_WiiUSetSWKBDVPAD(const void * vpad);

/**
* Sends KPAD input to the swkbd.
*
* Call this function at every frame if you call `KPADRead()` or `KPADReadEx()` in your
* application, instead of using the SDL game controller subsystem.
*
* \param channel Number of channel.
* \param kpad Pointer to a `KPADStatus` object.
* \returns `SDL_TRUE` if the swkbd is visible and is going to use the input.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_WiiUSetSWKBDKPAD(int channel, const void * kpad);

#endif /* Wii U */

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down
8 changes: 7 additions & 1 deletion include/SDL_syswm.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ typedef enum
SDL_SYSWM_OS2,
SDL_SYSWM_HAIKU,
SDL_SYSWM_KMSDRM,
SDL_SYSWM_RISCOS
SDL_SYSWM_RISCOS,
SDL_SYSWM_WIIU
} SDL_SYSWM_TYPE;

/**
Expand Down Expand Up @@ -211,6 +212,11 @@ struct SDL_SysWMmsg
MPARAM mp1; /**< The first first message parameter */
MPARAM mp2; /**< The second first message parameter */
} os2;
#endif
#if defined(SDL_VIDEO_DRIVER_WIIU)
struct {
unsigned event;
} wiiu;
#endif
/* Can't have an empty union */
int dummy;
Expand Down
9 changes: 9 additions & 0 deletions src/events/SDL_events_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

#include "../SDL_internal.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Useful functions and variables from SDL_events.c */
#include "SDL_events.h"
#include "SDL_thread.h"
Expand Down Expand Up @@ -58,6 +62,11 @@ extern void SDL_SendPendingSignalEvents(void);
extern int SDL_QuitInit(void);
extern void SDL_QuitQuit(void);

#ifdef __cplusplus
}
#endif


#endif /* SDL_events_c_h_ */

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