mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-05 02:52:13 +02:00
Add UnknownMessageHandler, correct typos and better formatting
This commit is contained in:
parent
9011f278b6
commit
fb31b8f184
@ -470,16 +470,19 @@ AppletFocusState appletGetFocusState(void);
|
||||
Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode);
|
||||
|
||||
/**
|
||||
* @brief Stops forwaring the input to the foreground app. Works only in the Overlay applet context
|
||||
* @brief Stops forwarding the input to the foreground app, works only in the Overlay applet context
|
||||
* @note You have to call this to receive inputs through the hid service when running as the overlay applet.
|
||||
*/
|
||||
Result appletBeginToWatchShortHomeButtonMessage(void);
|
||||
|
||||
/**
|
||||
* @brief Forwards input to the foreground app. Works only in the Overlay applet context
|
||||
* @brief Forwards input to the foreground app, works only in the Overlay applet context
|
||||
* @note After calling this the overlay applet won't receive any input until \ref appletBeginToWatchShortHomeButtonMessage is called again.
|
||||
*/
|
||||
Result appletEndToWatchShortHomeButtonMessage(void);
|
||||
|
||||
/**
|
||||
* @brief Get an event that fires when the home button is pressed, doesn't interfere with home menu
|
||||
* @brief Get an event that fires when the home button is pressed, doesn't interfere with home menu. This event does not auto clear.
|
||||
* @note Doesn't fire for long press.
|
||||
*/
|
||||
Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event);
|
@ -8,13 +8,12 @@
|
||||
#include "../kernel/event.h"
|
||||
#include "../services/sm.h"
|
||||
|
||||
Result hidSysInitialize(void);
|
||||
Result hidsysInitialize(void);
|
||||
void hidsysExit(void);
|
||||
|
||||
void hidSysExit(void);
|
||||
|
||||
Result hidSysEnableAppletToGetInput(bool enable);
|
||||
Result hidsysEnableAppletToGetInput(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Returns an event that fires when the home button is pressed, this will prevent the home menu from opening when the button is pressed.
|
||||
* @brief Returns an event that fires when the home button is pressed, this will prevent the home menu from opening when the button is pressed. This event does not auto clear
|
||||
**/
|
||||
Result hidSysAcquireHomeButtonEventHandle(Event* event_out);
|
||||
Result hidsysAcquireHomeButtonEventHandle(Event* event_out);
|
@ -19,6 +19,8 @@ __attribute__((weak)) u32 __nx_applet_PerformanceConfiguration[2] = {/*0x9222000
|
||||
//// Controls whether to use applet exit cmds during \ref appletExit. 0 (default): Only run exit cmds when running under a NSO. 1: Use exit cmds regardless. >1: Skip exit cmds.
|
||||
__attribute__((weak)) u32 __nx_applet_exit_mode = 0;
|
||||
|
||||
void __attribute__((weak)) __nx_applet_UnknownMessageHandler(u32);
|
||||
|
||||
static Service g_appletSrv;
|
||||
static Service g_appletProxySession;
|
||||
static u64 g_refCnt;
|
||||
@ -316,8 +318,8 @@ void appletExit(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eventClose(&HomeButtonReaderLockAccessorEvent);
|
||||
|
||||
eventClose(&HomeButtonReaderLockAccessorEvent);
|
||||
|
||||
eventClose(&g_appletLibraryAppletLaunchableEvent);
|
||||
|
||||
@ -2315,42 +2317,47 @@ bool appletMainLoop(void) {
|
||||
|
||||
appletCallHook(AppletHookType_OnPerformanceMode);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (__nx_applet_UnknownMessageHandler)
|
||||
__nx_applet_UnknownMessageHandler(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Result appletBeginToWatchShortHomeButtonMessage(void) {
|
||||
if (__nx_applet_type != AppletType_OverlayApplet)
|
||||
if (__nx_applet_type != AppletType_OverlayApplet)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return _appletCmdNoIO(&g_appletIFunctions, 0);
|
||||
|
||||
return _appletCmdNoIO(&g_appletIFunctions, 0);
|
||||
}
|
||||
|
||||
Result appletEndToWatchShortHomeButtonMessage(void) {
|
||||
if (__nx_applet_type != AppletType_OverlayApplet)
|
||||
if (__nx_applet_type != AppletType_OverlayApplet)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return _appletCmdNoIO(&g_appletIFunctions, 1);
|
||||
|
||||
return _appletCmdNoIO(&g_appletIFunctions, 1);
|
||||
}
|
||||
|
||||
Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event)
|
||||
{
|
||||
if (eventActive(&HomeButtonReaderLockAccessorEvent))
|
||||
{
|
||||
*out_event = HomeButtonReaderLockAccessorEvent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Service ILockAccessor = {0};
|
||||
Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30);
|
||||
if (!R_SUCCEEDED(rc))
|
||||
return rc;
|
||||
|
||||
rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3,true);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*out_event = HomeButtonReaderLockAccessorEvent;
|
||||
if (eventActive(&HomeButtonReaderLockAccessorEvent))
|
||||
{
|
||||
*out_event = HomeButtonReaderLockAccessorEvent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Service ILockAccessor = {0};
|
||||
Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30);
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*out_event = HomeButtonReaderLockAccessorEvent;
|
||||
|
||||
serviceClose(&ILockAccessor);
|
||||
return rc;
|
||||
serviceClose(&ILockAccessor);
|
||||
return rc;
|
||||
}
|
||||
|
@ -10,61 +10,61 @@
|
||||
#include "services/hidsys.h"
|
||||
#include "services/sm.h"
|
||||
|
||||
static Service g_hidSysSrv;
|
||||
static u64 g_hidSysRefCnt;
|
||||
static Service g_hidsysSrv;
|
||||
static u64 g_hidsysRefCnt;
|
||||
|
||||
static Event g_hidSysHomeEvent = {0};
|
||||
static Event g_hidSysCaptureEvent = {0};
|
||||
static Event g_hidSysSleeptEvent = {0};
|
||||
static Event g_hidsysHomeEvent = {0};
|
||||
static Event g_hidsysCaptureEvent = {0};
|
||||
static Event g_hidSysSleepEvent = {0};
|
||||
|
||||
static u64 g_hidSysAppletResourceUserId = 0;
|
||||
static u64 g_hidsysAppletResourceUserId = 0;
|
||||
|
||||
Result hidSysInitialize(void) {
|
||||
atomicIncrement64(&g_hidSysRefCnt);
|
||||
|
||||
if (serviceIsActive(&g_hidSysSrv))
|
||||
return 0;
|
||||
|
||||
Result rc = smGetService(&g_hidSysSrv, "hid:sys");
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
rc = appletGetAppletResourceUserId(&g_hidSysAppletResourceUserId);
|
||||
Result hidsysInitialize(void) {
|
||||
atomicIncrement64(&g_hidsysRefCnt);
|
||||
|
||||
if (serviceIsActive(&g_hidsysSrv))
|
||||
return 0;
|
||||
|
||||
Result rc = smGetService(&g_hidsysSrv, "hid:sys");
|
||||
if (R_FAILED(rc))
|
||||
g_hidSysAppletResourceUserId = 0;
|
||||
return rc;
|
||||
|
||||
rc = appletGetAppletResourceUserId(&g_hidsysAppletResourceUserId);
|
||||
if (R_FAILED(rc))
|
||||
g_hidsysAppletResourceUserId = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hidSysExit(void) {
|
||||
if (atomicDecrement64(&g_hidSysRefCnt) == 0) {
|
||||
eventClose(&g_hidSysHomeEvent);
|
||||
eventClose(&g_hidSysCaptureEvent);
|
||||
eventClose(&g_hidSysSleeptEvent);
|
||||
|
||||
serviceClose(&g_hidSysSrv);
|
||||
void hidsysExit(void) {
|
||||
if (atomicDecrement64(&g_hidsysRefCnt) == 0) {
|
||||
eventClose(&g_hidsysHomeEvent);
|
||||
eventClose(&g_hidsysCaptureEvent);
|
||||
eventClose(&g_hidSysSleepEvent);
|
||||
|
||||
serviceClose(&g_hidsysSrv);
|
||||
}
|
||||
}
|
||||
|
||||
Result hidSysEnableAppletToGetInput(bool enable) {
|
||||
Result hidsysEnableAppletToGetInput(bool enable) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct CmdStruct{
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmdid;
|
||||
bool permitInput;
|
||||
u64 appletResourceUserId;
|
||||
} *cmdStruct;
|
||||
} *raw;
|
||||
|
||||
cmdStruct = (struct CmdStruct*) serviceIpcPrepareHeader(&g_hidSysSrv, &c, sizeof(*cmdStruct));
|
||||
raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw));
|
||||
|
||||
cmdStruct->magic = SFCI_MAGIC;
|
||||
cmdStruct->cmdid = 503;
|
||||
cmdStruct->permitInput = enable;
|
||||
cmdStruct->appletResourceUserId = g_hidSysAppletResourceUserId;
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmdid = 503;
|
||||
raw->permitInput = enable;
|
||||
raw->appletResourceUserId = g_hidsysAppletResourceUserId;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_hidSysSrv);
|
||||
Result rc = serviceIpcDispatch(&g_hidsysSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
@ -73,7 +73,7 @@ Result hidSysEnableAppletToGetInput(bool enable) {
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp));
|
||||
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
@ -82,7 +82,7 @@ Result hidSysEnableAppletToGetInput(bool enable) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
|
||||
static Result _hidsysCmdWithResIdAndPid(u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
@ -92,14 +92,14 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
|
||||
u64 AppletResourceUserId;
|
||||
} *raw;
|
||||
|
||||
ipcSendPid(&c);
|
||||
raw = serviceIpcPrepareHeader(&g_hidSysSrv,&c, sizeof(*raw));
|
||||
ipcSendPid(&c);
|
||||
raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->AppletResourceUserId = g_hidSysAppletResourceUserId;
|
||||
raw->AppletResourceUserId = g_hidsysAppletResourceUserId;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_hidSysSrv);
|
||||
Result rc = serviceIpcDispatch(&g_hidsysSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
@ -108,7 +108,7 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp));
|
||||
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
@ -117,24 +117,24 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) {
|
||||
static Result _hidsysGetHandle(Handle* handle_out, u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 AppletResourceUserId;
|
||||
u64 AppletResourceUserId;
|
||||
} *raw;
|
||||
|
||||
ipcSendPid(&c);
|
||||
raw = serviceIpcPrepareHeader(&g_hidSysSrv,&c, sizeof(*raw));
|
||||
ipcSendPid(&c);
|
||||
raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->AppletResourceUserId = g_hidSysAppletResourceUserId;
|
||||
raw->AppletResourceUserId = g_hidsysAppletResourceUserId;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_hidSysSrv);
|
||||
Result rc = serviceIpcDispatch(&g_hidsysSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
@ -143,7 +143,7 @@ static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) {
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp));
|
||||
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
@ -156,60 +156,60 @@ static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _hidSysGetEvent(Event* event_out, u64 cmd_id, bool autoclear) {
|
||||
static Result _hidsysGetEvent(Event* event_out, u64 cmd_id, bool autoclear) {
|
||||
Handle tmp_handle=0;
|
||||
Result rc = 0;
|
||||
|
||||
rc = _hidSysGetHandle(&tmp_handle, cmd_id);
|
||||
rc = _hidsysGetHandle(&tmp_handle, cmd_id);
|
||||
if (R_SUCCEEDED(rc)) eventLoadRemote(event_out, tmp_handle, autoclear);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result hidSysAcquireHomeButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidSysHomeEvent))
|
||||
{
|
||||
*event_out = g_hidSysHomeEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidSysGetEvent(&g_hidSysHomeEvent, 101, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidSysHomeEvent;
|
||||
return rc;
|
||||
Result hidsysAcquireHomeButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidsysHomeEvent))
|
||||
{
|
||||
*event_out = g_hidsysHomeEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidsysGetEvent(&g_hidsysHomeEvent, 101, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidsysHomeEvent;
|
||||
return rc;
|
||||
}
|
||||
|
||||
//These functions don't seem to work in the overlaydisp applet context
|
||||
Result hidSysAcquireCaptureButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidSysCaptureEvent))
|
||||
{
|
||||
*event_out = g_hidSysCaptureEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidSysGetEvent(&g_hidSysCaptureEvent, 141, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidSysCaptureEvent;
|
||||
return rc;
|
||||
Result hidsysAcquireCaptureButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidsysCaptureEvent))
|
||||
{
|
||||
*event_out = g_hidsysCaptureEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidsysGetEvent(&g_hidsysCaptureEvent, 141, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidsysCaptureEvent;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result hidSysAcquireSleepButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidSysSleeptEvent))
|
||||
{
|
||||
*event_out = g_hidSysSleeptEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidSysGetEvent(&g_hidSysSleeptEvent, 121, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidSysSleeptEvent;
|
||||
return rc;
|
||||
Result hidsysAcquireSleepButtonEventHandle(Event* event_out) {
|
||||
if (eventActive(&g_hidSysSleepEvent))
|
||||
{
|
||||
*event_out = g_hidSysSleepEvent;
|
||||
return 0;
|
||||
}
|
||||
Result rc = _hidsysGetEvent(&g_hidSysSleepEvent, 121, false);
|
||||
if (R_SUCCEEDED(rc))
|
||||
*event_out = g_hidSysSleepEvent;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result hidSysActivateHomeButton(void) {
|
||||
return _hidSysCmdWithResIdAndPid(111);
|
||||
Result hidsysActivateHomeButton(void) {
|
||||
return _hidsysCmdWithResIdAndPid(111);
|
||||
}
|
||||
|
||||
Result hidSysActivateSleepButton(void) {
|
||||
return _hidSysCmdWithResIdAndPid(131);
|
||||
Result hidsysActivateSleepButton(void) {
|
||||
return _hidsysCmdWithResIdAndPid(131);
|
||||
}
|
||||
|
||||
Result hidSysActivateCaptureButton(void) {
|
||||
return _hidSysCmdWithResIdAndPid(151);
|
||||
Result hidsysActivateCaptureButton(void) {
|
||||
return _hidsysCmdWithResIdAndPid(151);
|
||||
}
|
Loading…
Reference in New Issue
Block a user