[bug] No meta keys work in UI elements
What happend?
While trying to hook into Enter key events in an InputText, I discovered that -- on my machine, at least -- no control/meta keys are being captured by giu CR, Del, Backspace, arrow keys -- none of them trigger any key capture events. With CallbackAlways, even mouse events trigger the callback, but none of the meta keys do. Output from xev looks ok, so I'm stuck about what's unique about my set-up.
The attached movie shows the behavior; I'm using screenkeys to show the keypresses.
Go: 1.21.6
giu: 0.7.0 (from go.mod)
OS/Platform:
https://github.com/AllenDang/giu/assets/60757196/9b02b126-5488-4e2c-a0ad-5f18e988c1fa
Code example
While I found this with different code, I also saw it in the giu examples/widgets program, as observed in the attached video.
To Reproduce
Since I'm seeing it in the giu code, it's likely that this is an environmental issue -- related to something particular to my set-up. I'm happy to help track it down.
Version
master
OS
Arch Linux kernel 6.7.1, Xorg 21.1.11
well what? :smile: its really strange imao. OMG But it happens to me too... let me debug this.
For now I can say that cimghui-go doesn't have this problem
ok, problem is about InputHandler, when I comment out MasterWindow.go:109 everything works
Reason
in imgui_impl_glfw.cpp:
glfwSetKeyCallback(vd->Window, ImGui_ImplGlfw_KeyCallback);
in glfw_backend.cpp:
void igGLFWWindow_SetKeyCallback(GLFWwindow *wnd) { glfwSetKeyCallback(wnd, (GLFWkeyfun)keyCallback); }
which is wrapped in glfw_backend.go:
func (b *GLFWBackend) SetKeyCallback(cbfun KeyCallback) {
b.keyCb = cbfun
C.igGLFWWindow_SetKeyCallback(b.handle())
}
and in giu we do (in MasterWindow.go):
w.backend.SetKeyCallback(func(key, scanCode, action, modifier int) {
fmt.Println(key, scanCode, action, modifier)
k, m, a := keyFromGLFWKey(imgui.GLFWKey(key)), Modifier(modifier), Action(action)
handler.Handle(k, m, a)
if w.additionalInputCallback != nil {
w.additionalInputCallback(k, m, a)
}
})
conclusion: we overwrite imgui's internal stuff. This issue should escalate to cimgui-go
I think our moves should be:
- remove this SetKeyCallback from cimgui-go - ImGui supposes we don't use it at all.
- re-implement InputHandler here in giu so that it uses ImGui API.
well, I have a problem, because it works now, but I have no Idea why... let me close this for now and I'll comment when I find what fixed that.
hehe, git blame said this: https://github.com/AllenDang/giu/pull/628