~eliasnaur/gio-patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH v3] gio: app: send keypress events for modifier keys in macos

Details
Message ID
<20241026143224.2196738-1-kanobe@gmail.com>
DKIM signature
pass
Download raw message
Patch: +31 -0
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
Details
Message ID
<D6333IWQ2BXK.K3FDCFO1ZRYX@eliasnaur.com>
In-Reply-To
<20241026143224.2196738-1-kanobe@gmail.com> (view parent)
DKIM signature
pass
Download raw message
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
Details
Message ID
<CAHe4cPncBErCVWLe44cZW=iUmbk_gCj6iWu3aBUL9egwSaQXaw@mail.gmail.com>
In-Reply-To
<D6333IWQ2BXK.K3FDCFO1ZRYX@eliasnaur.com> (view parent)
DKIM signature
pass
Download raw message
That sounds good, and I agree to the DCO. Thanks for handling it!

On Wed, Dec 4, 2024 at 12:15 PM Elias Naur <mail@eliasnaur.com> wrote:
>
> 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
Reply to thread Export thread (mbox)