mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[v3 alpha] implement setIcon on linux (#3354)
* implement `linuxApp.setIcon` * Move code into `linux_cgo.go`
This commit is contained in:
parent
16a029754f
commit
7c921d6a81
3 changed files with 23 additions and 5 deletions
|
|
@ -15,7 +15,6 @@ package application
|
|||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -42,6 +41,8 @@ type linuxApp struct {
|
|||
windowMapLock sync.Mutex
|
||||
|
||||
theme string
|
||||
|
||||
icon pointer
|
||||
}
|
||||
|
||||
func (a *linuxApp) GetFlags(options Options) map[string]any {
|
||||
|
|
@ -68,10 +69,6 @@ func (a *linuxApp) on(eventID uint) {
|
|||
//C.registerApplicationEvent(l.application, C.uint(eventID))
|
||||
}
|
||||
|
||||
func (a *linuxApp) setIcon(icon []byte) {
|
||||
log.Println("linuxApp.setIcon", "not implemented")
|
||||
}
|
||||
|
||||
func (a *linuxApp) name() string {
|
||||
return appName()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,6 +425,20 @@ func (a *linuxApp) showAllWindows() {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *linuxApp) setIcon(icon []byte) {
|
||||
gbytes := C.g_bytes_new_static(C.gconstpointer(unsafe.Pointer(&icon[0])), C.ulong(len(icon)))
|
||||
stream := C.g_memory_input_stream_new_from_bytes(gbytes)
|
||||
var gerror *C.GError
|
||||
pixbuf := C.gdk_pixbuf_new_from_stream(stream, nil, &gerror)
|
||||
if gerror != nil {
|
||||
a.parent.error("Failed to load application icon: " + C.GoString(gerror.message))
|
||||
C.g_error_free(gerror)
|
||||
return
|
||||
}
|
||||
|
||||
a.icon = pointer(pixbuf)
|
||||
}
|
||||
|
||||
// Clipboard
|
||||
func clipboardGet() string {
|
||||
clip := C.gtk_clipboard_get(C.GDK_SELECTION_CLIPBOARD)
|
||||
|
|
@ -1131,6 +1145,12 @@ func (w *linuxWebviewWindow) setTitle(title string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setIcon(icon pointer) {
|
||||
if icon != nil {
|
||||
C.gtk_window_set_icon(w.gtkWindow(), (*C.GdkPixbuf)(icon))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) gtkWindow() *C.GtkWindow {
|
||||
return (*C.GtkWindow)(w.window)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ func (w *linuxWebviewWindow) run() {
|
|||
w.enableDND()
|
||||
}
|
||||
w.setTitle(w.parent.options.Title)
|
||||
w.setIcon(app.icon)
|
||||
w.setAlwaysOnTop(w.parent.options.AlwaysOnTop)
|
||||
w.setResizable(!w.parent.options.DisableResize)
|
||||
// only set min/max size if actually set
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue