main.h 15 KB

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