Added applets/libapplet. Added appletSetThemeColorType and appletGetThemeColorType.

This commit is contained in:
yellows8 2018-12-19 19:49:27 -05:00
parent f448b0fbad
commit 6e10568589
6 changed files with 111 additions and 1 deletions

View File

@ -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

View File

@ -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"

View File

@ -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);

View File

@ -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.

View File

@ -0,0 +1,42 @@
#include <string.h>
#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);
}

View File

@ -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];