[Bf-blender-cvs] [d20bad914e3] master: Fix key repeat continuing after a window loses focus for GHOST/Wayland

Campbell Barton noreply at git.blender.org
Thu Jun 23 07:40:19 CEST 2022


Commit: d20bad914e310f93f53dba4decf6e1e534a08345
Author: Campbell Barton
Date:   Thu Jun 23 15:38:43 2022 +1000
Branches: master
https://developer.blender.org/rBd20bad914e310f93f53dba4decf6e1e534a08345

Fix key repeat continuing after a window loses focus for GHOST/Wayland

Also remove NULL checks in keyboard enter/leave handlers,
as they didn't serve any purpose.

===================================================================

M	intern/ghost/intern/GHOST_SystemWayland.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index a5359b8dd28..2adbca7ee40 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -47,6 +47,8 @@
 
 static GHOST_WindowWayland *window_from_surface(struct wl_surface *surface);
 
+static void keyboard_handle_key_repeat_cancel(struct input_t *input);
+
 /**
  * GNOME (mutter 42.2 had a bug with confine not respecting scale - Hi-DPI), See: T98793.
  * Even though this has been fixed, at time of writing it's not yet in a release.
@@ -365,9 +367,7 @@ static void display_destroy(display_t *d)
     }
     if (input->wl_keyboard) {
       if (input->key_repeat.timer) {
-        delete static_cast<key_repeat_payload_t *>(input->key_repeat.timer->getUserData());
-        input->system->removeTimer(input->key_repeat.timer);
-        input->key_repeat.timer = nullptr;
+        keyboard_handle_key_repeat_cancel(input);
       }
       wl_keyboard_destroy(input->wl_keyboard);
     }
@@ -1699,9 +1699,8 @@ static void keyboard_handle_enter(void *data,
                                   struct wl_surface *surface,
                                   struct wl_array * /*keys*/)
 {
-  if (surface != nullptr) {
-    static_cast<input_t *>(data)->focus_keyboard = surface;
-  }
+  input_t *input = static_cast<input_t *>(data);
+  input->focus_keyboard = surface;
 }
 
 /**
@@ -1713,10 +1712,14 @@ static void keyboard_handle_enter(void *data,
 static void keyboard_handle_leave(void *data,
                                   struct wl_keyboard * /*wl_keyboard*/,
                                   uint32_t /*serial*/,
-                                  struct wl_surface *surface)
+                                  struct wl_surface * /*surface*/)
 {
-  if (surface != nullptr) {
-    static_cast<input_t *>(data)->focus_keyboard = nullptr;
+  input_t *input = static_cast<input_t *>(data);
+  input->focus_keyboard = nullptr;
+
+  /* Losing focus must stop repeating text. */
+  if (input->key_repeat.timer) {
+    keyboard_handle_key_repeat_cancel(input);
   }
 }
 
@@ -1746,6 +1749,14 @@ static xkb_keysym_t xkb_state_key_get_one_sym_without_modifiers(struct xkb_state
   return sym;
 }
 
+static void keyboard_handle_key_repeat_cancel(input_t *input)
+{
+  GHOST_ASSERT(input->key_repeat.timer != nullptr, "Caller much check for timer");
+  delete static_cast<key_repeat_payload_t *>(input->key_repeat.timer->getUserData());
+  input->system->removeTimer(input->key_repeat.timer);
+  input->key_repeat.timer = nullptr;
+}
+
 /**
  * Restart the key-repeat timer.
  * \param use_delay: When false, use the interval



More information about the Bf-blender-cvs mailing list