diff --git a/main.go b/main.go index 6983fba..1f074bf 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ var iconPNG []byte var preferredTheme = flag.String("theme", "", "Specify the theme to be used. dark/light") var linger = flag.String("linger", "", "If specified, linger for the given duration (e.g. 10s) before actually closing.") +var x11 = flag.Bool("x11", false, "Force the X11 backend (Linux, XWayland): uses the window manager's decorations instead of shirei's client-side titlebar") type Gitmoji struct { Emoji string @@ -86,9 +87,8 @@ func main() { } } - app.SetupWindow("Gitmoji Picker", 300, 300) - app.SetupIconBytes(iconPNG) - app.Run(RootView) + setupWindow("Gitmoji Picker", 300, 300) + runWindow(RootView) } func loadEntries(gitmojiData *GitmojiData) { diff --git a/window_linux.go b/window_linux.go new file mode 100644 index 0000000..f86bd0d --- /dev/null +++ b/window_linux.go @@ -0,0 +1,36 @@ +//go:build linux + +package main + +import ( + "bytes" + "image/png" + + app "go.hasen.dev/shirei/app" + "go.hasen.dev/shirei/x11backend" +) + +// setupWindow opens the window via shirei's app backend, or directly via the +// X11 backend when -x11 is given: on Wayland sessions shirei always draws its +// own client-side titlebar (xdg-decoration negotiation is not implemented in +// shirei v0.8), while XWayland windows get real server-side decorations from +// the window manager. +func setupWindow(title string, width, height int) { + if *x11 { + x11backend.SetupWindow(title, width, height) + if img, err := png.Decode(bytes.NewReader(iconPNG)); err == nil { + x11backend.SetupIconImage(img) + } + return + } + app.SetupWindow(title, width, height) + app.SetupIconBytes(iconPNG) +} + +func runWindow(frameFn func()) { + if *x11 { + x11backend.Run(frameFn) + return + } + app.Run(frameFn) +} diff --git a/window_other.go b/window_other.go new file mode 100644 index 0000000..f558280 --- /dev/null +++ b/window_other.go @@ -0,0 +1,14 @@ +//go:build !linux + +package main + +import app "go.hasen.dev/shirei/app" + +func setupWindow(title string, width, height int) { + app.SetupWindow(title, width, height) + app.SetupIconBytes(iconPNG) +} + +func runWindow(frameFn func()) { + app.Run(frameFn) +}