progrium/darwinkit

unable to implement keyDown of NSView subclass

Closed this issue · 2 comments

It seems you can subclass alright, both NSObject and NSView, however when actually using it there seems to be some missing information. The examples/subclass program demonstrates a program with a Window that uses a custom NSView to capture keydown events. It implements and seems to call acceptsFirstResponder since a keypress will trigger the crash (without acceptsFirstResponder it will do nothing as expected, see this), but keyDown is not called because of this error (press a key after the window appears):

$ CGO_CFLAGS="-w" go run main.go
2023/03/10 16:57:52 Program started.
2023/03/10 16:57:52 App started.
panic: interface conversion: reflect.Type is nil, not *reflect.rtype

goroutine 1 [running]:
reflect.NewAt(...)
        /usr/local/Cellar/go/1.19/libexec/src/reflect/value.go:3103
github.com/progrium/macdriver/objc.goMethodCallEntryPoint(0x4006b86?)
        /Users/progrium/Source/github.com/progrium/macdriver/objc/call_amd64.go:173 +0x2d85
...
nickav commented

I'm not able to repro this on MacOS Mojave 10.14.6 (18G103). When I run make subclass (added new make command) the window opens as expected and I see Keydown!! being logged in the console when I press any key. What MacOS version are you seeing this on?

Edit: also tried with CGO_CFLAGS="-w" go run main.go from the subclass folder

This is macOS 12.5.1 (21G83) and go1.19 darwin/amd64 ...