From dce18d7c23e921e61ee6663e149b3153567b2858 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 30 Sep 2023 02:46:11 +0900 Subject: [PATCH] internal/ui: bug fix: SetWindowIcon(nil) didn't reset the window icon Closes #2796 --- examples/windowsize/main.go | 4 ++++ internal/goglfw/win32window_windows.go | 3 +++ internal/ui/ui_glfw.go | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index ab0f9f4e7..c2073e0cf 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -307,6 +307,9 @@ func (g *game) Update() error { if inpututil.IsKeyJustPressed(ebiten.KeyI) { ebiten.SetWindowIcon([]image.Image{createRandomIconImage()}) } + if inpututil.IsKeyJustPressed(ebiten.KeyJ) { + ebiten.SetWindowIcon(nil) + } ebiten.SetWindowMousePassthrough(mousePassthrough) @@ -358,6 +361,7 @@ func (g *game) Draw(screen *ebiten.Image) { [U] Switch the runnable-on-unfocused state [C] Switch the cursor mode (visible, hidden, or captured) [I] Change the window icon (only for desktops) +[J] Reset the window icon (only for desktops) [V] Switch the vsync [T] Switch TPS (ticks per second) [D] Switch the window decoration (only for desktops) diff --git a/internal/goglfw/win32window_windows.go b/internal/goglfw/win32window_windows.go index 3b2924ef0..81435dba2 100644 --- a/internal/goglfw/win32window_windows.go +++ b/internal/goglfw/win32window_windows.go @@ -1559,6 +1559,9 @@ func (w *Window) platformSetWindowIcon(images []*Image) error { if len(images) > 0 { w.platform.bigIcon = bigIcon w.platform.smallIcon = smallIcon + } else { + w.platform.bigIcon = 0 + w.platform.smallIcon = 0 } return nil } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index a20ddbe21..ab537a3b0 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -1204,11 +1204,17 @@ func (u *userInterfaceImpl) updateIconIfNeeded() error { } imgs := u.getAndResetIconImages() - if len(imgs) == 0 { + // A 0-size slice and nil are distinguished here. + // A 0-size slice means a user indicates to reset the icon. + // On the other hand, nil means a user didn't update the icon state. + if imgs == nil { return nil } - newImgs := make([]image.Image, len(imgs)) + var newImgs []image.Image + if len(imgs) > 0 { + newImgs = make([]image.Image, len(imgs)) + } for i, img := range imgs { // TODO: If img is not *ebiten.Image, this converting is not necessary. // However, this package cannot refer *ebiten.Image due to the package