Cleanup Linux SDL implementation

This commit is contained in:
2025-01-03 17:13:01 +02:00
parent 5b8c81dfac
commit c658dd72e7

View File

@@ -17,8 +17,12 @@
#include <SDL3/SDL_video.h> #include <SDL3/SDL_video.h>
#include <SDL3/SDL_system.h> #include <SDL3/SDL_system.h>
#include <SDL3/SDL_hints.h> #include <SDL3/SDL_hints.h>
#include <SDL3/SDL_timer.h>
// Wayland
wl_display* WaylandDisplay = nullptr;
// X11
Delegate<void*> LinuxPlatform::xEventReceived; Delegate<void*> LinuxPlatform::xEventReceived;
// Missing Wayland features: // Missing Wayland features:
@@ -29,7 +33,6 @@ Delegate<void*> LinuxPlatform::xEventReceived;
namespace namespace
{ {
bool UseWayland = false;
X11::Display* xDisplay = nullptr; X11::Display* xDisplay = nullptr;
X11::XIM IM = nullptr; X11::XIM IM = nullptr;
X11::XIC IC = nullptr; X11::XIC IC = nullptr;
@@ -245,7 +248,7 @@ DragDropEffect Window::DoDragDrop(const StringView& data)
if (CommandLine::Options.Headless) if (CommandLine::Options.Headless)
return DragDropEffect::None; return DragDropEffect::None;
if (UseWayland) if (SDLPlatform::UsesWayland())
return DoDragDropWayland(data); return DoDragDropWayland(data);
else else
return DoDragDropX11(data); return DoDragDropX11(data);
@@ -846,15 +849,12 @@ bool SDLPlatform::InitPlatform()
if (LinuxPlatform::Init()) if (LinuxPlatform::Init())
return true; return true;
if (!CommandLine::Options.Headless)
UseWayland = strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
return false; return false;
} }
bool SDLPlatform::InitPlatformX11(void* display) bool SDLPlatform::InitPlatformX11(void* display)
{ {
if (xDisplay || UseWayland) if (xDisplay || WaylandDisplay)
return false; return false;
// The Display instance must be the same one SDL uses internally // The Display instance must be the same one SDL uses internally
@@ -915,12 +915,12 @@ void SDLPlatform::SetHighDpiAwarenessEnabled(bool enable)
bool SDLPlatform::UsesWayland() bool SDLPlatform::UsesWayland()
{ {
return UseWayland; return WaylandDisplay != nullptr;
} }
bool SDLPlatform::UsesX11() bool SDLPlatform::UsesX11()
{ {
return !UseWayland; return xDisplay != nullptr;
} }
#endif #endif