summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/mouse/mouse_input.cpp38
-rw-r--r--src/input_common/mouse/mouse_input.h9
-rw-r--r--src/input_common/mouse/mouse_poller.cpp4
3 files changed, 25 insertions, 26 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp
index d0ee64ad7..10786a541 100644
--- a/src/input_common/mouse/mouse_input.cpp
+++ b/src/input_common/mouse/mouse_input.cpp
@@ -2,9 +2,6 @@
2// Licensed under GPLv2+ 2// Licensed under GPLv2+
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/logging/log.h"
6#include "common/math_util.h"
7#include "common/param_package.h"
8#include "input_common/mouse/mouse_input.h" 5#include "input_common/mouse/mouse_input.h"
9 6
10namespace MouseInput { 7namespace MouseInput {
@@ -24,8 +21,11 @@ void Mouse::UpdateThread() {
24 constexpr int update_time = 10; 21 constexpr int update_time = 10;
25 while (update_thread_running) { 22 while (update_thread_running) {
26 for (MouseInfo& info : mouse_info) { 23 for (MouseInfo& info : mouse_info) {
27 Common::Vec3f angular_direction = {-info.tilt_direction.y, 0.0f, 24 const Common::Vec3f angular_direction{
28 -info.tilt_direction.x}; 25 -info.tilt_direction.y,
26 0.0f,
27 -info.tilt_direction.x,
28 };
29 29
30 info.motion.SetGyroscope(angular_direction * info.tilt_speed); 30 info.motion.SetGyroscope(angular_direction * info.tilt_speed);
31 info.motion.UpdateRotation(update_time * 1000); 31 info.motion.UpdateRotation(update_time * 1000);
@@ -41,22 +41,24 @@ void Mouse::UpdateThread() {
41} 41}
42 42
43void Mouse::UpdateYuzuSettings() { 43void Mouse::UpdateYuzuSettings() {
44 MouseStatus pad_status{}; 44 if (buttons == 0) {
45 if (buttons != 0) { 45 return;
46 pad_status.button = last_button;
47 mouse_queue.Push(pad_status);
48 } 46 }
47
48 mouse_queue.Push(MouseStatus{
49 .button = last_button,
50 });
49} 51}
50 52
51void Mouse::PressButton(int x, int y, int button_) { 53void Mouse::PressButton(int x, int y, int button_) {
52 if (button_ >= static_cast<int>(mouse_info.size())) { 54 const auto button_index = static_cast<std::size_t>(button_);
55 if (button_index >= mouse_info.size()) {
53 return; 56 return;
54 } 57 }
55 58
56 int button = 1 << button_; 59 const auto button = 1U << button_index;
57 const auto button_index = static_cast<std::size_t>(button_);
58 buttons |= static_cast<u16>(button); 60 buttons |= static_cast<u16>(button);
59 last_button = static_cast<MouseButton>(button_); 61 last_button = static_cast<MouseButton>(button_index);
60 62
61 mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); 63 mouse_info[button_index].mouse_origin = Common::MakeVec(x, y);
62 mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); 64 mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y);
@@ -66,8 +68,8 @@ void Mouse::PressButton(int x, int y, int button_) {
66void Mouse::MouseMove(int x, int y) { 68void Mouse::MouseMove(int x, int y) {
67 for (MouseInfo& info : mouse_info) { 69 for (MouseInfo& info : mouse_info) {
68 if (info.data.pressed) { 70 if (info.data.pressed) {
69 auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; 71 const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin;
70 auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; 72 const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position;
71 info.last_mouse_position = Common::MakeVec(x, y); 73 info.last_mouse_position = Common::MakeVec(x, y);
72 info.data.axis = {mouse_move.x, -mouse_move.y}; 74 info.data.axis = {mouse_move.x, -mouse_move.y};
73 75
@@ -82,12 +84,12 @@ void Mouse::MouseMove(int x, int y) {
82} 84}
83 85
84void Mouse::ReleaseButton(int button_) { 86void Mouse::ReleaseButton(int button_) {
85 if (button_ >= static_cast<int>(mouse_info.size())) { 87 const auto button_index = static_cast<std::size_t>(button_);
88 if (button_index >= mouse_info.size()) {
86 return; 89 return;
87 } 90 }
88 91
89 int button = 1 << button_; 92 const auto button = 1U << button_index;
90 const auto button_index = static_cast<std::size_t>(button_);
91 buttons &= static_cast<u16>(0xFF - button); 93 buttons &= static_cast<u16>(0xFF - button);
92 94
93 mouse_info[button_index].tilt_speed = 0; 95 mouse_info[button_index].tilt_speed = 0;
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h
index 761663334..65e64bee7 100644
--- a/src/input_common/mouse/mouse_input.h
+++ b/src/input_common/mouse/mouse_input.h
@@ -4,15 +4,14 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <algorithm> 7#include <array>
8#include <functional>
9#include <mutex> 8#include <mutex>
10#include <thread> 9#include <thread>
11#include <unordered_map> 10
12#include "common/common_types.h" 11#include "common/common_types.h"
13#include "common/threadsafe_queue.h" 12#include "common/threadsafe_queue.h"
13#include "common/vector_math.h"
14#include "core/frontend/input.h" 14#include "core/frontend/input.h"
15#include "input_common/main.h"
16#include "input_common/motion_input.h" 15#include "input_common/motion_input.h"
17 16
18namespace MouseInput { 17namespace MouseInput {
@@ -50,7 +49,7 @@ public:
50 * Signals that a button is pressed. 49 * Signals that a button is pressed.
51 * @param x the x-coordinate of the cursor 50 * @param x the x-coordinate of the cursor
52 * @param y the y-coordinate of the cursor 51 * @param y the y-coordinate of the cursor
53 * @param button the button pressed 52 * @param button_ the button pressed
54 */ 53 */
55 void PressButton(int x, int y, int button_); 54 void PressButton(int x, int y, int button_);
56 55
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp
index 6213f3dbd..7445ad3ad 100644
--- a/src/input_common/mouse/mouse_poller.cpp
+++ b/src/input_common/mouse/mouse_poller.cpp
@@ -2,11 +2,9 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <atomic>
6#include <list>
7#include <mutex> 5#include <mutex>
8#include <utility> 6#include <utility>
9#include "common/assert.h" 7
10#include "common/threadsafe_queue.h" 8#include "common/threadsafe_queue.h"
11#include "input_common/mouse/mouse_input.h" 9#include "input_common/mouse/mouse_input.h"
12#include "input_common/mouse/mouse_poller.h" 10#include "input_common/mouse/mouse_poller.h"