mirror of
https://github.com/glfw/glfw.git
synced 2024-11-11 13:03:52 +00:00
wayland: Release input focus when window is destroyed
This fixes a seg. fault on the reopen test because events might occur after the window is destroyed (for example leave events).
This commit is contained in:
parent
c39ebfe1b8
commit
a7c9ca3b43
@ -33,7 +33,6 @@
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#include <wayland-cursor.h>
|
||||
|
||||
#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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user