From cf45ae04b83919d3ef97248a6454f799db2e80fc Mon Sep 17 00:00:00 2001 From: Filippo Luca Ferretti Date: Fri, 20 Dec 2024 17:55:44 +0100 Subject: [PATCH] Add support for Wayland in `iDynTree::Visualizer` --- src/visualization/src/Visualizer.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/visualization/src/Visualizer.cpp b/src/visualization/src/Visualizer.cpp index d76f7311f0..1e24f6c028 100644 --- a/src/visualization/src/Visualizer.cpp +++ b/src/visualization/src/Visualizer.cpp @@ -26,6 +26,7 @@ #define GLFW_EXPOSE_NATIVE_NSGL #elif defined(__linux__) #define GLFW_EXPOSE_NATIVE_X11 + #define GLFW_EXPOSE_NATIVE_WAYLAND #define GLFW_EXPOSE_NATIVE_GLX #endif @@ -162,7 +163,7 @@ struct Visualizer::VisualizerPimpl #elif defined(__APPLE__) id m_windowId; #elif defined(__linux__) - Window m_windowId; + void* m_windowId; // Pointer to either wl_surface* or X11 Window #endif #endif @@ -505,8 +506,22 @@ bool Visualizer::init(const VisualizerOptions &visualizerOptions) pimpl->m_windowId = glfwGetCocoaWindow(pimpl->m_window); irrDevParams.WindowId = (void*)(pimpl->m_windowId); #elif defined(__linux__) - pimpl->m_windowId = glfwGetX11Window(pimpl->m_window); - irrDevParams.WindowId = (void*)(pimpl->m_windowId); + void* nativeWindow = nullptr; + + // Try Wayland first + struct wl_surface* waylandWindow = glfwGetWaylandWindow(pimpl->m_window); + if (waylandWindow) + { + nativeWindow = static_cast(waylandWindow); + } + else + { + // Fallback to X11 + Window x11Window = glfwGetX11Window(pimpl->m_window); + if (x11Window) + nativeWindow = static_cast(reinterpret_cast(x11Window)); + } + irrDevParams.WindowId = nativeWindow; #endif irrDevParams.DeviceType = irr::EIDT_SDL;