main.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <clocale>
  5. #include <memory>
  6. #include <thread>
  7. #include <glad/glad.h>
  8. #define QT_NO_OPENGL
  9. #include <QDesktopWidget>
  10. #include <QFileDialog>
  11. #include <QMessageBox>
  12. #include <QtGui>
  13. #include "citra_qt/bootmanager.h"
  14. #include "citra_qt/config.h"
  15. #include "citra_qt/configure_dialog.h"
  16. #include "citra_qt/debugger/callstack.h"
  17. #include "citra_qt/debugger/disassembler.h"
  18. #include "citra_qt/debugger/graphics.h"
  19. #include "citra_qt/debugger/graphics_breakpoints.h"
  20. #include "citra_qt/debugger/graphics_cmdlists.h"
  21. #include "citra_qt/debugger/graphics_surface.h"
  22. #include "citra_qt/debugger/graphics_tracing.h"
  23. #include "citra_qt/debugger/graphics_vertex_shader.h"
  24. #include "citra_qt/debugger/profiler.h"
  25. #include "citra_qt/debugger/ramview.h"
  26. #include "citra_qt/debugger/registers.h"
  27. #include "citra_qt/game_list.h"
  28. #include "citra_qt/hotkeys.h"
  29. #include "citra_qt/main.h"
  30. #include "citra_qt/ui_settings.h"
  31. #include "common/logging/backend.h"
  32. #include "common/logging/filter.h"
  33. #include "common/logging/log.h"
  34. #include "common/logging/text_formatter.h"
  35. #include "common/microprofile.h"
  36. #include "common/platform.h"
  37. #include "common/scm_rev.h"
  38. #include "common/scope_exit.h"
  39. #include "common/string_util.h"
  40. #include "core/arm/disassembler/load_symbol_map.h"
  41. #include "core/core.h"
  42. #include "core/gdbstub/gdbstub.h"
  43. #include "core/loader/loader.h"
  44. #include "core/settings.h"
  45. #include "core/system.h"
  46. #include "qhexedit.h"
  47. #include "video_core/video_core.h"
  48. GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
  49. Pica::g_debug_context = Pica::DebugContext::Construct();
  50. ui.setupUi(this);
  51. statusBar()->hide();
  52. render_window = new GRenderWindow(this, emu_thread.get());
  53. render_window->hide();
  54. game_list = new GameList();
  55. ui.horizontalLayout->addWidget(game_list);
  56. profilerWidget = new ProfilerWidget(this);
  57. addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
  58. profilerWidget->hide();
  59. #if MICROPROFILE_ENABLED
  60. microProfileDialog = new MicroProfileDialog(this);
  61. microProfileDialog->hide();
  62. #endif
  63. disasmWidget = new DisassemblerWidget(this, emu_thread.get());
  64. addDockWidget(Qt::BottomDockWidgetArea, disasmWidget);
  65. disasmWidget->hide();
  66. registersWidget = new RegistersWidget(this);
  67. addDockWidget(Qt::RightDockWidgetArea, registersWidget);
  68. registersWidget->hide();
  69. callstackWidget = new CallstackWidget(this);
  70. addDockWidget(Qt::RightDockWidgetArea, callstackWidget);
  71. callstackWidget->hide();
  72. graphicsWidget = new GPUCommandStreamWidget(this);
  73. addDockWidget(Qt::RightDockWidgetArea, graphicsWidget);
  74. graphicsWidget->hide();
  75. graphicsCommandsWidget = new GPUCommandListWidget(this);
  76. addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget);
  77. graphicsCommandsWidget->hide();
  78. auto graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(Pica::g_debug_context, this);
  79. addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget);
  80. graphicsBreakpointsWidget->hide();
  81. auto graphicsVertexShaderWidget = new GraphicsVertexShaderWidget(Pica::g_debug_context, this);
  82. addDockWidget(Qt::RightDockWidgetArea, graphicsVertexShaderWidget);
  83. graphicsVertexShaderWidget->hide();
  84. auto graphicsTracingWidget = new GraphicsTracingWidget(Pica::g_debug_context, this);
  85. addDockWidget(Qt::RightDockWidgetArea, graphicsTracingWidget);
  86. graphicsTracingWidget->hide();
  87. auto graphicsSurfaceViewerAction = new QAction(tr("Create Pica surface viewer"), this);
  88. connect(graphicsSurfaceViewerAction, SIGNAL(triggered()), this,
  89. SLOT(OnCreateGraphicsSurfaceViewer()));
  90. QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging"));
  91. debug_menu->addAction(graphicsSurfaceViewerAction);
  92. debug_menu->addSeparator();
  93. debug_menu->addAction(profilerWidget->toggleViewAction());
  94. #if MICROPROFILE_ENABLED
  95. debug_menu->addAction(microProfileDialog->toggleViewAction());
  96. #endif
  97. debug_menu->addAction(disasmWidget->toggleViewAction());
  98. debug_menu->addAction(registersWidget->toggleViewAction());
  99. debug_menu->addAction(callstackWidget->toggleViewAction());
  100. debug_menu->addAction(graphicsWidget->toggleViewAction());
  101. debug_menu->addAction(graphicsCommandsWidget->toggleViewAction());
  102. debug_menu->addAction(graphicsBreakpointsWidget->toggleViewAction());
  103. debug_menu->addAction(graphicsVertexShaderWidget->toggleViewAction());
  104. debug_menu->addAction(graphicsTracingWidget->toggleViewAction());
  105. // Set default UI state
  106. // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
  107. QDesktopWidget* desktop = ((QApplication*)QApplication::instance())->desktop();
  108. QRect screenRect = desktop->screenGeometry(this);
  109. int x, y, w, h;
  110. w = screenRect.width() * 2 / 3;
  111. h = screenRect.height() / 2;
  112. x = (screenRect.x() + screenRect.width()) / 2 - w / 2;
  113. y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100;
  114. setGeometry(x, y, w, h);
  115. // Restore UI state
  116. restoreGeometry(UISettings::values.geometry);
  117. restoreState(UISettings::values.state);
  118. render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
  119. #if MICROPROFILE_ENABLED
  120. microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry);
  121. microProfileDialog->setVisible(UISettings::values.microprofile_visible);
  122. #endif
  123. game_list->LoadInterfaceLayout();
  124. ui.action_Single_Window_Mode->setChecked(UISettings::values.single_window_mode);
  125. ToggleWindowMode();
  126. ui.actionDisplay_widget_title_bars->setChecked(UISettings::values.display_titlebar);
  127. OnDisplayTitleBars(ui.actionDisplay_widget_title_bars->isChecked());
  128. // Prepare actions for recent files
  129. for (int i = 0; i < max_recent_files_item; ++i) {
  130. actions_recent_files[i] = new QAction(this);
  131. actions_recent_files[i]->setVisible(false);
  132. connect(actions_recent_files[i], SIGNAL(triggered()), this, SLOT(OnMenuRecentFile()));
  133. ui.menu_recent_files->addAction(actions_recent_files[i]);
  134. }
  135. UpdateRecentFiles();
  136. // Setup connections
  137. connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString)),
  138. Qt::DirectConnection);
  139. connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(OnConfigure()));
  140. connect(ui.action_Load_File, SIGNAL(triggered()), this, SLOT(OnMenuLoadFile()),
  141. Qt::DirectConnection);
  142. connect(ui.action_Load_Symbol_Map, SIGNAL(triggered()), this, SLOT(OnMenuLoadSymbolMap()));
  143. connect(ui.action_Select_Game_List_Root, SIGNAL(triggered()), this,
  144. SLOT(OnMenuSelectGameListRoot()));
  145. connect(ui.action_Start, SIGNAL(triggered()), this, SLOT(OnStartGame()));
  146. connect(ui.action_Pause, SIGNAL(triggered()), this, SLOT(OnPauseGame()));
  147. connect(ui.action_Stop, SIGNAL(triggered()), this, SLOT(OnStopGame()));
  148. connect(ui.action_Single_Window_Mode, SIGNAL(triggered(bool)), this, SLOT(ToggleWindowMode()));
  149. connect(this, SIGNAL(EmulationStarting(EmuThread*)), disasmWidget,
  150. SLOT(OnEmulationStarting(EmuThread*)));
  151. connect(this, SIGNAL(EmulationStopping()), disasmWidget, SLOT(OnEmulationStopping()));
  152. connect(this, SIGNAL(EmulationStarting(EmuThread*)), registersWidget,
  153. SLOT(OnEmulationStarting(EmuThread*)));
  154. connect(this, SIGNAL(EmulationStopping()), registersWidget, SLOT(OnEmulationStopping()));
  155. connect(this, SIGNAL(EmulationStarting(EmuThread*)), render_window,
  156. SLOT(OnEmulationStarting(EmuThread*)));
  157. connect(this, SIGNAL(EmulationStopping()), render_window, SLOT(OnEmulationStopping()));
  158. connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget,
  159. SLOT(OnEmulationStarting(EmuThread*)));
  160. connect(this, SIGNAL(EmulationStopping()), graphicsTracingWidget, SLOT(OnEmulationStopping()));
  161. // Setup hotkeys
  162. RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
  163. RegisterHotkey("Main Window", "Start Emulation");
  164. LoadHotkeys();
  165. connect(GetHotkey("Main Window", "Load File", this), SIGNAL(activated()), this,
  166. SLOT(OnMenuLoadFile()));
  167. connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this,
  168. SLOT(OnStartGame()));
  169. std::string window_title =
  170. Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
  171. setWindowTitle(window_title.c_str());
  172. show();
  173. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  174. QStringList args = QApplication::arguments();
  175. if (args.length() >= 2) {
  176. BootGame(args[1].toStdString());
  177. }
  178. }
  179. GMainWindow::~GMainWindow() {
  180. // will get automatically deleted otherwise
  181. if (render_window->parent() == nullptr)
  182. delete render_window;
  183. Pica::g_debug_context.reset();
  184. }
  185. void GMainWindow::OnDisplayTitleBars(bool show) {
  186. QList<QDockWidget*> widgets = findChildren<QDockWidget*>();
  187. if (show) {
  188. for (QDockWidget* widget : widgets) {
  189. QWidget* old = widget->titleBarWidget();
  190. widget->setTitleBarWidget(nullptr);
  191. if (old != nullptr)
  192. delete old;
  193. }
  194. } else {
  195. for (QDockWidget* widget : widgets) {
  196. QWidget* old = widget->titleBarWidget();
  197. widget->setTitleBarWidget(new QWidget());
  198. if (old != nullptr)
  199. delete old;
  200. }
  201. }
  202. }
  203. bool GMainWindow::InitializeSystem() {
  204. // Shutdown previous session if the emu thread is still active...
  205. if (emu_thread != nullptr)
  206. ShutdownGame();
  207. render_window->InitRenderTarget();
  208. render_window->MakeCurrent();
  209. if (!gladLoadGL()) {
  210. QMessageBox::critical(this, tr("Error while starting Citra!"),
  211. tr("Failed to initialize the video core!\n\n"
  212. "Please ensure that your GPU supports OpenGL 3.3 and that you "
  213. "have the latest graphics driver."));
  214. return false;
  215. }
  216. // Initialize the core emulation
  217. System::Result system_result = System::Init(render_window);
  218. if (System::Result::Success != system_result) {
  219. switch (system_result) {
  220. case System::Result::ErrorInitVideoCore:
  221. QMessageBox::critical(this, tr("Error while starting Citra!"),
  222. tr("Failed to initialize the video core!\n\n"
  223. "Please ensure that your GPU supports OpenGL 3.3 and that you "
  224. "have the latest graphics driver."));
  225. break;
  226. default:
  227. QMessageBox::critical(this, tr("Error while starting Citra!"),
  228. tr("Unknown error (please check the log)!"));
  229. break;
  230. }
  231. return false;
  232. }
  233. return true;
  234. }
  235. bool GMainWindow::LoadROM(const std::string& filename) {
  236. std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename);
  237. if (!app_loader) {
  238. LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str());
  239. QMessageBox::critical(this, tr("Error while loading ROM!"),
  240. tr("The ROM format is not supported."));
  241. return false;
  242. }
  243. Loader::ResultStatus result = app_loader->Load();
  244. if (Loader::ResultStatus::Success != result) {
  245. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  246. switch (result) {
  247. case Loader::ResultStatus::ErrorEncrypted: {
  248. // Build the MessageBox ourselves to have clickable link
  249. QMessageBox popup_error;
  250. popup_error.setTextFormat(Qt::RichText);
  251. popup_error.setWindowTitle(tr("Error while loading ROM!"));
  252. popup_error.setText(
  253. tr("The game that you are trying to load must be decrypted before being used with "
  254. "Citra.<br/><br/>"
  255. "For more information on dumping and decrypting games, please see: <a "
  256. "href='https://citra-emu.org/wiki/Dumping-Game-Cartridges'>https://"
  257. "citra-emu.org/wiki/Dumping-Game-Cartridges</a>"));
  258. popup_error.setIcon(QMessageBox::Critical);
  259. popup_error.exec();
  260. break;
  261. }
  262. case Loader::ResultStatus::ErrorInvalidFormat:
  263. QMessageBox::critical(this, tr("Error while loading ROM!"),
  264. tr("The ROM format is not supported."));
  265. break;
  266. case Loader::ResultStatus::Error:
  267. default:
  268. QMessageBox::critical(this, tr("Error while loading ROM!"), tr("Unknown error!"));
  269. break;
  270. }
  271. return false;
  272. }
  273. return true;
  274. }
  275. void GMainWindow::BootGame(const std::string& filename) {
  276. LOG_INFO(Frontend, "Citra starting...");
  277. StoreRecentFile(filename); // Put the filename on top of the list
  278. if (!InitializeSystem())
  279. return;
  280. if (!LoadROM(filename)) {
  281. System::Shutdown();
  282. return;
  283. }
  284. // Create and start the emulation thread
  285. emu_thread = std::make_unique<EmuThread>(render_window);
  286. emit EmulationStarting(emu_thread.get());
  287. render_window->moveContext();
  288. emu_thread->start();
  289. connect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame()));
  290. // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views
  291. // before the CPU continues
  292. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()),
  293. Qt::BlockingQueuedConnection);
  294. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), registersWidget,
  295. SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
  296. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), callstackWidget,
  297. SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
  298. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()),
  299. Qt::BlockingQueuedConnection);
  300. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()),
  301. Qt::BlockingQueuedConnection);
  302. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()),
  303. Qt::BlockingQueuedConnection);
  304. // Update the GUI
  305. registersWidget->OnDebugModeEntered();
  306. callstackWidget->OnDebugModeEntered();
  307. if (ui.action_Single_Window_Mode->isChecked()) {
  308. game_list->hide();
  309. }
  310. render_window->show();
  311. emulation_running = true;
  312. OnStartGame();
  313. }
  314. void GMainWindow::ShutdownGame() {
  315. emu_thread->RequestStop();
  316. // Release emu threads from any breakpoints
  317. // This belongs after RequestStop() and before wait() because if emulation stops on a GPU
  318. // breakpoint after (or before) RequestStop() is called, the emulation would never be able
  319. // to continue out to the main loop and terminate. Thus wait() would hang forever.
  320. // TODO(bunnei): This function is not thread safe, but it's being used as if it were
  321. Pica::g_debug_context->ClearBreakpoints();
  322. emit EmulationStopping();
  323. // Wait for emulation thread to complete and delete it
  324. emu_thread->wait();
  325. emu_thread = nullptr;
  326. // The emulation is stopped, so closing the window or not does not matter anymore
  327. disconnect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame()));
  328. // Update the GUI
  329. ui.action_Start->setEnabled(false);
  330. ui.action_Start->setText(tr("Start"));
  331. ui.action_Pause->setEnabled(false);
  332. ui.action_Stop->setEnabled(false);
  333. render_window->hide();
  334. game_list->show();
  335. emulation_running = false;
  336. }
  337. void GMainWindow::StoreRecentFile(const std::string& filename) {
  338. UISettings::values.recent_files.prepend(QString::fromStdString(filename));
  339. UISettings::values.recent_files.removeDuplicates();
  340. while (UISettings::values.recent_files.size() > max_recent_files_item) {
  341. UISettings::values.recent_files.removeLast();
  342. }
  343. UpdateRecentFiles();
  344. }
  345. void GMainWindow::UpdateRecentFiles() {
  346. unsigned int num_recent_files =
  347. std::min(UISettings::values.recent_files.size(), static_cast<int>(max_recent_files_item));
  348. for (unsigned int i = 0; i < num_recent_files; i++) {
  349. QString text = QString("&%1. %2").arg(i + 1).arg(
  350. QFileInfo(UISettings::values.recent_files[i]).fileName());
  351. actions_recent_files[i]->setText(text);
  352. actions_recent_files[i]->setData(UISettings::values.recent_files[i]);
  353. actions_recent_files[i]->setToolTip(UISettings::values.recent_files[i]);
  354. actions_recent_files[i]->setVisible(true);
  355. }
  356. for (int j = num_recent_files; j < max_recent_files_item; ++j) {
  357. actions_recent_files[j]->setVisible(false);
  358. }
  359. // Grey out the recent files menu if the list is empty
  360. if (num_recent_files == 0) {
  361. ui.menu_recent_files->setEnabled(false);
  362. } else {
  363. ui.menu_recent_files->setEnabled(true);
  364. }
  365. }
  366. void GMainWindow::OnGameListLoadFile(QString game_path) {
  367. BootGame(game_path.toStdString());
  368. }
  369. void GMainWindow::OnMenuLoadFile() {
  370. QString filename =
  371. QFileDialog::getOpenFileName(this, tr("Load File"), UISettings::values.roms_path,
  372. tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.cci *.cxi)"));
  373. if (!filename.isEmpty()) {
  374. UISettings::values.roms_path = QFileInfo(filename).path();
  375. BootGame(filename.toStdString());
  376. }
  377. }
  378. void GMainWindow::OnMenuLoadSymbolMap() {
  379. QString filename = QFileDialog::getOpenFileName(
  380. this, tr("Load Symbol Map"), UISettings::values.symbols_path, tr("Symbol map (*)"));
  381. if (!filename.isEmpty()) {
  382. UISettings::values.symbols_path = QFileInfo(filename).path();
  383. LoadSymbolMap(filename.toStdString());
  384. }
  385. }
  386. void GMainWindow::OnMenuSelectGameListRoot() {
  387. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  388. if (!dir_path.isEmpty()) {
  389. UISettings::values.gamedir = dir_path;
  390. game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan);
  391. }
  392. }
  393. void GMainWindow::OnMenuRecentFile() {
  394. QAction* action = qobject_cast<QAction*>(sender());
  395. assert(action);
  396. QString filename = action->data().toString();
  397. QFileInfo file_info(filename);
  398. if (file_info.exists()) {
  399. BootGame(filename.toStdString());
  400. } else {
  401. // Display an error message and remove the file from the list.
  402. QMessageBox::information(this, tr("File not found"),
  403. tr("File \"%1\" not found").arg(filename));
  404. UISettings::values.recent_files.removeOne(filename);
  405. UpdateRecentFiles();
  406. }
  407. }
  408. void GMainWindow::OnStartGame() {
  409. emu_thread->SetRunning(true);
  410. ui.action_Start->setEnabled(false);
  411. ui.action_Start->setText(tr("Continue"));
  412. ui.action_Pause->setEnabled(true);
  413. ui.action_Stop->setEnabled(true);
  414. }
  415. void GMainWindow::OnPauseGame() {
  416. emu_thread->SetRunning(false);
  417. ui.action_Start->setEnabled(true);
  418. ui.action_Pause->setEnabled(false);
  419. ui.action_Stop->setEnabled(true);
  420. }
  421. void GMainWindow::OnStopGame() {
  422. ShutdownGame();
  423. }
  424. void GMainWindow::ToggleWindowMode() {
  425. if (ui.action_Single_Window_Mode->isChecked()) {
  426. // Render in the main window...
  427. render_window->BackupGeometry();
  428. ui.horizontalLayout->addWidget(render_window);
  429. render_window->setFocusPolicy(Qt::ClickFocus);
  430. if (emulation_running) {
  431. render_window->setVisible(true);
  432. render_window->setFocus();
  433. game_list->hide();
  434. }
  435. } else {
  436. // Render in a separate window...
  437. ui.horizontalLayout->removeWidget(render_window);
  438. render_window->setParent(nullptr);
  439. render_window->setFocusPolicy(Qt::NoFocus);
  440. if (emulation_running) {
  441. render_window->setVisible(true);
  442. render_window->RestoreGeometry();
  443. game_list->show();
  444. }
  445. }
  446. }
  447. void GMainWindow::OnConfigure() {
  448. ConfigureDialog configureDialog(this);
  449. auto result = configureDialog.exec();
  450. if (result == QDialog::Accepted) {
  451. configureDialog.applyConfiguration();
  452. render_window->ReloadSetKeymaps();
  453. config->Save();
  454. }
  455. }
  456. void GMainWindow::OnCreateGraphicsSurfaceViewer() {
  457. auto graphicsSurfaceViewerWidget = new GraphicsSurfaceWidget(Pica::g_debug_context, this);
  458. addDockWidget(Qt::RightDockWidgetArea, graphicsSurfaceViewerWidget);
  459. // TODO: Maybe graphicsSurfaceViewerWidget->setFloating(true);
  460. graphicsSurfaceViewerWidget->show();
  461. }
  462. bool GMainWindow::ConfirmClose() {
  463. if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
  464. return true;
  465. auto answer =
  466. QMessageBox::question(this, tr("Citra"), tr("Are you sure you want to close Citra?"),
  467. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  468. return answer != QMessageBox::No;
  469. }
  470. void GMainWindow::closeEvent(QCloseEvent* event) {
  471. if (!ConfirmClose()) {
  472. event->ignore();
  473. return;
  474. }
  475. UISettings::values.geometry = saveGeometry();
  476. UISettings::values.state = saveState();
  477. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  478. #if MICROPROFILE_ENABLED
  479. UISettings::values.microprofile_geometry = microProfileDialog->saveGeometry();
  480. UISettings::values.microprofile_visible = microProfileDialog->isVisible();
  481. #endif
  482. UISettings::values.single_window_mode = ui.action_Single_Window_Mode->isChecked();
  483. UISettings::values.display_titlebar = ui.actionDisplay_widget_title_bars->isChecked();
  484. UISettings::values.first_start = false;
  485. game_list->SaveInterfaceLayout();
  486. SaveHotkeys();
  487. // Shutdown session if the emu thread is active...
  488. if (emu_thread != nullptr)
  489. ShutdownGame();
  490. render_window->close();
  491. QWidget::closeEvent(event);
  492. }
  493. #ifdef main
  494. #undef main
  495. #endif
  496. int main(int argc, char* argv[]) {
  497. Log::Filter log_filter(Log::Level::Info);
  498. Log::SetFilter(&log_filter);
  499. MicroProfileOnThreadCreate("Frontend");
  500. SCOPE_EXIT({ MicroProfileShutdown(); });
  501. // Init settings params
  502. QCoreApplication::setOrganizationName("Citra team");
  503. QCoreApplication::setApplicationName("Citra");
  504. QApplication::setAttribute(Qt::AA_X11InitThreads);
  505. QApplication app(argc, argv);
  506. // Qt changes the locale and causes issues in float conversion using std::to_string() when
  507. // generating shaders
  508. setlocale(LC_ALL, "C");
  509. GMainWindow main_window;
  510. // After settings have been loaded by GMainWindow, apply the filter
  511. log_filter.ParseFilterString(Settings::values.log_filter);
  512. main_window.show();
  513. return app.exec();
  514. }