main.h 14 KB

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