main.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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_surface.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 graphicsVertexShaderWidget = new GraphicsVertexShaderWidget(Pica::g_debug_context, this);
  84. addDockWidget(Qt::RightDockWidgetArea, graphicsVertexShaderWidget);
  85. graphicsVertexShaderWidget->hide();
  86. auto graphicsTracingWidget = new GraphicsTracingWidget(Pica::g_debug_context, this);
  87. addDockWidget(Qt::RightDockWidgetArea, graphicsTracingWidget);
  88. graphicsTracingWidget->hide();
  89. auto graphicsSurfaceViewerAction = new QAction(tr("Create Pica surface viewer"), this);
  90. connect(graphicsSurfaceViewerAction, SIGNAL(triggered()), this, SLOT(OnCreateGraphicsSurfaceViewer()));
  91. QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging"));
  92. debug_menu->addAction(graphicsSurfaceViewerAction);
  93. debug_menu->addSeparator();
  94. debug_menu->addAction(profilerWidget->toggleViewAction());
  95. #if MICROPROFILE_ENABLED
  96. debug_menu->addAction(microProfileDialog->toggleViewAction());
  97. #endif
  98. debug_menu->addAction(disasmWidget->toggleViewAction());
  99. debug_menu->addAction(registersWidget->toggleViewAction());
  100. debug_menu->addAction(callstackWidget->toggleViewAction());
  101. debug_menu->addAction(graphicsWidget->toggleViewAction());
  102. debug_menu->addAction(graphicsCommandsWidget->toggleViewAction());
  103. debug_menu->addAction(graphicsBreakpointsWidget->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->InitRenderTarget();
  201. render_window->MakeCurrent();
  202. if (!gladLoadGL()) {
  203. QMessageBox::critical(this, tr("Error while starting Citra!"),
  204. tr("Failed to initialize the video core!\n\n"
  205. "Please ensure that your GPU supports OpenGL 3.3 and that you have the latest graphics driver."));
  206. return false;
  207. }
  208. // Initialize the core emulation
  209. System::Result system_result = System::Init(render_window);
  210. if (System::Result::Success != system_result) {
  211. switch (system_result) {
  212. case System::Result::ErrorInitVideoCore:
  213. QMessageBox::critical(this, tr("Error while starting Citra!"),
  214. tr("Failed to initialize the video core!\n\n"
  215. "Please ensure that your GPU supports OpenGL 3.3 and that you have the latest graphics driver."));
  216. break;
  217. default:
  218. QMessageBox::critical(this, tr("Error while starting Citra!"),
  219. tr("Unknown error (please check the log)!"));
  220. break;
  221. }
  222. return false;
  223. }
  224. return true;
  225. }
  226. bool GMainWindow::LoadROM(const std::string& filename) {
  227. std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename);
  228. if (!app_loader) {
  229. LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str());
  230. QMessageBox::critical(this, tr("Error while loading ROM!"),
  231. tr("The ROM format is not supported."));
  232. return false;
  233. }
  234. Loader::ResultStatus result = app_loader->Load();
  235. if (Loader::ResultStatus::Success != result) {
  236. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  237. System::Shutdown();
  238. switch (result) {
  239. case Loader::ResultStatus::ErrorEncrypted: {
  240. // Build the MessageBox ourselves to have clickable link
  241. QMessageBox popup_error;
  242. popup_error.setTextFormat(Qt::RichText);
  243. popup_error.setWindowTitle(tr("Error while loading ROM!"));
  244. popup_error.setText(tr("The game that you are trying to load must be decrypted before being used with Citra.<br/><br/>"
  245. "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>"));
  246. popup_error.setIcon(QMessageBox::Critical);
  247. popup_error.exec();
  248. break;
  249. }
  250. case Loader::ResultStatus::ErrorInvalidFormat:
  251. QMessageBox::critical(this, tr("Error while loading ROM!"),
  252. tr("The ROM format is not supported."));
  253. break;
  254. case Loader::ResultStatus::Error:
  255. default:
  256. QMessageBox::critical(this, tr("Error while loading ROM!"),
  257. tr("Unknown error!"));
  258. break;
  259. }
  260. return false;
  261. }
  262. return true;
  263. }
  264. void GMainWindow::BootGame(const std::string& filename) {
  265. LOG_INFO(Frontend, "Citra starting...");
  266. StoreRecentFile(filename); // Put the filename on top of the list
  267. if (!InitializeSystem())
  268. return;
  269. if (!LoadROM(filename))
  270. return;
  271. // Create and start the emulation thread
  272. emu_thread = std::make_unique<EmuThread>(render_window);
  273. emit EmulationStarting(emu_thread.get());
  274. render_window->moveContext();
  275. emu_thread->start();
  276. connect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame()));
  277. // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
  278. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
  279. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), registersWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
  280. connect(emu_thread.get(), SIGNAL(DebugModeEntered()), callstackWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
  281. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
  282. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
  283. connect(emu_thread.get(), SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
  284. // Update the GUI
  285. registersWidget->OnDebugModeEntered();
  286. callstackWidget->OnDebugModeEntered();
  287. if (ui.action_Single_Window_Mode->isChecked()) {
  288. game_list->hide();
  289. }
  290. render_window->show();
  291. emulation_running = true;
  292. OnStartGame();
  293. }
  294. void GMainWindow::ShutdownGame() {
  295. emu_thread->RequestStop();
  296. // Release emu threads from any breakpoints
  297. // This belongs after RequestStop() and before wait() because if emulation stops on a GPU
  298. // breakpoint after (or before) RequestStop() is called, the emulation would never be able
  299. // to continue out to the main loop and terminate. Thus wait() would hang forever.
  300. // TODO(bunnei): This function is not thread safe, but it's being used as if it were
  301. Pica::g_debug_context->ClearBreakpoints();
  302. emit EmulationStopping();
  303. // Wait for emulation thread to complete and delete it
  304. emu_thread->wait();
  305. emu_thread = nullptr;
  306. // The emulation is stopped, so closing the window or not does not matter anymore
  307. disconnect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame()));
  308. // Update the GUI
  309. ui.action_Start->setEnabled(false);
  310. ui.action_Start->setText(tr("Start"));
  311. ui.action_Pause->setEnabled(false);
  312. ui.action_Stop->setEnabled(false);
  313. render_window->hide();
  314. game_list->show();
  315. emulation_running = false;
  316. }
  317. void GMainWindow::StoreRecentFile(const std::string& filename) {
  318. UISettings::values.recent_files.prepend(QString::fromStdString(filename));
  319. UISettings::values.recent_files.removeDuplicates();
  320. while (UISettings::values.recent_files.size() > max_recent_files_item) {
  321. UISettings::values.recent_files.removeLast();
  322. }
  323. UpdateRecentFiles();
  324. }
  325. void GMainWindow::UpdateRecentFiles() {
  326. unsigned int num_recent_files = std::min(UISettings::values.recent_files.size(), static_cast<int>(max_recent_files_item));
  327. for (unsigned int i = 0; i < num_recent_files; i++) {
  328. QString text = QString("&%1. %2").arg(i + 1).arg(QFileInfo(UISettings::values.recent_files[i]).fileName());
  329. actions_recent_files[i]->setText(text);
  330. actions_recent_files[i]->setData(UISettings::values.recent_files[i]);
  331. actions_recent_files[i]->setToolTip(UISettings::values.recent_files[i]);
  332. actions_recent_files[i]->setVisible(true);
  333. }
  334. for (int j = num_recent_files; j < max_recent_files_item; ++j) {
  335. actions_recent_files[j]->setVisible(false);
  336. }
  337. // Grey out the recent files menu if the list is empty
  338. if (num_recent_files == 0) {
  339. ui.menu_recent_files->setEnabled(false);
  340. } else {
  341. ui.menu_recent_files->setEnabled(true);
  342. }
  343. }
  344. void GMainWindow::OnGameListLoadFile(QString game_path) {
  345. BootGame(game_path.toStdString());
  346. }
  347. void GMainWindow::OnMenuLoadFile() {
  348. QString filename = QFileDialog::getOpenFileName(this, tr("Load File"), UISettings::values.roms_path, tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.cci *.cxi)"));
  349. if (!filename.isEmpty()) {
  350. UISettings::values.roms_path = QFileInfo(filename).path();
  351. BootGame(filename.toStdString());
  352. }
  353. }
  354. void GMainWindow::OnMenuLoadSymbolMap() {
  355. QString filename = QFileDialog::getOpenFileName(this, tr("Load Symbol Map"), UISettings::values.symbols_path, tr("Symbol map (*)"));
  356. if (!filename.isEmpty()) {
  357. UISettings::values.symbols_path = QFileInfo(filename).path();
  358. LoadSymbolMap(filename.toStdString());
  359. }
  360. }
  361. void GMainWindow::OnMenuSelectGameListRoot() {
  362. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  363. if (!dir_path.isEmpty()) {
  364. UISettings::values.gamedir = dir_path;
  365. game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan);
  366. }
  367. }
  368. void GMainWindow::OnMenuRecentFile() {
  369. QAction* action = qobject_cast<QAction*>(sender());
  370. assert(action);
  371. QString filename = action->data().toString();
  372. QFileInfo file_info(filename);
  373. if (file_info.exists()) {
  374. BootGame(filename.toStdString());
  375. } else {
  376. // Display an error message and remove the file from the list.
  377. QMessageBox::information(this, tr("File not found"), tr("File \"%1\" not found").arg(filename));
  378. UISettings::values.recent_files.removeOne(filename);
  379. UpdateRecentFiles();
  380. }
  381. }
  382. void GMainWindow::OnStartGame() {
  383. emu_thread->SetRunning(true);
  384. ui.action_Start->setEnabled(false);
  385. ui.action_Start->setText(tr("Continue"));
  386. ui.action_Pause->setEnabled(true);
  387. ui.action_Stop->setEnabled(true);
  388. }
  389. void GMainWindow::OnPauseGame() {
  390. emu_thread->SetRunning(false);
  391. ui.action_Start->setEnabled(true);
  392. ui.action_Pause->setEnabled(false);
  393. ui.action_Stop->setEnabled(true);
  394. }
  395. void GMainWindow::OnStopGame() {
  396. ShutdownGame();
  397. }
  398. void GMainWindow::ToggleWindowMode() {
  399. if (ui.action_Single_Window_Mode->isChecked()) {
  400. // Render in the main window...
  401. render_window->BackupGeometry();
  402. ui.horizontalLayout->addWidget(render_window);
  403. render_window->setFocusPolicy(Qt::ClickFocus);
  404. if (emulation_running) {
  405. render_window->setVisible(true);
  406. render_window->setFocus();
  407. game_list->hide();
  408. }
  409. } else {
  410. // Render in a separate window...
  411. ui.horizontalLayout->removeWidget(render_window);
  412. render_window->setParent(nullptr);
  413. render_window->setFocusPolicy(Qt::NoFocus);
  414. if (emulation_running) {
  415. render_window->setVisible(true);
  416. render_window->RestoreGeometry();
  417. game_list->show();
  418. }
  419. }
  420. }
  421. void GMainWindow::OnConfigure() {
  422. ConfigureDialog configureDialog(this);
  423. auto result = configureDialog.exec();
  424. if (result == QDialog::Accepted)
  425. {
  426. configureDialog.applyConfiguration();
  427. render_window->ReloadSetKeymaps();
  428. config->Save();
  429. }
  430. }
  431. void GMainWindow::OnCreateGraphicsSurfaceViewer() {
  432. auto graphicsSurfaceViewerWidget = new GraphicsSurfaceWidget(Pica::g_debug_context, this);
  433. addDockWidget(Qt::RightDockWidgetArea, graphicsSurfaceViewerWidget);
  434. // TODO: Maybe graphicsSurfaceViewerWidget->setFloating(true);
  435. graphicsSurfaceViewerWidget->show();
  436. }
  437. bool GMainWindow::ConfirmClose() {
  438. if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
  439. return true;
  440. auto answer = QMessageBox::question(this, tr("Citra"),
  441. tr("Are you sure you want to close Citra?"),
  442. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  443. return answer != QMessageBox::No;
  444. }
  445. void GMainWindow::closeEvent(QCloseEvent* event) {
  446. if (!ConfirmClose()) {
  447. event->ignore();
  448. return;
  449. }
  450. UISettings::values.geometry = saveGeometry();
  451. UISettings::values.state = saveState();
  452. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  453. #if MICROPROFILE_ENABLED
  454. UISettings::values.microprofile_geometry = microProfileDialog->saveGeometry();
  455. UISettings::values.microprofile_visible = microProfileDialog->isVisible();
  456. #endif
  457. UISettings::values.single_window_mode = ui.action_Single_Window_Mode->isChecked();
  458. UISettings::values.display_titlebar = ui.actionDisplay_widget_title_bars->isChecked();
  459. UISettings::values.first_start = false;
  460. game_list->SaveInterfaceLayout();
  461. SaveHotkeys();
  462. // Shutdown session if the emu thread is active...
  463. if (emu_thread != nullptr)
  464. ShutdownGame();
  465. render_window->close();
  466. QWidget::closeEvent(event);
  467. }
  468. #ifdef main
  469. #undef main
  470. #endif
  471. int main(int argc, char* argv[]) {
  472. Log::Filter log_filter(Log::Level::Info);
  473. Log::SetFilter(&log_filter);
  474. MicroProfileOnThreadCreate("Frontend");
  475. SCOPE_EXIT({
  476. MicroProfileShutdown();
  477. });
  478. // Init settings params
  479. QCoreApplication::setOrganizationName("Citra team");
  480. QCoreApplication::setApplicationName("Citra");
  481. QApplication::setAttribute(Qt::AA_X11InitThreads);
  482. QApplication app(argc, argv);
  483. // Qt changes the locale and causes issues in float conversion using std::to_string() when generating shaders
  484. setlocale(LC_ALL, "C");
  485. GMainWindow main_window;
  486. // After settings have been loaded by GMainWindow, apply the filter
  487. log_filter.ParseFilterString(Settings::values.log_filter);
  488. main_window.show();
  489. return app.exec();
  490. }