diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp index 12ad07f02..8322c1a37 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp @@ -17,8 +17,12 @@ #include #include #include -#include + +// Wayland +wl_display* WaylandDisplay = nullptr; + +// X11 Delegate LinuxPlatform::xEventReceived; // Missing Wayland features: @@ -29,8 +33,6 @@ Delegate LinuxPlatform::xEventReceived; namespace { - bool UseWayland = false; - bool UseXWayland = false; X11::Display* xDisplay = nullptr; X11::XIM IM = nullptr; X11::XIC IC = nullptr; @@ -246,7 +248,7 @@ DragDropEffect Window::DoDragDrop(const StringView& data) if (CommandLine::Options.Headless) return DragDropEffect::None; - if (UseWayland) + if (SDLPlatform::UsesWayland()) return DoDragDropWayland(data); else return DoDragDropX11(data); @@ -847,20 +849,12 @@ bool SDLPlatform::InitPlatform() if (LinuxPlatform::Init()) return true; - if (!CommandLine::Options.Headless) - { - UseWayland = strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0; - String waylandDisplay; - if (/*!UseWayland &&*/ !Platform::GetEnvironmentVariable(TEXT("WAYLAND_DISPLAY"), waylandDisplay)) - UseXWayland = waylandDisplay.Length() > 1; - } - return false; } bool SDLPlatform::InitPlatformX11(void* display) { - if (xDisplay || UseWayland) + if (xDisplay || WaylandDisplay) return false; // The Display instance must be the same one SDL uses internally @@ -921,17 +915,22 @@ void SDLPlatform::SetHighDpiAwarenessEnabled(bool enable) bool SDLPlatform::UsesWayland() { - return UseWayland; + return WaylandDisplay != nullptr; } bool SDLPlatform::UsesXWayland() { - return UseXWayland; + static bool foundWaylandDisplay = [] + { + String waylandDisplay; + return !GetEnvironmentVariable(TEXT("WAYLAND_DISPLAY"), waylandDisplay) && waylandDisplay.Length() > 0; + }(); + return xDisplay != nullptr && foundWaylandDisplay; } bool SDLPlatform::UsesX11() { - return !UseWayland; + return xDisplay != nullptr; } #endif