-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Allow status icons on macOS to adapt to light / dark mode #2861
Comments
I don't know if One of the bigger questions I have is how this would be interpreted on GTK and Windows. Those platforms don't have the |
The naming was just copied over from Apple platforms, there might indeed be better ways to express that concept. Regarding platform support, it's definitely going to be difficult to find an abstraction that works for all of them, especially due to restrictions on file format and content. macOS seems to like its "template" icons in black and clear colors with an alpha channel to adjust opacity. All typical file formats appear supported. Gnome and Gtk have the concept of symbolic icons, see https://wiki.gnome.org/Design/OS/SymbolicIcons and https://docs.gtk.org/gtk3/method.IconInfo.load_symbolic.html, but there appear to be quite tight restrictions about the input format (only SVG) and content that is allowed. I'm not at all familiar with Windows, but symbolic icons that are monochrome and adapt according to system style appear to be the default here. From https://learn.microsoft.com/en-us/windows/apps/design/style/icons, only ImageIcon retains color information from the loaded file |
What is toga's and your approach to APIs that might result in different results depending on the platform? For example, a |
The general approach to platform inconsistencies is to find the "higher order" idea that is being represented, and build an API for that; and if that idea doesn't make any sense on the platform, either log a warning, or not implement the API at all for that platform. In this case, it feels like there's 2 "higher order" features -
Both of these seem like the sort of thing that either exists natively, or can be reasonably implemented for a platform. We should be able to come up with a standard set of icons that are commonly available (Home, Back, Upload, Download etc); macOS may not have default icons, but we could source some standard icons that can be used as a fallback. Similarly, mask icons are definitely a quirk of macOS operation, but any image can be read/converted into a mask and then turned into a black/white-on transparent icon based on whether the app is in light or dark mode. So - I wouldn't object to a "mask=True" argument on I also wouldn't object to |
Agreed on distinguishing the concepts of "mask" and "symbolic" icons, and your suggested fallbacks when not natively supported by a platform.
I believe the concept also exists on Gtk and Windows, that's what I was trying to say in #2861 (comment), though the nomenclature varies for the platforms. What you call mask, Gnome seems to call symbolic (which is a different concept there from default icons for "home" etc). But it would indeed require either a correctly crafted SVG input, or some preceding conversion steps by toga. Similarly, Windows always tries to adapt icon colors to the theme, for all of its icon classes except for ImageIcon. E.g., the docs for a BitmapIcon specify:
|
My apologies - I didn't follow the link you provided, assuming I knew which part of the GTK API you were referring to. I assumed you were talking about named icons in icon themes; I see now that symbolic icons are a whole other thing. I'm not sure how we'd reconcile a hard SVG icon requirement, though. The best thought I've got off the top of my head would be make the list of accepted icon input formats tied to this new flag we're talking about - so a "mask" icon on GTK would require SVG format. This is in addition to baseline addition of support for SVG icons, which look like they will need a different loading mechanism to bitmap-based image sources.
I'd be interested to see how this interacts with Toga's existing icon support - we're doing a straightforward "icon from file"; I presume that means we're implicitly creating Bitmap icons, as I haven't seen any color adaptation. However, the docs you've referenced here are also WinUI3 docs, not Winforms, so maybe the treatment is different due to that, |
What is the problem or limitation you are having?
Menu bar icons on macOS should adapt with dark / light mode. This fits in with menu bar icons provided by the OS and most macOS apps. It also allows developers to use a black or white menu bar icon which would otherwise be almost invisible in dark or light mode, respectively.
Describe the solution you'd like
On macOS, icons automatically adapt to their surroundings when setting
template = true
on the NSImage. See https://developer.apple.com/documentation/appkit/nsimage/1520017-template.We should make
template: bool
a general argument totoga.Icon
for all platforms that support it. This would allow icons to be used more flexibly as templates and fit in more naturally in many environments besides the menu bar.Describe alternatives you've considered
We always set this flag in the toga-cocoa StatusIcon implementation. While macOS does allow colored menu bar icons, those are very uncommon.
Additional context
No response
The text was updated successfully, but these errors were encountered: