Always initialize keyboard input

This commit is contained in:
german 2021-01-10 08:36:31 -06:00
parent 8495e1bd83
commit b483f2d010
5 changed files with 20 additions and 25 deletions

View file

@ -28,12 +28,11 @@ private:
public: public:
explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {} explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {}
Input::TouchStatus GetStatus() const override { Input::TouchStatus GetStatus() const override {
Input::TouchStatus touch_status{};
if (auto state = touch_state.lock()) { if (auto state = touch_state.lock()) {
std::lock_guard guard{state->mutex}; std::lock_guard guard{state->mutex};
touch_status = state->status; return state->status;
} }
return touch_status; return {};
} }
private: private:

View file

@ -117,12 +117,13 @@ public:
* Signal that a touch pressed event has occurred (e.g. mouse click pressed) * Signal that a touch pressed event has occurred (e.g. mouse click pressed)
* @param framebuffer_x Framebuffer x-coordinate that was pressed * @param framebuffer_x Framebuffer x-coordinate that was pressed
* @param framebuffer_y Framebuffer y-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); 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); 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) * 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_x Framebuffer x-coordinate
* @param framebuffer_y Framebuffer y-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); void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id);

View file

@ -100,11 +100,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
void Controller_Touchscreen::OnLoadInputDevices() { void Controller_Touchscreen::OnLoadInputDevices() {
touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window"); touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");
touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp"); touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp");
if (Settings::values.use_touch_from_button) { touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");
touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");
} else {
touch_btn_device.reset();
}
} }
std::optional<std::size_t> Controller_Touchscreen::GetUnusedFingerID() const { std::optional<std::size_t> Controller_Touchscreen::GetUnusedFingerID() const {

View file

@ -136,9 +136,7 @@ static void SocketLoop(Socket* socket) {
Client::Client() { Client::Client() {
LOG_INFO(Input, "Udp Initialization started"); LOG_INFO(Input, "Udp Initialization started");
for (std::size_t id = 0; id < MAX_TOUCH_FINGERS; ++id) { finger_id.fill(MAX_TOUCH_FINGERS);
finger_id[id] = MAX_TOUCH_FINGERS;
}
ReloadSockets(); ReloadSockets();
} }
@ -347,17 +345,17 @@ void Client::UpdateTouchInput(Response::TouchPad& touch_pad, std::size_t client,
const u16 min_y = static_cast<u16>(touch_param.Get("min_y", 50)); const u16 min_y = static_cast<u16>(touch_param.Get("min_y", 50));
const u16 max_x = static_cast<u16>(touch_param.Get("max_x", 1800)); const u16 max_x = static_cast<u16>(touch_param.Get("max_x", 1800));
const u16 max_y = static_cast<u16>(touch_param.Get("max_y", 850)); const u16 max_y = static_cast<u16>(touch_param.Get("max_y", 850));
const std::size_t touch_id = client * 2 + id;
if (touch_pad.is_active) { 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(); const auto first_free_id = GetUnusedFingerID();
if (!first_free_id) { if (!first_free_id) {
// Invalid finger id skip to next input // Invalid finger id skip to next input
return; 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<float>(std::clamp(static_cast<u16>(touch_pad.x), min_x, max_x) - min_x) / x = static_cast<float>(std::clamp(static_cast<u16>(touch_pad.x), min_x, max_x) - min_x) /
static_cast<float>(max_x - min_x); static_cast<float>(max_x - min_x);
y = static_cast<float>(std::clamp(static_cast<u16>(touch_pad.y), min_y, max_y) - min_y) / y = static_cast<float>(std::clamp(static_cast<u16>(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; return;
} }
if (finger_id[client * 2 + id] != MAX_TOUCH_FINGERS) { if (finger_id[touch_id] != MAX_TOUCH_FINGERS) {
touch_status[finger_id[client * 2 + id]] = {}; touch_status[finger_id[touch_id]] = {};
finger_id[client * 2 + id] = MAX_TOUCH_FINGERS; finger_id[touch_id] = MAX_TOUCH_FINGERS;
} }
} }

View file

@ -475,7 +475,7 @@ bool GRenderWindow::TouchStart(const QTouchEvent::TouchPoint& touch_point) {
bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) { bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) {
for (std::size_t id = 0; id < touch_ids.size(); ++id) { 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<std::size_t>(touch_point.id() + 1)) {
const auto [x, y] = ScaleTouch(touch_point.pos()); const auto [x, y] = ScaleTouch(touch_point.pos());
this->TouchMoved(x, y, id + 1); this->TouchMoved(x, y, id + 1);
return true; return true;
@ -486,8 +486,9 @@ bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) {
bool GRenderWindow::TouchExist(std::size_t id, bool GRenderWindow::TouchExist(std::size_t id,
const QList<QTouchEvent::TouchPoint>& touch_points) const { const QList<QTouchEvent::TouchPoint>& touch_points) const {
return std::any_of(touch_points.begin(), touch_points.end(), return std::any_of(touch_points.begin(), touch_points.end(), [id](const auto& point) {
[id](const auto& point) { return id == point.id() + 1; }); return id == static_cast<std::size_t>(point.id() + 1);
});
} }
bool GRenderWindow::event(QEvent* event) { bool GRenderWindow::event(QEvent* event) {