From 7f0c48100eb0e1f0b8d29172bf95f9b0bdd98894 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 25 Sep 2026 22:59:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=20Allow=20x11=20mode=20to=20get=20?= =?UTF-8?q?window=20decorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 +++--- window_linux.go | 36 ++++++++++++++++++++++++++++++++++++ window_other.go | 14 ++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 window_linux.go create mode 100644 window_other.go 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) +}