[PATCH v3] gio: app: send keypress events for modifier keys in macos
Export this patch
This change generates keypress and release events for modifier keys in
MacOS. Specifically the Control, Alt, Shift and Command keys.
---
app/os_macos.go | 27 +++++++++++++++++++++++++++
app/os_macos.m | 4 ++++
2 files changed, 31 insertions(+)
diff --git a/app/os_macos.go b/app/os_macos.go
index d62bb645..ef51d7d6 100644
--- a/app/os_macos.go
+++ b/app/os_macos.go
@@ -340,6 +340,7 @@ type window struct {
cursor pointer.Cursor
pointerBtns pointer.Buttons
loop *eventLoop
+ lastMods C.NSUInteger
scale float32
config Config
@@ -561,6 +562,32 @@ func gio_onKeys(h C.uintptr_t, cstr C.CFTypeRef, ti C.double, mods C.NSUInteger,
}
}
+ //export gio_onFlagsChanged
+ func gio_onFlagsChanged(h C.uintptr_t, curMods C.NSUInteger) {
+ w := windowFor(h)
+
+ mods := []C.NSUInteger{C.NSControlKeyMask, C.NSAlternateKeyMask, C.NSShiftKeyMask, C.NSCommandKeyMask}
+ keys := []key.Name{key.NameCtrl, key.NameAlt, key.NameShift, key.NameCommand}
+
+ for i, mod := range mods {
+ wasPressed := w.lastMods&mod != 0
+ isPressed := curMods&mod != 0
+
+ if wasPressed != isPressed {
+ st := key.Release
+ if isPressed {
+ st = key.Press
+ }
+ w.ProcessEvent(key.Event{
+ Name: keys[i],
+ State: st,
+ })
+ }
+ }
+
+ w.lastMods = curMods
+ }
+
//export gio_onText
func gio_onText(h C.uintptr_t, cstr C.CFTypeRef) {
str := nsstringToString(cstr)
diff --git a/app/os_macos.m b/app/os_macos.m
index 9c895148..6e3438e3 100644
--- a/app/os_macos.m
+++ b/app/os_macos.m
@@ -136,6 +136,10 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
NSString *keys = [event charactersIgnoringModifiers];
gio_onKeys(self.handle, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], true);
}
+ - (void)flagsChanged:(NSEvent *)event {
+ [self interpretKeyEvents:[NSArray arrayWithObject:event]];
+ gio_onFlagsChanged(self.handle, [event modifierFlags]);
+ }
- (void)keyUp:(NSEvent *)event {
NSString *keys = [event charactersIgnoringModifiers];
gio_onKeys(self.handle, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], false);
--
2.30.2
Thank you. I forgot to ask you to sign off your change, so I added
a Signed-off-by line by you because of my high latency.
Please reply to this email and let me know whether you agree to the
DCO https://developercertificate.org/ that the sign-off line implies.
Thanks,
Elias