From 6e105685898647cf57ef9f06db5d963dd25292f4 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 19 Dec 2018 19:49:27 -0500 Subject: [PATCH] Added applets/libapplet. Added appletSetThemeColorType and appletGetThemeColorType. --- nx/Makefile | 2 +- nx/include/switch.h | 2 ++ nx/include/switch/applets/libapplet.h | 43 +++++++++++++++++++++++++++ nx/include/switch/services/applet.h | 13 ++++++++ nx/source/applets/libapplet.c | 42 ++++++++++++++++++++++++++ nx/source/services/applet.c | 10 +++++++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 nx/include/switch/applets/libapplet.h create mode 100644 nx/source/applets/libapplet.c diff --git a/nx/Makefile b/nx/Makefile index 05438ed2..0f744c5e 100644 --- a/nx/Makefile +++ b/nx/Makefile @@ -24,7 +24,7 @@ VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH) #--------------------------------------------------------------------------------- TARGET := nx #BUILD := build -SOURCES := source/arm source/kernel source/services source/nvidia source/nvidia/ioctl source/display source/audio source/runtime source/runtime/devices source/runtime/util/utf +SOURCES := source/arm source/kernel source/services source/nvidia source/nvidia/ioctl source/display source/audio source/applets source/runtime source/runtime/devices source/runtime/util/utf DATA := data INCLUDES := include external/bsd/include diff --git a/nx/include/switch.h b/nx/include/switch.h index 3cbf1edc..99599e53 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -100,6 +100,8 @@ extern "C" { #include "switch/audio/driver.h" +#include "switch/applets/libapplet.h" + #include "switch/runtime/env.h" #include "switch/runtime/nxlink.h" diff --git a/nx/include/switch/applets/libapplet.h b/nx/include/switch/applets/libapplet.h new file mode 100644 index 00000000..0a1d0cb1 --- /dev/null +++ b/nx/include/switch/applets/libapplet.h @@ -0,0 +1,43 @@ +/** + * @file libapplet.h + * @brief LibraryApplet wrapper. + * @author yellows8 + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../services/applet.h" + +/// CommonArguments +typedef struct { + u32 CommonArgs_version; + u32 CommonArgs_size; + + u32 LaVersion; ///< LibraryApplet API version + s32 ExpectedThemeColor; ///< Set to the output from \ref appletGetThemeColorType by \ref libappletArgsCreate. + u8 PlayStartupSound; ///< bool flag, default is false. + u8 pad[7]; + u64 tick; +} LibAppletArgs; + +/** + * @brief Creates a LibAppletArgs struct. + * @param a LibAppletArgs struct. + * @param version LaVersion for \ref LibAppletArgs. + */ +void libappletArgsCreate(LibAppletArgs* a, u32 version); + +/** + * @brief Sets the PlayStartupSound field in \ref LibAppletArgs. + * @param a LibAppletArgs struct. + * @param flag Value for \ref LibAppletArgs PlayStartupSound. + */ +void libappletArgsSetPlayStartupSound(LibAppletArgs* a, bool flag); + +/** + * @brief Sets the tick field in LibAppletArgs, then creates a storage with it which is pushed to the AppletHolder via \ref appletHolderPushInData. + * @param a LibAppletArgs struct. + * @param h AppletHolder object. + */ +Result libappletArgsPush(LibAppletArgs* a, AppletHolder *h); + diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 80e3b2bf..5f180cbe 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -95,6 +95,13 @@ typedef enum { LibAppletExitReason_Unexpected = 10, } LibAppletExitReason; +typedef enum { + AppletThemeColorType_Default = 0, + AppletThemeColorType_Unknown1 = 1, + AppletThemeColorType_Unknown2 = 2, + AppletThemeColorType_Unknown3 = 3, +} AppletThemeColorType; + /// applet hook function. typedef void (*AppletHookFn)(AppletHookType hook, void* param); @@ -133,6 +140,12 @@ AppletType appletGetAppletType(void); void appletNotifyRunning(u8 *out); Result appletCreateManagedDisplayLayer(u64 *out); +/// Sets the state field for \ref AppletThemeColorType. +void appletSetThemeColorType(AppletThemeColorType theme); + +/// Gets the state field for \ref AppletThemeColorType. Used internally by \ref libappletArgsCreate. +AppletThemeColorType appletGetThemeColorType(void); + /** * @brief Pops a LaunchParameter AppletStorage, the storage will be removed from sysmodule state during this. * @param s Output storage. diff --git a/nx/source/applets/libapplet.c b/nx/source/applets/libapplet.c new file mode 100644 index 00000000..ae4d6cb8 --- /dev/null +++ b/nx/source/applets/libapplet.c @@ -0,0 +1,42 @@ +#include +#include "types.h" +#include "result.h" +#include "arm/counter.h" +#include "services/applet.h" +#include "applets/libapplet.h" + +void libappletArgsCreate(LibAppletArgs* a, u32 version) { + memset(a, 0, sizeof(LibAppletArgs)); + + a->CommonArgs_version = 1; + a->CommonArgs_size = sizeof(LibAppletArgs); + + a->LaVersion = version; + a->ExpectedThemeColor = appletGetThemeColorType(); +} + +void libappletArgsSetPlayStartupSound(LibAppletArgs* a, bool flag) { + a->PlayStartupSound = flag!=0; +} + +Result libappletArgsPush(LibAppletArgs* a, AppletHolder *h) { + Result rc=0; + AppletStorage storage; + + //Official sw stores the header in LibAppletArgs seperately (first 8-bytes), but here we're including it with the LibAppletCommonArguments struct. + //Official sw uses appletStorageWrite twice, for writing the header then the rest of the struct. + + a->tick = armGetSystemTick(); + + rc = appletCreateStorage(&storage, sizeof(LibAppletArgs)); + if (R_FAILED(rc)) return rc; + + rc = appletStorageWrite(&storage, 0, a, sizeof(LibAppletArgs)); + if (R_FAILED(rc)) { + appletStorageClose(&storage); + return rc; + } + + return appletHolderPushInData(h, &storage); +} + diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 937d939f..0ce11c96 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -57,6 +57,8 @@ static u32 g_appletRecordingInitialized; static Event g_appletLibraryAppletLaunchableEvent; +static AppletThemeColorType g_appletThemeColorType = AppletThemeColorType_Default; + static Result _appletGetHandle(Service* srv, Handle* handle_out, u64 cmd_id); static Result _appletGetEvent(Service* srv, Event* event_out, u64 cmd_id, bool autoclear); static Result _appletGetSession(Service* srv, Service* srv_out, u64 cmd_id); @@ -387,6 +389,14 @@ void appletUnhook(AppletHookCookie* cookie) } } +void appletSetThemeColorType(AppletThemeColorType theme) { + g_appletThemeColorType = theme; +} + +AppletThemeColorType appletGetThemeColorType(void) { + return g_appletThemeColorType; +} + Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode) { Result rc; u8 invals[4];