main.cpp 23 KB

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