Tk Source Code

View Ticket
Login
Ticket UUID: 01f58bf8f1ae4e5194cfa2d1b483c01309864172
Title: Aqua color rgb values do not behave as expected when appearance is changed
Type: Bug Version: 9.0
Submitter: marc_culler Created on: 2024-10-11 14:16:43
Subsystem: 02. Appearance Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-10-14 13:50:16
Resolution: Fixed Closed By: marc_culler
    Closed on: 2024-10-14 13:50:16
Description:
Run the following commands in wish:

% # Start in light mode
% winfo rgb . systemWindowBackgroundColor
60652 60652 60652
% # Now switch to dark mode -- root window remains light
% winfo rgb . systemWindowBackgroundColor
60652 60652 60652

As indicated in the comments, the background color of the root toplevel does
not change appearance as expected.  (Note: ttk::frames work better.) Also the
rgb values of semantic colors do not change when the appearance changes.

I have a proposed fix (and simplification of the color code) in the branch
named aqua_color.

The new behavior is as expected:

% # Start in light mode
% winfo rgb . systemWindowBackgroundColor
60652 60652 60652
% # Now switch to dark mode -- root window becomes dark
% winfo rgb . systemWindowBackgroundColor
12850 12850 12850
User Comments: marc_culler (claiming to be Marc Culler) added on 2024-10-14 13:50:16:
Fixed in commit 47f17f3d.  Closing the ticket.

marc_culler (claiming to be Marc Culler) added on 2024-10-12 16:57:35:
Indeed, it would not be easy to use semantic colors in the svg images.
And that is exactly the sort of thing that those virtual events were
intended to make possible.

nemethi (claiming to be Csaba Nemethi) added on 2024-10-11 17:53:12:

I have successfully tested the new version. Your sample script works as expected for me, too.

The binding scripts for the virtual events <<LightAqua>> and <<DarkAqua>> in the Widget Demo are needed with the new version, too. This is because the colors of the SVG images must be specified in the form #RRGGBB (the SVG library used by Tk doesn't support color names), and this value depends on the appearance.


marc_culler (claiming to be Marc Culler) added on 2024-10-11 14:48:28:
An implementation note:  It turned out that the attempt to manage semantic
colors by repurposing the otherwise unused colormap was already in place.
But it could not be made to work because the colorNameTable maintained in
the display only uses names for keys, not (name, colormap) pairs.  When
a color is extracted from a TclObj of type color, the color is looked up
by name but if a color is found with the right name but the wrong colormap
then it is ignored.  Essentially there is an undocumented assumption that
two colormaps will never share any color names.  That assumption does not
hold on macOS if light mode and dark mode colors are placed in two
different colormaps.  However, by some miracle it turns out that if all
colors use the same colormap then the rgb values work correctly when
changing the appearance.  That simplifies the code.