main.h 14 KB

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