summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hid/emulated_console.cpp3
-rw-r--r--src/core/hid/emulated_devices.cpp3
-rw-r--r--src/input_common/drivers/mouse.cpp67
-rw-r--r--src/input_common/drivers/mouse.h38
-rw-r--r--src/input_common/input_mapping.cpp4
-rw-r--r--src/yuzu/bootmanager.cpp10
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp2
-rw-r--r--src/yuzu/configuration/configure_ringcon.cpp2
-rw-r--r--src/yuzu/main.cpp8
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp8
10 files changed, 114 insertions, 31 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 1c91bbe40..17d663379 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -23,7 +23,8 @@ void EmulatedConsole::SetTouchParams() {
23 23
24 // We can't use mouse as touch if native mouse is enabled 24 // We can't use mouse as touch if native mouse is enabled
25 if (!Settings::values.mouse_enabled) { 25 if (!Settings::values.mouse_enabled) {
26 touch_params[index++] = Common::ParamPackage{"engine:mouse,axis_x:10,axis_y:11,button:0"}; 26 touch_params[index++] =
27 Common::ParamPackage{"engine:mouse,axis_x:0,axis_y:1,button:0,port:2"};
27 } 28 }
28 29
29 touch_params[index++] = 30 touch_params[index++] =
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp
index 836f32c0f..578a6ff61 100644
--- a/src/core/hid/emulated_devices.cpp
+++ b/src/core/hid/emulated_devices.cpp
@@ -34,9 +34,12 @@ void EmulatedDevices::ReloadInput() {
34 // First two axis are reserved for mouse position 34 // First two axis are reserved for mouse position
35 key_index = 2; 35 key_index = 2;
36 for (auto& mouse_device : mouse_analog_devices) { 36 for (auto& mouse_device : mouse_analog_devices) {
37 // Mouse axis are only mapped on port 1, pad 0
37 Common::ParamPackage mouse_params; 38 Common::ParamPackage mouse_params;
38 mouse_params.Set("engine", "mouse"); 39 mouse_params.Set("engine", "mouse");
39 mouse_params.Set("axis", static_cast<int>(key_index)); 40 mouse_params.Set("axis", static_cast<int>(key_index));
41 mouse_params.Set("port", 1);
42 mouse_params.Set("pad", 0);
40 mouse_device = Common::Input::CreateInputDevice(mouse_params); 43 mouse_device = Common::Input::CreateInputDevice(mouse_params);
41 key_index++; 44 key_index++;
42 } 45 }
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index faf9cbdc3..da50e0a24 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -15,23 +15,39 @@ constexpr int mouse_axis_y = 1;
15constexpr int wheel_axis_x = 2; 15constexpr int wheel_axis_x = 2;
16constexpr int wheel_axis_y = 3; 16constexpr int wheel_axis_y = 3;
17constexpr int motion_wheel_y = 4; 17constexpr int motion_wheel_y = 4;
18constexpr int touch_axis_x = 10;
19constexpr int touch_axis_y = 11;
20constexpr PadIdentifier identifier = { 18constexpr PadIdentifier identifier = {
21 .guid = Common::UUID{}, 19 .guid = Common::UUID{},
22 .port = 0, 20 .port = 0,
23 .pad = 0, 21 .pad = 0,
24}; 22};
25 23
24constexpr PadIdentifier real_mouse_identifier = {
25 .guid = Common::UUID{},
26 .port = 1,
27 .pad = 0,
28};
29
30constexpr PadIdentifier touch_identifier = {
31 .guid = Common::UUID{},
32 .port = 2,
33 .pad = 0,
34};
35
26Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) { 36Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
27 PreSetController(identifier); 37 PreSetController(identifier);
38 PreSetController(real_mouse_identifier);
39 PreSetController(touch_identifier);
40
41 // Initialize all mouse axis
28 PreSetAxis(identifier, mouse_axis_x); 42 PreSetAxis(identifier, mouse_axis_x);
29 PreSetAxis(identifier, mouse_axis_y); 43 PreSetAxis(identifier, mouse_axis_y);
30 PreSetAxis(identifier, wheel_axis_x); 44 PreSetAxis(identifier, wheel_axis_x);
31 PreSetAxis(identifier, wheel_axis_y); 45 PreSetAxis(identifier, wheel_axis_y);
32 PreSetAxis(identifier, motion_wheel_y); 46 PreSetAxis(identifier, motion_wheel_y);
33 PreSetAxis(identifier, touch_axis_x); 47 PreSetAxis(real_mouse_identifier, mouse_axis_x);
34 PreSetAxis(identifier, touch_axis_y); 48 PreSetAxis(real_mouse_identifier, mouse_axis_y);
49 PreSetAxis(touch_identifier, mouse_axis_x);
50 PreSetAxis(touch_identifier, mouse_axis_y);
35 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); 51 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
36} 52}
37 53
@@ -39,7 +55,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
39 Common::SetCurrentThreadName("Mouse"); 55 Common::SetCurrentThreadName("Mouse");
40 constexpr int update_time = 10; 56 constexpr int update_time = 10;
41 while (!stop_token.stop_requested()) { 57 while (!stop_token.stop_requested()) {
42 if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) { 58 if (Settings::values.mouse_panning) {
43 // Slow movement by 4% 59 // Slow movement by 4%
44 last_mouse_change *= 0.96f; 60 last_mouse_change *= 0.96f;
45 const float sensitivity = 61 const float sensitivity =
@@ -57,17 +73,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
57 } 73 }
58} 74}
59 75
60void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y) { 76void Mouse::Move(int x, int y, int center_x, int center_y) {
61 // If native mouse is enabled just set the screen coordinates
62 if (Settings::values.mouse_enabled) {
63 SetAxis(identifier, mouse_axis_x, touch_x);
64 SetAxis(identifier, mouse_axis_y, touch_y);
65 return;
66 }
67
68 SetAxis(identifier, touch_axis_x, touch_x);
69 SetAxis(identifier, touch_axis_y, touch_y);
70
71 if (Settings::values.mouse_panning) { 77 if (Settings::values.mouse_panning) {
72 auto mouse_change = 78 auto mouse_change =
73 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); 79 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
@@ -113,20 +119,41 @@ void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int
113 } 119 }
114} 120}
115 121
116void Mouse::PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button) { 122void Mouse::MouseMove(f32 touch_x, f32 touch_y) {
117 SetAxis(identifier, touch_axis_x, touch_x); 123 SetAxis(real_mouse_identifier, mouse_axis_x, touch_x);
118 SetAxis(identifier, touch_axis_y, touch_y); 124 SetAxis(real_mouse_identifier, mouse_axis_y, touch_y);
125}
126
127void Mouse::TouchMove(f32 touch_x, f32 touch_y) {
128 SetAxis(touch_identifier, mouse_axis_x, touch_x);
129 SetAxis(touch_identifier, mouse_axis_y, touch_y);
130}
131
132void Mouse::PressButton(int x, int y, MouseButton button) {
119 SetButton(identifier, static_cast<int>(button), true); 133 SetButton(identifier, static_cast<int>(button), true);
134
120 // Set initial analog parameters 135 // Set initial analog parameters
121 mouse_origin = {x, y}; 136 mouse_origin = {x, y};
122 last_mouse_position = {x, y}; 137 last_mouse_position = {x, y};
123 button_pressed = true; 138 button_pressed = true;
124} 139}
125 140
141void Mouse::PressMouseButton(MouseButton button) {
142 SetButton(real_mouse_identifier, static_cast<int>(button), true);
143}
144
145void Mouse::PressTouchButton(f32 touch_x, f32 touch_y, MouseButton button) {
146 SetAxis(touch_identifier, mouse_axis_x, touch_x);
147 SetAxis(touch_identifier, mouse_axis_y, touch_y);
148 SetButton(touch_identifier, static_cast<int>(button), true);
149}
150
126void Mouse::ReleaseButton(MouseButton button) { 151void Mouse::ReleaseButton(MouseButton button) {
127 SetButton(identifier, static_cast<int>(button), false); 152 SetButton(identifier, static_cast<int>(button), false);
153 SetButton(real_mouse_identifier, static_cast<int>(button), false);
154 SetButton(touch_identifier, static_cast<int>(button), false);
128 155
129 if (!Settings::values.mouse_panning && !Settings::values.mouse_enabled) { 156 if (!Settings::values.mouse_panning) {
130 SetAxis(identifier, mouse_axis_x, 0); 157 SetAxis(identifier, mouse_axis_x, 0);
131 SetAxis(identifier, mouse_axis_y, 0); 158 SetAxis(identifier, mouse_axis_y, 0);
132 } 159 }
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
index 72073cc23..f3b65bdd1 100644
--- a/src/input_common/drivers/mouse.h
+++ b/src/input_common/drivers/mouse.h
@@ -37,13 +37,43 @@ public:
37 * @param center_x the x-coordinate of the middle of the screen 37 * @param center_x the x-coordinate of the middle of the screen
38 * @param center_y the y-coordinate of the middle of the screen 38 * @param center_y the y-coordinate of the middle of the screen
39 */ 39 */
40 void MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y); 40 void Move(int x, int y, int center_x, int center_y);
41 41
42 /** 42 /**
43 * Sets the status of all buttons bound with the key to pressed 43 * Signals that real mouse has moved.
44 * @param key_code the code of the key to press 44 * @param x the absolute position on the touchscreen of the cursor
45 * @param y the absolute position on the touchscreen of the cursor
45 */ 46 */
46 void PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button); 47 void MouseMove(f32 touch_x, f32 touch_y);
48
49 /**
50 * Signals that touch finger has moved.
51 * @param x the absolute position on the touchscreen of the cursor
52 * @param y the absolute position on the touchscreen of the cursor
53 */
54 void TouchMove(f32 touch_x, f32 touch_y);
55
56 /**
57 * Sets the status of a button to pressed
58 * @param x the x-coordinate of the cursor
59 * @param y the y-coordinate of the cursor
60 * @param button the id of the button to press
61 */
62 void PressButton(int x, int y, MouseButton button);
63
64 /**
65 * Sets the status of a mouse button to pressed
66 * @param button the id of the button to press
67 */
68 void PressMouseButton(MouseButton button);
69
70 /**
71 * Sets the status of touch finger to pressed
72 * @param x the absolute position on the touchscreen of the cursor
73 * @param y the absolute position on the touchscreen of the cursor
74 * @param button the id of the button to press
75 */
76 void PressTouchButton(f32 touch_x, f32 touch_y, MouseButton button);
47 77
48 /** 78 /**
49 * Sets the status of all buttons bound with the key to released 79 * Sets the status of all buttons bound with the key to released
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp
index d6e49d2c5..6990a86b9 100644
--- a/src/input_common/input_mapping.cpp
+++ b/src/input_common/input_mapping.cpp
@@ -194,6 +194,10 @@ bool MappingFactory::IsDriverValid(const MappingData& data) const {
194 if (data.engine == "keyboard" && data.pad.port != 0) { 194 if (data.engine == "keyboard" && data.pad.port != 0) {
195 return false; 195 return false;
196 } 196 }
197 // Only port 0 can be mapped on the mouse
198 if (data.engine == "mouse" && data.pad.port != 0) {
199 return false;
200 }
197 // To prevent mapping with two devices we disable any UDP except motion 201 // To prevent mapping with two devices we disable any UDP except motion
198 if (!Settings::values.enable_udp_controller && data.engine == "cemuhookudp" && 202 if (!Settings::values.enable_udp_controller && data.engine == "cemuhookudp" &&
199 data.type != EngineInputType::Motion) { 203 data.type != EngineInputType::Motion) {
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index a64e63a39..17acd3933 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -645,7 +645,10 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
645 const auto pos = mapFromGlobal(QCursor::pos()); 645 const auto pos = mapFromGlobal(QCursor::pos());
646 const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); 646 const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y());
647 const auto button = QtButtonToMouseButton(event->button()); 647 const auto button = QtButtonToMouseButton(event->button());
648 input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), touch_x, touch_y, button); 648
649 input_subsystem->GetMouse()->PressMouseButton(button);
650 input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), button);
651 input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, button);
649 652
650 emit MouseActivity(); 653 emit MouseActivity();
651} 654}
@@ -661,7 +664,10 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
661 const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); 664 const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y());
662 const int center_x = width() / 2; 665 const int center_x = width() / 2;
663 const int center_y = height() / 2; 666 const int center_y = height() / 2;
664 input_subsystem->GetMouse()->MouseMove(pos.x(), pos.y(), touch_x, touch_y, center_x, center_y); 667
668 input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
669 input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
670 input_subsystem->GetMouse()->Move(pos.x(), pos.y(), center_x, center_y);
665 671
666 if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) { 672 if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
667 QCursor::setPos(mapToGlobal(QPoint{center_x, center_y})); 673 QCursor::setPos(mapToGlobal(QPoint{center_x, center_y}));
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 723690e71..50b62293e 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -1490,7 +1490,7 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) {
1490 } 1490 }
1491 1491
1492 const auto button = GRenderWindow::QtButtonToMouseButton(event->button()); 1492 const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
1493 input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button); 1493 input_subsystem->GetMouse()->PressButton(0, 0, button);
1494} 1494}
1495 1495
1496void ConfigureInputPlayer::wheelEvent(QWheelEvent* event) { 1496void ConfigureInputPlayer::wheelEvent(QWheelEvent* event) {
diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp
index 1275f10c8..71afbc423 100644
--- a/src/yuzu/configuration/configure_ringcon.cpp
+++ b/src/yuzu/configuration/configure_ringcon.cpp
@@ -371,7 +371,7 @@ void ConfigureRingController::mousePressEvent(QMouseEvent* event) {
371 } 371 }
372 372
373 const auto button = GRenderWindow::QtButtonToMouseButton(event->button()); 373 const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
374 input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button); 374 input_subsystem->GetMouse()->PressButton(0, 0, button);
375} 375}
376 376
377void ConfigureRingController::keyPressEvent(QKeyEvent* event) { 377void ConfigureRingController::keyPressEvent(QKeyEvent* event) {
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index a1c18ff90..a689a32db 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1165,6 +1165,14 @@ void GMainWindow::InitializeHotkeys() {
1165 Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue()); 1165 Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue());
1166 }); 1166 });
1167 connect_shortcut(QStringLiteral("Toggle Mouse Panning"), [&] { 1167 connect_shortcut(QStringLiteral("Toggle Mouse Panning"), [&] {
1168 if (Settings::values.mouse_enabled) {
1169 Settings::values.mouse_panning = false;
1170 QMessageBox::warning(
1171 this, tr("Emulated mouse is enabled"),
1172 tr("Real mouse input and mouse panning are incompatible. Please disable the "
1173 "emulated mouse in input advanced settings to allow mouse panning."));
1174 return;
1175 }
1168 Settings::values.mouse_panning = !Settings::values.mouse_panning; 1176 Settings::values.mouse_panning = !Settings::values.mouse_panning;
1169 if (Settings::values.mouse_panning) { 1177 if (Settings::values.mouse_panning) {
1170 render_window->installEventFilter(render_window); 1178 render_window->installEventFilter(render_window);
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 5450b8c38..5153cdb79 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -62,7 +62,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
62 const auto mouse_button = SDLButtonToMouseButton(button); 62 const auto mouse_button = SDLButtonToMouseButton(button);
63 if (state == SDL_PRESSED) { 63 if (state == SDL_PRESSED) {
64 const auto [touch_x, touch_y] = MouseToTouchPos(x, y); 64 const auto [touch_x, touch_y] = MouseToTouchPos(x, y);
65 input_subsystem->GetMouse()->PressButton(x, y, touch_x, touch_y, mouse_button); 65 input_subsystem->GetMouse()->PressButton(x, y, mouse_button);
66 input_subsystem->GetMouse()->PressMouseButton(mouse_button);
67 input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, mouse_button);
66 } else { 68 } else {
67 input_subsystem->GetMouse()->ReleaseButton(mouse_button); 69 input_subsystem->GetMouse()->ReleaseButton(mouse_button);
68 } 70 }
@@ -70,7 +72,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
70 72
71void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { 73void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
72 const auto [touch_x, touch_y] = MouseToTouchPos(x, y); 74 const auto [touch_x, touch_y] = MouseToTouchPos(x, y);
73 input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, 0, 0); 75 input_subsystem->GetMouse()->Move(x, y, 0, 0);
76 input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
77 input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
74} 78}
75 79
76void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { 80void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) {