From fd0617f3aed358d10c08b0aa2dcfa3da2542e2c0 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Mon, 21 Apr 2025 14:24:21 +0300 Subject: [PATCH] Cleanup --- .../Vulkan/Linux/LinuxVulkanPlatform.cpp | 11 +++++------ Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp | 6 +++--- Source/Engine/Platform/SDL/SDLWindow.cpp | 10 ---------- Source/Engine/Platform/SDL/SDLWindow.h | 13 ++++--------- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.cpp b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.cpp index 272f8e226..d8912a767 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.cpp @@ -41,22 +41,21 @@ void LinuxVulkanPlatform::CreateSurface(Window* window, GPUDeviceVulkan* device, VALIDATE_VULKAN_RESULT(vkCreateXlibSurfaceKHR(instance, &surfaceCreateInfo, nullptr, surface)); #else SDLWindow* sdlWindow = static_cast(window); - X11::Window x11Window = (X11::Window)sdlWindow->GetX11WindowHandle(); - wl_surface* waylandSurface = (wl_surface*)sdlWindow->GetWaylandSurfacePtr(); - if (waylandSurface != nullptr) + void* windowHandle = window->GetNativePtr(); + if (SDLPlatform::UsesWayland()) { VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo; RenderToolsVulkan::ZeroStruct(surfaceCreateInfo, VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR); surfaceCreateInfo.display = (wl_display*)sdlWindow->GetWaylandDisplay(); - surfaceCreateInfo.surface = waylandSurface; + surfaceCreateInfo.surface = (wl_surface*)windowHandle; VALIDATE_VULKAN_RESULT(vkCreateWaylandSurfaceKHR(instance, &surfaceCreateInfo, nullptr, surface)); } - else if (x11Window != 0) + else if (SDLPlatform::UsesX11()) { VkXlibSurfaceCreateInfoKHR surfaceCreateInfo; RenderToolsVulkan::ZeroStruct(surfaceCreateInfo, VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR); surfaceCreateInfo.dpy = (X11::Display*)sdlWindow->GetX11Display(); - surfaceCreateInfo.window = x11Window; + surfaceCreateInfo.window = (X11::Window)windowHandle; VALIDATE_VULKAN_RESULT(vkCreateXlibSurfaceKHR(instance, &surfaceCreateInfo, nullptr, surface)); } #endif diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp index c72d573a0..168653ff0 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp @@ -656,7 +656,7 @@ DragDropEffect Window::DoDragDropX11(const StringView& data) #if !PLATFORM_SDL X11::Window mainWindow = _window; #else - X11::Window mainWindow = static_cast(GetX11WindowHandle()); + X11::Window mainWindow = reinterpret_cast(GetNativePtr()); #endif // Make sure SDL hasn't grabbed the pointer, and force ungrab it @@ -1105,7 +1105,7 @@ void SDLClipboard::SetText(const StringView& text) if (X11Impl::xDisplay) { - X11::Window window = (X11::Window)(mainWindow->GetX11WindowHandle()); + X11::Window window = (X11::Window)(mainWindow->GetNativePtr()); X11Impl::ClipboardText.Set(text.Get(), text.Length()); X11::XSetSelectionOwner(X11Impl::xDisplay, X11Impl::xAtomClipboard, window, CurrentTime); // CLIPBOARD //X11::XSetSelectionOwner(xDisplay, xAtomPrimary, window, CurrentTime); // XA_PRIMARY @@ -1135,7 +1135,7 @@ String SDLClipboard::GetText() return result; if (X11Impl::xDisplay) { - X11::Window window = static_cast(mainWindow->GetX11WindowHandle()); + X11::Window window = reinterpret_cast(mainWindow->GetNativePtr()); X11Impl::ClipboardGetText(result, X11Impl::xAtomClipboard, X11Impl::xAtomUTF8String, window); if (result.HasChars()) diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index 9aa05a5e4..37d89a211 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -221,21 +221,11 @@ SDL_Window* SDLWindow::GetSDLWindow() const #if PLATFORM_LINUX -void* SDLWindow::GetWaylandSurfacePtr() const -{ - return SDL_GetPointerProperty(SDL_GetWindowProperties(_window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, nullptr); -} - void* SDLWindow::GetWaylandDisplay() const { return SDL_GetPointerProperty(SDL_GetWindowProperties(_window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr); } -uintptr SDLWindow::GetX11WindowHandle() const -{ - return (uintptr)SDL_GetNumberProperty(SDL_GetWindowProperties(_window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); -} - void* SDLWindow::GetX11Display() const { return SDL_GetPointerProperty(SDL_GetWindowProperties(_window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr); diff --git a/Source/Engine/Platform/SDL/SDLWindow.h b/Source/Engine/Platform/SDL/SDLWindow.h index 8e00cd950..70b9ff354 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.h +++ b/Source/Engine/Platform/SDL/SDLWindow.h @@ -56,7 +56,6 @@ public: ~SDLWindow(); private: - static SDLWindow* GetWindowFromEvent(const SDL_Event& event); static SDLWindow* GetWindowWithSDLWindow(SDL_Window* window); void HandleEvent(SDL_Event& event); @@ -64,18 +63,10 @@ private: void CheckForWindowResize(); void UpdateCursor(); -#if PLATFORM_LINUX - DragDropEffect DoDragDropWayland(const StringView& data, Window* dragSourceWindow = nullptr, Float2 dragOffset = Float2::Zero); - DragDropEffect DoDragDropX11(const StringView& data); -#endif - public: - SDL_Window* GetSDLWindow() const; #if PLATFORM_LINUX - void* GetWaylandSurfacePtr() const; void* GetWaylandDisplay() const; - uintptr GetX11WindowHandle() const; void* GetX11Display() const; #endif @@ -128,6 +119,10 @@ public: Windows::HRESULT __stdcall DragLeave() override; Windows::HRESULT __stdcall Drop(Windows::IDataObject* pDataObj, Windows::DWORD grfKeyState, Windows::POINTL pt, Windows::DWORD* pdwEffect) override; #endif +#if PLATFORM_LINUX + DragDropEffect DoDragDropWayland(const StringView& data, Window* dragSourceWindow = nullptr, Float2 dragOffset = Float2::Zero); + DragDropEffect DoDragDropX11(const StringView& data); +#endif }; #endif