From bf0ea26596251d3a1af536b8dfe5f9c9d98d0cd9 Mon Sep 17 00:00:00 2001 From: WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com> Date: Thu, 21 Jan 2021 18:48:25 +0000 Subject: Add option to hide mouse on inactivity (#955) Also allow user to specify how long to wait before hiding --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/InterfaceSettingsDialog.cpp | 71 +++++++++++++++++++ src/frontend/qt_sdl/InterfaceSettingsDialog.h | 65 +++++++++++++++++ src/frontend/qt_sdl/InterfaceSettingsDialog.ui | 94 +++++++++++++++++++++++++ src/frontend/qt_sdl/PlatformConfig.cpp | 6 ++ src/frontend/qt_sdl/PlatformConfig.h | 3 + src/frontend/qt_sdl/main.cpp | 77 ++++++++++++++++++-- src/frontend/qt_sdl/main.h | 12 ++++ 8 files changed, 322 insertions(+), 7 deletions(-) create mode 100644 src/frontend/qt_sdl/InterfaceSettingsDialog.cpp create mode 100644 src/frontend/qt_sdl/InterfaceSettingsDialog.h create mode 100644 src/frontend/qt_sdl/InterfaceSettingsDialog.ui (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 72bf7c8..237ccca 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -9,6 +9,7 @@ SET(SOURCES_QT_SDL VideoSettingsDialog.cpp AudioSettingsDialog.cpp WifiSettingsDialog.cpp + InterfaceSettingsDialog.cpp Input.cpp LAN_PCap.cpp LAN_Socket.cpp diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp new file mode 100644 index 0000000..7dcb421 --- /dev/null +++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp @@ -0,0 +1,71 @@ +/* + Copyright 2016-2021 Arisotura, WaluigiWare64 + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include "InterfaceSettingsDialog.h" +#include "ui_InterfaceSettingsDialog.h" + +#include "types.h" +#include "Platform.h" +#include "Config.h" +#include "PlatformConfig.h" + +InterfaceSettingsDialog* InterfaceSettingsDialog::currentDlg = nullptr; + +InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InterfaceSettingsDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + ui->cbMouseHide->setChecked(Config::MouseHide != 0); + ui->spinMouseHideSeconds->setEnabled(Config::MouseHide != 0); + ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds); +} + +InterfaceSettingsDialog::~InterfaceSettingsDialog() +{ + delete ui; +} + +void InterfaceSettingsDialog::on_cbMouseHide_clicked() +{ + if (ui->spinMouseHideSeconds->isEnabled()) + { + ui->spinMouseHideSeconds->setEnabled(false); + } + else + { + ui->spinMouseHideSeconds->setEnabled(true); + } +} + +void InterfaceSettingsDialog::done(int r) +{ + if (r == QDialog::Accepted) + { + Config::MouseHide = ui->cbMouseHide->isChecked() ? 1:0; + Config::MouseHideSeconds = ui->spinMouseHideSeconds->value(); + + Config::Save(); + + emit updateMouseTimer(); + } + + QDialog::done(r); + + closeDlg(); +} diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.h b/src/frontend/qt_sdl/InterfaceSettingsDialog.h new file mode 100644 index 0000000..ae21e3f --- /dev/null +++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.h @@ -0,0 +1,65 @@ +/* + Copyright 2016-2021 Arisotura, WaluigiWare64 + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef INTERFACESETTINGSDIALOG_H +#define INTERFACESETTINGSDIALOG_H + +#include + +namespace Ui { class InterfaceSettingsDialog; } +class InterfaceSettingsDialog; + +class InterfaceSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit InterfaceSettingsDialog(QWidget* parent); + ~InterfaceSettingsDialog(); + + static InterfaceSettingsDialog* currentDlg; + static InterfaceSettingsDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new InterfaceSettingsDialog(parent); + currentDlg->open(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +signals: + void updateMouseTimer(); + +private slots: + void done(int r); + + void on_cbMouseHide_clicked(); + +private: + Ui::InterfaceSettingsDialog* ui; +}; + +#endif // INTERFACESETTINGSDIALOG_H diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.ui b/src/frontend/qt_sdl/InterfaceSettingsDialog.ui new file mode 100644 index 0000000..4891da9 --- /dev/null +++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.ui @@ -0,0 +1,94 @@ + + + InterfaceSettingsDialog + + + + 0 + 0 + 209 + 110 + + + + + 0 + 0 + + + + Interface settings - melonDS + + + + + + Hide mouse after inactivity + + + + + + + Hide after + + + + + + + + + + seconds of inactivity + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + InterfaceSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + InterfaceSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 03c7285..ac890ee 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -77,6 +77,9 @@ char RecentROMList[10][1024]; int EnableCheats; +int MouseHide; +int MouseHideSeconds; + bool EnableJIT; ConfigEntry PlatformConfigFile[] = @@ -185,6 +188,9 @@ ConfigEntry PlatformConfigFile[] = {"EnableCheats", 0, &EnableCheats, 0, NULL, 0}, + {"MouseHide", 0, &MouseHide, 0, NULL, 0}, + {"MouseHideSeconds", 0, &MouseHideSeconds, 5, NULL, 0}, + {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index 1d996c8..a37411e 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -92,6 +92,9 @@ extern char RecentROMList[10][1024]; extern int EnableCheats; +extern int MouseHide; +extern int MouseHideSeconds; + } #endif // PLATFORMCONFIG_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 6cfb7b8..f64494d 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -52,6 +52,7 @@ #include "VideoSettingsDialog.h" #include "AudioSettingsDialog.h" #include "WifiSettingsDialog.h" +#include "InterfaceSettingsDialog.h" #include "types.h" #include "version.h" @@ -719,6 +720,9 @@ void ScreenHandler::screenOnMouseRelease(QMouseEvent* event) void ScreenHandler::screenOnMouseMove(QMouseEvent* event) { event->accept(); + + showCursor(); + if (!(event->buttons() & Qt::LeftButton)) return; if (!touching) return; @@ -736,6 +740,21 @@ void ScreenHandler::screenOnMouseMove(QMouseEvent* event) NDS::TouchScreen(x, y); } +void ScreenHandler::showCursor() +{ + mainWindow->panel->setCursor(Qt::ArrowCursor); + mouseTimer->start(); +} + +QTimer* ScreenHandler::setupMouseTimer() +{ + mouseTimer = new QTimer(); + mouseTimer->setSingleShot(true); + mouseTimer->setInterval(Config::MouseHideSeconds*1000); + mouseTimer->start(); + + return mouseTimer; +} ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent) { @@ -753,6 +772,7 @@ ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent) ScreenPanelNative::~ScreenPanelNative() { OSD::DeInit(nullptr); + mouseTimer->stop(); } void ScreenPanelNative::setupScreenLayout() @@ -836,6 +856,8 @@ ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) ScreenPanelGL::~ScreenPanelGL() { + mouseTimer->stop(); + makeCurrent(); OSD::DeInit(this); @@ -1167,6 +1189,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actWifiSettings = menu->addAction("Wifi settings"); connect(actWifiSettings, &QAction::triggered, this, &MainWindow::onOpenWifiSettings); + + actInterfaceSettings = menu->addAction("Interface settings"); + connect(actInterfaceSettings, &QAction::triggered, this, &MainWindow::onOpenInterfaceSettings); { QMenu* submenu = menu->addMenu("Savestate settings"); @@ -1342,9 +1367,11 @@ void MainWindow::createScreenPanel() { hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + QTimer* mouseTimer; + if (hasOGL) { - ScreenPanelGL* panelGL = new ScreenPanelGL(this); + panelGL = new ScreenPanelGL(this); panelGL->show(); if (!panelGL->isValid()) @@ -1358,17 +1385,25 @@ void MainWindow::createScreenPanel() if (!hasOGL) delete panelGL; - else - panel = panelGL; + + panel = panelGL; + panelGL->setMouseTracking(true); + mouseTimer = panelGL->setupMouseTimer(); + connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelGL->setCursor(Qt::BlankCursor);}); } if (!hasOGL) { - panel = new ScreenPanelNative(this); + panelNative = new ScreenPanelNative(this); + panel = panelNative; panel->show(); + + panelNative->setMouseTracking(true); + mouseTimer = panelNative->setupMouseTimer(); + connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelNative->setCursor(Qt::BlankCursor);}); } - setCentralWidget(panel); + connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); emit screenLayoutChange(); } @@ -1997,6 +2032,27 @@ void MainWindow::onWifiSettingsFinished(int res) emuThread->emuUnpause(); } +void MainWindow::onOpenInterfaceSettings() +{ + emuThread->emuPause(); + InterfaceSettingsDialog* dlg = InterfaceSettingsDialog::openDlg(this); + connect(dlg, &InterfaceSettingsDialog::finished, this, &MainWindow::onInterfaceSettingsFinished); + connect(dlg, &InterfaceSettingsDialog::updateMouseTimer, this, &MainWindow::onUpdateMouseTimer); +} + +void MainWindow::onUpdateMouseTimer() +{ + if (hasOGL) + panelGL->mouseTimer->setInterval(Config::MouseHideSeconds*1000); + else + panelNative->mouseTimer->setInterval(Config::MouseHideSeconds*1000); +} + +void MainWindow::onInterfaceSettingsFinished(int res) +{ + emuThread->emuUnpause(); +} + void MainWindow::onChangeSavestateSRAMReloc(bool checked) { Config::SavestateRelocSRAM = checked?1:0; @@ -2182,8 +2238,15 @@ void MainWindow::onUpdateVideoSettings(bool glchange) { emuThread->emuPause(); - if (hasOGL) emuThread->deinitOpenGL(); - delete panel; + if (hasOGL) + { + emuThread->deinitOpenGL(); + delete panelGL; + } + else + { + delete panelNative; + } createScreenPanel(); connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(update())); if (hasOGL) emuThread->initOpenGL(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 22fe0f1..ba67401 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -91,6 +92,9 @@ class ScreenHandler public: virtual ~ScreenHandler() {} + QTimer* setupMouseTimer(); + void updateMouseTimer(); + QTimer* mouseTimer; protected: void screenSetupLayout(int w, int h); @@ -104,6 +108,8 @@ protected: float screenMatrix[2][6]; bool touching; + + void showCursor(); }; @@ -219,6 +225,9 @@ private slots: void onAudioSettingsFinished(int res); void onOpenWifiSettings(); void onWifiSettingsFinished(int res); + void onOpenInterfaceSettings(); + void onInterfaceSettingsFinished(int res); + void onUpdateMouseTimer(); void onChangeSavestateSRAMReloc(bool checked); void onChangeScreenSize(); void onChangeScreenRotation(QAction* act); @@ -253,6 +262,8 @@ private: public: QWidget* panel; + ScreenPanelGL* panelGL; + ScreenPanelNative* panelNative; QAction* actOpenROM; QAction* actOpenROMArchive; @@ -274,6 +285,7 @@ public: QAction* actVideoSettings; QAction* actAudioSettings; QAction* actWifiSettings; + QAction* actInterfaceSettings; QAction* actSavestateSRAMReloc; QAction* actScreenSize[4]; QActionGroup* grpScreenRotation; -- cgit v1.2.3