Moved state field from swkbdInlineUpdate into SwkbdInline, and added out_state param. Removed unused State param from _swkbdProcessReply. Added SwkbdState enum.

This commit is contained in:
yellows8 2019-01-18 23:48:31 -05:00
parent dbadcd76ed
commit be8e196eb0
2 changed files with 22 additions and 6 deletions

View File

@ -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.
@ -231,6 +241,7 @@ typedef struct {
AppletHolder holder;
SwkbdInlineCalcArg calcArg;
bool directionalButtonAssignFlag;
SwkbdState state;
u8* interactive_tmpbuf;
size_t interactive_tmpbuf_size;
@ -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.

View File

@ -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];
@ -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;
@ -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;
}
@ -543,7 +545,7 @@ 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);
@ -551,9 +553,11 @@ Result swkbdInlineUpdate(SwkbdInline* s) {
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;
}