mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
app/internal/window: implement key.Press and key.Release on macOS
Update key.State documentation and add State.String while here. Also update Event.String to include State. Signed-off-by: Raffaele Sena <raff367@gmail.com>
This commit is contained in:
committed by
Elias Naur
parent
e195309d55
commit
8a3ff4abcb
@@ -76,9 +76,13 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo
|
|||||||
}
|
}
|
||||||
- (void)keyDown:(NSEvent *)event {
|
- (void)keyDown:(NSEvent *)event {
|
||||||
NSString *keys = [event charactersIgnoringModifiers];
|
NSString *keys = [event charactersIgnoringModifiers];
|
||||||
gio_onKeys((__bridge CFTypeRef)self, (char *)[keys UTF8String], [event timestamp], [event modifierFlags]);
|
gio_onKeys((__bridge CFTypeRef)self, (char *)[keys UTF8String], [event timestamp], [event modifierFlags], true);
|
||||||
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||||
}
|
}
|
||||||
|
- (void)keyUp:(NSEvent *)event {
|
||||||
|
NSString *keys = [event charactersIgnoringModifiers];
|
||||||
|
gio_onKeys((__bridge CFTypeRef)self, (char *)[keys UTF8String], [event timestamp], [event modifierFlags], false);
|
||||||
|
}
|
||||||
- (void)insertText:(id)string {
|
- (void)insertText:(id)string {
|
||||||
const char *utf8 = [string UTF8String];
|
const char *utf8 = [string UTF8String];
|
||||||
gio_onText((__bridge CFTypeRef)self, (char *)utf8);
|
gio_onText((__bridge CFTypeRef)self, (char *)utf8);
|
||||||
|
|||||||
@@ -151,15 +151,20 @@ func (w *window) setStage(stage system.Stage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onKeys
|
//export gio_onKeys
|
||||||
func gio_onKeys(view C.CFTypeRef, cstr *C.char, ti C.double, mods C.NSUInteger) {
|
func gio_onKeys(view C.CFTypeRef, cstr *C.char, ti C.double, mods C.NSUInteger, keyDown C.bool) {
|
||||||
str := C.GoString(cstr)
|
str := C.GoString(cstr)
|
||||||
kmods := convertMods(mods)
|
kmods := convertMods(mods)
|
||||||
|
ks := key.Release
|
||||||
|
if keyDown {
|
||||||
|
ks = key.Press
|
||||||
|
}
|
||||||
w := mustView(view)
|
w := mustView(view)
|
||||||
for _, k := range str {
|
for _, k := range str {
|
||||||
if n, ok := convertKey(k); ok {
|
if n, ok := convertKey(k); ok {
|
||||||
w.w.Event(key.Event{
|
w.w.Event(key.Event{
|
||||||
Name: n,
|
Name: n,
|
||||||
Modifiers: kmods,
|
Modifiers: kmods,
|
||||||
|
State: ks,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-2
@@ -10,6 +10,7 @@ events.
|
|||||||
package key
|
package key
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gioui.org/internal/opconst"
|
"gioui.org/internal/opconst"
|
||||||
@@ -64,7 +65,7 @@ const (
|
|||||||
// Release is the state of a key that has been released.
|
// Release is the state of a key that has been released.
|
||||||
//
|
//
|
||||||
// Note: release events are only implemented on the following platforms:
|
// Note: release events are only implemented on the following platforms:
|
||||||
// Linux, Windows, WebAssembly.
|
// macOS, Linux, Windows, WebAssembly.
|
||||||
Release
|
Release
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ func (Event) ImplementsEvent() {}
|
|||||||
func (FocusEvent) ImplementsEvent() {}
|
func (FocusEvent) ImplementsEvent() {}
|
||||||
|
|
||||||
func (e Event) String() string {
|
func (e Event) String() string {
|
||||||
return "{" + string(e.Name) + " " + e.Modifiers.String() + "}"
|
return fmt.Sprintf("%v %v %v}", e.Name, e.Modifiers, e.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Modifiers) String() string {
|
func (m Modifiers) String() string {
|
||||||
@@ -151,3 +152,14 @@ func (m Modifiers) String() string {
|
|||||||
}
|
}
|
||||||
return strings.Join(strs, "|")
|
return strings.Join(strs, "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s State) String() string {
|
||||||
|
switch s {
|
||||||
|
case Press:
|
||||||
|
return "Press"
|
||||||
|
case Release:
|
||||||
|
return "Release"
|
||||||
|
default:
|
||||||
|
panic("invalid State")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user