From d79d45a117a219c3d47128f9458004b2560b7db8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 27 Oct 2024 16:21:09 +0100 Subject: [PATCH] properly sync up menus between windows of a same instance --- src/frontend/qt_sdl/EmuInstance.cpp | 11 ++++++++++ src/frontend/qt_sdl/EmuInstance.h | 2 ++ src/frontend/qt_sdl/Window.cpp | 34 +++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 7efa6509..1387686e 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -240,6 +240,17 @@ void EmuInstance::deleteAllWindows() deleteWindow(i, true); } +void EmuInstance::doOnAllWindows(std::function func, int exclude) +{ + for (int i = 0; i < kMaxWindows; i++) + { + if (i == exclude) continue; + if (!windowList[i]) continue; + + func(windowList[i]); + } +} + void EmuInstance::broadcastCommand(int cmd, QVariant param) { diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index a79b4f75..ed6ca0df 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -89,6 +89,8 @@ public: MainWindow* getMainWindow() { return mainWindow; } MainWindow* getWindow(int id) { return windowList[id]; } + void doOnAllWindows(std::function func, int exclude = -1); + Config::Table& getGlobalConfig() { return globalCfg; } Config::Table& getLocalConfig() { return localCfg; } diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 5115045a..8f90a47f 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -781,6 +781,9 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : actPreferences->setEnabled(false); #endif // __APPLE__ } + + if (emuThread->emuIsActive()) + onEmuStart(); } QObject::connect(qApp, &QApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged); @@ -1226,21 +1229,34 @@ QStringList MainWindow::pickROM(bool gba) void MainWindow::updateCartInserted(bool gba) { bool inserted; + QString label; if (gba) { - inserted = emuInstance->gbaCartInserted() && (globalCfg.GetInt("Emu.ConsoleType") == 0); - actCurrentGBACart->setText("GBA slot: " + emuInstance->gbaCartLabel()); - actEjectGBACart->setEnabled(inserted); + inserted = emuInstance->gbaCartInserted() && (emuInstance->getConsoleType() == 0); + label = "GBA slot: " + emuInstance->gbaCartLabel(); + + emuInstance->doOnAllWindows([=](MainWindow* win) + { + if (!win->hasMenu) return; + win->actCurrentGBACart->setText(label); + win->actEjectGBACart->setEnabled(inserted); + }); } else { inserted = emuInstance->cartInserted(); - actCurrentCart->setText("DS slot: " + emuInstance->cartLabel()); - actEjectCart->setEnabled(inserted); - actImportSavefile->setEnabled(inserted); - actSetupCheats->setEnabled(inserted); - actROMInfo->setEnabled(inserted); - actRAMInfo->setEnabled(inserted); + label = "DS slot: " + emuInstance->cartLabel(); + + emuInstance->doOnAllWindows([=](MainWindow* win) + { + if (!win->hasMenu) return; + win->actCurrentCart->setText(label); + win->actEjectCart->setEnabled(inserted); + win->actImportSavefile->setEnabled(inserted); + win->actSetupCheats->setEnabled(inserted); + win->actROMInfo->setEnabled(inserted); + win->actRAMInfo->setEnabled(inserted); + }); } }