5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 12:00:07 +08:00

v2: linux: add icon to linux specific app option and load it during w… (#1272)

* v2: linux: add icon to linux specific app option and load it during window creation

Signed-off-by: Martin Gysel <me@bearsh.org>

* doc: linux specific option: icon
This commit is contained in:
bearsh 2022-03-30 09:15:58 +02:00 committed by GitHub
parent ec31d49b59
commit d8bcf7ac70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 0 deletions

View File

@ -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)

View File

@ -2,4 +2,5 @@ package linux
// Options specific to Linux builds
type Options struct {
Icon []byte
}

View File

@ -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:
</div>
<br/>
## 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, dont scale the image before passing it.
Scaling is postponed until the last minute, when the desired final size is known, to allow best quality.