mirror of https://git.suyu.dev/suyu/suyu
Always initialize keyboard input
This commit is contained in:
parent
8495e1bd83
commit
b483f2d010
|
@ -28,12 +28,11 @@ private:
|
|||
public:
|
||||
explicit Device(std::weak_ptr<TouchState>&& 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:
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -100,11 +100,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
|
|||
void Controller_Touchscreen::OnLoadInputDevices() {
|
||||
touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");
|
||||
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");
|
||||
} else {
|
||||
touch_btn_device.reset();
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::size_t> Controller_Touchscreen::GetUnusedFingerID() const {
|
||||
|
|
|
@ -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<u16>(touch_param.Get("min_y", 50));
|
||||
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 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<float>(std::clamp(static_cast<u16>(touch_pad.x), min_x, 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) /
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<std::size_t>(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<QTouchEvent::TouchPoint>& 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<std::size_t>(point.id() + 1);
|
||||
});
|
||||
}
|
||||
|
||||
bool GRenderWindow::event(QEvent* event) {
|
||||
|
|
Loading…
Reference in New Issue