main.h 17 KB

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