giu icon indicating copy to clipboard operation
giu copied to clipboard

[bug] No meta keys work in UI elements

Open xxxserxxx opened this issue 1 year ago • 5 comments

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

xxxserxxx avatar Jan 25 '24 22:01 xxxserxxx

well what? :smile: its really strange imao. OMG But it happens to me too... let me debug this.

gucio321 avatar Jan 31 '24 10:01 gucio321

For now I can say that cimghui-go doesn't have this problem

gucio321 avatar Feb 01 '24 22:02 gucio321

ok, problem is about InputHandler, when I comment out MasterWindow.go:109 everything works

gucio321 avatar Feb 01 '24 22:02 gucio321

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

gucio321 avatar Feb 20 '24 19:02 gucio321

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.

gucio321 avatar Mar 01 '24 08:03 gucio321

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.

gucio321 avatar Jul 10 '24 12:07 gucio321

hehe, git blame said this: https://github.com/AllenDang/giu/pull/628

gucio321 avatar Jul 10 '24 12:07 gucio321