Use an id for keyboard focus tracking as well

This commit is contained in:
Kovid Goyal 2021-01-29 11:22:39 +05:30
parent 0443e5ad7f
commit 6d18223f17
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 10 deletions

14
glfw/wl_init.c vendored
View File

@ -393,7 +393,7 @@ static void keyboardHandleEnter(void* data UNUSED,
}
_glfw.wl.serial = serial;
_glfw.wl.keyboardFocus = window;
_glfw.wl.keyboardFocusId = window->id;
_glfwInputWindowFocus(window, true);
uint32_t* key;
if (keys && _glfw.wl.keyRepeatInfo.key) {
@ -411,21 +411,23 @@ static void keyboardHandleLeave(void* data UNUSED,
uint32_t serial,
struct wl_surface* surface UNUSED)
{
_GLFWwindow* window = _glfw.wl.keyboardFocus;
_GLFWwindow* window = _glfwWindowForId(_glfw.wl.keyboardFocusId);
if (!window)
return;
_glfw.wl.serial = serial;
_glfw.wl.keyboardFocus = NULL;
_glfw.wl.keyboardFocusId = 0;
_glfwInputWindowFocus(window, false);
toggleTimer(&_glfw.wl.eventLoopData, _glfw.wl.keyRepeatInfo.keyRepeatTimer, 0);
}
static void
dispatchPendingKeyRepeats(id_type timer_id UNUSED, void *data UNUSED) {
if ((!_glfw.wl.keyboardFocus || _glfw.wl.keyRepeatInfo.keyboardFocusId != _glfw.wl.keyboardFocus->id) || _glfw.wl.keyboardRepeatRate == 0) return;
glfw_xkb_handle_key_event(_glfw.wl.keyboardFocus, &_glfw.wl.xkb, _glfw.wl.keyRepeatInfo.key, GLFW_REPEAT);
if (_glfw.wl.keyRepeatInfo.keyboardFocusId != _glfw.wl.keyboardFocusId || _glfw.wl.keyboardRepeatRate == 0) return;
_GLFWwindow* window = _glfwWindowForId(_glfw.wl.keyboardFocusId);
if (!window) return;
glfw_xkb_handle_key_event(window, &_glfw.wl.xkb, _glfw.wl.keyRepeatInfo.key, GLFW_REPEAT);
changeTimerInterval(&_glfw.wl.eventLoopData, _glfw.wl.keyRepeatInfo.keyRepeatTimer, (s_to_monotonic_t(1ll) / (monotonic_t)_glfw.wl.keyboardRepeatRate));
toggleTimer(&_glfw.wl.eventLoopData, _glfw.wl.keyRepeatInfo.keyRepeatTimer, 1);
}
@ -438,7 +440,7 @@ static void keyboardHandleKey(void* data UNUSED,
uint32_t key,
uint32_t state)
{
_GLFWwindow* window = _glfw.wl.keyboardFocus;
_GLFWwindow* window = _glfwWindowForId(_glfw.wl.keyboardFocusId);
if (!window)
return;
int action = state == WL_KEYBOARD_KEY_STATE_PRESSED ? GLFW_PRESS : GLFW_RELEASE;

2
glfw/wl_platform.h vendored
View File

@ -237,7 +237,7 @@ typedef struct _GLFWlibraryWayland
_GLFWDBUSData dbus;
_GLFWwindow* pointerFocus;
_GLFWwindow* keyboardFocus;
GLFWid keyboardFocusId;
struct {
void* handle;

9
glfw/wl_window.c vendored
View File

@ -942,11 +942,14 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
_glfw.wl.pointerFocus = NULL;
_glfwInputCursorEnter(window, false);
}
if (window == _glfw.wl.keyboardFocus)
if (window->id == _glfw.wl.keyboardFocusId)
{
_glfw.wl.keyboardFocus = NULL;
_glfw.wl.keyboardFocusId = 0;
_glfwInputWindowFocus(window, false);
}
if (window->id == _glfw.wl.keyRepeatInfo.keyboardFocusId) {
_glfw.wl.keyRepeatInfo.keyboardFocusId = 0;
}
if (window->wl.idleInhibitor)
zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor);
@ -1198,7 +1201,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
return _glfw.wl.keyboardFocus == window;
return _glfw.wl.keyboardFocusId = window ? window->id : 0;
}
int _glfwPlatformWindowOccluded(_GLFWwindow* window UNUSED)