Skip to content

Commit

Permalink
Moved state field from swkbdInlineUpdate into SwkbdInline, and added …
Browse files Browse the repository at this point in the history
…out_state param. Removed unused State param from _swkbdProcessReply. Added SwkbdState enum.
  • Loading branch information
yellows8 committed Jan 19, 2019
1 parent dbadcd7 commit be8e196
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 13 additions & 1 deletion nx/include/switch/applets/swkbd.h
Expand Up @@ -62,6 +62,16 @@ typedef enum {
SwkbdReplyType_ReleasedUserWordInfo = 0xB,
} SwkbdReplyType;

/// SwkbdInline State
typedef enum {
SwkbdState_Inactive = 0x0, ///< Default state from \ref swkbdInlineCreate, before a state is set by \ref swkbdInlineUpdate when a reply is received. Also indicates that the applet is no longer running.
SwkbdState_Initialized = 0x1,
SwkbdState_Unknown2 = 0x2,
SwkbdState_TextAvailable = 0x3, ///< Text is available since a ChangedString* reply was received.
SwkbdState_Submitted = 0x4, ///< The user pressed the ok-button, submitting the text and closing the applet.
SwkbdState_Unknown5 = 0x5,
} SwkbdState;

/// Value for \ref SwkbdInitializeArg mode. Controls the LibAppletMode when launching the applet.
typedef enum {
SwkbdInlineMode_UserDisplay = 0, ///< LibAppletMode_Unknown3. This is the default. The user-process must handle displaying the swkbd gfx on the screen. Attempting to get the swkbd gfx data for this currently throws an error (unknown why), SwkbdInlineMode_AppletDisplay should be used instead.
Expand Down Expand Up @@ -231,6 +241,7 @@ typedef struct {
AppletHolder holder;
SwkbdInlineCalcArg calcArg;
bool directionalButtonAssignFlag;
SwkbdState state;

u8* interactive_tmpbuf;
size_t interactive_tmpbuf_size;
Expand Down Expand Up @@ -391,8 +402,9 @@ Result swkbdInlineLaunch(SwkbdInline* s);
* @note Handles applet exit if needed, and also sends the \ref SwkbdInlineCalcArg to the applet if needed. Hence, this should be called at some point after writing to \ref SwkbdInlineCalcArg.
* @note Handles applet Interactive storage output when needed.
* @param s SwkbdInline object.
* @param out_state Optional output \ref SwkbdState.
*/
Result swkbdInlineUpdate(SwkbdInline* s);
Result swkbdInlineUpdate(SwkbdInline* s, SwkbdState* out_state);

/**
* @brief Sets the FinishedInitialize callback, used by \ref swkbdInlineUpdate. The default is NULL for none.
Expand Down
14 changes: 9 additions & 5 deletions nx/source/applets/swkbd.c
Expand Up @@ -447,7 +447,7 @@ Result swkbdInlineLaunch(SwkbdInline* s) {
return rc;
}

static void _swkbdProcessReply(SwkbdInline* s, u32 State, SwkbdReplyType ReplyType, size_t size) {
static void _swkbdProcessReply(SwkbdInline* s, SwkbdReplyType ReplyType, size_t size) {
size_t stringendoff_utf8 = 0x7D4;
size_t stringendoff_utf16 = 0x3EC;
void* argdataend_utf8 = &s->interactive_tmpbuf[stringendoff_utf8];
Expand Down Expand Up @@ -508,10 +508,9 @@ static void _swkbdProcessReply(SwkbdInline* s, u32 State, SwkbdReplyType ReplyTy
}
}

Result swkbdInlineUpdate(SwkbdInline* s) {
Result swkbdInlineUpdate(SwkbdInline* s, SwkbdState* out_state) {
Result rc=0;
AppletStorage storage;
u32 State=0;
SwkbdReplyType ReplyType=0;

u8 fadetype=0;
Expand All @@ -528,6 +527,9 @@ Result swkbdInlineUpdate(SwkbdInline* s) {
if (appletHolderCheckFinished(&s->holder)) {
appletHolderJoin(&s->holder);
appletHolderClose(&s->holder);

s->state = SwkbdState_Inactive;
if (out_state) *out_state = s->state;
return 0;
}

Expand All @@ -543,17 +545,19 @@ Result swkbdInlineUpdate(SwkbdInline* s) {
memset(s->interactive_tmpbuf, 0, s->interactive_tmpbuf_size);

if (R_SUCCEEDED(rc) && (tmpsize < 8 || tmpsize-8 > s->interactive_tmpbuf_size)) rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
if (R_SUCCEEDED(rc)) rc = appletStorageRead(&storage, 0x0, &State, sizeof(u32));
if (R_SUCCEEDED(rc)) rc = appletStorageRead(&storage, 0x0, &s->state, sizeof(s->state));
if (R_SUCCEEDED(rc)) rc = appletStorageRead(&storage, 0x4, &ReplyType, sizeof(u32));
if (R_SUCCEEDED(rc) && tmpsize >= 8) rc = appletStorageRead(&storage, 0x8, s->interactive_tmpbuf, tmpsize-8);

appletStorageClose(&storage);

if (R_FAILED(rc)) break;

_swkbdProcessReply(s, State, ReplyType, tmpsize-8);
_swkbdProcessReply(s, ReplyType, tmpsize-8);
}

if (out_state) *out_state = s->state;

return rc;
}

Expand Down

0 comments on commit be8e196

Please sign in to comment.