main.h 15 KB

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