Tk Source Code

View Ticket
Login
Ticket UUID: 2beda17141bb4e8f9ba3a18fd64845aaadf1d8f5
Title: Default canvas item colors are hard to see on dark mode
Type: Bug Version: core-8-6-branch
Submitter: chrstphrchvz Created on: 2019-08-07 05:59:54
Subsystem: 05. Canvas Items Assigned To: kevin_walzer
Priority: 6 Severity: Minor
Status: Closed Last Modified: 2019-11-10 23:53:03
Resolution: Fixed Closed By: chrstphrchvz
    Closed on: 2019-11-10 23:53:03
Description:

Some canvas items have hardcoded default colors, while others and the canvas itself do not. Colors that were hardcoded assume light theming is used. As a result, when a program does not override any canvas colors, and dark theming is in use, then the canvas will be a dark color but various items in it (text, shapes, etc.) will be difficult to see.

I have been combing through the canvas code to try removing hardcoded colors by adding constants to the tkWinDefault.h, tkMacOSXDefault.h, and tkUnixDefault.h files, but it now occurred to me that I should first instead ask:

Should all default canvas colors, including the background of the canvas itself, be hardcoded (i.e. to "white"), or should the canvas use dark theme-compatible colors?

I would prefer the latter, but want to see if anyone disagrees.

Behavior on 8.6.9.1/light theming:

Current core-8-6-branch behavior on dark theming:

Behavior on dark theming if background were to be hardcoded (an obvious problem being that windows' default colors will be window manager-influenced rather than hardcoded):

Behavior on dark theming, if colors can instead be influenced by window manager (unfinished example to give an idea):

(There are inconsistencies between different items and platforms regarding how certain options like -stipple and -fill behave, as well as contradictions between the documentation and the demos, but those are probably separate issues to file.)

User Comments: chrstphrchvz added on 2019-11-10 23:53:03:

There was some discussion about the effects on Windows. On recent Windows versions (e.g. Windows 10), the system-wide dark mode normally only affects newer UWP apps, and not older Win32 API programs like Tk (see [6b47d7eba8]). And as of Windows 8, the old theming engine is "gone", limiting the user's options for adjusting the appearance of Win32 programs.

One way to obtain a dark appearance for Win32 programs is using the system-wide high contrast mode. I neglected to mention here that I had tested my patch using this mode, and observed improved appearance. (Maybe high contrast mode is something Tk should support anyways.)

Before (8.6.9):

After:


jan.nijtmans added on 2019-10-04 13:21:26:

Here is the difference in layout between today's Tk 8.6 and 8.7 (left is 8.6, right is 8.7) on Windows.

Hopefully, this is convincing enough, why this change is not for 8.6!


jan.nijtmans added on 2019-10-04 12:46:01:
Well, I came to the conclusion that the polygon change is more than a simple change: If no -fill is specified, the new behavior is that there really is no fill. I don't think that's acceptable in a patch release. Sorry!

For Tk 8.7, I think it's a good idea to fix this, but there - indeed - should be a big **POTENTIONAL INCOMPATIBILITY** mark in the changelog. I adapted the demo (look at the green start in the right upper square) to see the effect: In Tk 8.7 it has a green border only, while the lower shape has a border. In Tk 8.6, the star is filled black, and the lower shape has no border.

I prefer the 8.7 behavior, that's not the point! But too many scripts will already depend on the current behavior, even our own canvas demo!

Hope this helps!

jan.nijtmans added on 2019-10-04 07:42:17:
@kevin_walzer/@marc_culler: Point taken. The question is here how much 'incompatibility' is allowed for a patch release. Since 8.6.10 is coming soon (seen by the frequent merges to the rc branch), I woulnd't take too much risk.
But I like to put in the 8.6.10 release something like "some support for Dark Mode added"    ;-)

Little changes in colors don't worry me. What worries me is borders appearing when there were no borders before or reverse. I'll spend some time to investigate this on Windows, and I will come back here with my conclusions.
I think we still have some time to investigate this further before coming to a final decision.

Thanks, again! This is a usefull discussion!

kevin_walzer added on 2019-10-04 01:26:38:
Do I understand that the objections here are boiling down to cosmetic changes? 

Perhaps it's because I'm too accustomed to the Mac, but I see zero issue with things looking a bit different in a patch release of Tk. In Aqua, things look different every time Apple releases a new OS. It's a given. If a cosmetic change in Tk presents issues on other platforms--not a script incompatibility, but simply a change in appearance--then it's because those platforms are unaccustomed to change. 

Since it was my quick commit of this patch that started this whole debate, I was going to revert the patch since that seemed to be the clear direction of the discussion. But I'm going to hold off. The patch offers clear benefits on Aqua, and I haven't heard any discussion of the canvas suddenly being broken on X and Windows.

