winemac: Discard key repeat events after a modifier key has been pressed.

Ken Thomases ken at codeweavers.com
Fri Mar 10 02:22:02 CST 2017


Sierra (macOS 10.12) changed the behavior of key repeat.  In previous versions
of macOS, key repeat stops when a modifier key is pressed or released.  In
Sierra, it does not; it just keeps repeating as newly-modified.

On Windows, key repeat stops when a modifier key is pressed, although not when
one is released.  Some programs depend on this behavior.  So, the Mac driver
emulates it.

Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
 dlls/winemac.drv/cocoa_window.h |  2 ++
 dlls/winemac.drv/cocoa_window.m | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/dlls/winemac.drv/cocoa_window.h b/dlls/winemac.drv/cocoa_window.h
index f037b08..b4cc018 100644
--- a/dlls/winemac.drv/cocoa_window.h
+++ b/dlls/winemac.drv/cocoa_window.h
@@ -81,6 +81,8 @@ @interface WineWindow : NSPanel <NSWindowDelegate>
 
     NSTimeInterval lastDockIconSnapshot;
 
+    BOOL allowKeyRepeats;
+
     BOOL ignore_windowDeminiaturize;
     BOOL ignore_windowResize;
     BOOL fakingClose;
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index 118bf3c..af8ebe7 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -2424,7 +2424,18 @@ - (void) setRetinaMode:(int)mode
     /*
      * ---------- NSResponder method overrides ----------
      */
-    - (void) keyDown:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
+    - (void) keyDown:(NSEvent *)theEvent
+    {
+        if ([theEvent isARepeat])
+        {
+            if (!allowKeyRepeats)
+                return;
+        }
+        else
+            allowKeyRepeats = YES;
+
+        [self postKeyEvent:theEvent];
+    }
 
     - (void) flagsChanged:(NSEvent *)theEvent
     {
@@ -2461,6 +2472,9 @@ - (void) flagsChanged:(NSEvent *)theEvent
             {
                 BOOL pressed = (modifierFlags & modifiers[i].mask) != 0;
 
+                if (pressed)
+                    allowKeyRepeats = NO;
+
                 if (i == last_changed)
                     lastModifierFlags = modifierFlags;
                 else
-- 
2.10.2




More information about the wine-patches mailing list