sceMouse HLE (#4568)

* libSceMouse HLE v1

* fix getting event device id, init lib, logging

* rest of the mouse events

* lol how did it take me this long to notice this

* stop the hidden mouse from clicking on random shit

* yet another mouse state bug

* Implement merged mode

* Move RingBufferQueue to common/

* sir clang offnir, the all-formatting

* config option for this

* review comments
This commit is contained in:
kalaposfos13
2026-06-18 18:55:28 +02:00
committed by GitHub
parent 1785b98fbf
commit d54e6b07f5
10 changed files with 314 additions and 59 deletions

View File

@@ -1,15 +1,26 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-FileCopyrightText: Copyright 2024-2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include "SDL3/SDL_mouse.h"
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
#include "core/user_settings.h"
#include "mouse.h"
#include "mouse_error.h"
#include "sdl_window.h"
extern Frontend::WindowSDL* g_window;
namespace Libraries::Mouse {
int PS4_SYSV_ABI sceMouseClose() {
RingBufferQueue<OrbisMouseData> mouse_states[2]{{64}, {64}};
s32 mouse_handles[2]{-1, -1};
s32 mouse_sdl_handles[2]{-1, -1};
bool g_lib_init = false, g_is_merged_mode = false;
int PS4_SYSV_ABI sceMouseClose(s32 handle) {
LOG_ERROR(Lib_Mouse, "(STUBBED) called");
return ORBIS_OK;
}
@@ -45,7 +56,16 @@ int PS4_SYSV_ABI sceMouseGetDeviceInfo() {
}
int PS4_SYSV_ABI sceMouseInit() {
LOG_ERROR(Lib_Mouse, "(STUBBED) called");
SDL_WarpMouseInWindow(g_window->GetSDLWindow(), 1, 1);
SDL_SetWindowRelativeMouseMode(g_window->GetSDLWindow(), true);
int micecount = 0;
auto micelist = SDL_GetMice(&micecount);
LOG_INFO(Input, "{} mice are currently connected", micecount);
for (int i = 0; i < micecount; i++) {
LOG_INFO(Lib_Mouse, "{}: {} id: {}", i, SDL_GetMouseNameForID(micelist[i]), micelist[i]);
}
SDL_free(micelist);
g_lib_init = true;
return ORBIS_OK;
}
@@ -54,14 +74,47 @@ int PS4_SYSV_ABI sceMouseMbusInit() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceMouseOpen() {
LOG_ERROR(Lib_Mouse, "(STUBBED) called");
return ORBIS_OK;
int PS4_SYSV_ABI sceMouseOpen(Libraries::UserService::OrbisUserServiceUserId userId, s32 type,
s32 index, OrbisMouseOpenParam* pParam) {
LOG_WARNING(Lib_Mouse, "(DUMMY) called, uid: {}, type: {}, index: {}", userId, type, index);
auto u = UserManagement.GetUserByID(userId);
if (!u || !pParam || (u8)pParam->flag > 1 || index < 0 || index > 1) {
LOG_ERROR(Lib_Mouse, "invalid argument");
return ORBIS_MOUSE_ERROR_INVALID_ARG;
}
if (pParam->flag == MouseOpenBehaviour::Merged && index != 0) {
LOG_ERROR(Lib_Mouse, "Only one mouse can be opened in merged mode!");
return ORBIS_MOUSE_ERROR_ALREADY_OPENED;
}
g_is_merged_mode = pParam->flag == MouseOpenBehaviour::Merged;
if (mouse_handles[index] != -1) {
LOG_ERROR(Lib_Mouse, "already opened");
return ORBIS_MOUSE_ERROR_ALREADY_OPENED;
}
mouse_handles[index] = index;
LOG_INFO(Lib_Mouse, "out handle: {}", mouse_handles[index]);
return mouse_handles[index];
}
int PS4_SYSV_ABI sceMouseRead() {
LOG_DEBUG(Lib_Mouse, "(STUBBED) called");
return ORBIS_OK;
int PS4_SYSV_ABI sceMouseRead(s32 handle, OrbisMouseData* pData, s32 num) {
LOG_DEBUG(Lib_Mouse, "(DUMMY) called, h: {}, n: {}", handle, num);
if (!pData || num > 64) {
return ORBIS_MOUSE_ERROR_INVALID_ARG;
}
if (mouse_handles[0] != handle && mouse_handles[1] != handle) {
return ORBIS_MOUSE_ERROR_INVALID_HANDLE;
}
u64 m = mouse_handles[0] == handle ? 0 : 1;
int i = 0;
for (; i < num; i++) {
std::optional<OrbisMouseData> st = mouse_states[m].Pop();
if (!st) {
break;
}
pData[i] = *st;
pData[i].connected = mouse_sdl_handles[m] != -1;
}
return i;
}
int PS4_SYSV_ABI sceMouseSetHandType() {