[Bf-blender-cvs] [8bc76bf4b95] master: Fix T66088: Modifier keys ignored when the window doesn't have focus

Campbell Barton noreply at git.blender.org
Thu Aug 11 08:49:26 CEST 2022


Commit: 8bc76bf4b957c51ddc5a13c6305f05c64b218a27
Author: Campbell Barton
Date:   Thu Aug 11 15:06:13 2022 +1000
Branches: master
https://developer.blender.org/rB8bc76bf4b957c51ddc5a13c6305f05c64b218a27

Fix T66088: Modifier keys ignored when the window doesn't have focus

Always use modifier keys from the active window, as changes to the
modifiers aren't sent to inactive windows.

Also resolves modifier keys being lost on window de-activation.
Activating the window again would check the previous state of the
modifiers which was always cleared as of [0],
now clearing is no longer needed.

[0]: 472595f1d3533f143bdc84700b26f20a7b2ba1c1

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

M	source/blender/windowmanager/intern/wm_event_system.cc
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc
index d90259c0cde..77f6b3c861f 100644
--- a/source/blender/windowmanager/intern/wm_event_system.cc
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -5214,6 +5214,13 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
   event.prev_type = event.type;
   event.prev_val = event.val;
 
+  /* Always use modifiers from the active window since
+     changes to modifiers aren't sent to inactive windows, see: T66088. */
+  if ((wm->winactive != win) && (wm->winactive && wm->winactive->eventstate)) {
+    event.modifier = wm->winactive->eventstate->modifier;
+    event.keymodifier = wm->winactive->eventstate->keymodifier;
+  }
+
   /* Ensure the event state is correct, any deviation from this may cause bugs.
    *
    * NOTE: #EVENT_NONE is set when unknown keys are pressed,
@@ -5256,6 +5263,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
       if (win_other) {
         wmEvent event_other = *win_other->eventstate;
 
+        /* Use the modifier state of this window. */
+        event_other.modifier = event.modifier;
+        event_other.keymodifier = event.keymodifier;
+
         /* See comment for this operation on `event` for details. */
         event_other.prev_type = event_other.type;
         event_other.prev_val = event_other.val;
@@ -5345,6 +5356,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
       if (win_other) {
         wmEvent event_other = *win_other->eventstate;
 
+        /* Use the modifier state of this window. */
+        event_other.modifier = event.modifier;
+        event_other.keymodifier = event.keymodifier;
+
         /* See comment for this operation on `event` for details. */
         event_other.prev_type = event_other.type;
         event_other.prev_val = event_other.val;
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index a5690b52a5a..0c31ff87fdd 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1113,14 +1113,22 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
     }
     wmWindow *win = GHOST_GetWindowUserData(ghostwin);
 
+    /* Win23/GHOST modifier bug, see T40317 */
+#ifndef WIN32
+//#  define USE_WIN_ACTIVATE
+#endif
+
     switch (type) {
       case GHOST_kEventWindowDeactivate:
         wm_event_add_ghostevent(wm, win, type, data);
         win->active = 0; /* XXX */
 
-        /* clear modifiers for inactive windows */
+        /* When window activation is enabled, these modifiers are set with window activation.
+         * Otherwise leave them set so re-activation doesn't loose keys which are held. */
+#ifdef USE_WIN_ACTIVATE
         win->eventstate->modifier = 0;
         win->eventstate->keymodifier = 0;
+#endif
 
         break;
       case GHOST_kEventWindowActivate: {
@@ -1128,11 +1136,6 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
                                  (query_qual(CONTROL) ? KM_CTRL : 0) |
                                  (query_qual(ALT) ? KM_ALT : 0) | (query_qual(OS) ? KM_OSKEY : 0));
 
-        /* Win23/GHOST modifier bug, see T40317 */
-#ifndef WIN32
-//#  define USE_WIN_ACTIVATE
-#endif
-
         /* No context change! C->wm->windrawable is drawable, or for area queues. */
         wm->winactive = win;



More information about the Bf-blender-cvs mailing list