Skip to content

Commit

Permalink
properly sync up menus between windows of a same instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Oct 27, 2024
1 parent 94955ae commit d79d45a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ void EmuInstance::deleteAllWindows()
deleteWindow(i, true);
}

void EmuInstance::doOnAllWindows(std::function<void(MainWindow*)> 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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/EmuInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class EmuInstance
MainWindow* getMainWindow() { return mainWindow; }
MainWindow* getWindow(int id) { return windowList[id]; }

void doOnAllWindows(std::function<void(MainWindow*)> func, int exclude = -1);

Config::Table& getGlobalConfig() { return globalCfg; }
Config::Table& getLocalConfig() { return localCfg; }

Expand Down
34 changes: 25 additions & 9 deletions src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
}
}

Expand Down

0 comments on commit d79d45a

Please sign in to comment.