From 6d2003d07a3e502050d51b04c8b9aeb37840f4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 6 Jul 2020 23:37:33 +0200 Subject: [PATCH] Move management of shared state to shared code Platform code may not modify shared state. Related to #1568. --- src/cocoa_window.m | 1 - src/win32_window.c | 2 -- src/window.c | 21 ++++++++++++++------- src/wl_window.c | 4 ---- src/x11_window.c | 5 ----- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 84908967..81b22e2f 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1373,7 +1373,6 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enabled) { - window->mousePassthrough = enabled; @autoreleasepool { [window->ns.object setIgnoresMouseEvents:enabled]; } diff --git a/src/win32_window.c b/src/win32_window.c index c7434f9a..bc93c62a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1887,8 +1887,6 @@ void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enable if (enabled) SetLayeredWindowAttributes(window->win32.handle, key, alpha, flags); - - window->mousePassthrough = enabled; } float _glfwPlatformGetWindowOpacity(_GLFWwindow* window) diff --git a/src/window.c b/src/window.c index 94a4ac68..e706c95a 100644 --- a/src/window.c +++ b/src/window.c @@ -197,13 +197,14 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->videoMode.blueBits = fbconfig.blueBits; window->videoMode.refreshRate = _glfw.hints.refreshRate; - window->monitor = (_GLFWmonitor*) monitor; - window->resizable = wndconfig.resizable; - window->decorated = wndconfig.decorated; - window->autoIconify = wndconfig.autoIconify; - window->floating = wndconfig.floating; - window->focusOnShow = wndconfig.focusOnShow; - window->cursorMode = GLFW_CURSOR_NORMAL; + window->monitor = (_GLFWmonitor*) monitor; + window->resizable = wndconfig.resizable; + window->decorated = wndconfig.decorated; + window->autoIconify = wndconfig.autoIconify; + window->floating = wndconfig.floating; + window->focusOnShow = wndconfig.focusOnShow; + window->mousePassthrough = wndconfig.mousePassthrough; + window->cursorMode = GLFW_CURSOR_NORMAL; window->minwidth = GLFW_DONT_CARE; window->minheight = GLFW_DONT_CARE; @@ -908,7 +909,13 @@ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value) else if (attrib == GLFW_FOCUS_ON_SHOW) window->focusOnShow = value; else if (attrib == GLFW_MOUSE_PASSTHROUGH) + { + if (window->mousePassthrough == value) + return; + + window->mousePassthrough = value; _glfwPlatformSetWindowMousePassthrough(window, value); + } else _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib); } diff --git a/src/wl_window.c b/src/wl_window.c index 13d801b0..5da645dd 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1129,9 +1129,6 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enabled) { - if (enabled == window->mousePassthrough) - return; - if (enabled) { struct wl_region* region = wl_compositor_create_region(_glfw.wl.compositor); @@ -1141,7 +1138,6 @@ void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enable else wl_surface_set_input_region(window->wl.surface, 0); wl_surface_commit(window->wl.surface); - window->mousePassthrough = enabled; } float _glfwPlatformGetWindowOpacity(_GLFWwindow* window) diff --git a/src/x11_window.c b/src/x11_window.c index 88c145e1..76f1483e 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2707,9 +2707,6 @@ void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enable if (!_glfw.x11.xshape.available) return; - if (enabled == window->mousePassthrough) - return; - if (enabled) { Region region = XCreateRegion(); @@ -2722,8 +2719,6 @@ void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enable XShapeCombineMask(_glfw.x11.display, window->x11.handle, ShapeInput, 0, 0, None, ShapeSet); } - - window->mousePassthrough = enabled; } float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)