Add UnknownMessageHandler, correct typos and better formatting

This commit is contained in:
exelix 2019-02-24 17:35:14 +01:00
parent 9011f278b6
commit fb31b8f184
4 changed files with 128 additions and 119 deletions

View File

@ -470,16 +470,19 @@ AppletFocusState appletGetFocusState(void);
Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode); 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); 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); 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); Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event);

View File

@ -8,13 +8,12 @@
#include "../kernel/event.h" #include "../kernel/event.h"
#include "../services/sm.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);

View File

@ -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. //// 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; __attribute__((weak)) u32 __nx_applet_exit_mode = 0;
void __attribute__((weak)) __nx_applet_UnknownMessageHandler(u32);
static Service g_appletSrv; static Service g_appletSrv;
static Service g_appletProxySession; static Service g_appletProxySession;
static u64 g_refCnt; static u64 g_refCnt;
@ -316,8 +318,8 @@ void appletExit(void)
} }
} }
} }
eventClose(&HomeButtonReaderLockAccessorEvent); eventClose(&HomeButtonReaderLockAccessorEvent);
eventClose(&g_appletLibraryAppletLaunchableEvent); eventClose(&g_appletLibraryAppletLaunchableEvent);
@ -2315,42 +2317,47 @@ bool appletMainLoop(void) {
appletCallHook(AppletHookType_OnPerformanceMode); appletCallHook(AppletHookType_OnPerformanceMode);
break; break;
default:
if (__nx_applet_UnknownMessageHandler)
__nx_applet_UnknownMessageHandler(msg);
break;
} }
return true; return true;
} }
Result appletBeginToWatchShortHomeButtonMessage(void) { Result appletBeginToWatchShortHomeButtonMessage(void) {
if (__nx_applet_type != AppletType_OverlayApplet) if (__nx_applet_type != AppletType_OverlayApplet)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
return _appletCmdNoIO(&g_appletIFunctions, 0); return _appletCmdNoIO(&g_appletIFunctions, 0);
} }
Result appletEndToWatchShortHomeButtonMessage(void) { Result appletEndToWatchShortHomeButtonMessage(void) {
if (__nx_applet_type != AppletType_OverlayApplet) if (__nx_applet_type != AppletType_OverlayApplet)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
return _appletCmdNoIO(&g_appletIFunctions, 1); return _appletCmdNoIO(&g_appletIFunctions, 1);
} }
Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event) Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event)
{ {
if (eventActive(&HomeButtonReaderLockAccessorEvent)) if (eventActive(&HomeButtonReaderLockAccessorEvent))
{ {
*out_event = HomeButtonReaderLockAccessorEvent; *out_event = HomeButtonReaderLockAccessorEvent;
return 0; return 0;
} }
Service ILockAccessor = {0}; Service ILockAccessor = {0};
Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30); Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30);
if (!R_SUCCEEDED(rc)) if (R_FAILED(rc))
return rc; return rc;
rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3,true); rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3, false);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
*out_event = HomeButtonReaderLockAccessorEvent; *out_event = HomeButtonReaderLockAccessorEvent;
serviceClose(&ILockAccessor); serviceClose(&ILockAccessor);
return rc; return rc;
} }

View File

