AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.11k stars 127 forks source link

[bug] No meta keys work in UI elements #754

Open xxxserxxx opened 5 months ago

xxxserxxx commented 5 months ago

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

gucio321 commented 5 months ago

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

gucio321 commented 5 months ago

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

gucio321 commented 5 months ago

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

gucio321 commented 4 months ago

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 commented 4 months ago

I think our moves should be: