From b483f2d010bf745ab873e8f8bfaca5515e56d39f Mon Sep 17 00:00:00 2001 From: german Date: Sun, 10 Jan 2021 08:36:31 -0600 Subject: [PATCH] Always initialize keyboard input --- src/core/frontend/emu_window.cpp | 5 ++--- src/core/frontend/emu_window.h | 9 +++++---- .../service/hid/controllers/touchscreen.cpp | 6 +----- src/input_common/udp/client.cpp | 18 ++++++++---------- src/yuzu/bootmanager.cpp | 7 ++++--- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index af6c1633a..ee7a58b1c 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -28,12 +28,11 @@ private: public: explicit Device(std::weak_ptr&& touch_state) : touch_state(touch_state) {} Input::TouchStatus GetStatus() const override { - Input::TouchStatus touch_status{}; if (auto state = touch_state.lock()) { std::lock_guard guard{state->mutex}; - touch_status = state->status; + return state->status; } - return touch_status; + return {}; } private: diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index f8db42ab4..2436c6580 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h @@ -117,12 +117,13 @@ public: * Signal that a touch pressed event has occurred (e.g. mouse click pressed) * @param framebuffer_x Framebuffer x-coordinate that was pressed * @param framebuffer_y Framebuffer y-coordinate that was pressed - * @param id Touch event id + * @param id Touch event ID */ void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id); - /** Signal that a touch released event has occurred (e.g. mouse click released) - *@param id Touch event id + /** + * Signal that a touch released event has occurred (e.g. mouse click released) + * @param id Touch event ID */ void TouchReleased(std::size_t id); @@ -130,7 +131,7 @@ public: * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) * @param framebuffer_x Framebuffer x-coordinate * @param framebuffer_y Framebuffer y-coordinate - * @param id Touch event id + * @param id Touch event ID */ void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id); diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index cd318f25b..5219f2dad 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -100,11 +100,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin void Controller_Touchscreen::OnLoadInputDevices() { touch_mouse_device = Input::CreateDevice("engine:emu_window"); touch_udp_device = Input::CreateDevice("engine:cemuhookudp"); - if (Settings::values.use_touch_from_button) { - touch_btn_device = Input::CreateDevice("engine:touch_from_button"); - } else { - touch_btn_device.reset(); - } + touch_btn_device = Input::CreateDevice("engine:touch_from_button"); } std::optional Controller_Touchscreen::GetUnusedFingerID() const { diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 5e39fdce2..e7e50d789 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -136,9 +136,7 @@ static void SocketLoop(Socket* socket) { Client::Client() { LOG_INFO(Input, "Udp Initialization started"); - for (std::size_t id = 0; id < MAX_TOUCH_FINGERS; ++id) { - finger_id[id] = MAX_TOUCH_FINGERS; - } + finger_id.fill(MAX_TOUCH_FINGERS); ReloadSockets(); } @@ -347,17 +345,17 @@ void Client::UpdateTouchInput(Response::TouchPad& touch_pad, std::size_t client, const u16 min_y = static_cast(touch_param.Get("min_y", 50)); const u16 max_x = static_cast(touch_param.Get("max_x", 1800)); const u16 max_y = static_cast(touch_param.Get("max_y", 850)); - + const std::size_t touch_id = client * 2 + id; if (touch_pad.is_active) { - if (finger_id[client * 2 + id] == MAX_TOUCH_FINGERS) { + if (finger_id[touch_id] == MAX_TOUCH_FINGERS) { const auto first_free_id = GetUnusedFingerID(); if (!first_free_id) { // Invalid finger id skip to next input return; } - finger_id[client * 2 + id] = first_free_id.value(); + finger_id[touch_id] = *first_free_id; } - auto& [x, y, pressed] = touch_status[finger_id[client * 2 + id]]; + auto& [x, y, pressed] = touch_status[finger_id[touch_id]]; x = static_cast(std::clamp(static_cast(touch_pad.x), min_x, max_x) - min_x) / static_cast(max_x - min_x); y = static_cast(std::clamp(static_cast(touch_pad.y), min_y, max_y) - min_y) / @@ -366,9 +364,9 @@ void Client::UpdateTouchInput(Response::TouchPad& touch_pad, std::size_t client, return; } - if (finger_id[client * 2 + id] != MAX_TOUCH_FINGERS) { - touch_status[finger_id[client * 2 + id]] = {}; - finger_id[client * 2 + id] = MAX_TOUCH_FINGERS; + if (finger_id[touch_id] != MAX_TOUCH_FINGERS) { + touch_status[finger_id[touch_id]] = {}; + finger_id[touch_id] = MAX_TOUCH_FINGERS; } } diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 1f91514ef..4528eb196 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -475,7 +475,7 @@ bool GRenderWindow::TouchStart(const QTouchEvent::TouchPoint& touch_point) { bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) { for (std::size_t id = 0; id < touch_ids.size(); ++id) { - if (touch_ids[id] == touch_point.id() + 1) { + if (touch_ids[id] == static_cast(touch_point.id() + 1)) { const auto [x, y] = ScaleTouch(touch_point.pos()); this->TouchMoved(x, y, id + 1); return true; @@ -486,8 +486,9 @@ bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) { bool GRenderWindow::TouchExist(std::size_t id, const QList& touch_points) const { - return std::any_of(touch_points.begin(), touch_points.end(), - [id](const auto& point) { return id == point.id() + 1; }); + return std::any_of(touch_points.begin(), touch_points.end(), [id](const auto& point) { + return id == static_cast(point.id() + 1); + }); } bool GRenderWindow::event(QEvent* event) {