mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-26 23:02:39 +02:00
Added initial swkbd impl.
This commit is contained in:
parent
d821185e3d
commit
32f93bef5d
@ -101,6 +101,7 @@ extern "C" {
|
||||
#include "switch/audio/driver.h"
|
||||
|
||||
#include "switch/applets/libapplet.h"
|
||||
#include "switch/applets/swkbd.h"
|
||||
|
||||
#include "switch/runtime/env.h"
|
||||
#include "switch/runtime/nxlink.h"
|
||||
|
30
nx/include/switch/applets/swkbd.h
Normal file
30
nx/include/switch/applets/swkbd.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file swkbd.h
|
||||
* @brief Wrapper for using the swkbd LibraryApplet.
|
||||
* @author yellows8
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "../services/applet.h"
|
||||
|
||||
typedef struct {
|
||||
u8 data[0x3E0];//TODO: Fill this in.
|
||||
} SwkbdArg;
|
||||
|
||||
typedef struct {
|
||||
SwkbdArg arg;
|
||||
} SwkbdConfig;
|
||||
|
||||
/**
|
||||
* @brief Creates a SwkbdConfig struct.
|
||||
* @param c SwkbdConfig struct.
|
||||
*/
|
||||
void swkbdCreate(SwkbdConfig* c);
|
||||
|
||||
/**
|
||||
* @brief Launch swkbd with the specified config. This will return once swkbd is finished running.
|
||||
* @param c SwkbdConfig struct.
|
||||
*/
|
||||
Result swkbdShow(SwkbdConfig* c);
|
||||
|
65
nx/source/applets/swkbd.c
Normal file
65
nx/source/applets/swkbd.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "result.h"
|
||||
#include "services/applet.h"
|
||||
#include "applets/libapplet.h"
|
||||
#include "applets/swkbd.h"
|
||||
|
||||
void swkbdCreate(SwkbdConfig* c) {
|
||||
memset(c, 0, sizeof(SwkbdConfig));
|
||||
}
|
||||
|
||||
Result swkbdShow(SwkbdConfig* c) {
|
||||
Result rc=0;
|
||||
AppletHolder holder;
|
||||
AppletStorage storage;
|
||||
u8 *workbuf = NULL;//TODO
|
||||
size_t workbuf_size = 0x1000;//TODO
|
||||
|
||||
memset(&storage, 0, sizeof(AppletStorage));
|
||||
|
||||
rc = appletCreateLibraryApplet(&holder, AppletId_swkbd, LibAppletMode_AllForeground);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
LibAppletArgs commonargs;
|
||||
libappletArgsCreate(&commonargs, 0x5);//1.0.0+ version
|
||||
rc = libappletArgsPush(&commonargs, &holder);
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = libappletPushInData(&holder, &c->arg, sizeof(c->arg));
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (R_SUCCEEDED(rc)) rc = appletCreateTransferMemoryStorage(&storage, workbuf, workbuf_size, true);
|
||||
appletHolderPushInData(&holder, &storage);
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = appletHolderStart(&holder);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
while(appletHolderWaitInteractiveOut(&holder)) {
|
||||
//TODO: Handle Interactive data here.
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
appletHolderJoin(&holder);
|
||||
|
||||
LibAppletExitReason reason = appletHolderGetExitReason(&holder);
|
||||
|
||||
if (reason == LibAppletExitReason_Canceled) {
|
||||
rc = 0x29f;//TODO: Official sw returns this, replace it with something else.
|
||||
}
|
||||
else if (reason == LibAppletExitReason_Abnormal || reason == LibAppletExitReason_Unexpected) {
|
||||
//TODO: Official sw asserts here - return a proper error here.
|
||||
return -1;
|
||||
}
|
||||
else { //success
|
||||
//TODO: Process the output storage here. When the output CloseResult indicates failure, official sw returns same error as above.
|
||||
}
|
||||
}
|
||||
|
||||
appletHolderClose(&holder);
|
||||
appletStorageCloseTmem(&storage);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user