From 938ec204f57fdc81b5dc7d507ac5dde9fcb1af65 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Thu, 2 Feb 2023 05:41:41 -0800 Subject: [PATCH] qt: Fix paintEvent not being called until window resize on macOS. (#25) * qt: Remove need for AppleSurfaceHelper. * qt: Fix paintEvent not being called until window resize on macOS. --- src/citra_qt/CMakeLists.txt | 2 -- src/citra_qt/applesurfacehelper.h | 11 ----------- src/citra_qt/applesurfacehelper.mm | 16 --------------- src/citra_qt/bootmanager.cpp | 31 +++++++++++++++++------------- src/citra_qt/main.cpp | 4 ---- 5 files changed, 18 insertions(+), 46 deletions(-) delete mode 100644 src/citra_qt/applesurfacehelper.h delete mode 100644 src/citra_qt/applesurfacehelper.mm diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 48c7e9d4f..d139594f0 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -250,8 +250,6 @@ if (APPLE) set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE TRUE) set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) target_sources(citra-qt PRIVATE - applesurfacehelper.h - applesurfacehelper.mm macos_authorization.h macos_authorization.mm ) diff --git a/src/citra_qt/applesurfacehelper.h b/src/citra_qt/applesurfacehelper.h deleted file mode 100644 index 4839747d4..000000000 --- a/src/citra_qt/applesurfacehelper.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2022 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -namespace AppleSurfaceHelper { - -void* GetSurfaceLayer(void* surface); - -} // namespace AppleSurfaceHelper diff --git a/src/citra_qt/applesurfacehelper.mm b/src/citra_qt/applesurfacehelper.mm deleted file mode 100644 index a6fc11b39..000000000 --- a/src/citra_qt/applesurfacehelper.mm +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#import - -#include "citra_qt/applesurfacehelper.h" - -namespace AppleSurfaceHelper { - -void* GetSurfaceLayer(void* surface) { - NSView* view = static_cast(surface); - return view.layer; -} - -} // namespace AppleSurfaceHelper diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index fd34d084f..9a8423059 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -25,7 +25,8 @@ #include "video_core/video_core.h" #if defined(__APPLE__) -#include "citra_qt/applesurfacehelper.h" +#include +#include #endif #if !defined(WIN32) @@ -351,22 +352,26 @@ static Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window Frontend::EmuWindow::WindowSystemInfo wsi; wsi.type = GetWindowSystemType(); - // Our Win32 Qt external doesn't have the private API. + if (window) { #if defined(WIN32) - wsi.render_surface = window ? reinterpret_cast(window->winId()) : nullptr; + // Our Win32 Qt external doesn't have the private API. + wsi.render_surface = reinterpret_cast(window->winId()); #elif defined(__APPLE__) - wsi.render_surface = - window ? AppleSurfaceHelper::GetSurfaceLayer(reinterpret_cast(window->winId())) - : nullptr; + wsi.render_surface = reinterpret_cast(objc_msgSend)( + reinterpret_cast(window->winId()), sel_registerName("layer")); #else - QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); - wsi.display_connection = pni->nativeResourceForWindow("display", window); - if (wsi.type == Frontend::WindowSystemType::Wayland) - wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr; - else - wsi.render_surface = window ? reinterpret_cast(window->winId()) : nullptr; + QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); + wsi.display_connection = pni->nativeResourceForWindow("display", window); + if (wsi.type == Frontend::WindowSystemType::Wayland) + wsi.render_surface = pni->nativeResourceForWindow("surface", window); + else + wsi.render_surface = reinterpret_cast(window->winId()); #endif - wsi.render_surface_scale = window ? static_cast(window->devicePixelRatio()) : 1.0f; + wsi.render_surface_scale = static_cast(window->devicePixelRatio()); + } else { + wsi.render_surface = nullptr; + wsi.render_surface_scale = 1.0f; + } return wsi; } diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index dd4ad6857..c80e382ad 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1184,10 +1184,6 @@ void GMainWindow::BootGame(const QString& filename) { setMouseTracking(true); } - // show and hide the render_window to create the context - render_window->show(); - render_window->hide(); - loading_screen->Prepare(Core::System::GetInstance().GetAppLoader()); loading_screen->show();