Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MacOSProperties.IsTemplateIcon attached property on TrayIcon #14348

Merged
merged 5 commits into from
Feb 20, 2024

Conversation

maxkatz6
Copy link
Member

@maxkatz6 maxkatz6 commented Jan 25, 2024

What does the pull request do?

We need an API to allow theme aware TrayIcon icons on MacOS.
On other platforms, it is already somewhat possible by handling system theme changes and replacing whole icon. Though this approach is limited, when you have to reuse single icon for both Window and taskbar, that might have a different theme variant (see #12107 (comment)).

On macOS, unfortunately, this approach wouldn't work at all. Nor ThemedWindowIcon as a concept can be used there.
MacOS tray icon color depends on the background wallpaper image. If it's dark, macOS will invert colors of the tray icon (assuming this icon has IsTemplate=true set). System or application theme can be completely different from these. With that, we don't have flexibility to have a different solution, but implement MacOS.IsTemplateIcon that maps directly on the native [image setTemplate] call.

On both screenshots System theme is Dark, and App theme is Light, but status bar icon is independent from there, changing only with the wallpaper:
Screenshot 2024-01-24 at 7 48 09 PM

Screenshot 2024-01-24 at 7 48 29 PM

Alternative solutions

Only thing that could be different is naming. MacOS uses "IsTemplate", Qt uses "IsMark", UWP used "ShowAsMonochrome" (BitmapIcon.ShowAsMonochrome, which is unrelated to the status bar/tray icon. Since it's a MacOS specific attached property, I chouse MacOS naming.
Also, another option was to add this property to the WindowIcon class. But it would affect way too much class usage, and WindowIcon can't have attached properties.

Checklist

Fixed issues

Related #12107 cc @TomEdwardsEnscape
Fixes #12954 cc @pixsperdavid
Part of #11384

@maxkatz6 maxkatz6 requested a review from grokys January 25, 2024 03:46
@maxkatz6 maxkatz6 added backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch customer-priority Issue reported by a customer with a support agreement. labels Jan 25, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043929-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 changed the title Implement MacOS.IsTemplateIcon attached property on TrayIcon Implement MacOSProperties.IsTemplateIcon attached property on TrayIcon Feb 20, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045110-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Feb 20, 2024
Merged via the queue into master with commit 628a62e Feb 20, 2024
7 checks passed
@maxkatz6 maxkatz6 deleted the template-icon branch February 20, 2024 17:52
@maxkatz6 maxkatz6 removed the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Feb 20, 2024
@grokys grokys added the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Jun 11, 2024
grokys pushed a commit that referenced this pull request Jun 11, 2024
#14348)

* Implement MacOS.IsTemplateIcon attached property on TrayIcon

* Use MacOS.IsTemplateIcon in the ControlCatalog

* Rename MacOS to MacOSProperties

* Extract IsTemplateIcon to ITrayIconWithIsTemplateImpl
@grokys grokys added backported-11.0.x and removed backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch labels Jun 11, 2024
grokys pushed a commit that referenced this pull request Jun 12, 2024
#14348)

* Implement MacOS.IsTemplateIcon attached property on TrayIcon

* Use MacOS.IsTemplateIcon in the ControlCatalog

* Rename MacOS to MacOSProperties

* Extract IsTemplateIcon to ITrayIconWithIsTemplateImpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported-11.0.x customer-priority Issue reported by a customer with a support agreement. os-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants