From 09653b8c5490ebb605933537e897587c9129f159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 6 Apr 2022 21:13:48 +0200 Subject: [PATCH] Move last bits of window setup to platform code This avoids glfwCreateWindow emitting GLFW_FEATURE_UNAVAILABLE or GLFW_FEATURE_UNIMPLEMENTED on Wayland because shared code was calling unimplemented or unavailable platform functions during final setup. It also makes it consistent with the final setup of full screen windows. --- README.md | 1 + src/cocoa_window.m | 18 ++++++++++++++++++ src/null_window.c | 18 ++++++++++++++++++ src/win32_window.c | 18 ++++++++++++++++++ src/window.c | 28 ---------------------------- src/wl_window.c | 6 ++++++ src/x11_window.c | 18 ++++++++++++++++++ 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 67d57a2f..72cbef36 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: Drag and drop data was misinterpreted as clipboard string - [Wayland] Bugfix: MIME type matching was not performed for clipboard string - [Wayland] Bugfix: The OSMesa library was not unloaded on termination + - [Wayland] Bugfix: `glfwCreateWindow` could emit `GLFW_FEATURE_UNAVAILABLE` - [POSIX] Removed use of deprecated function `gettimeofday` - [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled - [WGL] Disabled the DWM swap interval hack for Windows 8 and later (#1072) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index e461b267..444bd563 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -931,13 +931,31 @@ int _glfwCreateWindowCocoa(_GLFWwindow* window, if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) return GLFW_FALSE; } + + if (!_glfwRefreshContextAttribs(window, ctxconfig)) + return GLFW_FALSE; } + if (wndconfig->mousePassthrough) + _glfwSetWindowMousePassthroughCocoa(window, GLFW_TRUE); + if (window->monitor) { _glfwShowWindowCocoa(window); _glfwFocusWindowCocoa(window); acquireMonitor(window); + + if (wndconfig->centerCursor) + _glfwCenterCursorInContentArea(window); + } + else + { + if (wndconfig->visible) + { + _glfwShowWindowCocoa(window); + if (wndconfig->focused) + _glfwFocusWindowCocoa(window); + } } return GLFW_TRUE; diff --git a/src/null_window.c b/src/null_window.c index 7e87b9da..b40110b8 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -128,13 +128,31 @@ int _glfwCreateWindowNull(_GLFWwindow* window, if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } + + if (!_glfwRefreshContextAttribs(window, ctxconfig)) + return GLFW_FALSE; } + if (wndconfig->mousePassthrough) + _glfwSetWindowMousePassthroughNull(window, GLFW_TRUE); + if (window->monitor) { _glfwShowWindowNull(window); _glfwFocusWindowNull(window); acquireMonitor(window); + + if (wndconfig->centerCursor) + _glfwCenterCursorInContentArea(window); + } + else + { + if (wndconfig->visible) + { + _glfwShowWindowNull(window); + if (wndconfig->focused) + _glfwFocusWindowNull(window); + } } return GLFW_TRUE; diff --git a/src/win32_window.c b/src/win32_window.c index 14f2fe5b..87c2b4a1 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1493,14 +1493,32 @@ int _glfwCreateWindowWin32(_GLFWwindow* window, if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) return GLFW_FALSE; } + + if (!_glfwRefreshContextAttribs(window, ctxconfig)) + return GLFW_FALSE; } + if (wndconfig->mousePassthrough) + _glfwSetWindowMousePassthroughWin32(window, GLFW_TRUE); + if (window->monitor) { _glfwShowWindowWin32(window); _glfwFocusWindowWin32(window); acquireMonitor(window); fitToMonitor(window); + + if (wndconfig->centerCursor) + _glfwCenterCursorInContentArea(window); + } + else + { + if (wndconfig->visible) + { + _glfwShowWindowWin32(window); + if (wndconfig->focused) + _glfwFocusWindowWin32(window); + } } return GLFW_TRUE; diff --git a/src/window.c b/src/window.c index a24feb60..621e2e64 100644 --- a/src/window.c +++ b/src/window.c @@ -215,40 +215,12 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->numer = GLFW_DONT_CARE; window->denom = GLFW_DONT_CARE; - // Open the actual window and create its context if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig)) { glfwDestroyWindow((GLFWwindow*) window); return NULL; } - if (ctxconfig.client != GLFW_NO_API) - { - if (!_glfwRefreshContextAttribs(window, &ctxconfig)) - { - glfwDestroyWindow((GLFWwindow*) window); - return NULL; - } - } - - if (wndconfig.mousePassthrough) - _glfw.platform.setWindowMousePassthrough(window, GLFW_TRUE); - - if (window->monitor) - { - if (wndconfig.centerCursor) - _glfwCenterCursorInContentArea(window); - } - else - { - if (wndconfig.visible) - { - _glfw.platform.showWindow(window); - if (wndconfig.focused) - _glfw.platform.focusWindow(window); - } - } - return (GLFWwindow*) window; } diff --git a/src/wl_window.c b/src/wl_window.c index 047b9eb6..a1f93185 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1730,8 +1730,14 @@ int _glfwCreateWindowWayland(_GLFWwindow* window, if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) return GLFW_FALSE; } + + if (!_glfwRefreshContextAttribs(window, ctxconfig)) + return GLFW_FALSE; } + if (wndconfig->mousePassthrough) + _glfwSetWindowMousePassthroughWayland(window, GLFW_TRUE); + return GLFW_TRUE; } diff --git a/src/x11_window.c b/src/x11_window.c index 85b844a1..280dc986 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1952,13 +1952,31 @@ int _glfwCreateWindowX11(_GLFWwindow* window, if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) return GLFW_FALSE; } + + if (!_glfwRefreshContextAttribs(window, ctxconfig)) + return GLFW_FALSE; } + if (wndconfig->mousePassthrough) + _glfwSetWindowMousePassthroughX11(window, GLFW_TRUE); + if (window->monitor) { _glfwShowWindowX11(window); updateWindowMode(window); acquireMonitor(window); + + if (wndconfig->centerCursor) + _glfwCenterCursorInContentArea(window); + } + else + { + if (wndconfig->visible) + { + _glfwShowWindowX11(window); + if (wndconfig->focused) + _glfwFocusWindowX11(window); + } } XFlush(_glfw.x11.display);