diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/main.cpp | 40 | ||||
| -rw-r--r-- | src/yuzu/main.h | 3 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 52879a989..5e26aad29 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -152,7 +152,8 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; | |||
| 152 | } | 152 | } |
| 153 | #endif | 153 | #endif |
| 154 | 154 | ||
| 155 | constexpr int default_mouse_timeout = 2500; | 155 | constexpr int default_mouse_hide_timeout = 2500; |
| 156 | constexpr int default_mouse_center_timeout = 10; | ||
| 156 | 157 | ||
| 157 | /** | 158 | /** |
| 158 | * "Callouts" are one-time instructional messages shown to the user. In the config settings, there | 159 | * "Callouts" are one-time instructional messages shown to the user. In the config settings, there |
| @@ -287,10 +288,13 @@ GMainWindow::GMainWindow() | |||
| 287 | ui->menubar->setCursor(QCursor()); | 288 | ui->menubar->setCursor(QCursor()); |
| 288 | statusBar()->setCursor(QCursor()); | 289 | statusBar()->setCursor(QCursor()); |
| 289 | 290 | ||
| 290 | mouse_hide_timer.setInterval(default_mouse_timeout); | 291 | mouse_hide_timer.setInterval(default_mouse_hide_timeout); |
| 291 | connect(&mouse_hide_timer, &QTimer::timeout, this, &GMainWindow::HideMouseCursor); | 292 | connect(&mouse_hide_timer, &QTimer::timeout, this, &GMainWindow::HideMouseCursor); |
| 292 | connect(ui->menubar, &QMenuBar::hovered, this, &GMainWindow::ShowMouseCursor); | 293 | connect(ui->menubar, &QMenuBar::hovered, this, &GMainWindow::ShowMouseCursor); |
| 293 | 294 | ||
| 295 | mouse_center_timer.setInterval(default_mouse_center_timeout); | ||
| 296 | connect(&mouse_center_timer, &QTimer::timeout, this, &GMainWindow::CenterMouseCursor); | ||
| 297 | |||
| 294 | MigrateConfigFiles(); | 298 | MigrateConfigFiles(); |
| 295 | 299 | ||
| 296 | #if defined(HAVE_SDL2) && !defined(_WIN32) | 300 | #if defined(HAVE_SDL2) && !defined(_WIN32) |
| @@ -3301,10 +3305,26 @@ void GMainWindow::ShowMouseCursor() { | |||
| 3301 | } | 3305 | } |
| 3302 | } | 3306 | } |
| 3303 | 3307 | ||
| 3308 | void GMainWindow::CenterMouseCursor() { | ||
| 3309 | if (emu_thread == nullptr || !Settings::values.mouse_panning) { | ||
| 3310 | mouse_center_timer.stop(); | ||
| 3311 | return; | ||
| 3312 | } | ||
| 3313 | if (!this->isActiveWindow()) { | ||
| 3314 | mouse_center_timer.stop(); | ||
| 3315 | return; | ||
| 3316 | } | ||
| 3317 | const int center_x = render_window->width() / 2; | ||
| 3318 | const int center_y = render_window->height() / 2; | ||
| 3319 | |||
| 3320 | QCursor::setPos(mapToGlobal({center_x, center_y})); | ||
| 3321 | } | ||
| 3322 | |||
| 3304 | void GMainWindow::OnMouseActivity() { | 3323 | void GMainWindow::OnMouseActivity() { |
| 3305 | if (!Settings::values.mouse_panning) { | 3324 | if (!Settings::values.mouse_panning) { |
| 3306 | ShowMouseCursor(); | 3325 | ShowMouseCursor(); |
| 3307 | } | 3326 | } |
| 3327 | mouse_center_timer.stop(); | ||
| 3308 | } | 3328 | } |
| 3309 | 3329 | ||
| 3310 | void GMainWindow::OnCoreError(Core::SystemResultStatus result, std::string details) { | 3330 | void GMainWindow::OnCoreError(Core::SystemResultStatus result, std::string details) { |
| @@ -3577,6 +3597,22 @@ void GMainWindow::dragMoveEvent(QDragMoveEvent* event) { | |||
| 3577 | AcceptDropEvent(event); | 3597 | AcceptDropEvent(event); |
| 3578 | } | 3598 | } |
| 3579 | 3599 | ||
| 3600 | void GMainWindow::leaveEvent(QEvent* event) { | ||
| 3601 | if (Settings::values.mouse_panning) { | ||
| 3602 | const QRect& rect = geometry(); | ||
| 3603 | QPoint position = QCursor::pos(); | ||
| 3604 | |||
| 3605 | qint32 x = qBound(rect.left(), position.x(), rect.right()); | ||
| 3606 | qint32 y = qBound(rect.top(), position.y(), rect.bottom()); | ||
| 3607 | // Only start the timer if the mouse has left the window bound. | ||
| 3608 | // The leave event is also triggered when the window looses focus. | ||
| 3609 | if (x != position.x() || y != position.y()) { | ||
| 3610 | mouse_center_timer.start(); | ||
| 3611 | } | ||
| 3612 | event->accept(); | ||
| 3613 | } | ||
| 3614 | } | ||
| 3615 | |||
| 3580 | bool GMainWindow::ConfirmChangeGame() { | 3616 | bool GMainWindow::ConfirmChangeGame() { |
| 3581 | if (emu_thread == nullptr) | 3617 | if (emu_thread == nullptr) |
| 3582 | return true; | 3618 | return true; |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index ab95a7518..b399e9b01 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -328,6 +328,7 @@ private: | |||
| 328 | void UpdateUISettings(); | 328 | void UpdateUISettings(); |
| 329 | void HideMouseCursor(); | 329 | void HideMouseCursor(); |
| 330 | void ShowMouseCursor(); | 330 | void ShowMouseCursor(); |
| 331 | void CenterMouseCursor(); | ||
| 331 | void OpenURL(const QUrl& url); | 332 | void OpenURL(const QUrl& url); |
| 332 | void LoadTranslation(); | 333 | void LoadTranslation(); |
| 333 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); | 334 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); |
| @@ -372,6 +373,7 @@ private: | |||
| 372 | bool auto_paused = false; | 373 | bool auto_paused = false; |
| 373 | bool auto_muted = false; | 374 | bool auto_muted = false; |
| 374 | QTimer mouse_hide_timer; | 375 | QTimer mouse_hide_timer; |
| 376 | QTimer mouse_center_timer; | ||
| 375 | 377 | ||
| 376 | // FS | 378 | // FS |
| 377 | std::shared_ptr<FileSys::VfsFilesystem> vfs; | 379 | std::shared_ptr<FileSys::VfsFilesystem> vfs; |
| @@ -418,4 +420,5 @@ protected: | |||
| 418 | void dropEvent(QDropEvent* event) override; | 420 | void dropEvent(QDropEvent* event) override; |
| 419 | void dragEnterEvent(QDragEnterEvent* event) override; | 421 | void dragEnterEvent(QDragEnterEvent* event) override; |
| 420 | void dragMoveEvent(QDragMoveEvent* event) override; | 422 | void dragMoveEvent(QDragMoveEvent* event) override; |
| 423 | void leaveEvent(QEvent* event) override; | ||
| 421 | }; | 424 | }; |