main.h 16 KB

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