main.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <memory>
  5. #include <optional>
  6. #include <QMainWindow>
  7. #include <QTimer>
  8. #include <QTranslator>
  9. #include "common/announce_multiplayer_room.h"
  10. #include "common/common_types.h"
  11. #include "yuzu/compatibility_list.h"
  12. #include "yuzu/hotkeys.h"
  13. #ifdef __unix__
  14. #include <QVariant>
  15. #include <QtDBus/QDBusInterface>
  16. #include <QtDBus/QtDBus>
  17. #endif
  18. class Config;
  19. class ClickableLabel;
  20. class EmuThread;
  21. class GameList;
  22. class GImageInfo;
  23. class GRenderWindow;
  24. class LoadingScreen;
  25. class MicroProfileDialog;
  26. class ProfilerWidget;
  27. class ControllerDialog;
  28. class QLabel;
  29. class MultiplayerState;
  30. class QPushButton;
  31. class QProgressDialog;
  32. class WaitTreeWidget;
  33. enum class GameListOpenTarget;
  34. enum class GameListRemoveTarget;
  35. enum class GameListShortcutTarget;
  36. enum class DumpRomFSTarget;
  37. enum class InstalledEntryType;
  38. class GameListPlaceholder;
  39. class QtSoftwareKeyboardDialog;
  40. enum class StartGameType {
  41. Normal, // Can use custom configuration
  42. Global, // Only uses global configuration
  43. };
  44. namespace Core {
  45. enum class SystemResultStatus : u32;
  46. class System;
  47. } // namespace Core
  48. namespace Core::Frontend {
  49. struct CabinetParameters;
  50. struct ControllerParameters;
  51. struct InlineAppearParameters;
  52. struct InlineTextParameters;
  53. struct KeyboardInitializeParameters;
  54. } // namespace Core::Frontend
  55. namespace DiscordRPC {
  56. class DiscordInterface;
  57. }
  58. namespace FileSys {
  59. class ContentProvider;
  60. class ManualContentProvider;
  61. class VfsFilesystem;
  62. } // namespace FileSys
  63. namespace InputCommon {
  64. class InputSubsystem;
  65. }
  66. namespace Service::AM::Applets {
  67. enum class SwkbdResult : u32;
  68. enum class SwkbdTextCheckResult : u32;
  69. enum class SwkbdReplyType : u32;
  70. enum class WebExitReason : u32;
  71. } // namespace Service::AM::Applets
  72. namespace Service::NFP {
  73. class NfpDevice;
  74. } // namespace Service::NFP
  75. namespace Ui {
  76. class MainWindow;
  77. }
  78. enum class EmulatedDirectoryTarget {
  79. NAND,
  80. SDMC,
  81. };
  82. enum class InstallResult {
  83. Success,
  84. Overwrite,
  85. Failure,
  86. BaseInstallAttempted,
  87. };
  88. enum class ReinitializeKeyBehavior {
  89. NoWarning,
  90. Warning,
  91. };
  92. class GMainWindow : public QMainWindow {
  93. Q_OBJECT
  94. /// Max number of recently loaded items to keep track of
  95. static const int max_recent_files_item = 10;
  96. // TODO: Make use of this!
  97. enum {
  98. UI_IDLE,
  99. UI_EMU_BOOTING,
  100. UI_EMU_RUNNING,
  101. UI_EMU_STOPPING,
  102. };
  103. public:
  104. void filterBarSetChecked(bool state);
  105. void UpdateUITheme();
  106. explicit GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan);
  107. ~GMainWindow() override;
  108. bool DropAction(QDropEvent* event);
  109. void AcceptDropEvent(QDropEvent* event);
  110. signals:
  111. /**
  112. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  113. * about to start. At this time, the core system emulation has been initialized, and all
  114. * emulation handles and memory should be valid.
  115. *
  116. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  117. * access/change emulation state).
  118. */
  119. void EmulationStarting(EmuThread* emu_thread);
  120. /**
  121. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  122. * system emulation handles and memory are still valid, but are about become invalid.
  123. */
  124. void EmulationStopping();
  125. // Signal that tells widgets to update icons to use the current theme
  126. void UpdateThemedIcons();
  127. void UpdateInstallProgress();
  128. void AmiiboSettingsFinished(bool is_success, const std::string& name);
  129. void ControllerSelectorReconfigureFinished();
  130. void ErrorDisplayFinished();
  131. void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
  132. void SoftwareKeyboardSubmitNormalText(Service::AM::Applets::SwkbdResult result,
  133. std::u16string submitted_text, bool confirmed);
  134. void SoftwareKeyboardSubmitInlineText(Service::AM::Applets::SwkbdReplyType reply_type,
  135. std::u16string submitted_text, s32 cursor_position);
  136. void WebBrowserExtractOfflineRomFS();
  137. void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url);
  138. void SigInterrupt();
  139. public slots:
  140. void OnLoadComplete();
  141. void OnExecuteProgram(std::size_t program_index);
  142. void OnExit();
  143. void OnSaveConfig();
  144. void AmiiboSettingsShowDialog(const Core::Frontend::CabinetParameters& parameters,
  145. std::shared_ptr<Service::NFP::NfpDevice> nfp_device);
  146. void ControllerSelectorReconfigureControllers(
  147. const Core::Frontend::ControllerParameters& parameters);
  148. void SoftwareKeyboardInitialize(
  149. bool is_inline, Core::Frontend::KeyboardInitializeParameters initialize_parameters);
  150. void SoftwareKeyboardShowNormal();
  151. void SoftwareKeyboardShowTextCheck(Service::AM::Applets::SwkbdTextCheckResult text_check_result,
  152. std::u16string text_check_message);
  153. void SoftwareKeyboardShowInline(Core::Frontend::InlineAppearParameters appear_parameters);
  154. void SoftwareKeyboardHideInline();
  155. void SoftwareKeyboardInlineTextChanged(Core::Frontend::InlineTextParameters text_parameters);
  156. void SoftwareKeyboardExit();
  157. void ErrorDisplayDisplayError(QString error_code, QString error_text);
  158. void ProfileSelectorSelectProfile();
  159. void WebBrowserOpenWebPage(const std::string& main_url, const std::string& additional_args,
  160. bool is_local);
  161. void OnAppFocusStateChanged(Qt::ApplicationState state);
  162. void OnTasStateChanged();
  163. private:
  164. /// Updates an action's shortcut and text to reflect an updated hotkey from the hotkey registry.
  165. void LinkActionShortcut(QAction* action, const QString& action_name);
  166. void RegisterMetaTypes();
  167. void InitializeWidgets();
  168. void InitializeDebugWidgets();
  169. void InitializeRecentFileMenuActions();
  170. void SetDefaultUIGeometry();
  171. void RestoreUIState();
  172. void ConnectWidgetEvents();
  173. void ConnectMenuEvents();
  174. void UpdateMenuState();
  175. void SetupPrepareForSleep();
  176. void PreventOSSleep();
  177. void AllowOSSleep();
  178. bool LoadROM(const QString& filename, u64 program_id, std::size_t program_index);
  179. void BootGame(const QString& filename, u64 program_id = 0, std::size_t program_index = 0,
  180. StartGameType with_config = StartGameType::Normal);
  181. void ShutdownGame();
  182. void ShowTelemetryCallout();
  183. void SetDiscordEnabled(bool state);
  184. void LoadAmiibo(const QString& filename);
  185. bool SelectAndSetCurrentUser();
  186. /**
  187. * Stores the filename in the recently loaded files list.
  188. * The new filename is stored at the beginning of the recently loaded files list.
  189. * After inserting the new entry, duplicates are removed meaning that if
  190. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  191. * and remove from its previous position.
  192. *
  193. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  194. *
  195. * @param filename the filename to store
  196. */
  197. void StoreRecentFile(const QString& filename);
  198. /**
  199. * Updates the recent files menu.
  200. * Menu entries are rebuilt from the configuration file.
  201. * If there is no entry in the menu, the menu is greyed out.
  202. */
  203. void UpdateRecentFiles();
  204. /**
  205. * If the emulation is running,
  206. * asks the user if he really want to close the emulator
  207. *
  208. * @return true if the user confirmed
  209. */
  210. bool ConfirmClose();
  211. bool ConfirmChangeGame();
  212. bool ConfirmForceLockedExit();
  213. void RequestGameExit();
  214. void RequestGameResume();
  215. void changeEvent(QEvent* event) override;
  216. void closeEvent(QCloseEvent* event) override;
  217. #ifdef __unix__
  218. void SetupSigInterrupts();
  219. static void HandleSigInterrupt(int);
  220. void OnSigInterruptNotifierActivated();
  221. #endif
  222. private slots:
  223. void OnStartGame();
  224. void OnRestartGame();
  225. void OnPauseGame();
  226. void OnPauseContinueGame();
  227. void OnStopGame();
  228. void OnPrepareForSleep(bool prepare_sleep);
  229. void OnMenuReportCompatibility();
  230. void OnOpenModsPage();
  231. void OnOpenQuickstartGuide();
  232. void OnOpenFAQ();
  233. /// Called whenever a user selects a game in the game list widget.
  234. void OnGameListLoadFile(QString game_path, u64 program_id);
  235. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
  236. const std::string& game_path);
  237. void OnTransferableShaderCacheOpenFile(u64 program_id);
  238. void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type);
  239. void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target,
  240. const std::string& game_path);
  241. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path, DumpRomFSTarget target);
  242. void OnGameListCopyTID(u64 program_id);
  243. void OnGameListNavigateToGamedbEntry(u64 program_id,
  244. const CompatibilityList& compatibility_list);
  245. void OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
  246. GameListShortcutTarget target);
  247. void OnGameListOpenDirectory(const QString& directory);
  248. void OnGameListAddDirectory();
  249. void OnGameListShowList(bool show);
  250. void OnGameListOpenPerGameProperties(const std::string& file);
  251. void OnMenuLoadFile();
  252. void OnMenuLoadFolder();
  253. void IncrementInstallProgress();
  254. void OnMenuInstallToNAND();
  255. void OnMenuRecentFile();
  256. void OnConfigure();
  257. void OnConfigureTas();
  258. void OnTasStartStop();
  259. void OnTasRecord();
  260. void OnTasReset();
  261. void OnToggleGraphicsAPI();
  262. void OnToggleDockedMode();
  263. void OnToggleGpuAccuracy();
  264. void OnToggleAdaptingFilter();
  265. void OnConfigurePerGame();
  266. void OnLoadAmiibo();
  267. void OnOpenYuzuFolder();
  268. void OnAbout();
  269. void OnToggleFilterBar();
  270. void OnToggleStatusBar();
  271. void OnDisplayTitleBars(bool);
  272. void InitializeHotkeys();
  273. void ToggleFullscreen();
  274. bool UsingExclusiveFullscreen();
  275. void ShowFullscreen();
  276. void HideFullscreen();
  277. void ToggleWindowMode();
  278. void ResetWindowSize(u32 width, u32 height);
  279. void ResetWindowSize720();
  280. void ResetWindowSize900();
  281. void ResetWindowSize1080();
  282. void OnCaptureScreenshot();
  283. void OnCoreError(Core::SystemResultStatus, std::string);
  284. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  285. void OnLanguageChanged(const QString& locale);
  286. void OnMouseActivity();
  287. private:
  288. QString GetGameListErrorRemoving(InstalledEntryType type) const;
  289. void RemoveBaseContent(u64 program_id, InstalledEntryType type);
  290. void RemoveUpdateContent(u64 program_id, InstalledEntryType type);
  291. void RemoveAddOnContent(u64 program_id, InstalledEntryType type);
  292. void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target);
  293. void RemoveAllTransferableShaderCaches(u64 program_id);
  294. void RemoveCustomConfiguration(u64 program_id, const std::string& game_path);
  295. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  296. InstallResult InstallNSPXCI(const QString& filename);
  297. InstallResult InstallNCA(const QString& filename);
  298. void MigrateConfigFiles();
  299. void UpdateWindowTitle(std::string_view title_name = {}, std::string_view title_version = {},
  300. std::string_view gpu_vendor = {});
  301. void UpdateDockedButton();
  302. void UpdateAPIText();
  303. void UpdateFilterText();
  304. void UpdateAAText();
  305. void UpdateStatusBar();
  306. void UpdateGPUAccuracyButton();
  307. void UpdateStatusButtons();
  308. void UpdateUISettings();
  309. void UpdateInputDrivers();
  310. void HideMouseCursor();
  311. void ShowMouseCursor();
  312. void CenterMouseCursor();
  313. void OpenURL(const QUrl& url);
  314. void LoadTranslation();
  315. void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
  316. bool CheckDarkMode();
  317. QString GetTasStateDescription() const;
  318. bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
  319. const std::string& comment, const std::string& icon_path,
  320. const std::string& command, const std::string& arguments,
  321. const std::string& categories, const std::string& keywords);
  322. std::unique_ptr<Ui::MainWindow> ui;
  323. std::unique_ptr<Core::System> system;
  324. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  325. std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
  326. MultiplayerState* multiplayer_state = nullptr;
  327. GRenderWindow* render_window;
  328. GameList* game_list;
  329. LoadingScreen* loading_screen;
  330. GameListPlaceholder* game_list_placeholder;
  331. // Status bar elements
  332. QLabel* message_label = nullptr;
  333. QLabel* shader_building_label = nullptr;
  334. QLabel* res_scale_label = nullptr;
  335. QLabel* emu_speed_label = nullptr;
  336. QLabel* game_fps_label = nullptr;
  337. QLabel* emu_frametime_label = nullptr;
  338. QLabel* tas_label = nullptr;
  339. QPushButton* gpu_accuracy_button = nullptr;
  340. QPushButton* renderer_status_button = nullptr;
  341. QPushButton* dock_status_button = nullptr;
  342. QPushButton* filter_status_button = nullptr;
  343. QPushButton* aa_status_button = nullptr;
  344. QTimer status_bar_update_timer;
  345. std::unique_ptr<Config> config;
  346. // Whether emulation is currently running in yuzu.
  347. bool emulation_running = false;
  348. std::unique_ptr<EmuThread> emu_thread;
  349. // The path to the game currently running
  350. QString current_game_path;
  351. bool auto_paused = false;
  352. bool auto_muted = false;
  353. QTimer mouse_hide_timer;
  354. QTimer mouse_center_timer;
  355. QTimer update_input_timer;
  356. QString startup_icon_theme;
  357. bool os_dark_mode = false;
  358. // FS
  359. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  360. std::unique_ptr<FileSys::ManualContentProvider> provider;
  361. // Debugger panes
  362. ProfilerWidget* profilerWidget;
  363. MicroProfileDialog* microProfileDialog;
  364. WaitTreeWidget* waitTreeWidget;
  365. ControllerDialog* controller_dialog;
  366. QAction* actions_recent_files[max_recent_files_item];
  367. // stores default icon theme search paths for the platform
  368. QStringList default_theme_paths;
  369. HotkeyRegistry hotkey_registry;
  370. QTranslator translator;
  371. // Install progress dialog
  372. QProgressDialog* install_progress;
  373. // Last game booted, used for multi-process apps
  374. QString last_filename_booted;
  375. // Applets
  376. QtSoftwareKeyboardDialog* software_keyboard = nullptr;
  377. // True if amiibo file select is visible
  378. bool is_amiibo_file_select_active{};
  379. // True if load file select is visible
  380. bool is_load_file_select_active{};
  381. // True if TAS recording dialog is visible
  382. bool is_tas_recording_dialog_active{};
  383. #ifdef __unix__
  384. QSocketNotifier* sig_interrupt_notifier;
  385. static std::array<int, 3> sig_interrupt_fds;
  386. QDBusObjectPath wake_lock{};
  387. #endif
  388. protected:
  389. void dropEvent(QDropEvent* event) override;
  390. void dragEnterEvent(QDragEnterEvent* event) override;
  391. void dragMoveEvent(QDragMoveEvent* event) override;
  392. void leaveEvent(QEvent* event) override;
  393. };