From ffbd0f78ad1c155a666c7fdafe1917a68d7890ec Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 07:50:34 +0000 Subject: [PATCH] Eigenes Fenster: App-Icon als Fenstersymbol (16/32/48/256 px) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018i4GUhyZeAnaXMQzGXmQU3 --- assets/icon/window.go | 27 +++++++++++++++++++++++++++ assets/icon/window_test.go | 15 +++++++++++++++ cmd/sshtermy/main.go | 5 +++-- internal/gui/options.go | 6 +++--- internal/gui/window.go | 4 ++-- 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 assets/icon/window.go create mode 100644 assets/icon/window_test.go diff --git a/assets/icon/window.go b/assets/icon/window.go new file mode 100644 index 0000000..72b023b --- /dev/null +++ b/assets/icon/window.go @@ -0,0 +1,27 @@ +package icon + +import ( + "bytes" + "embed" + "image" + "image/png" +) + +//go:embed sshtermy-16.png sshtermy-32.png sshtermy-48.png sshtermy-256.png +var windowPNGs embed.FS + +// Window liefert das Fenstersymbol in mehreren Größen (Titelleiste, +// Taskleiste, Alt+Tab); das System nimmt die passende. +func Window() []image.Image { + var out []image.Image + for _, n := range []string{"sshtermy-16.png", "sshtermy-32.png", "sshtermy-48.png", "sshtermy-256.png"} { + b, err := windowPNGs.ReadFile(n) + if err != nil { + continue + } + if im, err := png.Decode(bytes.NewReader(b)); err == nil { + out = append(out, im) + } + } + return out +} diff --git a/assets/icon/window_test.go b/assets/icon/window_test.go new file mode 100644 index 0000000..90f134a --- /dev/null +++ b/assets/icon/window_test.go @@ -0,0 +1,15 @@ +package icon + +import "testing" + +func TestWindow(t *testing.T) { + ims := Window() + if len(ims) != 4 { + t.Fatalf("%d Bilder, erwartet 4", len(ims)) + } + for i, want := range []int{16, 32, 48, 256} { + if b := ims[i].Bounds(); b.Dx() != want || b.Dy() != want { + t.Errorf("Bild %d: %v, erwartet %d px", i, b, want) + } + } +} diff --git a/cmd/sshtermy/main.go b/cmd/sshtermy/main.go index 7b806fc..28dc650 100644 --- a/cmd/sshtermy/main.go +++ b/cmd/sshtermy/main.go @@ -16,6 +16,7 @@ import ( tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/term" + "github.com/db9979/sshtermy/assets/icon" "github.com/db9979/sshtermy/internal/crash" "github.com/db9979/sshtermy/internal/fullbackup" "github.com/db9979/sshtermy/internal/gui" @@ -65,7 +66,7 @@ func main() { // neues Fenster eines abgetrennten Tabs (⇧F10), siehe internal/detach; // „-window“: aus dem eigenen Fenster heraus, also wieder ein eigenes if len(os.Args) == 4 && os.Args[3] == "-window" && gui.Available() { - os.Exit(gui.RunAttach(os.Args[2], gui.Options{Title: version.Name})) + os.Exit(gui.RunAttach(os.Args[2], gui.Options{Title: version.Name, Icon: icon.Window()})) } if len(os.Args) != 3 { fail(fmt.Errorf("attach [-window]")) @@ -140,7 +141,7 @@ func main() { log.SetOutput(io.Discard) if windowed { app.SetWindowed() - _, err = gui.Run(app, gui.Options{Title: version.Name, CloseMsg: ui.WindowClosedMsg{}}) + _, err = gui.Run(app, gui.Options{Title: version.Name, Icon: icon.Window(), CloseMsg: ui.WindowClosedMsg{}}) } else { _, err = tea.NewProgram(app).Run() } diff --git a/internal/gui/options.go b/internal/gui/options.go index 1cfb19b..a01903b 100644 --- a/internal/gui/options.go +++ b/internal/gui/options.go @@ -8,9 +8,9 @@ import ( // Options für Run. type Options struct { - Title string // Fenstertitel (Standard „sshTermy“) - FontSize float64 // Schriftgröße in logischen Pixeln (Standard 14) - Icon image.Image // Fenstersymbol (Windows/Linux) + Title string // Fenstertitel (Standard „sshTermy“) + FontSize float64 // Schriftgröße in logischen Pixeln (Standard 14) + Icon []image.Image // Fenstersymbol in mehreren Größen (Windows/Linux) // CloseMsg geht an das Programm, wenn jemand das Fenster schließt, damit // es Sitzungen und Protokolle sauber beendet. nil = sofort beenden. CloseMsg tea.Msg diff --git a/internal/gui/window.go b/internal/gui/window.go index 7baed83..8e52235 100644 --- a/internal/gui/window.go +++ b/internal/gui/window.go @@ -160,8 +160,8 @@ func (w *window) run() error { // Bild bleibt stehen; Draw zeichnet nur neu, wenn sich etwas geändert hat // (Akku, GPU). ebiten.SetScreenClearedEveryFrame(false) - if icon := w.opts.Icon; icon != nil { - ebiten.SetWindowIcon([]image.Image{icon}) + if len(w.opts.Icon) > 0 { + ebiten.SetWindowIcon(w.opts.Icon) } return ebiten.RunGameWithOptions(w, &ebiten.RunGameOptions{InitUnfocused: false}) }