AllenDang / giu

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

Dynamically selecting between X11 and Wayland backend #686

Open Vendicated opened 1 year ago

Vendicated commented 1 year ago

Using --tags wayland, it is possible to create a wayland binary

However, I haven't found a way to create one binary that will run on both x11 and wayland, dynamically selecting the correct backend.

Is there any good way to do so? It seems like go-glfw doesn't even let you specify both x11 and wayland tag at once

GLFW itself does seem to support this though, see https://github.com/glfw/glfw/commit/56a4cb0a3a2c7a44a2fd8ab3335adf915e19d30c

gucio321 commented 1 year ago

@Vendicated I can't reproduce. For me one giu binary works on both wayland and xorg

Vendicated commented 9 months ago

Apologies for the late reply, I'm only now looking into this again

Are you sure you're not just running the binary through XWayland?

For me, when compiling with -tags wayland, it will fail to open on X11 with

2023/12/25 00:49:35 PlatformError: Wayland: Failed to connect to display
panic: NotInitialized: The GLFW library is not initialized

When compiling without the tag and using Wayland, it will open in XWayland. Or, if you are not using XWayland, error with

2023/12/25 00:59:38 PlatformError: X11: The DISPLAY environment variable is missing
panic: NotInitialized: The GLFW library is not initialized

glfw has a GLFW_PLATFORM hint you can set to explicitly pick wayland/x11, introduced by the above linked commit that adds automatic platform selection, but go-glfw doesn't seem to even have this code. Does that mean it hasn't updated its glfw files to have that commit?

I tried to hardcode the values in my code (glfw.InitHint(0x00050003, 0x00060003)) but it paniced with panic: InvalidEnum: Invalid init hint 0x00050003

Looking more at go-glfw source, it seems like X11 and Wayland are mutually exclusive:

So it seems this is something that needs to be fixed by go-glfw?

I'm sorry if i'm missing anything. Help would be greatly appreciated

gucio321 commented 9 months ago

Could you try with the latest code? We're not using gogl glfw anymore

Vendicated commented 9 months ago

Oh I missed that. I did a go get -u but it didn't upgrade to that

Anyway, I updated to latest main and it's still failing without XWayland. Do i have to pass any specific build tags?

Glfw Error 65544: X11: The DISPLAY environment variable is missing
panic: Failed to initialize GLFW

goroutine 1 [running, locked to thread]:
github.com/AllenDang/cimgui-go.NewGLFWBackend(...)
    /home/vee/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20231219093052-24bd5dc22643/glfw_backend.go:201
github.com/AllenDang/giu.NewMasterWindow({0xd13a6a, 0x11}, 0x4b0, 0x320, 0xc000030000?)
    /home/vee/go/pkg/mod/github.com/!allen!dang/giu@v0.7.1-0.20231219095113-bf1aacdc1161/MasterWindow.go:88 +0x4ac
main.main()
    /home/vee/Coding/Installer/gui.go:70 +0x9c

(On a side note, Text is also really messed up but you might already be aware of this?)

gucio321 commented 9 months ago

Ok, let me check this

gucio321 commented 9 months ago

(On a side note, Text is also really messed up but you might already be aware of this?)

Yeah they're is something wrong with font atlas