From a448ef536b49c251f8d60cd1a30ec0c0f926c543 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 9 Jun 2018 16:28:15 -0700 Subject: [PATCH] Qt: Toggle fullscreen like on all other platforms. --- Qt/QtMain.cpp | 7 +---- Qt/QtMain.h | 3 +- Qt/mainwindow.cpp | 58 ++++++++++++++++++------------------- Qt/mainwindow.h | 3 +- UI/NativeApp.cpp | 6 ++-- Windows/main.cpp | 3 -- ext/native/base/NativeApp.h | 2 +- 7 files changed, 38 insertions(+), 44 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 197eed4984..304d164ab0 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -528,12 +528,7 @@ int main(int argc, char *argv[]) savegame_dir += "/"; external_dir += "/"; - bool fullscreenCLI=false; - for (int i = 1; i < argc; i++) { - if (!strcmp(argv[i],"--fullscreen")) - fullscreenCLI=true; - } - NativeInit(argc, (const char **)argv, savegame_dir.c_str(), external_dir.c_str(), nullptr, fullscreenCLI); + NativeInit(argc, (const char **)argv, savegame_dir.c_str(), external_dir.c_str(), nullptr); // TODO: Support other backends than GL, like Vulkan, in the Qt backend. g_Config.iGPUBackend = (int)GPUBackend::OPENGL; diff --git a/Qt/QtMain.h b/Qt/QtMain.h index 7f67794487..958e139bcc 100644 --- a/Qt/QtMain.h +++ b/Qt/QtMain.h @@ -110,6 +110,8 @@ public: explicit MainUI(QWidget *parent = 0); ~MainUI(); + void resizeGL(int w, int h); + public slots: QString InputBoxGetQString(QString title, QString defaultValue); @@ -123,7 +125,6 @@ protected: bool event(QEvent *e); void initializeGL(); - void resizeGL(int w, int h); void paintGL(); void updateAccelerometer(); diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index 904edc6095..9d28dac208 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -36,10 +36,7 @@ MainWindow::MainWindow(QWidget *parent, bool fullscreen) : createMenus(); updateMenus(); - SetWindowScale(-1); - - if(fullscreen) - fullscrAct(); + SetFullScreen(fullscreen); QObject::connect(emugl, SIGNAL(doubleClick()), this, SLOT(fullscrAct())); QObject::connect(emugl, SIGNAL(newFrame()), this, SLOT(newFrame())); @@ -99,9 +96,6 @@ void MainWindow::updateMenus() foreach(QAction * action, displayLayoutGroup->actions()) { if (g_Config.iSmallDisplayZoomType == action->data().toInt()) { - - NativeMessageReceived("gpu_resized", ""); - action->setChecked(true); break; } @@ -135,8 +129,8 @@ void MainWindow::updateMenus() void MainWindow::bootDone() { - if(g_Config.bFullScreen != isFullScreen()) - fullscrAct(); + if (g_Config.bFullScreen != isFullScreen()) + SetFullScreen(g_Config.bFullScreen); if (nextState == CORE_RUNNING) runAct(); @@ -300,40 +294,43 @@ void MainWindow::raiseTopMost() { setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); raise(); - activateWindow(); - + activateWindow(); } -void MainWindow::fullscrAct() -{ - if(isFullScreen()) { - g_Config.bFullScreen = false; +void MainWindow::SetFullScreen(bool fullscreen) { + if (fullscreen) { + menuBar()->hide(); + + emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + emugl->resizeGL(emugl->size().width(), emugl->size().height()); + // TODO: Won't showFullScreen do this for us? + setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + + showFullScreen(); + InitPadLayout(dp_xres, dp_yres); + + if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls) + QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); + } else { menuBar()->show(); updateMenus(); showNormal(); SetWindowScale(-1); InitPadLayout(dp_xres, dp_yres); + if (GetUIState() == UISTATE_INGAME && QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); } - else { - g_Config.bFullScreen = true; - menuBar()->hide(); +} - emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +void MainWindow::fullscrAct() +{ + // Toggle the current state. + g_Config.bFullScreen = !isFullScreen(); + SetFullScreen(g_Config.bFullScreen); - showFullScreen(); - - NativeMessageReceived("gpu_resized", ""); - InitPadLayout(dp_xres, dp_yres); - if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls) - QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); - - } - QTimer::singleShot(1000, this, SLOT(raiseTopMost())); } @@ -396,6 +393,7 @@ void MainWindow::SetWindowScale(int zoom) { g_Config.iWindowHeight = height; emugl->setFixedSize(g_Config.iWindowWidth, g_Config.iWindowHeight); + emugl->resizeGL(g_Config.iWindowWidth, g_Config.iWindowHeight); setFixedSize(sizeHint()); } diff --git a/Qt/mainwindow.h b/Qt/mainwindow.h index 57d24acce1..516d07bcdf 100644 --- a/Qt/mainwindow.h +++ b/Qt/mainwindow.h @@ -30,7 +30,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0, bool fullscreen=false); + explicit MainWindow(QWidget *parent = nullptr, bool fullscreen = false); ~MainWindow() { }; CoreState GetNextState() { return nextState; } @@ -144,6 +144,7 @@ private: void bootDone(); void SetWindowScale(int zoom); void SetGameTitle(QString text); + void SetFullScreen(bool fullscreen); void loadLanguage(const QString &language, bool retranslate); void createMenus(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 97b42ffca1..5f2ca00c09 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -345,7 +345,7 @@ void CreateDirectoriesAndroid() { File::CreateEmptyFile(g_Config.memStickDirectory + "PSP/SAVEDATA/.nomedia"); } -void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir, bool fs) { +void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir) { net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times. InitFastMath(cpu_info.bNEON); @@ -474,6 +474,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch #endif if (!strncmp(argv[i], "--pause-menu-exit", strlen("--pause-menu-exit"))) g_Config.bPauseMenuExitsEmulator = true; + if (!strcmp(argv[i], "--fullscreen")) + g_Config.bFullScreen = true; break; } } else { @@ -615,7 +617,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch isOuya = KeyMap::IsOuya(sysName); #if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) - MainWindow* mainWindow = new MainWindow(0,fs); + MainWindow *mainWindow = new MainWindow(nullptr, g_Config.bFullScreen); mainWindow->show(); if (host == nullptr) { host = new QtHost(mainWindow); diff --git a/Windows/main.cpp b/Windows/main.cpp index 8d81eae7fa..a003e3739a 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -458,9 +458,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin break; } - if (wideArgs[i] == L"--fullscreen") - g_Config.bFullScreen = true; - if (wideArgs[i] == L"--windowed") g_Config.bFullScreen = false; diff --git a/ext/native/base/NativeApp.h b/ext/native/base/NativeApp.h index 36ef2d3d8b..39638436ab 100644 --- a/ext/native/base/NativeApp.h +++ b/ext/native/base/NativeApp.h @@ -45,7 +45,7 @@ bool NativeIsAtTopLevel(); // The very first function to be called after NativeGetAppInfo. Even NativeMix is not called // before this, although it may be called at any point in time afterwards (on any thread!) // This functions must NOT call OpenGL. Main thread. -void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir, bool fs=false); +void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir); // Runs after NativeInit() at some point. May (and probably should) call OpenGL. // Should not initialize anything screen-size-dependent - do that in NativeResized.