Skip to content

Set macOS dock icon when applying ImGuiApp window icon - #403

Merged
matt-edmondson merged 4 commits into
mainfrom
copilot/fix-application-icon-macos
Sep 14, 2026
Merged

matt-edmondson merged 4 commits into
mainfrom
copilot/fix-application-icon-macos

Conversation

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

IconPath/SetWindowIcon updated the GLFW window icon but did not reliably affect the macOS app icon shown in the Dock. This change adds a macOS-specific app-icon path while keeping existing cross-platform window-icon behavior intact.

  • macOS app icon path

    • Added TrySetMacOSApplicationIcon(string iconPath) in ImGui.App to call AppKit via Objective-C runtime (NSApplication.sharedApplication.setApplicationIconImage:).
    • Invoked from SetWindowIcon before calling Silk/GLFW SetWindowIcon, so macOS receives both app-level and window-level icon updates.
  • Native interop surface

    • Added Objective-C runtime bindings in NativeMethods:
      • objc_getClass
      • sel_registerName
      • objc_msgSend overloads used by icon setup
  • API/docs alignment

    • Updated API docs for SetWindowIcon and ImGuiAppConfig.IconPath to state macOS dock icon behavior explicitly.
public static void SetWindowIcon(string iconPath)
{
	// existing image decode/resize for window icons
	_ = TrySetMacOSApplicationIcon(iconPath); // macOS dock/app icon
	Invoker.Invoke(() => window?.SetWindowIcon([.. icons])); // existing behavior
}

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix application icon issue on macOS Set macOS dock icon when applying ImGuiApp window icon Sep 14, 2026
@matt-edmondson

Copy link
Copy Markdown
Contributor

@copilot do the other platforms need something similar, for the taskbar and whatever?

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot do the other platforms need something similar, for the taskbar and whatever?

Not usually. On Windows/Linux, window.SetWindowIcon(...) (GLFW/Silk) is the normal path and is what taskbar/window icons use where the desktop supports runtime icon updates. macOS is the outlier because the Dock app icon is app-level (NSApplication) rather than just window-level. The only things this won’t change cross-platform are package/shortcut-level icons (e.g., pinned shortcut icons, desktop-file bundle icons), which are build/distribution metadata, not runtime window state.

@matt-edmondson
matt-edmondson marked this pull request as ready for review September 14, 2026 05:30
@matt-edmondson

Copy link
Copy Markdown
Contributor

@copilot pkease address the sonar gate

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot pkease address the sonar gate

Addressed in 96ca55c. I fixed the Sonar gate failure by adding coverage for the new icon path and excluding the macOS-native AppKit interop helper from coverage (platform-dependent interop boundary), then validated with the window-management/icon tests.

Comment thread tests/ImGui.App.Tests/ImGuiAppWindowManagementTests.cs Fixed
@matt-edmondson

Copy link
Copy Markdown
Contributor

@copilot please address the code quality comments

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please address the code quality comments

Addressed in bf5a0fb. I removed the generic catch (Exception)/Assert.Fail pattern and kept cleanup via try/finally in SetWindowIcon_WithValidPng_DoesNotThrow, then ran ImGuiAppWindowManagementTests (50/50 passing).

@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ea7f9e6 into main Sep 14, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the copilot/fix-application-icon-macos branch September 14, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Application icon doesnt seem to work on macos

2 participants