mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-05 10:52:15 +02:00
home button block/unblock via hid:dbg and hid:sys
This commit is contained in:
parent
93dabfab3f
commit
8d48921bab
@ -48,6 +48,8 @@ extern "C" {
|
|||||||
#include "switch/services/time.h"
|
#include "switch/services/time.h"
|
||||||
#include "switch/services/usb.h"
|
#include "switch/services/usb.h"
|
||||||
#include "switch/services/hid.h"
|
#include "switch/services/hid.h"
|
||||||
|
#include "switch/services/hid_sys.h"
|
||||||
|
#include "switch/services/hid_dbg.h"
|
||||||
#include "switch/services/irs.h"
|
#include "switch/services/irs.h"
|
||||||
#include "switch/services/pl.h"
|
#include "switch/services/pl.h"
|
||||||
#include "switch/services/vi.h"
|
#include "switch/services/vi.h"
|
||||||
|
17
nx/include/switch/services/hid_dbg.h
Normal file
17
nx/include/switch/services/hid_dbg.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* @file hid.h
|
||||||
|
* @brief Human input device (hid:dbg) service IPC wrapper.
|
||||||
|
* @author p-sam
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
|
#define HID_DBG_DHB_MAX_TRIES 100
|
||||||
|
#define HID_DBG_DHB_RC (0x16eca)
|
||||||
|
|
||||||
|
Result hidDbgInitialize(void);
|
||||||
|
void hidDbgExit(void);
|
||||||
|
|
||||||
|
/// Enables the default behavior of the HOME button (going back to the main menu) if it was disabled
|
||||||
|
Result hidDbgDeactivateHomeButton();
|
14
nx/include/switch/services/hid_sys.h
Normal file
14
nx/include/switch/services/hid_sys.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* @file hid.h
|
||||||
|
* @brief Human input device (hid:sys) service IPC wrapper.
|
||||||
|
* @author p-sam
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
|
Result hidSysInitialize(void);
|
||||||
|
void hidSysExit(void);
|
||||||
|
|
||||||
|
/// Disables the default behavior of the HOME button (going back to the main menu) if it was enabled
|
||||||
|
Result hidSysActivateHomeButton();
|
77
nx/source/services/hid_dbg.c
Normal file
77
nx/source/services/hid_dbg.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "types.h"
|
||||||
|
#include "arm/atomics.h"
|
||||||
|
#include "kernel/ipc.h"
|
||||||
|
#include "services/sm.h"
|
||||||
|
#include "services/hid_dbg.h"
|
||||||
|
|
||||||
|
static Service g_hidDbgSrv;
|
||||||
|
static u64 g_refCnt;
|
||||||
|
|
||||||
|
Result hidDbgInitialize(void)
|
||||||
|
{
|
||||||
|
atomicIncrement64(&g_refCnt);
|
||||||
|
|
||||||
|
if (serviceIsActive(&g_hidDbgSrv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return smGetService(&g_hidDbgSrv, "hid:dbg");
|
||||||
|
}
|
||||||
|
|
||||||
|
void hidDbgExit(void)
|
||||||
|
{
|
||||||
|
if (atomicDecrement64(&g_refCnt) == 0)
|
||||||
|
{
|
||||||
|
serviceClose(&g_hidDbgSrv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result _hidDbgDeactivateHomeButton() {
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 110;
|
||||||
|
|
||||||
|
rc = serviceIpcDispatch(&g_hidDbgSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result hidDbgDeactivateHomeButton() {
|
||||||
|
int i = HID_DBG_DHB_MAX_TRIES;
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
i--;
|
||||||
|
rc = _hidDbgDeactivateHomeButton();
|
||||||
|
} while(rc == 0 && i > 0);
|
||||||
|
|
||||||
|
if(rc == 0) {
|
||||||
|
return HID_DBG_DHB_RC;
|
||||||
|
} else if(rc == HID_DBG_DHB_RC) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
70
nx/source/services/hid_sys.c
Normal file
70
nx/source/services/hid_sys.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "types.h"
|
||||||
|
#include "arm/atomics.h"
|
||||||
|
#include "kernel/ipc.h"
|
||||||
|
#include "services/sm.h"
|
||||||
|
#include "services/applet.h"
|
||||||
|
#include "services/hid_sys.h"
|
||||||
|
|
||||||
|
static Service g_hidSysSrv;
|
||||||
|
static u64 g_refCnt;
|
||||||
|
|
||||||
|
Result hidSysInitialize(void)
|
||||||
|
{
|
||||||
|
atomicIncrement64(&g_refCnt);
|
||||||
|
|
||||||
|
if (serviceIsActive(&g_hidSysSrv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return smGetService(&g_hidSysSrv, "hid:sys");
|
||||||
|
}
|
||||||
|
|
||||||
|
void hidSysExit(void)
|
||||||
|
{
|
||||||
|
if (atomicDecrement64(&g_refCnt) == 0)
|
||||||
|
{
|
||||||
|
serviceClose(&g_hidSysSrv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result hidSysActivateHomeButton() {
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
u64 AppletResourceUserId;
|
||||||
|
rc = appletGetAppletResourceUserId(&AppletResourceUserId);
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
|
AppletResourceUserId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 AppletResourceUserId;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
ipcSendPid(&c);
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 111;
|
||||||
|
raw->AppletResourceUserId = AppletResourceUserId;
|
||||||
|
|
||||||
|
rc = serviceIpcDispatch(&g_hidSysSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user