From 12a2c02379807151047c4fd918153450f9098ce6 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:41:40 +0100 Subject: [PATCH] Avoid Wayland window position queries --- simulate/glfw_adapter.cc | 16 ++++++++++++++-- simulate/glfw_dispatch.cc | 3 +++ simulate/glfw_dispatch.h | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/simulate/glfw_adapter.cc b/simulate/glfw_adapter.cc index 6bae8822cf4..5e79d4d2ea3 100644 --- a/simulate/glfw_adapter.cc +++ b/simulate/glfw_adapter.cc @@ -42,6 +42,14 @@ int MaybeGlfwInit() { GlfwAdapter& GlfwAdapterFromWindow(GLFWwindow* window) { return *static_cast(Glfw().glfwGetWindowUserPointer(window)); } + +bool WindowPositionAvailable() { +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4) + return Glfw().glfwGetPlatform() != GLFW_PLATFORM_WAYLAND; +#else + return true; +#endif +} } // namespace GlfwAdapter::GlfwAdapter() { @@ -65,7 +73,9 @@ GlfwAdapter::GlfwAdapter() { } // save window position and size - Glfw().glfwGetWindowPos(window_, &window_pos_.first, &window_pos_.second); + if (WindowPositionAvailable()) { + Glfw().glfwGetWindowPos(window_, &window_pos_.first, &window_pos_.second); + } Glfw().glfwGetWindowSize(window_, &window_size_.first, &window_size_.second); // set callbacks @@ -193,7 +203,9 @@ void GlfwAdapter::ToggleFullscreen() { // currently windowed: switch to full screen else { // save window data - Glfw().glfwGetWindowPos(window_, &window_pos_.first, &window_pos_.second); + if (WindowPositionAvailable()) { + Glfw().glfwGetWindowPos(window_, &window_pos_.first, &window_pos_.second); + } Glfw().glfwGetWindowSize(window_, &window_size_.first, &window_size_.second); diff --git a/simulate/glfw_dispatch.cc b/simulate/glfw_dispatch.cc index cc408e343d3..d5bbc0eb42e 100644 --- a/simulate/glfw_dispatch.cc +++ b/simulate/glfw_dispatch.cc @@ -86,6 +86,9 @@ const struct Glfw& Glfw(void* dlhandle) { mjGLFW_INITIALIZE_SYMBOL(glfwGetKey); mjGLFW_INITIALIZE_SYMBOL(glfwGetMonitorPhysicalSize); mjGLFW_INITIALIZE_SYMBOL(glfwGetMouseButton); +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4) + mjGLFW_INITIALIZE_SYMBOL(glfwGetPlatform); +#endif mjGLFW_INITIALIZE_SYMBOL(glfwGetPrimaryMonitor); mjGLFW_INITIALIZE_SYMBOL(glfwGetTime); mjGLFW_INITIALIZE_SYMBOL(glfwGetVideoMode); diff --git a/simulate/glfw_dispatch.h b/simulate/glfw_dispatch.h index f3bec97e28e..87cc75bab7e 100644 --- a/simulate/glfw_dispatch.h +++ b/simulate/glfw_dispatch.h @@ -36,6 +36,9 @@ struct Glfw { mjGLFW_DECLARE_SYMBOL(glfwGetKey); mjGLFW_DECLARE_SYMBOL(glfwGetMonitorPhysicalSize); mjGLFW_DECLARE_SYMBOL(glfwGetMouseButton); +#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4) + mjGLFW_DECLARE_SYMBOL(glfwGetPlatform); +#endif mjGLFW_DECLARE_SYMBOL(glfwGetPrimaryMonitor); mjGLFW_DECLARE_SYMBOL(glfwGetTime); mjGLFW_DECLARE_SYMBOL(glfwGetVideoMode);