@ -10,61 +10,61 @@
#include "services/hidsys.h" #include "services/hidsys.h"
#include "services/sm.h" #include "services/sm.h"
static Service g_hidSysSrv; static Service g_hidsysSrv;
static u64 g_hidSysRefCnt; static u64 g_hidsysRefCnt;
static Event g_hidSysHomeEvent = {0}; static Event g_hidsysHomeEvent = {0};
static Event g_hidSysCaptureEvent = {0}; static Event g_hidsysCaptureEvent = {0};
static Event g_hidSysSleeptEvent = {0}; static Event g_hidSysSleepEvent = {0};
static u64 g_hidSysAppletResourceUserId = 0; static u64 g_hidsysAppletResourceUserId = 0;
Result hidSysInitialize(void) { Result hidsysInitialize(void) {
atomicIncrement64(&g_hidSysRefCnt); atomicIncrement64(&g_hidsysRefCnt);
if (serviceIsActive(&g_hidSysSrv)) if (serviceIsActive(&g_hidsysSrv))
return 0; return 0;
Result rc = smGetService(&g_hidSysSrv, "hid:sys"); Result rc = smGetService(&g_hidsysSrv, "hid:sys");
if (R_FAILED(rc))
return rc;
rc = appletGetAppletResourceUserId(&g_hidSysAppletResourceUserId);
if (R_FAILED(rc)) if (R_FAILED(rc))
g_hidSysAppletResourceUserId = 0; return rc;
rc = appletGetAppletResourceUserId(&g_hidsysAppletResourceUserId);
if (R_FAILED(rc))
g_hidsysAppletResourceUserId = 0;
return 0; return 0;
} }
void hidSysExit(void) { void hidsysExit(void) {
if (atomicDecrement64(&g_hidSysRefCnt) == 0) { if (atomicDecrement64(&g_hidsysRefCnt) == 0) {
eventClose(&g_hidSysHomeEvent); eventClose(&g_hidsysHomeEvent);
eventClose(&g_hidSysCaptureEvent); eventClose(&g_hidsysCaptureEvent);
eventClose(&g_hidSysSleeptEvent); eventClose(&g_hidSysSleepEvent);
serviceClose(&g_hidSysSrv); serviceClose(&g_hidsysSrv);
} }
} }
Result hidSysEnableAppletToGetInput(bool enable) { Result hidsysEnableAppletToGetInput(bool enable) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
struct CmdStruct{ struct {
u64 magic; u64 magic;
u64 cmdid; u64 cmdid;
bool permitInput; bool permitInput;
u64 appletResourceUserId; u64 appletResourceUserId;
} *cmdStruct; } *raw;
cmdStruct = (struct CmdStruct*) serviceIpcPrepareHeader(&g_hidSysSrv, &c, sizeof(*cmdStruct)); raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw));
cmdStruct->magic = SFCI_MAGIC; raw->magic = SFCI_MAGIC;
cmdStruct->cmdid = 503; raw->cmdid = 503;
cmdStruct->permitInput = enable; raw->permitInput = enable;
cmdStruct->appletResourceUserId = g_hidSysAppletResourceUserId; raw->appletResourceUserId = g_hidsysAppletResourceUserId;
Result rc = serviceIpcDispatch(&g_hidSysSrv); Result rc = serviceIpcDispatch(&g_hidsysSrv);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -73,7 +73,7 @@ Result hidSysEnableAppletToGetInput(bool enable) {
u64 result; u64 result;
} *resp; } *resp;
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp)); serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw; resp = r.Raw;
rc = resp->result; rc = resp->result;
@ -82,7 +82,7 @@ Result hidSysEnableAppletToGetInput(bool enable) {
return rc; return rc;
} }
static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) { static Result _hidsysCmdWithResIdAndPid(u64 cmd_id) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
@ -92,14 +92,14 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
u64 AppletResourceUserId; u64 AppletResourceUserId;
} *raw; } *raw;
ipcSendPid(&c); ipcSendPid(&c);
raw = serviceIpcPrepareHeader(&g_hidSysSrv,&c, sizeof(*raw)); raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw));
raw->magic = SFCI_MAGIC; raw->magic = SFCI_MAGIC;
raw->cmd_id = cmd_id; 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)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -108,7 +108,7 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
u64 result; u64 result;
} *resp; } *resp;
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp)); serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw; resp = r.Raw;
rc = resp->result; rc = resp->result;
@ -117,24 +117,24 @@ static Result _hidSysCmdWithResIdAndPid(u64 cmd_id) {
return rc; return rc;
} }
static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) { static Result _hidsysGetHandle(Handle* handle_out, u64 cmd_id) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
struct { struct {
u64 magic; u64 magic;
u64 cmd_id; u64 cmd_id;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} *raw; } *raw;
ipcSendPid(&c); ipcSendPid(&c);
raw = serviceIpcPrepareHeader(&g_hidSysSrv,&c, sizeof(*raw)); raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw));
raw->magic = SFCI_MAGIC; raw->magic = SFCI_MAGIC;
raw->cmd_id = cmd_id; 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)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -143,7 +143,7 @@ static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) {
u64 result; u64 result;
} *resp; } *resp;
serviceIpcParse(&g_hidSysSrv, &r, sizeof(*resp)); serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw; resp = r.Raw;
rc = resp->result; rc = resp->result;
@ -156,60 +156,60 @@ static Result _hidSysGetHandle(Handle* handle_out, u64 cmd_id) {
return rc; 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; Handle tmp_handle=0;
Result rc = 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); if (R_SUCCEEDED(rc)) eventLoadRemote(event_out, tmp_handle, autoclear);
return rc; return rc;
} }
Result hidSysAcquireHomeButtonEventHandle(Event* event_out) { Result hidsysAcquireHomeButtonEventHandle(Event* event_out) {
if (eventActive(&g_hidSysHomeEvent)) if (eventActive(&g_hidsysHomeEvent))
{ {
*event_out = g_hidSysHomeEvent; *event_out = g_hidsysHomeEvent;
return 0; return 0;
} }
Result rc = _hidSysGetEvent(&g_hidSysHomeEvent, 101, false); Result rc = _hidsysGetEvent(&g_hidsysHomeEvent, 101, false);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
*event_out = g_hidSysHomeEvent; *event_out = g_hidsysHomeEvent;
return rc; return rc;
} }
//These functions don't seem to work in the overlaydisp applet context //These functions don't seem to work in the overlaydisp applet context
Result hidSysAcquireCaptureButtonEventHandle(Event* event_out) { Result hidsysAcquireCaptureButtonEventHandle(Event* event_out) {
if (eventActive(&g_hidSysCaptureEvent)) if (eventActive(&g_hidsysCaptureEvent))
{ {
*event_out = g_hidSysCaptureEvent; *event_out = g_hidsysCaptureEvent;
return 0; return 0;
} }
Result rc = _hidSysGetEvent(&g_hidSysCaptureEvent, 141, false); Result rc = _hidsysGetEvent(&g_hidsysCaptureEvent, 141, false);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
*event_out = g_hidSysCaptureEvent; *event_out = g_hidsysCaptureEvent;
return rc; return rc;
} }
Result hidSysAcquireSleepButtonEventHandle(Event* event_out) { Result hidsysAcquireSleepButtonEventHandle(Event* event_out) {
if (eventActive(&g_hidSysSleeptEvent)) if (eventActive(&g_hidSysSleepEvent))
{ {
*event_out = g_hidSysSleeptEvent; *event_out = g_hidSysSleepEvent;
return 0; return 0;
} }
Result rc = _hidSysGetEvent(&g_hidSysSleeptEvent, 121, false); Result rc = _hidsysGetEvent(&g_hidSysSleepEvent, 121, false);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
*event_out = g_hidSysSleeptEvent; *event_out = g_hidSysSleepEvent;
return rc; return rc;
} }
Result hidSysActivateHomeButton(void) { Result hidsysActivateHomeButton(void) {
return _hidSysCmdWithResIdAndPid(111); return _hidsysCmdWithResIdAndPid(111);
} }
Result hidSysActivateSleepButton(void) { Result hidsysActivateSleepButton(void) {
return _hidSysCmdWithResIdAndPid(131); return _hidsysCmdWithResIdAndPid(131);
} }
Result hidSysActivateCaptureButton(void) { Result hidsysActivateCaptureButton(void) {
return _hidSysCmdWithResIdAndPid(151); return _hidsysCmdWithResIdAndPid(151);
} }