yuzu: Option to hide mouse on inactivity

Co-Authored-By: Vitor K <vitor-k@users.noreply.github.com>
This commit is contained in:
FearlessTobi 2020-04-11 04:22:50 +02:00
parent 4932010c6f
commit e7664b7a4f
7 changed files with 78 additions and 0 deletions

View File

@ -292,6 +292,8 @@ GRenderWindow::GRenderWindow(GMainWindow* parent_, EmuThread* emu_thread_)
setLayout(layout); setLayout(layout);
InputCommon::Init(); InputCommon::Init();
this->setMouseTracking(true);
connect(this, &GRenderWindow::FirstFrameDisplayed, parent_, &GMainWindow::OnLoadComplete); connect(this, &GRenderWindow::FirstFrameDisplayed, parent_, &GMainWindow::OnLoadComplete);
} }
@ -385,6 +387,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
} else if (event->button() == Qt::RightButton) { } else if (event->button() == Qt::RightButton) {
InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y()); InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y());
} }
QWidget::mousePressEvent(event);
} }
void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
@ -397,6 +400,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
const auto [x, y] = ScaleTouch(pos); const auto [x, y] = ScaleTouch(pos);
this->TouchMoved(x, y); this->TouchMoved(x, y);
InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y()); InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y());
QWidget::mouseMoveEvent(event);
} }
void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {

View File

@ -740,6 +740,8 @@ void Config::ReadUIValues() {
UISettings::values.profile_index = ReadSetting(QStringLiteral("profileIndex"), 0).toUInt(); UISettings::values.profile_index = ReadSetting(QStringLiteral("profileIndex"), 0).toUInt();
UISettings::values.pause_when_in_background = UISettings::values.pause_when_in_background =
ReadSetting(QStringLiteral("pauseWhenInBackground"), false).toBool(); ReadSetting(QStringLiteral("pauseWhenInBackground"), false).toBool();
UISettings::values.hide_mouse =
ReadSetting(QStringLiteral("hideInactiveMouse"), false).toBool();
ApplyDefaultProfileIfInputInvalid(); ApplyDefaultProfileIfInputInvalid();
@ -1164,6 +1166,7 @@ void Config::SaveUIValues() {
WriteSetting(QStringLiteral("profileIndex"), UISettings::values.profile_index, 0); WriteSetting(QStringLiteral("profileIndex"), UISettings::values.profile_index, 0);
WriteSetting(QStringLiteral("pauseWhenInBackground"), WriteSetting(QStringLiteral("pauseWhenInBackground"),
UISettings::values.pause_when_in_background, false); UISettings::values.pause_when_in_background, false);
WriteSetting(QStringLiteral("hideInactiveMouse"), UISettings::values.hide_mouse, false);
qt_config->endGroup(); qt_config->endGroup();
} }

View File

@ -26,6 +26,7 @@ void ConfigureGeneral::SetConfiguration() {
ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing);
ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot); ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot);
ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background); ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background);
ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse);
ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit); ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked());
@ -36,6 +37,7 @@ void ConfigureGeneral::ApplyConfiguration() {
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked(); UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked(); Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked();
Settings::values.frame_limit = ui->frame_limit->value(); Settings::values.frame_limit = ui->frame_limit->value();

View File

@ -72,6 +72,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="toggle_hide_mouse">
<property name="text">
<string>Hide mouse on inactivity</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -135,6 +135,8 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
} }
#endif #endif
constexpr int default_mouse_timeout = 2500;
constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000;
/** /**
@ -236,6 +238,14 @@ GMainWindow::GMainWindow()
// Show one-time "callout" messages to the user // Show one-time "callout" messages to the user
ShowTelemetryCallout(); 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(); QStringList args = QApplication::arguments();
if (args.length() >= 2) { if (args.length() >= 2) {
BootGame(args[1]); BootGame(args[1]);
@ -1012,6 +1022,13 @@ void GMainWindow::BootGame(const QString& filename) {
async_status_button->setDisabled(true); async_status_button->setDisabled(true);
renderer_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(); const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
std::string title_name; std::string title_name;
@ -1080,6 +1097,10 @@ void GMainWindow::ShutdownGame() {
game_list->show(); game_list->show();
game_list->setFilterFocus(); game_list->setFilterFocus();
setMouseTracking(false);
ui.centralwidget->setMouseTracking(false);
ui.menubar->setMouseTracking(false);
UpdateWindowTitle(); UpdateWindowTitle();
// Disable status bar updates // Disable status bar updates
@ -1835,6 +1856,17 @@ void GMainWindow::OnConfigure() {
config->Save(); 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); dock_status_button->setChecked(Settings::values.use_docked_mode);
async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation);
#ifdef HAS_VULKAN #ifdef HAS_VULKAN
@ -1968,6 +2000,30 @@ void GMainWindow::UpdateStatusBar() {
emu_frametime_label->setVisible(true); 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) { void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
QMessageBox::StandardButton answer; QMessageBox::StandardButton answer;
QString status_message; QString status_message;

View File

@ -216,6 +216,8 @@ private:
std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
void UpdateWindowTitle(const QString& title_name = {}); void UpdateWindowTitle(const QString& title_name = {});
void UpdateStatusBar(); void UpdateStatusBar();
void HideMouseCursor();
void ShowMouseCursor();
Ui::MainWindow ui; Ui::MainWindow ui;
@ -244,6 +246,7 @@ private:
QString game_path; QString game_path;
bool auto_paused = false; bool auto_paused = false;
QTimer mouse_hide_timer;
// FS // FS
std::shared_ptr<FileSys::VfsFilesystem> vfs; std::shared_ptr<FileSys::VfsFilesystem> vfs;
@ -265,4 +268,6 @@ protected:
void dropEvent(QDropEvent* event) override; void dropEvent(QDropEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override; void dragMoveEvent(QDragMoveEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
}; };

View File

@ -59,6 +59,7 @@ struct Values {
bool confirm_before_closing; bool confirm_before_closing;
bool first_start; bool first_start;
bool pause_when_in_background; bool pause_when_in_background;
bool hide_mouse;
bool select_user_on_boot; bool select_user_on_boot;