diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 12 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 25 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 7 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 4 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 19 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 24 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.h | 7 |
9 files changed, 89 insertions, 25 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index b864d26f2..d81e790ee 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -59,7 +59,7 @@ void Mouse::UpdateYuzuSettings() { | |||
| 59 | }); | 59 | }); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void Mouse::PressButton(int x, int y, int button_) { | 62 | void Mouse::PressButton(int x, int y, MouseButton button_) { |
| 63 | const auto button_index = static_cast<std::size_t>(button_); | 63 | const auto button_index = static_cast<std::size_t>(button_); |
| 64 | if (button_index >= mouse_info.size()) { | 64 | if (button_index >= mouse_info.size()) { |
| 65 | return; | 65 | return; |
| @@ -67,7 +67,7 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 67 | 67 | ||
| 68 | const auto button = 1U << button_index; | 68 | const auto button = 1U << button_index; |
| 69 | buttons |= static_cast<u16>(button); | 69 | buttons |= static_cast<u16>(button); |
| 70 | last_button = static_cast<MouseButton>(button_index); | 70 | last_button = button_; |
| 71 | 71 | ||
| 72 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); | 72 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); |
| 73 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); | 73 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); |
| @@ -129,7 +129,7 @@ void Mouse::MouseMove(int x, int y, int center_x, int center_y) { | |||
| 129 | } | 129 | } |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | void Mouse::ReleaseButton(int button_) { | 132 | void Mouse::ReleaseButton(MouseButton button_) { |
| 133 | const auto button_index = static_cast<std::size_t>(button_); | 133 | const auto button_index = static_cast<std::size_t>(button_); |
| 134 | if (button_index >= mouse_info.size()) { | 134 | if (button_index >= mouse_info.size()) { |
| 135 | return; | 135 | return; |
| @@ -152,6 +152,11 @@ void Mouse::BeginConfiguration() { | |||
| 152 | 152 | ||
| 153 | void Mouse::EndConfiguration() { | 153 | void Mouse::EndConfiguration() { |
| 154 | buttons = 0; | 154 | buttons = 0; |
| 155 | for (MouseInfo& info : mouse_info) { | ||
| 156 | info.tilt_speed = 0; | ||
| 157 | info.data.pressed = false; | ||
| 158 | info.data.axis = {0, 0}; | ||
| 159 | } | ||
| 155 | last_button = MouseButton::Undefined; | 160 | last_button = MouseButton::Undefined; |
| 156 | mouse_queue.Clear(); | 161 | mouse_queue.Clear(); |
| 157 | configuring = false; | 162 | configuring = false; |
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 46aa676c1..3622fe080 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h | |||
| @@ -18,10 +18,12 @@ namespace MouseInput { | |||
| 18 | 18 | ||
| 19 | enum class MouseButton { | 19 | enum class MouseButton { |
| 20 | Left, | 20 | Left, |
| 21 | Wheel, | ||
| 22 | Right, | 21 | Right, |
| 23 | Forward, | 22 | Wheel, |
| 24 | Backward, | 23 | Backward, |
| 24 | Forward, | ||
| 25 | Task, | ||
| 26 | Extra, | ||
| 25 | Undefined, | 27 | Undefined, |
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| @@ -51,7 +53,7 @@ public: | |||
| 51 | * @param y the y-coordinate of the cursor | 53 | * @param y the y-coordinate of the cursor |
| 52 | * @param button_ the button pressed | 54 | * @param button_ the button pressed |
| 53 | */ | 55 | */ |
| 54 | void PressButton(int x, int y, int button_); | 56 | void PressButton(int x, int y, MouseButton button_); |
| 55 | 57 | ||
| 56 | /** | 58 | /** |
| 57 | * Signals that mouse has moved. | 59 | * Signals that mouse has moved. |
| @@ -65,7 +67,7 @@ public: | |||
| 65 | /** | 67 | /** |
| 66 | * Signals that a motion sensor tilt has ended. | 68 | * Signals that a motion sensor tilt has ended. |
| 67 | */ | 69 | */ |
| 68 | void ReleaseButton(int button_); | 70 | void ReleaseButton(MouseButton button_); |
| 69 | 71 | ||
| 70 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); | 72 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); |
| 71 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; | 73 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; |
| @@ -94,7 +96,7 @@ private: | |||
| 94 | u16 buttons{}; | 96 | u16 buttons{}; |
| 95 | std::thread update_thread; | 97 | std::thread update_thread; |
| 96 | MouseButton last_button{MouseButton::Undefined}; | 98 | MouseButton last_button{MouseButton::Undefined}; |
| 97 | std::array<MouseInfo, 5> mouse_info; | 99 | std::array<MouseInfo, 7> mouse_info; |
| 98 | Common::SPSCQueue<MouseStatus> mouse_queue; | 100 | Common::SPSCQueue<MouseStatus> mouse_queue; |
| 99 | bool configuring{false}; | 101 | bool configuring{false}; |
| 100 | bool update_thread_running{true}; | 102 | bool update_thread_running{true}; |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 1c61d419d..ae49cbb45 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -383,6 +383,25 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | |||
| 383 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | 383 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | MouseInput::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) { | ||
| 387 | switch (button) { | ||
| 388 | case Qt::LeftButton: | ||
| 389 | return MouseInput::MouseButton::Left; | ||
| 390 | case Qt::RightButton: | ||
| 391 | return MouseInput::MouseButton::Right; | ||
| 392 | case Qt::MiddleButton: | ||
| 393 | return MouseInput::MouseButton::Wheel; | ||
| 394 | case Qt::BackButton: | ||
| 395 | return MouseInput::MouseButton::Backward; | ||
| 396 | case Qt::ForwardButton: | ||
| 397 | return MouseInput::MouseButton::Forward; | ||
| 398 | case Qt::TaskButton: | ||
| 399 | return MouseInput::MouseButton::Task; | ||
| 400 | default: | ||
| 401 | return MouseInput::MouseButton::Extra; | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 386 | void GRenderWindow::mousePressEvent(QMouseEvent* event) { | 405 | void GRenderWindow::mousePressEvent(QMouseEvent* event) { |
| 387 | // Touch input is handled in TouchBeginEvent | 406 | // Touch input is handled in TouchBeginEvent |
| 388 | if (event->source() == Qt::MouseEventSynthesizedBySystem) { | 407 | if (event->source() == Qt::MouseEventSynthesizedBySystem) { |
| @@ -391,7 +410,8 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) { | |||
| 391 | 410 | ||
| 392 | auto pos = event->pos(); | 411 | auto pos = event->pos(); |
| 393 | const auto [x, y] = ScaleTouch(pos); | 412 | const auto [x, y] = ScaleTouch(pos); |
| 394 | input_subsystem->GetMouse()->PressButton(x, y, event->button()); | 413 | const auto button = QtButtonToMouseButton(event->button()); |
| 414 | input_subsystem->GetMouse()->PressButton(x, y, button); | ||
| 395 | 415 | ||
| 396 | if (event->button() == Qt::LeftButton) { | 416 | if (event->button() == Qt::LeftButton) { |
| 397 | this->TouchPressed(x, y, 0); | 417 | this->TouchPressed(x, y, 0); |
| @@ -425,7 +445,8 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { | |||
| 425 | return; | 445 | return; |
| 426 | } | 446 | } |
| 427 | 447 | ||
| 428 | input_subsystem->GetMouse()->ReleaseButton(event->button()); | 448 | const auto button = QtButtonToMouseButton(event->button()); |
| 449 | input_subsystem->GetMouse()->ReleaseButton(button); | ||
| 429 | 450 | ||
| 430 | if (event->button() == Qt::LeftButton) { | 451 | if (event->button() == Qt::LeftButton) { |
| 431 | this->TouchReleased(0); | 452 | this->TouchReleased(0); |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index b5ec7de07..acfe2bc8c 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -28,6 +28,10 @@ namespace InputCommon { | |||
| 28 | class InputSubsystem; | 28 | class InputSubsystem; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | namespace MouseInput { | ||
| 32 | enum class MouseButton; | ||
| 33 | } | ||
| 34 | |||
| 31 | namespace VideoCore { | 35 | namespace VideoCore { |
| 32 | enum class LoadCallbackStage; | 36 | enum class LoadCallbackStage; |
| 33 | } | 37 | } |
| @@ -149,6 +153,9 @@ public: | |||
| 149 | void keyPressEvent(QKeyEvent* event) override; | 153 | void keyPressEvent(QKeyEvent* event) override; |
| 150 | void keyReleaseEvent(QKeyEvent* event) override; | 154 | void keyReleaseEvent(QKeyEvent* event) override; |
| 151 | 155 | ||
| 156 | /// Converts a Qt mouse button into MouseInput mouse button | ||
| 157 | static MouseInput::MouseButton QtButtonToMouseButton(Qt::MouseButton button); | ||
| 158 | |||
| 152 | void mousePressEvent(QMouseEvent* event) override; | 159 | void mousePressEvent(QMouseEvent* event) override; |
| 153 | void mouseMoveEvent(QMouseEvent* event) override; | 160 | void mouseMoveEvent(QMouseEvent* event) override; |
| 154 | void mouseReleaseEvent(QMouseEvent* event) override; | 161 | void mouseReleaseEvent(QMouseEvent* event) override; |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index b319d69fc..1bac57bb2 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -235,7 +235,7 @@ const std::array<UISettings::Shortcut, 17> Config::default_hotkeys{{ | |||
| 235 | {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, | 235 | {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, |
| 236 | {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, | 236 | {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, |
| 237 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, | 237 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, |
| 238 | {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("F9"), Qt::ApplicationShortcut}}, | 238 | {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}}, |
| 239 | {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, | 239 | {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, |
| 240 | {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, | 240 | {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, |
| 241 | }}; | 241 | }}; |
| @@ -508,7 +508,7 @@ void Config::ReadControlValues() { | |||
| 508 | 508 | ||
| 509 | Settings::values.emulate_analog_keyboard = | 509 | Settings::values.emulate_analog_keyboard = |
| 510 | ReadSetting(QStringLiteral("emulate_analog_keyboard"), false).toBool(); | 510 | ReadSetting(QStringLiteral("emulate_analog_keyboard"), false).toBool(); |
| 511 | Settings::values.mouse_panning = ReadSetting(QStringLiteral("mouse_panning"), false).toBool(); | 511 | Settings::values.mouse_panning = false; |
| 512 | Settings::values.mouse_panning_sensitivity = | 512 | Settings::values.mouse_panning_sensitivity = |
| 513 | ReadSetting(QStringLiteral("mouse_panning_sensitivity"), 1).toFloat(); | 513 | ReadSetting(QStringLiteral("mouse_panning_sensitivity"), 1).toFloat(); |
| 514 | 514 | ||
| @@ -1182,7 +1182,6 @@ void Config::SaveControlValues() { | |||
| 1182 | WriteSetting(QStringLiteral("keyboard_enabled"), Settings::values.keyboard_enabled, false); | 1182 | WriteSetting(QStringLiteral("keyboard_enabled"), Settings::values.keyboard_enabled, false); |
| 1183 | WriteSetting(QStringLiteral("emulate_analog_keyboard"), | 1183 | WriteSetting(QStringLiteral("emulate_analog_keyboard"), |
| 1184 | Settings::values.emulate_analog_keyboard, false); | 1184 | Settings::values.emulate_analog_keyboard, false); |
| 1185 | WriteSetting(QStringLiteral("mouse_panning"), Settings::values.mouse_panning, false); | ||
| 1186 | WriteSetting(QStringLiteral("mouse_panning_sensitivity"), | 1185 | WriteSetting(QStringLiteral("mouse_panning_sensitivity"), |
| 1187 | Settings::values.mouse_panning_sensitivity, 1.0f); | 1186 | Settings::values.mouse_panning_sensitivity, 1.0f); |
| 1188 | qt_config->endGroup(); | 1187 | qt_config->endGroup(); |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 21d0d3449..bc572d319 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "input_common/mouse/mouse_poller.h" | 21 | #include "input_common/mouse/mouse_poller.h" |
| 22 | #include "input_common/udp/udp.h" | 22 | #include "input_common/udp/udp.h" |
| 23 | #include "ui_configure_input_player.h" | 23 | #include "ui_configure_input_player.h" |
| 24 | #include "yuzu/bootmanager.h" | ||
| 24 | #include "yuzu/configuration/config.h" | 25 | #include "yuzu/configuration/config.h" |
| 25 | #include "yuzu/configuration/configure_input_player.h" | 26 | #include "yuzu/configuration/configure_input_player.h" |
| 26 | #include "yuzu/configuration/configure_input_player_widget.h" | 27 | #include "yuzu/configuration/configure_input_player_widget.h" |
| @@ -1345,7 +1346,8 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) { | |||
| 1345 | return; | 1346 | return; |
| 1346 | } | 1347 | } |
| 1347 | 1348 | ||
| 1348 | input_subsystem->GetMouse()->PressButton(0, 0, event->button()); | 1349 | const auto button = GRenderWindow::QtButtonToMouseButton(event->button()); |
| 1350 | input_subsystem->GetMouse()->PressButton(0, 0, button); | ||
| 1349 | } | 1351 | } |
| 1350 | 1352 | ||
| 1351 | void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { | 1353 | void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 0ba7c07cc..56d892a31 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -854,8 +854,7 @@ void GMainWindow::InitializeHotkeys() { | |||
| 854 | connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Mouse Panning"), this), | 854 | connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Mouse Panning"), this), |
| 855 | &QShortcut::activated, this, [&] { | 855 | &QShortcut::activated, this, [&] { |
| 856 | Settings::values.mouse_panning = !Settings::values.mouse_panning; | 856 | Settings::values.mouse_panning = !Settings::values.mouse_panning; |
| 857 | if (UISettings::values.hide_mouse || Settings::values.mouse_panning) { | 857 | if (Settings::values.mouse_panning) { |
| 858 | mouse_hide_timer.start(); | ||
| 859 | render_window->installEventFilter(render_window); | 858 | render_window->installEventFilter(render_window); |
| 860 | render_window->setAttribute(Qt::WA_Hover, true); | 859 | render_window->setAttribute(Qt::WA_Hover, true); |
| 861 | } | 860 | } |
| @@ -1208,11 +1207,14 @@ void GMainWindow::BootGame(const QString& filename, std::size_t program_index) { | |||
| 1208 | renderer_status_button->setDisabled(true); | 1207 | renderer_status_button->setDisabled(true); |
| 1209 | 1208 | ||
| 1210 | if (UISettings::values.hide_mouse || Settings::values.mouse_panning) { | 1209 | if (UISettings::values.hide_mouse || Settings::values.mouse_panning) { |
| 1211 | mouse_hide_timer.start(); | ||
| 1212 | render_window->installEventFilter(render_window); | 1210 | render_window->installEventFilter(render_window); |
| 1213 | render_window->setAttribute(Qt::WA_Hover, true); | 1211 | render_window->setAttribute(Qt::WA_Hover, true); |
| 1214 | } | 1212 | } |
| 1215 | 1213 | ||
| 1214 | if (UISettings::values.hide_mouse) { | ||
| 1215 | mouse_hide_timer.start(); | ||
| 1216 | } | ||
| 1217 | |||
| 1216 | std::string title_name; | 1218 | std::string title_name; |
| 1217 | std::string title_version; | 1219 | std::string title_version; |
| 1218 | const auto res = system.GetGameName(title_name); | 1220 | const auto res = system.GetGameName(title_name); |
| @@ -2372,12 +2374,15 @@ void GMainWindow::OnConfigure() { | |||
| 2372 | if ((UISettings::values.hide_mouse || Settings::values.mouse_panning) && emulation_running) { | 2374 | if ((UISettings::values.hide_mouse || Settings::values.mouse_panning) && emulation_running) { |
| 2373 | render_window->installEventFilter(render_window); | 2375 | render_window->installEventFilter(render_window); |
| 2374 | render_window->setAttribute(Qt::WA_Hover, true); | 2376 | render_window->setAttribute(Qt::WA_Hover, true); |
| 2375 | mouse_hide_timer.start(); | ||
| 2376 | } else { | 2377 | } else { |
| 2377 | render_window->removeEventFilter(render_window); | 2378 | render_window->removeEventFilter(render_window); |
| 2378 | render_window->setAttribute(Qt::WA_Hover, false); | 2379 | render_window->setAttribute(Qt::WA_Hover, false); |
| 2379 | } | 2380 | } |
| 2380 | 2381 | ||
| 2382 | if (UISettings::values.hide_mouse) { | ||
| 2383 | mouse_hide_timer.start(); | ||
| 2384 | } | ||
| 2385 | |||
| 2381 | UpdateStatusButtons(); | 2386 | UpdateStatusButtons(); |
| 2382 | } | 2387 | } |
| 2383 | 2388 | ||
| @@ -2615,8 +2620,7 @@ void GMainWindow::UpdateUISettings() { | |||
| 2615 | } | 2620 | } |
| 2616 | 2621 | ||
| 2617 | void GMainWindow::HideMouseCursor() { | 2622 | void GMainWindow::HideMouseCursor() { |
| 2618 | if (emu_thread == nullptr || | 2623 | if (emu_thread == nullptr && UISettings::values.hide_mouse) { |
| 2619 | (!UISettings::values.hide_mouse && !Settings::values.mouse_panning)) { | ||
| 2620 | mouse_hide_timer.stop(); | 2624 | mouse_hide_timer.stop(); |
| 2621 | ShowMouseCursor(); | 2625 | ShowMouseCursor(); |
| 2622 | return; | 2626 | return; |
| @@ -2626,8 +2630,7 @@ void GMainWindow::HideMouseCursor() { | |||
| 2626 | 2630 | ||
| 2627 | void GMainWindow::ShowMouseCursor() { | 2631 | void GMainWindow::ShowMouseCursor() { |
| 2628 | render_window->unsetCursor(); | 2632 | render_window->unsetCursor(); |
| 2629 | if (emu_thread != nullptr && | 2633 | if (emu_thread != nullptr && UISettings::values.hide_mouse) { |
| 2630 | (UISettings::values.hide_mouse || Settings::values.mouse_panning)) { | ||
| 2631 | mouse_hide_timer.start(); | 2634 | mouse_hide_timer.start(); |
| 2632 | } | 2635 | } |
| 2633 | } | 2636 | } |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 7e391ab89..ce8b7c218 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -35,18 +35,36 @@ void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { | |||
| 35 | input_subsystem->GetMouse()->MouseMove(x, y, 0, 0); | 35 | input_subsystem->GetMouse()->MouseMove(x, y, 0, 0); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | MouseInput::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { | ||
| 39 | switch (button) { | ||
| 40 | case SDL_BUTTON_LEFT: | ||
| 41 | return MouseInput::MouseButton::Left; | ||
| 42 | case SDL_BUTTON_RIGHT: | ||
| 43 | return MouseInput::MouseButton::Right; | ||
| 44 | case SDL_BUTTON_MIDDLE: | ||
| 45 | return MouseInput::MouseButton::Wheel; | ||
| 46 | case SDL_BUTTON_X1: | ||
| 47 | return MouseInput::MouseButton::Backward; | ||
| 48 | case SDL_BUTTON_X2: | ||
| 49 | return MouseInput::MouseButton::Forward; | ||
| 50 | default: | ||
| 51 | return MouseInput::MouseButton::Undefined; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 38 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { | 55 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { |
| 56 | const auto mouse_button = SDLButtonToMouseButton(button); | ||
| 39 | if (button == SDL_BUTTON_LEFT) { | 57 | if (button == SDL_BUTTON_LEFT) { |
| 40 | if (state == SDL_PRESSED) { | 58 | if (state == SDL_PRESSED) { |
| 41 | TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); | 59 | TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); |
| 42 | } else { | 60 | } else { |
| 43 | TouchReleased(0); | 61 | TouchReleased(0); |
| 44 | } | 62 | } |
| 45 | } else if (button == SDL_BUTTON_RIGHT) { | 63 | } else { |
| 46 | if (state == SDL_PRESSED) { | 64 | if (state == SDL_PRESSED) { |
| 47 | input_subsystem->GetMouse()->PressButton(x, y, button); | 65 | input_subsystem->GetMouse()->PressButton(x, y, mouse_button); |
| 48 | } else { | 66 | } else { |
| 49 | input_subsystem->GetMouse()->ReleaseButton(button); | 67 | input_subsystem->GetMouse()->ReleaseButton(mouse_button); |
| 50 | } | 68 | } |
| 51 | } | 69 | } |
| 52 | } | 70 | } |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h index 51a12a6a9..0e17bbca7 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h | |||
| @@ -18,6 +18,10 @@ namespace InputCommon { | |||
| 18 | class InputSubsystem; | 18 | class InputSubsystem; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | namespace MouseInput { | ||
| 22 | enum class MouseButton; | ||
| 23 | } | ||
| 24 | |||
| 21 | class EmuWindow_SDL2 : public Core::Frontend::EmuWindow { | 25 | class EmuWindow_SDL2 : public Core::Frontend::EmuWindow { |
| 22 | public: | 26 | public: |
| 23 | explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); | 27 | explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); |
| @@ -42,6 +46,9 @@ protected: | |||
| 42 | /// Called by WaitEvent when the mouse moves. | 46 | /// Called by WaitEvent when the mouse moves. |
| 43 | void OnMouseMotion(s32 x, s32 y); | 47 | void OnMouseMotion(s32 x, s32 y); |
| 44 | 48 | ||
| 49 | /// Converts a SDL mouse button into MouseInput mouse button | ||
| 50 | MouseInput::MouseButton SDLButtonToMouseButton(u32 button) const; | ||
| 51 | |||
| 45 | /// Called by WaitEvent when a mouse button is pressed or released | 52 | /// Called by WaitEvent when a mouse button is pressed or released |
| 46 | void OnMouseButton(u32 button, u8 state, s32 x, s32 y); | 53 | void OnMouseButton(u32 button, u8 state, s32 x, s32 y); |
| 47 | 54 | ||