bootmanager.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <glad/glad.h>
  4. #include <QApplication>
  5. #include <QCameraImageCapture>
  6. #include <QCameraInfo>
  7. #include <QHBoxLayout>
  8. #include <QMessageBox>
  9. #include <QPainter>
  10. #include <QScreen>
  11. #include <QString>
  12. #include <QStringList>
  13. #include <QWindow>
  14. #ifdef HAS_OPENGL
  15. #include <QOffscreenSurface>
  16. #include <QOpenGLContext>
  17. #endif
  18. #if !defined(WIN32)
  19. #include <qpa/qplatformnativeinterface.h>
  20. #endif
  21. #include <fmt/format.h>
  22. #include "common/assert.h"
  23. #include "common/microprofile.h"
  24. #include "common/scm_rev.h"
  25. #include "common/settings.h"
  26. #include "core/core.h"
  27. #include "core/cpu_manager.h"
  28. #include "core/frontend/framebuffer_layout.h"
  29. #include "input_common/drivers/camera.h"
  30. #include "input_common/drivers/keyboard.h"
  31. #include "input_common/drivers/mouse.h"
  32. #include "input_common/drivers/tas_input.h"
  33. #include "input_common/drivers/touch_screen.h"
  34. #include "input_common/main.h"
  35. #include "video_core/renderer_base.h"
  36. #include "yuzu/bootmanager.h"
  37. #include "yuzu/main.h"
  38. EmuThread::EmuThread(Core::System& system_) : system{system_} {}
  39. EmuThread::~EmuThread() = default;
  40. void EmuThread::run() {
  41. std::string name = "EmuControlThread";
  42. MicroProfileOnThreadCreate(name.c_str());
  43. Common::SetCurrentThreadName(name.c_str());
  44. auto& gpu = system.GPU();
  45. auto stop_token = stop_source.get_token();
  46. bool debugger_should_start = system.DebuggerEnabled();
  47. system.RegisterHostThread();
  48. // Main process has been loaded. Make the context current to this thread and begin GPU and CPU
  49. // execution.
  50. gpu.Start();
  51. gpu.ObtainContext();
  52. emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
  53. if (Settings::values.use_disk_shader_cache.GetValue()) {
  54. system.Renderer().ReadRasterizer()->LoadDiskResources(
  55. system.GetCurrentProcessProgramID(), stop_token,
  56. [this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
  57. emit LoadProgress(stage, value, total);
  58. });
  59. }
  60. emit LoadProgress(VideoCore::LoadCallbackStage::Complete, 0, 0);
  61. gpu.ReleaseContext();
  62. system.GetCpuManager().OnGpuReady();
  63. // Holds whether the cpu was running during the last iteration,
  64. // so that the DebugModeLeft signal can be emitted before the
  65. // next execution step
  66. bool was_active = false;
  67. while (!stop_token.stop_requested()) {
  68. if (running) {
  69. if (was_active) {
  70. emit DebugModeLeft();
  71. }
  72. running_guard = true;
  73. Core::SystemResultStatus result = system.Run();
  74. if (result != Core::SystemResultStatus::Success) {
  75. running_guard = false;
  76. this->SetRunning(false);
  77. emit ErrorThrown(result, system.GetStatusDetails());
  78. }
  79. if (debugger_should_start) {
  80. system.InitializeDebugger();
  81. debugger_should_start = false;
  82. }
  83. running_wait.Wait();
  84. result = system.Pause();
  85. if (result != Core::SystemResultStatus::Success) {
  86. running_guard = false;
  87. this->SetRunning(false);
  88. emit ErrorThrown(result, system.GetStatusDetails());
  89. }
  90. running_guard = false;
  91. if (!stop_token.stop_requested()) {
  92. was_active = true;
  93. emit DebugModeEntered();
  94. }
  95. } else {
  96. std::unique_lock lock{running_mutex};
  97. running_cv.wait(lock, stop_token, [this] { return IsRunning(); });
  98. }
  99. }
  100. // Shutdown the core emulation
  101. system.Shutdown();
  102. #if MICROPROFILE_ENABLED
  103. MicroProfileOnThreadExit();
  104. #endif
  105. }
  106. #ifdef HAS_OPENGL
  107. class OpenGLSharedContext : public Core::Frontend::GraphicsContext {
  108. public:
  109. /// Create the original context that should be shared from
  110. explicit OpenGLSharedContext(QSurface* surface_) : surface{surface_} {
  111. QSurfaceFormat format;
  112. format.setVersion(4, 6);
  113. format.setProfile(QSurfaceFormat::CompatibilityProfile);
  114. format.setOption(QSurfaceFormat::FormatOption::DeprecatedFunctions);
  115. if (Settings::values.renderer_debug) {
  116. format.setOption(QSurfaceFormat::FormatOption::DebugContext);
  117. }
  118. // TODO: expose a setting for buffer value (ie default/single/double/triple)
  119. format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
  120. format.setSwapInterval(0);
  121. context = std::make_unique<QOpenGLContext>();
  122. context->setFormat(format);
  123. if (!context->create()) {
  124. LOG_ERROR(Frontend, "Unable to create main openGL context");
  125. }
  126. }
  127. /// Create the shared contexts for rendering and presentation
  128. explicit OpenGLSharedContext(QOpenGLContext* share_context, QSurface* main_surface = nullptr) {
  129. // disable vsync for any shared contexts
  130. auto format = share_context->format();
  131. format.setSwapInterval(main_surface ? Settings::values.use_vsync.GetValue() : 0);
  132. context = std::make_unique<QOpenGLContext>();
  133. context->setShareContext(share_context);
  134. context->setFormat(format);
  135. if (!context->create()) {
  136. LOG_ERROR(Frontend, "Unable to create shared openGL context");
  137. }
  138. if (!main_surface) {
  139. offscreen_surface = std::make_unique<QOffscreenSurface>(nullptr);
  140. offscreen_surface->setFormat(format);
  141. offscreen_surface->create();
  142. surface = offscreen_surface.get();
  143. } else {
  144. surface = main_surface;
  145. }
  146. }
  147. ~OpenGLSharedContext() {
  148. DoneCurrent();
  149. }
  150. void SwapBuffers() override {
  151. context->swapBuffers(surface);
  152. }
  153. void MakeCurrent() override {
  154. // We can't track the current state of the underlying context in this wrapper class because
  155. // Qt may make the underlying context not current for one reason or another. In particular,
  156. // the WebBrowser uses GL, so it seems to conflict if we aren't careful.
  157. // Instead of always just making the context current (which does not have any caching to
  158. // check if the underlying context is already current) we can check for the current context
  159. // in the thread local data by calling `currentContext()` and checking if its ours.
  160. if (QOpenGLContext::currentContext() != context.get()) {
  161. context->makeCurrent(surface);
  162. }
  163. }
  164. void DoneCurrent() override {
  165. context->doneCurrent();
  166. }
  167. QOpenGLContext* GetShareContext() {
  168. return context.get();
  169. }
  170. const QOpenGLContext* GetShareContext() const {
  171. return context.get();
  172. }
  173. private:
  174. // Avoid using Qt parent system here since we might move the QObjects to new threads
  175. // As a note, this means we should avoid using slots/signals with the objects too
  176. std::unique_ptr<QOpenGLContext> context;
  177. std::unique_ptr<QOffscreenSurface> offscreen_surface{};
  178. QSurface* surface;
  179. };
  180. #endif
  181. class DummyContext : public Core::Frontend::GraphicsContext {};
  182. class RenderWidget : public QWidget {
  183. public:
  184. explicit RenderWidget(GRenderWindow* parent) : QWidget(parent), render_window(parent) {
  185. setAttribute(Qt::WA_NativeWindow);
  186. setAttribute(Qt::WA_PaintOnScreen);
  187. }
  188. virtual ~RenderWidget() = default;
  189. QPaintEngine* paintEngine() const override {
  190. return nullptr;
  191. }
  192. private:
  193. GRenderWindow* render_window;
  194. };
  195. class OpenGLRenderWidget : public RenderWidget {
  196. public:
  197. explicit OpenGLRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  198. windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
  199. }
  200. void SetContext(std::unique_ptr<Core::Frontend::GraphicsContext>&& context_) {
  201. context = std::move(context_);
  202. }
  203. private:
  204. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  205. };
  206. class VulkanRenderWidget : public RenderWidget {
  207. public:
  208. explicit VulkanRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  209. windowHandle()->setSurfaceType(QWindow::VulkanSurface);
  210. }
  211. };
  212. static Core::Frontend::WindowSystemType GetWindowSystemType() {
  213. // Determine WSI type based on Qt platform.
  214. QString platform_name = QGuiApplication::platformName();
  215. if (platform_name == QStringLiteral("windows"))
  216. return Core::Frontend::WindowSystemType::Windows;
  217. else if (platform_name == QStringLiteral("xcb"))
  218. return Core::Frontend::WindowSystemType::X11;
  219. else if (platform_name == QStringLiteral("wayland"))
  220. return Core::Frontend::WindowSystemType::Wayland;
  221. LOG_CRITICAL(Frontend, "Unknown Qt platform!");
  222. return Core::Frontend::WindowSystemType::Windows;
  223. }
  224. static Core::Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window) {
  225. Core::Frontend::EmuWindow::WindowSystemInfo wsi;
  226. wsi.type = GetWindowSystemType();
  227. // Our Win32 Qt external doesn't have the private API.
  228. #if defined(WIN32) || defined(__APPLE__)
  229. wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
  230. #else
  231. QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
  232. wsi.display_connection = pni->nativeResourceForWindow("display", window);
  233. if (wsi.type == Core::Frontend::WindowSystemType::Wayland)
  234. wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr;
  235. else
  236. wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
  237. #endif
  238. wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
  239. return wsi;
  240. }
  241. GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
  242. std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
  243. Core::System& system_)
  244. : QWidget(parent),
  245. emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)}, system{system_} {
  246. setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
  247. .arg(QString::fromUtf8(Common::g_build_name),
  248. QString::fromUtf8(Common::g_scm_branch),
  249. QString::fromUtf8(Common::g_scm_desc)));
  250. setAttribute(Qt::WA_AcceptTouchEvents);
  251. auto* layout = new QHBoxLayout(this);
  252. layout->setContentsMargins(0, 0, 0, 0);
  253. setLayout(layout);
  254. input_subsystem->Initialize();
  255. this->setMouseTracking(true);
  256. connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
  257. connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram,
  258. Qt::QueuedConnection);
  259. connect(this, &GRenderWindow::ExitSignal, parent, &GMainWindow::OnExit, Qt::QueuedConnection);
  260. connect(this, &GRenderWindow::TasPlaybackStateChanged, parent, &GMainWindow::OnTasStateChanged);
  261. }
  262. void GRenderWindow::ExecuteProgram(std::size_t program_index) {
  263. emit ExecuteProgramSignal(program_index);
  264. }
  265. void GRenderWindow::Exit() {
  266. emit ExitSignal();
  267. }
  268. GRenderWindow::~GRenderWindow() {
  269. input_subsystem->Shutdown();
  270. }
  271. void GRenderWindow::OnFrameDisplayed() {
  272. input_subsystem->GetTas()->UpdateThread();
  273. const InputCommon::TasInput::TasState new_tas_state =
  274. std::get<0>(input_subsystem->GetTas()->GetStatus());
  275. if (!first_frame) {
  276. last_tas_state = new_tas_state;
  277. first_frame = true;
  278. emit FirstFrameDisplayed();
  279. }
  280. if (new_tas_state != last_tas_state) {
  281. last_tas_state = new_tas_state;
  282. emit TasPlaybackStateChanged();
  283. }
  284. }
  285. bool GRenderWindow::IsShown() const {
  286. return !isMinimized();
  287. }
  288. // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).
  289. //
  290. // Older versions get the window size (density independent pixels),
  291. // and hence, do not support DPI scaling ("retina" displays).
  292. // The result will be a viewport that is smaller than the extent of the window.
  293. void GRenderWindow::OnFramebufferSizeChanged() {
  294. // Screen changes potentially incur a change in screen DPI, hence we should update the
  295. // framebuffer size
  296. const qreal pixel_ratio = windowPixelRatio();
  297. const u32 width = this->width() * pixel_ratio;
  298. const u32 height = this->height() * pixel_ratio;
  299. UpdateCurrentFramebufferLayout(width, height);
  300. }
  301. void GRenderWindow::BackupGeometry() {
  302. geometry = QWidget::saveGeometry();
  303. }
  304. void GRenderWindow::RestoreGeometry() {
  305. // We don't want to back up the geometry here (obviously)
  306. QWidget::restoreGeometry(geometry);
  307. }
  308. void GRenderWindow::restoreGeometry(const QByteArray& geometry_) {
  309. // Make sure users of this class don't need to deal with backing up the geometry themselves
  310. QWidget::restoreGeometry(geometry_);
  311. BackupGeometry();
  312. }
  313. QByteArray GRenderWindow::saveGeometry() {
  314. // If we are a top-level widget, store the current geometry
  315. // otherwise, store the last backup
  316. if (parent() == nullptr) {
  317. return QWidget::saveGeometry();
  318. }
  319. return geometry;
  320. }
  321. qreal GRenderWindow::windowPixelRatio() const {
  322. return devicePixelRatioF();
  323. }
  324. std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF& pos) const {
  325. const qreal pixel_ratio = windowPixelRatio();
  326. return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
  327. static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
  328. }
  329. void GRenderWindow::closeEvent(QCloseEvent* event) {
  330. emit Closed();
  331. QWidget::closeEvent(event);
  332. }
  333. int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) {
  334. switch (qt_key) {
  335. case Qt::Key_A:
  336. return Settings::NativeKeyboard::A;
  337. case Qt::Key_B:
  338. return Settings::NativeKeyboard::B;
  339. case Qt::Key_C:
  340. return Settings::NativeKeyboard::C;
  341. case Qt::Key_D:
  342. return Settings::NativeKeyboard::D;
  343. case Qt::Key_E:
  344. return Settings::NativeKeyboard::E;
  345. case Qt::Key_F:
  346. return Settings::NativeKeyboard::F;
  347. case Qt::Key_G:
  348. return Settings::NativeKeyboard::G;
  349. case Qt::Key_H:
  350. return Settings::NativeKeyboard::H;
  351. case Qt::Key_I:
  352. return Settings::NativeKeyboard::I;
  353. case Qt::Key_J:
  354. return Settings::NativeKeyboard::J;
  355. case Qt::Key_K:
  356. return Settings::NativeKeyboard::K;
  357. case Qt::Key_L:
  358. return Settings::NativeKeyboard::L;
  359. case Qt::Key_M:
  360. return Settings::NativeKeyboard::M;
  361. case Qt::Key_N:
  362. return Settings::NativeKeyboard::N;
  363. case Qt::Key_O:
  364. return Settings::NativeKeyboard::O;
  365. case Qt::Key_P:
  366. return Settings::NativeKeyboard::P;
  367. case Qt::Key_Q:
  368. return Settings::NativeKeyboard::Q;
  369. case Qt::Key_R:
  370. return Settings::NativeKeyboard::R;
  371. case Qt::Key_S:
  372. return Settings::NativeKeyboard::S;
  373. case Qt::Key_T:
  374. return Settings::NativeKeyboard::T;
  375. case Qt::Key_U:
  376. return Settings::NativeKeyboard::U;
  377. case Qt::Key_V:
  378. return Settings::NativeKeyboard::V;
  379. case Qt::Key_W:
  380. return Settings::NativeKeyboard::W;
  381. case Qt::Key_X:
  382. return Settings::NativeKeyboard::X;
  383. case Qt::Key_Y:
  384. return Settings::NativeKeyboard::Y;
  385. case Qt::Key_Z:
  386. return Settings::NativeKeyboard::Z;
  387. case Qt::Key_1:
  388. return Settings::NativeKeyboard::N1;
  389. case Qt::Key_2:
  390. return Settings::NativeKeyboard::N2;
  391. case Qt::Key_3:
  392. return Settings::NativeKeyboard::N3;
  393. case Qt::Key_4:
  394. return Settings::NativeKeyboard::N4;
  395. case Qt::Key_5:
  396. return Settings::NativeKeyboard::N5;
  397. case Qt::Key_6:
  398. return Settings::NativeKeyboard::N6;
  399. case Qt::Key_7:
  400. return Settings::NativeKeyboard::N7;
  401. case Qt::Key_8:
  402. return Settings::NativeKeyboard::N8;
  403. case Qt::Key_9:
  404. return Settings::NativeKeyboard::N9;
  405. case Qt::Key_0:
  406. return Settings::NativeKeyboard::N0;
  407. case Qt::Key_Return:
  408. return Settings::NativeKeyboard::Return;
  409. case Qt::Key_Escape:
  410. return Settings::NativeKeyboard::Escape;
  411. case Qt::Key_Backspace:
  412. return Settings::NativeKeyboard::Backspace;
  413. case Qt::Key_Tab:
  414. return Settings::NativeKeyboard::Tab;
  415. case Qt::Key_Space:
  416. return Settings::NativeKeyboard::Space;
  417. case Qt::Key_Minus:
  418. return Settings::NativeKeyboard::Minus;
  419. case Qt::Key_Plus:
  420. case Qt::Key_questiondown:
  421. return Settings::NativeKeyboard::Plus;
  422. case Qt::Key_BracketLeft:
  423. case Qt::Key_BraceLeft:
  424. return Settings::NativeKeyboard::OpenBracket;
  425. case Qt::Key_BracketRight:
  426. case Qt::Key_BraceRight:
  427. return Settings::NativeKeyboard::CloseBracket;
  428. case Qt::Key_Bar:
  429. return Settings::NativeKeyboard::Pipe;
  430. case Qt::Key_Dead_Tilde:
  431. return Settings::NativeKeyboard::Tilde;
  432. case Qt::Key_Ntilde:
  433. case Qt::Key_Semicolon:
  434. return Settings::NativeKeyboard::Semicolon;
  435. case Qt::Key_Apostrophe:
  436. return Settings::NativeKeyboard::Quote;
  437. case Qt::Key_Dead_Grave:
  438. return Settings::NativeKeyboard::Backquote;
  439. case Qt::Key_Comma:
  440. return Settings::NativeKeyboard::Comma;
  441. case Qt::Key_Period:
  442. return Settings::NativeKeyboard::Period;
  443. case Qt::Key_Slash:
  444. return Settings::NativeKeyboard::Slash;
  445. case Qt::Key_CapsLock:
  446. return Settings::NativeKeyboard::CapsLock;
  447. case Qt::Key_F1:
  448. return Settings::NativeKeyboard::F1;
  449. case Qt::Key_F2:
  450. return Settings::NativeKeyboard::F2;
  451. case Qt::Key_F3:
  452. return Settings::NativeKeyboard::F3;
  453. case Qt::Key_F4:
  454. return Settings::NativeKeyboard::F4;
  455. case Qt::Key_F5:
  456. return Settings::NativeKeyboard::F5;
  457. case Qt::Key_F6:
  458. return Settings::NativeKeyboard::F6;
  459. case Qt::Key_F7:
  460. return Settings::NativeKeyboard::F7;
  461. case Qt::Key_F8:
  462. return Settings::NativeKeyboard::F8;
  463. case Qt::Key_F9:
  464. return Settings::NativeKeyboard::F9;
  465. case Qt::Key_F10:
  466. return Settings::NativeKeyboard::F10;
  467. case Qt::Key_F11:
  468. return Settings::NativeKeyboard::F11;
  469. case Qt::Key_F12:
  470. return Settings::NativeKeyboard::F12;
  471. case Qt::Key_Print:
  472. return Settings::NativeKeyboard::PrintScreen;
  473. case Qt::Key_ScrollLock:
  474. return Settings::NativeKeyboard::ScrollLock;
  475. case Qt::Key_Pause:
  476. return Settings::NativeKeyboard::Pause;
  477. case Qt::Key_Insert:
  478. return Settings::NativeKeyboard::Insert;
  479. case Qt::Key_Home:
  480. return Settings::NativeKeyboard::Home;
  481. case Qt::Key_PageUp:
  482. return Settings::NativeKeyboard::PageUp;
  483. case Qt::Key_Delete:
  484. return Settings::NativeKeyboard::Delete;
  485. case Qt::Key_End:
  486. return Settings::NativeKeyboard::End;
  487. case Qt::Key_PageDown:
  488. return Settings::NativeKeyboard::PageDown;
  489. case Qt::Key_Right:
  490. return Settings::NativeKeyboard::Right;
  491. case Qt::Key_Left:
  492. return Settings::NativeKeyboard::Left;
  493. case Qt::Key_Down:
  494. return Settings::NativeKeyboard::Down;
  495. case Qt::Key_Up:
  496. return Settings::NativeKeyboard::Up;
  497. case Qt::Key_NumLock:
  498. return Settings::NativeKeyboard::NumLock;
  499. // Numpad keys are missing here
  500. case Qt::Key_F13:
  501. return Settings::NativeKeyboard::F13;
  502. case Qt::Key_F14:
  503. return Settings::NativeKeyboard::F14;
  504. case Qt::Key_F15:
  505. return Settings::NativeKeyboard::F15;
  506. case Qt::Key_F16:
  507. return Settings::NativeKeyboard::F16;
  508. case Qt::Key_F17:
  509. return Settings::NativeKeyboard::F17;
  510. case Qt::Key_F18:
  511. return Settings::NativeKeyboard::F18;
  512. case Qt::Key_F19:
  513. return Settings::NativeKeyboard::F19;
  514. case Qt::Key_F20:
  515. return Settings::NativeKeyboard::F20;
  516. case Qt::Key_F21:
  517. return Settings::NativeKeyboard::F21;
  518. case Qt::Key_F22:
  519. return Settings::NativeKeyboard::F22;
  520. case Qt::Key_F23:
  521. return Settings::NativeKeyboard::F23;
  522. case Qt::Key_F24:
  523. return Settings::NativeKeyboard::F24;
  524. // case Qt:::
  525. // return Settings::NativeKeyboard::KPComma;
  526. // case Qt:::
  527. // return Settings::NativeKeyboard::Ro;
  528. case Qt::Key_Hiragana_Katakana:
  529. return Settings::NativeKeyboard::KatakanaHiragana;
  530. case Qt::Key_yen:
  531. return Settings::NativeKeyboard::Yen;
  532. case Qt::Key_Henkan:
  533. return Settings::NativeKeyboard::Henkan;
  534. case Qt::Key_Muhenkan:
  535. return Settings::NativeKeyboard::Muhenkan;
  536. // case Qt:::
  537. // return Settings::NativeKeyboard::NumPadCommaPc98;
  538. case Qt::Key_Hangul:
  539. return Settings::NativeKeyboard::HangulEnglish;
  540. case Qt::Key_Hangul_Hanja:
  541. return Settings::NativeKeyboard::Hanja;
  542. case Qt::Key_Katakana:
  543. return Settings::NativeKeyboard::KatakanaKey;
  544. case Qt::Key_Hiragana:
  545. return Settings::NativeKeyboard::HiraganaKey;
  546. case Qt::Key_Zenkaku_Hankaku:
  547. return Settings::NativeKeyboard::ZenkakuHankaku;
  548. // Modifier keys are handled by the modifier property
  549. default:
  550. return Settings::NativeKeyboard::None;
  551. }
  552. }
  553. int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers) {
  554. int modifier = 0;
  555. if ((qt_modifiers & Qt::KeyboardModifier::ShiftModifier) != 0) {
  556. modifier |= 1 << Settings::NativeKeyboard::LeftShift;
  557. }
  558. if ((qt_modifiers & Qt::KeyboardModifier::ControlModifier) != 0) {
  559. modifier |= 1 << Settings::NativeKeyboard::LeftControl;
  560. }
  561. if ((qt_modifiers & Qt::KeyboardModifier::AltModifier) != 0) {
  562. modifier |= 1 << Settings::NativeKeyboard::LeftAlt;
  563. }
  564. if ((qt_modifiers & Qt::KeyboardModifier::MetaModifier) != 0) {
  565. modifier |= 1 << Settings::NativeKeyboard::LeftMeta;
  566. }
  567. // TODO: These keys can't be obtained with Qt::KeyboardModifier
  568. // if ((qt_modifiers & 0x10) != 0) {
  569. // modifier |= 1 << Settings::NativeKeyboard::RightShift;
  570. // }
  571. // if ((qt_modifiers & 0x20) != 0) {
  572. // modifier |= 1 << Settings::NativeKeyboard::RightControl;
  573. // }
  574. // if ((qt_modifiers & 0x40) != 0) {
  575. // modifier |= 1 << Settings::NativeKeyboard::RightAlt;
  576. // }
  577. // if ((qt_modifiers & 0x80) != 0) {
  578. // modifier |= 1 << Settings::NativeKeyboard::RightMeta;
  579. // }
  580. // if ((qt_modifiers & 0x100) != 0) {
  581. // modifier |= 1 << Settings::NativeKeyboard::CapsLock;
  582. // }
  583. // if ((qt_modifiers & 0x200) != 0) {
  584. // modifier |= 1 << Settings::NativeKeyboard::NumLock;
  585. // }
  586. // if ((qt_modifiers & ???) != 0) {
  587. // modifier |= 1 << Settings::NativeKeyboard::ScrollLock;
  588. // }
  589. // if ((qt_modifiers & ???) != 0) {
  590. // modifier |= 1 << Settings::NativeKeyboard::Katakana;
  591. // }
  592. // if ((qt_modifiers & ???) != 0) {
  593. // modifier |= 1 << Settings::NativeKeyboard::Hiragana;
  594. // }
  595. return modifier;
  596. }
  597. void GRenderWindow::keyPressEvent(QKeyEvent* event) {
  598. /**
  599. * This feature can be enhanced with the following functions, but they do not provide
  600. * cross-platform behavior.
  601. *
  602. * event->nativeVirtualKey() can distinguish between keys on the numpad.
  603. * event->nativeModifiers() can distinguish between left and right keys and numlock,
  604. * capslock, scroll lock.
  605. */
  606. if (!event->isAutoRepeat()) {
  607. const auto modifier = QtModifierToSwitchModifier(event->modifiers());
  608. const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
  609. input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
  610. input_subsystem->GetKeyboard()->PressKeyboardKey(key);
  611. // This is used for gamepads that can have any key mapped
  612. input_subsystem->GetKeyboard()->PressKey(event->key());
  613. }
  614. }
  615. void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
  616. /**
  617. * This feature can be enhanced with the following functions, but they do not provide
  618. * cross-platform behavior.
  619. *
  620. * event->nativeVirtualKey() can distinguish between keys on the numpad.
  621. * event->nativeModifiers() can distinguish between left and right buttons and numlock,
  622. * capslock, scroll lock.
  623. */
  624. if (!event->isAutoRepeat()) {
  625. const auto modifier = QtModifierToSwitchModifier(event->modifiers());
  626. const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
  627. input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
  628. input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key);
  629. // This is used for gamepads that can have any key mapped
  630. input_subsystem->GetKeyboard()->ReleaseKey(event->key());
  631. }
  632. }
  633. InputCommon::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) {
  634. switch (button) {
  635. case Qt::LeftButton:
  636. return InputCommon::MouseButton::Left;
  637. case Qt::RightButton:
  638. return InputCommon::MouseButton::Right;
  639. case Qt::MiddleButton:
  640. return InputCommon::MouseButton::Wheel;
  641. case Qt::BackButton:
  642. return InputCommon::MouseButton::Backward;
  643. case Qt::ForwardButton:
  644. return InputCommon::MouseButton::Forward;
  645. case Qt::TaskButton:
  646. return InputCommon::MouseButton::Task;
  647. default:
  648. return InputCommon::MouseButton::Extra;
  649. }
  650. }
  651. void GRenderWindow::mousePressEvent(QMouseEvent* event) {
  652. // Touch input is handled in TouchBeginEvent
  653. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  654. return;
  655. }
  656. // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse
  657. // coordinates and map them to the current render area
  658. const auto pos = mapFromGlobal(QCursor::pos());
  659. const auto [x, y] = ScaleTouch(pos);
  660. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  661. const auto button = QtButtonToMouseButton(event->button());
  662. input_subsystem->GetMouse()->PressButton(x, y, touch_x, touch_y, button);
  663. emit MouseActivity();
  664. }
  665. void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
  666. // Touch input is handled in TouchUpdateEvent
  667. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  668. return;
  669. }
  670. // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse
  671. // coordinates and map them to the current render area
  672. const auto pos = mapFromGlobal(QCursor::pos());
  673. const auto [x, y] = ScaleTouch(pos);
  674. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  675. const int center_x = width() / 2;
  676. const int center_y = height() / 2;
  677. input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, center_x, center_y);
  678. if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
  679. QCursor::setPos(mapToGlobal(QPoint{center_x, center_y}));
  680. }
  681. emit MouseActivity();
  682. }
  683. void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
  684. // Touch input is handled in TouchEndEvent
  685. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  686. return;
  687. }
  688. const auto button = QtButtonToMouseButton(event->button());
  689. input_subsystem->GetMouse()->ReleaseButton(button);
  690. }
  691. void GRenderWindow::wheelEvent(QWheelEvent* event) {
  692. const int x = event->angleDelta().x();
  693. const int y = event->angleDelta().y();
  694. input_subsystem->GetMouse()->MouseWheelChange(x, y);
  695. }
  696. void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
  697. QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
  698. for (const auto& touch_point : touch_points) {
  699. const auto [x, y] = ScaleTouch(touch_point.pos());
  700. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  701. input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id());
  702. }
  703. }
  704. void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) {
  705. QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
  706. input_subsystem->GetTouchScreen()->ClearActiveFlag();
  707. for (const auto& touch_point : touch_points) {
  708. const auto [x, y] = ScaleTouch(touch_point.pos());
  709. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  710. input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id());
  711. }
  712. input_subsystem->GetTouchScreen()->ReleaseInactiveTouch();
  713. }
  714. void GRenderWindow::TouchEndEvent() {
  715. input_subsystem->GetTouchScreen()->ReleaseAllTouch();
  716. }
  717. void GRenderWindow::InitializeCamera() {
  718. constexpr auto camera_update_ms = std::chrono::milliseconds{50}; // (50ms, 20Hz)
  719. if (!Settings::values.enable_ir_sensor) {
  720. return;
  721. }
  722. bool camera_found = false;
  723. const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
  724. for (const QCameraInfo& cameraInfo : cameras) {
  725. if (Settings::values.ir_sensor_device.GetValue() == cameraInfo.deviceName().toStdString() ||
  726. Settings::values.ir_sensor_device.GetValue() == "Auto") {
  727. camera = std::make_unique<QCamera>(cameraInfo);
  728. if (!camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder) &&
  729. !camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
  730. LOG_ERROR(Frontend,
  731. "Camera doesn't support CaptureViewfinder or CaptureStillImage");
  732. continue;
  733. }
  734. camera_found = true;
  735. break;
  736. }
  737. }
  738. if (!camera_found) {
  739. return;
  740. }
  741. camera_capture = std::make_unique<QCameraImageCapture>(camera.get());
  742. if (!camera_capture->isCaptureDestinationSupported(
  743. QCameraImageCapture::CaptureDestination::CaptureToBuffer)) {
  744. LOG_ERROR(Frontend, "Camera doesn't support saving to buffer");
  745. return;
  746. }
  747. camera_capture->setCaptureDestination(QCameraImageCapture::CaptureDestination::CaptureToBuffer);
  748. connect(camera_capture.get(), &QCameraImageCapture::imageCaptured, this,
  749. &GRenderWindow::OnCameraCapture);
  750. camera->unload();
  751. if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder)) {
  752. camera->setCaptureMode(QCamera::CaptureViewfinder);
  753. } else if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
  754. camera->setCaptureMode(QCamera::CaptureStillImage);
  755. }
  756. camera->load();
  757. camera->start();
  758. pending_camera_snapshots = 0;
  759. is_virtual_camera = false;
  760. camera_timer = std::make_unique<QTimer>();
  761. connect(camera_timer.get(), &QTimer::timeout, [this] { RequestCameraCapture(); });
  762. // This timer should be dependent of camera resolution 5ms for every 100 pixels
  763. camera_timer->start(camera_update_ms);
  764. }
  765. void GRenderWindow::FinalizeCamera() {
  766. if (camera_timer) {
  767. camera_timer->stop();
  768. }
  769. if (camera) {
  770. camera->unload();
  771. }
  772. }
  773. void GRenderWindow::RequestCameraCapture() {
  774. if (!Settings::values.enable_ir_sensor) {
  775. return;
  776. }
  777. // If the camera doesn't capture, test for virtual cameras
  778. if (pending_camera_snapshots > 5) {
  779. is_virtual_camera = true;
  780. }
  781. // Virtual cameras like obs need to reset the camera every capture
  782. if (is_virtual_camera) {
  783. camera->stop();
  784. camera->start();
  785. }
  786. pending_camera_snapshots++;
  787. camera_capture->capture();
  788. }
  789. void GRenderWindow::OnCameraCapture(int requestId, const QImage& img) {
  790. constexpr std::size_t camera_width = 320;
  791. constexpr std::size_t camera_height = 240;
  792. const auto converted =
  793. img.scaled(camera_width, camera_height, Qt::AspectRatioMode::IgnoreAspectRatio,
  794. Qt::TransformationMode::SmoothTransformation)
  795. .mirrored(false, true);
  796. std::vector<u32> camera_data{};
  797. camera_data.resize(camera_width * camera_height);
  798. std::memcpy(camera_data.data(), converted.bits(), camera_width * camera_height * sizeof(u32));
  799. input_subsystem->GetCamera()->SetCameraData(camera_width, camera_height, camera_data);
  800. pending_camera_snapshots = 0;
  801. }
  802. bool GRenderWindow::event(QEvent* event) {
  803. if (event->type() == QEvent::TouchBegin) {
  804. TouchBeginEvent(static_cast<QTouchEvent*>(event));
  805. return true;
  806. } else if (event->type() == QEvent::TouchUpdate) {
  807. TouchUpdateEvent(static_cast<QTouchEvent*>(event));
  808. return true;
  809. } else if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
  810. TouchEndEvent();
  811. return true;
  812. }
  813. return QWidget::event(event);
  814. }
  815. void GRenderWindow::focusOutEvent(QFocusEvent* event) {
  816. QWidget::focusOutEvent(event);
  817. input_subsystem->GetKeyboard()->ReleaseAllKeys();
  818. input_subsystem->GetMouse()->ReleaseAllButtons();
  819. input_subsystem->GetTouchScreen()->ReleaseAllTouch();
  820. }
  821. void GRenderWindow::resizeEvent(QResizeEvent* event) {
  822. QWidget::resizeEvent(event);
  823. OnFramebufferSizeChanged();
  824. }
  825. std::unique_ptr<Core::Frontend::GraphicsContext> GRenderWindow::CreateSharedContext() const {
  826. #ifdef HAS_OPENGL
  827. if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) {
  828. auto c = static_cast<OpenGLSharedContext*>(main_context.get());
  829. // Bind the shared contexts to the main surface in case the backend wants to take over
  830. // presentation
  831. return std::make_unique<OpenGLSharedContext>(c->GetShareContext(),
  832. child_widget->windowHandle());
  833. }
  834. #endif
  835. return std::make_unique<DummyContext>();
  836. }
  837. bool GRenderWindow::InitRenderTarget() {
  838. ReleaseRenderTarget();
  839. {
  840. // Create a dummy render widget so that Qt
  841. // places the render window at the correct position.
  842. const RenderWidget dummy_widget{this};
  843. }
  844. first_frame = false;
  845. switch (Settings::values.renderer_backend.GetValue()) {
  846. case Settings::RendererBackend::OpenGL:
  847. if (!InitializeOpenGL()) {
  848. return false;
  849. }
  850. break;
  851. case Settings::RendererBackend::Vulkan:
  852. if (!InitializeVulkan()) {
  853. return false;
  854. }
  855. break;
  856. }
  857. // Update the Window System information with the new render target
  858. window_info = GetWindowSystemInfo(child_widget->windowHandle());
  859. child_widget->resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  860. layout()->addWidget(child_widget);
  861. // Reset minimum required size to avoid resizing issues on the main window after restarting.
  862. setMinimumSize(1, 1);
  863. resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  864. OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
  865. OnFramebufferSizeChanged();
  866. BackupGeometry();
  867. if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) {
  868. if (!LoadOpenGL()) {
  869. return false;
  870. }
  871. }
  872. return true;
  873. }
  874. void GRenderWindow::ReleaseRenderTarget() {
  875. if (child_widget) {
  876. layout()->removeWidget(child_widget);
  877. child_widget->deleteLater();
  878. child_widget = nullptr;
  879. }
  880. main_context.reset();
  881. }
  882. void GRenderWindow::CaptureScreenshot(const QString& screenshot_path) {
  883. auto& renderer = system.Renderer();
  884. const f32 res_scale = Settings::values.resolution_info.up_factor;
  885. if (renderer.IsScreenshotPending()) {
  886. LOG_WARNING(Render,
  887. "A screenshot is already requested or in progress, ignoring the request");
  888. return;
  889. }
  890. const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
  891. screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
  892. renderer.RequestScreenshot(
  893. screenshot_image.bits(),
  894. [=, this](bool invert_y) {
  895. const std::string std_screenshot_path = screenshot_path.toStdString();
  896. if (screenshot_image.mirrored(false, invert_y).save(screenshot_path)) {
  897. LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
  898. } else {
  899. LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
  900. }
  901. },
  902. layout);
  903. }
  904. bool GRenderWindow::IsLoadingComplete() const {
  905. return first_frame;
  906. }
  907. void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
  908. setMinimumSize(minimal_size.first, minimal_size.second);
  909. }
  910. bool GRenderWindow::InitializeOpenGL() {
  911. #ifdef HAS_OPENGL
  912. // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground,
  913. // WA_DontShowOnScreen, WA_DeleteOnClose
  914. auto child = new OpenGLRenderWidget(this);
  915. child_widget = child;
  916. child_widget->windowHandle()->create();
  917. auto context = std::make_shared<OpenGLSharedContext>(child->windowHandle());
  918. main_context = context;
  919. child->SetContext(
  920. std::make_unique<OpenGLSharedContext>(context->GetShareContext(), child->windowHandle()));
  921. return true;
  922. #else
  923. QMessageBox::warning(this, tr("OpenGL not available!"),
  924. tr("yuzu has not been compiled with OpenGL support."));
  925. return false;
  926. #endif
  927. }
  928. bool GRenderWindow::InitializeVulkan() {
  929. auto child = new VulkanRenderWidget(this);
  930. child_widget = child;
  931. child_widget->windowHandle()->create();
  932. main_context = std::make_unique<DummyContext>();
  933. return true;
  934. }
  935. bool GRenderWindow::LoadOpenGL() {
  936. auto context = CreateSharedContext();
  937. auto scope = context->Acquire();
  938. if (!gladLoadGL()) {
  939. QMessageBox::warning(
  940. this, tr("Error while initializing OpenGL!"),
  941. tr("Your GPU may not support OpenGL, or you do not have the latest graphics driver."));
  942. return false;
  943. }
  944. const QString renderer =
  945. QString::fromUtf8(reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
  946. if (!GLAD_GL_VERSION_4_6) {
  947. LOG_ERROR(Frontend, "GPU does not support OpenGL 4.6: {}", renderer.toStdString());
  948. QMessageBox::warning(this, tr("Error while initializing OpenGL 4.6!"),
  949. tr("Your GPU may not support OpenGL 4.6, or you do not have the "
  950. "latest graphics driver.<br><br>GL Renderer:<br>%1")
  951. .arg(renderer));
  952. return false;
  953. }
  954. QStringList unsupported_gl_extensions = GetUnsupportedGLExtensions();
  955. if (!unsupported_gl_extensions.empty()) {
  956. QMessageBox::warning(
  957. this, tr("Error while initializing OpenGL!"),
  958. tr("Your GPU may not support one or more required OpenGL extensions. Please ensure you "
  959. "have the latest graphics driver.<br><br>GL Renderer:<br>%1<br><br>Unsupported "
  960. "extensions:<br>%2")
  961. .arg(renderer)
  962. .arg(unsupported_gl_extensions.join(QStringLiteral("<br>"))));
  963. return false;
  964. }
  965. return true;
  966. }
  967. QStringList GRenderWindow::GetUnsupportedGLExtensions() const {
  968. QStringList unsupported_ext;
  969. // Extensions required to support some texture formats.
  970. if (!GLAD_GL_EXT_texture_compression_s3tc) {
  971. unsupported_ext.append(QStringLiteral("EXT_texture_compression_s3tc"));
  972. }
  973. if (!GLAD_GL_ARB_texture_compression_rgtc) {
  974. unsupported_ext.append(QStringLiteral("ARB_texture_compression_rgtc"));
  975. }
  976. if (!unsupported_ext.empty()) {
  977. const std::string gl_renderer{reinterpret_cast<const char*>(glGetString(GL_RENDERER))};
  978. LOG_ERROR(Frontend, "GPU does not support all required extensions: {}", gl_renderer);
  979. }
  980. for (const QString& ext : unsupported_ext) {
  981. LOG_ERROR(Frontend, "Unsupported GL extension: {}", ext.toStdString());
  982. }
  983. return unsupported_ext;
  984. }
  985. void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread_) {
  986. emu_thread = emu_thread_;
  987. }
  988. void GRenderWindow::OnEmulationStopping() {
  989. emu_thread = nullptr;
  990. }
  991. void GRenderWindow::showEvent(QShowEvent* event) {
  992. QWidget::showEvent(event);
  993. // windowHandle() is not initialized until the Window is shown, so we connect it here.
  994. connect(windowHandle(), &QWindow::screenChanged, this, &GRenderWindow::OnFramebufferSizeChanged,
  995. Qt::UniqueConnection);
  996. }
  997. bool GRenderWindow::eventFilter(QObject* object, QEvent* event) {
  998. if (event->type() == QEvent::HoverMove) {
  999. if (Settings::values.mouse_panning || Settings::values.mouse_enabled) {
  1000. auto* hover_event = static_cast<QMouseEvent*>(event);
  1001. mouseMoveEvent(hover_event);
  1002. return false;
  1003. }
  1004. emit MouseActivity();
  1005. }
  1006. return false;
  1007. }