main.cpp 21 KB

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