marc_culler (claiming to be Marc Culler) added on 2019-10-04 00:10:49:

Sorry, but this backwards incomptibility argument makes no sense to me. I think it is detached from the facts.

First, making the default polygon -outline color agree with the manual is a bug fix, not a backwards incompatibility.

Second, as far as I know this patch does not change the appearance of anything, provided that the window system is not in "dark mode" (for macOS) or the equivalent for Windows. Since I know nothing about the Windows version of "dark mode" I can only speak about macOS. In macOS, code which was written before "Dark Aqua" existed, i.e. more than one year ago, would not have been written to use any of the new features (mainly the "semantic colors") which were added to 8.6 in order to make Tk usable when "Dark Aqua" is enabled. However the previous changes to 8.6 included changing default color values in a way which would make Tk code that worked fine in "Light Aqua" also be usable in "Dark Aqua". The primary effect of the changes is to avoid white text on a white background and black text on a black background, which I think anyone would agree is not usable. This patch is a small extension of the previous ones which aims to also make it so that Canvas items which worked in "Light Aqua" are usable in "Dark Aqua". I do not think it has any effect on how those Canvas items look in "Light Aqua".

It just seems crazy to me to use "backwards compatibility" as a reason to force Tk 8.6 code written before "Dark Aqua" existed to be unusable when "Dark Mode" is enabled. That seems like the opposite of compatibility. It seems like forced incompatibility.


jan.nijtmans added on 2019-10-03 21:43:02:
So, let me add my doubts too for 8.6. My preference would also be to revert it for 8.6, and keeping it in 8.7.  Since 8.6 is coming soon, it's a too high risk. It's not an incompatibility on script level, but canvas items will start looking differently. That - indeed - is not expected in a patch release.

So, my +1 to revert it for 8.6, and +1 to keep it in 8.7

fvogel added on 2019-10-03 19:37:33:

I completely agree. This patch should never have been merged into core-8-6-branch, only into trunk. I had expressed my thoughts about this on the Tcl core list.

Unless someone objects with good reasons, I think we should revert [a714ac08] and [3ab284f6], and keep only the (modified) patch as it is currently in trunk.


pspjuth added on 2019-10-03 19:17:41:
Changing the defaults of -fill and -outline on the polygon is not backwards compatible. I cannot see how that can be acceptable specially in a patch release.

I can agree that it might be prettier to have the same as the others, but that really is not good enough reason to make an incompatible change.

At least, if this is kept, put a big incompatibility warning in.

jan.nijtmans added on 2019-10-03 08:36:39:
The simple observation that at least the default for polygons, arcs and ovals should be equal, I'm agreeing with Marc and François.

So, it's most logical to adapt the test-case value.

Thanks!  Not closing yet (changed to "pending"), let's test the implications thourougly.

marc_culler (claiming to be Marc Culler) added on 2019-10-02 21:48:07:
Before this change the default value of the -outline option was NULL which I
believe is equivalent to setting the -outline option to an empty string.
According to the manual, this means that no outline should be drawn.

Testing in Wish I see that setting the -outline option of a polygon to a
non-empty value causes the bounding box to expand by 1 pixel at the left, top,
right and bottom sides.  That is exactly what is happening in the test.  So
all that we are seeing in the test failure is that the polygon now has a
non-empty -outline color.

However, the manual actually says that the default value of the -outline
option (as well as the -activeoutline and -disabledoutline options) should be
"black", not {}.  So I think that Christopher thought he was changing the
default value of -outline from "black" to a possibly different color, based on
reading the manual.  But in fact he was changing it from {} to a non-empty color
string, causing the polygon to expand by 1 pixel in each direction and the test
to fail.  Since the previous behavior did not agree with the manual I think we
should probably adjust the test result.

fvogel added on 2019-10-02 05:56:41:
I didn't analyze the impact of such partial revert of the patch proposed in this ticket, did you? I guess if Christopher included this in his patch, and Marc validated this (see below 2019-09-09 16:31:20), then it means it answered a need for an the improved rendering of the canvas polygon item.

It is not clear to me how that (color?) change triggered a change in the polygon item bounding box after rotation, which is what canvas-22.6 reveals. I think we should make our (at least, my) ideas clear with this before rushing in changing and merging further.

Perhaps the expected result of the test really was what needed to be changed. I'll have a further look as time permits.

kevin_walzer added on 2019-10-02 01:40:13:
All tests passed in core-8-6-branch and so I did not run the test suite in trunk; that's on me. Per your suggestion, I have backed out the change you referenced and no longer see that failure in the test suite for trunk. You are welcome to close this ticket if you feel the issue is addressed.

