diff --git a/nx/include/switch/applets/swkbd.h b/nx/include/switch/applets/swkbd.h index 260598a6..e4970abe 100644 --- a/nx/include/switch/applets/swkbd.h +++ b/nx/include/switch/applets/swkbd.h @@ -132,6 +132,11 @@ typedef struct { u8 unk_x0[0x64]; } SwkbdDictWord; +/// Input data for SwkbdInline request SetCustomizeDic. +typedef struct { + u8 unk_x0[0x70]; +} SwkbdCustomizeDicInfo; + typedef struct { u32 unk_x0; u8 mode; ///< See \ref SwkbdInlineMode. @@ -196,10 +201,10 @@ typedef struct { /// Struct data for SwkbdInline Interactive reply storage ChangedString*, at the end following the string. typedef struct { - u32 stringLen; ///< String length in characters, without NUL-terminator. - s32 unk_x4; - s32 unk_x8; - s32 cursorPos; ///< Cursor position. + u32 stringLen; ///< String length in characters, without NUL-terminator. + s32 dicStartCursorPos; ///< Starting cursorPos for the current dictionary word in the current text string. -1 for none. + s32 dicEndCursorPos; ///< Ending cursorPos for the current dictionary word in the current text string. -1 for none. + s32 cursorPos; ///< Cursor position. } SwkbdChangedStringArg; /// Struct data for SwkbdInline Interactive reply storage MovedCursor*, at the end following the string. @@ -243,6 +248,9 @@ typedef struct { bool directionalButtonAssignFlag; SwkbdState state; + bool dicCustomInitialized; + AppletStorage dicStorage; + u8* interactive_tmpbuf; size_t interactive_tmpbuf_size; char* interactive_strbuf; @@ -506,6 +514,25 @@ void swkbdInlineSetCursorPos(SwkbdInline* s, s32 pos); */ void swkbdInlineSetUtf8Mode(SwkbdInline* s, bool flag); +/** + * @brief Sets the CustomizeDic. + * @note Not avilable when \ref SwkbdState is above \ref SwkbdState_Initialized. Can't be used if this was already used previously. + * @note The specified buffer must not be used after this, until \ref swkbdInlineClose is used. + * @param s SwkbdInline object. + * @param buffer 0x1000-byte aligned buffer. + * @param size 0x1000-byte aligned buffer size. + * @param info Input \ref SwkbdCustomizeDicInfo + */ +Result swkbdInlineSetCustomizeDic(SwkbdInline* s, void* buffer, size_t size, SwkbdCustomizeDicInfo *info); + +/** + * @brief Request UnsetCustomizeDic. + * @note \ref swkbdInlineUpdate must be called at some point afterwards for this to take affect. + * @note Not avilable when \ref SwkbdState is above \ref SwkbdState_Initialized. + * @param s SwkbdInline object. + */ +void swkbdInlineUnsetCustomizeDic(SwkbdInline* s); + /** * @brief Sets InputModeFadeType. * @note \ref swkbdInlineUpdate must be called at some point afterwards for this to take affect. diff --git a/nx/source/applets/swkbd.c b/nx/source/applets/swkbd.c index 82801071..728244dc 100644 --- a/nx/source/applets/swkbd.c +++ b/nx/source/applets/swkbd.c @@ -427,6 +427,10 @@ Result swkbdInlineClose(SwkbdInline* s) { s->interactive_strbuf = NULL; s->interactive_strbuf_size = 0; + appletStorageCloseTmem(&s->dicStorage); + + memset(s, 0, sizeof(SwkbdInline)); + return rc; } @@ -685,6 +689,27 @@ void swkbdInlineSetUtf8Mode(SwkbdInline* s, bool flag) { _swkbdInlineSetBoolFlag(s, &s->calcArg.utf8Mode, flag, 0x20); } +Result swkbdInlineSetCustomizeDic(SwkbdInline* s, void* buffer, size_t size, SwkbdCustomizeDicInfo *info) { + Result rc=0; + + if (s->state > SwkbdState_Initialized || s->dicCustomInitialized) return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); + + rc = appletCreateHandleStorageTmem(&s->dicStorage, buffer, size); + if (R_FAILED(rc)) return rc; + s->dicCustomInitialized = true; + rc = appletHolderPushInteractiveInData(&s->holder, &s->dicStorage); + if (R_FAILED(rc)) return rc; + + rc = _swkbdSendRequest(s, SwkbdRequestCommand_SetCustomizeDic, info, sizeof(SwkbdCustomizeDicInfo)); + + return rc; +} + +void swkbdInlineUnsetCustomizeDic(SwkbdInline* s) { + if (s->state > SwkbdState_Initialized || !s->dicCustomInitialized) return; + s->calcArg.flags |= 0x40; +} + void swkbdInlineSetInputModeFadeType(SwkbdInline* s, u8 type) { if (s->calcArg.inputModeFadeType == type) return; s->calcArg.inputModeFadeType = type;