diff --git a/src/wl_init.c b/src/wl_init.c index 53638470..b8d5d0d1 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "xkb_unicode.h" @@ -56,7 +55,10 @@ static void pointerHandleLeave(void* data, uint32_t serial, struct wl_surface* surface) { - _GLFWwindow* window = wl_surface_get_user_data(surface); + _GLFWwindow* window = _glfw.wl.pointerFocus; + + if (!window) + return; _glfw.wl.pointerFocus = NULL; _glfwInputCursorEnter(window, GL_FALSE); @@ -70,6 +72,9 @@ static void pointerHandleMotion(void* data, { _GLFWwindow* window = _glfw.wl.pointerFocus; + if (!window) + return; + if (window->cursorMode == GLFW_CURSOR_DISABLED) { /* TODO */ @@ -93,6 +98,9 @@ static void pointerHandleButton(void* data, _GLFWwindow* window = _glfw.wl.pointerFocus; int glfwButton; + if (!window) + return; + /* Makes left, right and middle 0, 1 and 2. Overall order follows evdev * codes. */ glfwButton = button - BTN_LEFT; @@ -115,6 +123,9 @@ static void pointerHandleAxis(void* data, double scroll_factor; double x, y; + if (!window) + return; + /* Wayland scroll events are in pointer motion coordinate space (think * two finger scroll). The factor 10 is commonly used to convert to * "scroll step means 1.0. */ @@ -224,6 +235,9 @@ static void keyboardHandleLeave(void* data, { _GLFWwindow* window = _glfw.wl.keyboardFocus; + if (!window) + return; + _glfw.wl.keyboardFocus = NULL; _glfwInputWindowFocus(window, GL_FALSE); } @@ -366,6 +380,9 @@ static void keyboardHandleKey(void* data, const xkb_keysym_t *syms; _GLFWwindow* window = _glfw.wl.keyboardFocus; + if (!window) + return; + keyCode = toGLFWKeyCode(key); action = state == WL_KEYBOARD_KEY_STATE_PRESSED ? GLFW_PRESS : GLFW_RELEASE; diff --git a/src/wl_window.c b/src/wl_window.c index 6b5b08ee..25a533bc 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -127,6 +127,17 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, void _glfwPlatformDestroyWindow(_GLFWwindow* window) { + if (window == _glfw.wl.pointerFocus) + { + _glfw.wl.pointerFocus = NULL; + _glfwInputCursorEnter(window, GL_FALSE); + } + if (window == _glfw.wl.keyboardFocus) + { + _glfw.wl.keyboardFocus = NULL; + _glfwInputWindowFocus(window, GL_FALSE); + } + _glfwDestroyContext(window); if (window->wl.native)