main.cpp 21 KB

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