From 238c5525997c49d9c2ad50d51bb53e86f57d58a3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 27 Oct 2024 16:26:29 +0100 Subject: [PATCH] limit to 4 windows, and disable 'new window' menu item when that amount is reached --- src/frontend/qt_sdl/EmuInstance.cpp | 14 ++++++++++++++ src/frontend/qt_sdl/EmuInstance.h | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 1387686e..12afb12b 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -203,6 +203,12 @@ void EmuInstance::createWindow() // if creating a secondary window, we may need to initialize its OpenGL context here if (win->hasOpenGL() && (id != 0)) emuThread->initContext(id); + + bool enable = (numWindows < kMaxWindows); + doOnAllWindows([=](MainWindow* win) + { + win->actNewWindow->setEnabled(enable); + }); } void EmuInstance::deleteWindow(int id, bool close) @@ -232,6 +238,14 @@ void EmuInstance::deleteWindow(int id, bool close) // if the main window is closed, Qt will take care of closing any secondary windows deleteEmuInstance(instanceID); } + else + { + bool enable = (numWindows < kMaxWindows); + doOnAllWindows([=](MainWindow* win) + { + win->actNewWindow->setEnabled(enable); + }); + } } void EmuInstance::deleteAllWindows() diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index ed6ca0df..0122b0d9 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -28,7 +28,7 @@ #include "Config.h" #include "SaveManager.h" -const int kMaxWindows = 16; +const int kMaxWindows = 4; enum { @@ -87,6 +87,7 @@ public: melonDS::NDS* getNDS() { return nds; } MainWindow* getMainWindow() { return mainWindow; } + int getNumWindows() { return numWindows; } MainWindow* getWindow(int id) { return windowList[id]; } void doOnAllWindows(std::function func, int exclude = -1);