diff options
author | FearlessTobi <thm.frey@gmail.com> | 2020-04-11 04:22:50 +0200 |
---|---|---|
committer | FearlessTobi <thm.frey@gmail.com> | 2020-04-20 04:21:58 +0200 |
commit | e7664b7a4fe1035bc3c9afb51254bfff1f25654a (patch) | |
tree | 1ef014c1cebc971271f26cc7669c0010ffe1a463 /src/yuzu/main.cpp | |
parent | 4932010c6f5fc5f2d0c78e69285eaccd64a32c0f (diff) |
yuzu: Option to hide mouse on inactivity
Co-Authored-By: Vitor K <vitor-k@users.noreply.github.com>
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r-- | src/yuzu/main.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 05baec7e13..1e76f789c5 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -135,6 +135,8 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; } #endif +constexpr int default_mouse_timeout = 2500; + constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; /** @@ -236,6 +238,14 @@ GMainWindow::GMainWindow() // Show one-time "callout" messages to the user ShowTelemetryCallout(); + // make sure menubar has the arrow cursor instead of inheriting from this + ui.menubar->setCursor(QCursor()); + statusBar()->setCursor(QCursor()); + + mouse_hide_timer.setInterval(default_mouse_timeout); + connect(&mouse_hide_timer, &QTimer::timeout, this, &GMainWindow::HideMouseCursor); + connect(ui.menubar, &QMenuBar::hovered, this, &GMainWindow::ShowMouseCursor); + QStringList args = QApplication::arguments(); if (args.length() >= 2) { BootGame(args[1]); @@ -1012,6 +1022,13 @@ void GMainWindow::BootGame(const QString& filename) { async_status_button->setDisabled(true); renderer_status_button->setDisabled(true); + if (UISettings::values.hide_mouse) { + mouse_hide_timer.start(); + setMouseTracking(true); + ui.centralwidget->setMouseTracking(true); + ui.menubar->setMouseTracking(true); + } + const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); std::string title_name; @@ -1080,6 +1097,10 @@ void GMainWindow::ShutdownGame() { game_list->show(); game_list->setFilterFocus(); + setMouseTracking(false); + ui.centralwidget->setMouseTracking(false); + ui.menubar->setMouseTracking(false); + UpdateWindowTitle(); // Disable status bar updates @@ -1835,6 +1856,17 @@ void GMainWindow::OnConfigure() { config->Save(); + if (UISettings::values.hide_mouse && emulation_running) { + setMouseTracking(true); + ui.centralwidget->setMouseTracking(true); + ui.menubar->setMouseTracking(true); + mouse_hide_timer.start(); + } else { + setMouseTracking(false); + ui.centralwidget->setMouseTracking(false); + ui.menubar->setMouseTracking(false); + } + dock_status_button->setChecked(Settings::values.use_docked_mode); async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); #ifdef HAS_VULKAN @@ -1968,6 +2000,30 @@ void GMainWindow::UpdateStatusBar() { emu_frametime_label->setVisible(true); } +void GMainWindow::HideMouseCursor() { + if (emu_thread == nullptr || UISettings::values.hide_mouse == false) { + mouse_hide_timer.stop(); + ShowMouseCursor(); + return; + } + setCursor(QCursor(Qt::BlankCursor)); +} + +void GMainWindow::ShowMouseCursor() { + unsetCursor(); + if (emu_thread != nullptr && UISettings::values.hide_mouse) { + mouse_hide_timer.start(); + } +} + +void GMainWindow::mouseMoveEvent(QMouseEvent* event) { + ShowMouseCursor(); +} + +void GMainWindow::mousePressEvent(QMouseEvent* event) { + ShowMouseCursor(); +} + void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) { QMessageBox::StandardButton answer; QString status_message; |