fvogel added on 2019-10-01 19:45:55:
Forgot to add: this test suite failure can be seen in trunk only, there is no canvas-22.6 test in core-8-6-branch. Canvas items rotation was added through TIP #164, which targeted 8.7 (i.e. trunk) only.

fvogel added on 2019-10-01 19:36:39:

The patch got merged but it triggers a new failure in the test suite:

==== canvas-22.6 canvas rotate: polygon item rotation behaviour FAILED
==== Contents of test case:

    .c create polygon 50 50 75 50 50 75 75 75
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}]  [lmap o {} {.c itemcget all $o}]  [.c bbox all]

---- Result was:
{50.00 150.00 50.00 125.00 75.00 150.00 75.00 125.00} {} {48 123 77 152}
---- Result should have been (exact matching):
{50.00 150.00 50.00 125.00 75.00 150.00 75.00 125.00} {} {49 124 76 151}
==== canvas-22.6 FAILED

Therefore reopening.

The problem is the change from NULL to DEF_CANVITEM_OUTLINE in the -outline option in tkCanvPoly.c. Reverting this change makes the failure disappear.

It would have been nice to see this before merging. This new failure can be seen on all three platforms (Win, macOS, Linux), simply by running the test suite in any of them.


fvogel added on 2019-09-29 08:11:13:

Kevin Walzer called for review and comments on Tcl-Core list and further discussion about the proposed patch happened here.

The patch got merged therefore I'm closing this ticket.


chrstphrchvz added on 2019-09-09 17:10:32:

Thanks for reviewing the patch.

…using systemSelectedTextBackgroundColor in the arrow and scrolling canvas demos. I assume this was done as a way of producing a color which is guaranteed to contrast with the background whether or not dark mode is in effect.

That is correct. At a minimum I probably should have left a comment explaining the color choice.

The question is whether we should add a new Tk "semantic" color, "systemSelectedContentBackgroundColor" based on Apple's selectedContentBackgroundColor.

Maybe, if it would be useful elsewhere besides the demos I updated (though even in those cases, it still would be used as a contrasting fill rather than indicating content selection). Essentially, if it makes a better choice than SELECT_BG/systemSelectedTextBackgroundColor for various defaults in e.g. tkMacOSXDefault.h.


marc_culler (claiming to be Marc Culler) added on 2019-09-09 16:31:20:

I support all of the changes in this patch. Adding default colors for canvas objects to the header files that get included into defaults.h (and using those defaults) is a good idea. Choosing defaults that behave reasonably in dark mode is a good idea. The modifications to the behavior of polygons is an improvement. Cleaning up the demos so they behave well in dark mode is helpful.

For the documentation on outlines and lines I think it would be reasonable to say that the default color is the same as that used for the default text foreground color which, like the widget's default background color, changes when dark mode is in effect and constrasts with the background in either mode.

I have one question that I think deserves further discussion, although I don't think the question needs to be resolved before applying the patch. The question is prompted by the choice of using systemSelectedTextBackgroundColor in the arrow and scrolling canvas demos. I assume this was done as a way of producing a color which is guaranteed to contrast with the background whether or not dark mode is in effect. But clearly that color was intended for a specific purpose which is related, but somewhat different. The question is whether we should add a new Tk "semantic" color, "systemSelectedContentBackgroundColor" based on Apple's selectedContentBackgroundColor. That color was introduced in 10.14 so we would need to simulate it for older versions of the OS, as was done in several other cases.


kevin_walzer added on 2019-09-09 11:45:52:
Given the extensive nature of this patch, I am deferring consideration of it until Marc Culler has time to review, as the Dark Mode changes were mainly his.

chrstphrchvz added on 2019-08-22 21:36:24:

I have attached a patch to adds constants for default colors that can be influenced by the window manager on Aqua and Windows; I haven't figured out how to address this issue on X11, so appearance on X11 is mostly unaffected. The canvas widget demos are also updated to have better appearance under dark mode, using either semantic colors, or colors that contrast better with both with black and white.

  • The default polygon fill is now NULL (i.e. {}); it used to be black. Based on existing documentation, this should probably already have been NULL, as it is for arcs, ovals, and rectangles (this was reported in [2860519]).
  • The default polygon outline is now NORMAL_FG instead of NULL, though based on existing documentation, it was probably supposed to have been black, just like for other items.
  • The default text fill, bitmap foreground, arc/oval/rectangle outline, and line fill color are now NORMAL_FG instead of black, deviating from previously documented behavior. (Q: What should the documentation now say instead? I have so far only removed mention of the previously hardcoded default.)


marc_culler (claiming to be Marc Culler) added on 2019-08-14 19:40:53:
I agree that the default canvas background and foreground colors should be
compatible with dark themes, i.e. appropriate semantic colors in the case of
macOS.

Attachments: