diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index e2e212063..ccc6fcc18 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -551,6 +551,19 @@ void DisableContextMenu(void* webview) { g_signal_connect(WEBKIT_WEB_VIEW(webview), "context-menu", G_CALLBACK(disableContextMenu), NULL); } +void SetWindowIcon(GtkWindow* window, const guchar* buf, gsize len) { + GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); + if (!loader) { + return; + } + if (gdk_pixbuf_loader_write(loader, buf, len, NULL) && gdk_pixbuf_loader_close(loader, NULL)) { + GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); + if (pixbuf) { + gtk_window_set_icon(window, pixbuf); + } + } + g_object_unref(loader); +} */ import "C" @@ -637,6 +650,11 @@ func NewWindow(appoptions *options.App, debug bool) *Window { result.SetTitle(appoptions.Title) result.SetMinSize(appoptions.MinWidth, appoptions.MinHeight) result.SetMaxSize(appoptions.MaxWidth, appoptions.MaxHeight) + if appoptions.Linux != nil { + if appoptions.Linux.Icon != nil { + result.SetWindowIcon(appoptions.Linux.Icon) + } + } // Menu result.SetApplicationMenu(appoptions.Menu) @@ -763,6 +781,13 @@ func (w *Window) SetRGBA(r uint8, g uint8, b uint8, a uint8) { } +func (w *Window) SetWindowIcon(icon []byte) { + if len(icon) == 0 { + return + } + C.SetWindowIcon(w.asGTKWindow(), (*C.guchar)(&icon[0]), (C.gsize)(len(icon))) +} + func (w *Window) Run() { if w.menubar != nil { C.gtk_box_pack_start(C.GTKBOX(unsafe.Pointer(w.vbox)), w.menubar, 0, 0, 0) diff --git a/v2/pkg/options/linux/linux.go b/v2/pkg/options/linux/linux.go index 4feb29bca..2e73064a0 100644 --- a/v2/pkg/options/linux/linux.go +++ b/v2/pkg/options/linux/linux.go @@ -2,4 +2,5 @@ package linux // Options specific to Linux builds type Options struct { + Icon []byte } diff --git a/website/docs/reference/options.mdx b/website/docs/reference/options.mdx index 529bbd2e9..a8c9d8159 100644 --- a/website/docs/reference/options.mdx +++ b/website/docs/reference/options.mdx @@ -75,6 +75,9 @@ func main() { Icon: icon, }, }, + Linux: &linux.Options{ + Icon: icon, + }, }) if err != nil { log.Fatal(err) @@ -337,6 +340,14 @@ Type: \*mac.Options This defines [Mac specific options](#mac-specific-options). +### Linux + +Name: Linux + +Type: \*linux.Options + +This defines [Linux specific options](#linux-specific-options). + ## Windows Specific Options ### WebviewIsTransparent @@ -605,3 +616,20 @@ When clicked, that will open an about message box:
+## Linux Specific Options + +### Icon + +Name: Icon + +Type: []byte + +Sets up the icon representing the window. This icon is used when the window is minimized (also known as iconified). +Some window managers or desktop environments may also place it in the window frame, or display it in other contexts. +On others, the icon is not used at all, so your mileage may vary. + +NOTE: Gnome on Wayland at least does not display this icon. To have a application icon there, a `.desktop` file has to be used. +On KDE it should work. + +The icon should be provided in whatever size it was naturally drawn; that is, don’t scale the image before passing it. +Scaling is postponed until the last minute, when the desired final size is known, to allow best quality.