Tk Source Code

View Ticket
Login
Ticket UUID: c6292f7bd94137f17faad7a7c130de01cd19ba0a
Title: Use the native selection colors for listbox and ttk::treeview widgets on aqua
Type: Patch Version: all
Submitter: nemethi Created on: 2025-12-29 19:47:38
Subsystem: 66. Aqua Window Operations Assigned To: nemethi
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-02-21 20:31:03
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-02-21 20:31:03
Description:

The file macosx/tkMacOSXDefault.h contains the lines

#define SELECT_BG               "systemSelectedTextBackgroundColor"
#define SELECT_FG               "systemSelectedTextColor"

#define DEF_LISTBOX_SELECT_COLOR        SELECT_BG
#define DEF_LISTBOX_SELECT_FG_COLOR     SELECT_FG

These colors are used not only for text, (ttk::)entry, (ttk::)spinbox, and ttk::combobox widgets, but also for listbox and ttk::treeview widgets.  For the themed widgets this is due to the following lines in the file library/ttk/aquaTheme.tcl:

ttk::style configure . \
    ...
    -selectbackground systemSelectedTextBackgroundColor \
    -selectforeground systemSelectedTextColor \
    ...

ttk::style map Treeview \
    -background {
        selected systemSelectedTextBackgroundColor
    }

However, the resulting appearance of the selected rows/cells of a listbox or ttk::treeview widget is different from what the mac users can see in native list and table view windows.  The patch implemented in the branch aqua_select_colors eliminates this long-standing discrepancy by applying a few straightforward changes to the files library/ttk/aquaTheme.tcl and macosx/ttkMacOSXTheme.c.

I have successfully tested the proposed patch with the macOS versions 10.13.6, 10.14.6, 10.15.6, 15.7, and 26.2.  Any comments are highly appreciated!

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-02-21 20:31:03:

Fixed in trunk with commits [19bc3769] and [4edc873d], and in core-9-0-branch with commits [107dce5b], [4b4fd370], and [d323fc1f].


nemethi (claiming to be Csaba Nemethi) added on 2026-02-20 20:20:47:

Many thanks, Jan!

I can recall a discussion concerning the minimum supported macOS version. AFAIR, it was Marc who opted for 10.13 as earliest OS version to support.


jan.nijtmans added on 2026-02-20 19:58:06:

All tests pass on MacOS 12

MacOS 10.13 (High Sierra) is obsolete reached end-of-life status on November 12, 2020 (so 5 years ago). Many 3th-party apps don't work on it any more. I would be OK for me (for Tk 9.1) to drop support for MacOS < 10.14.

I'm running MacOS 12, which went end-of-life the end of 2024.

Thanks!


nemethi (claiming to be Csaba Nemethi) added on 2026-02-20 17:39:39:
"I successful" -> "If successful", sorry!

nemethi (claiming to be Csaba Nemethi) added on 2026-02-20 17:38:11:

Jan, could you repeat the test, please? I successful then I will apply the changes to core-9-0-branch, too.


nemethi (claiming to be Csaba Nemethi) added on 2026-02-20 15:32:56:

Many thanks, Jan! This is bad news, indeed. I have just seen your comment. I have started to fix this issue, I will commit a new version ASAP.


jan.nijtmans added on 2026-02-20 14:45:17:

Starting with [107dce5beb17e227|this] commit, Tk 9.0 has the same problem :-(


jan.nijtmans added on 2026-02-20 14:33:05:

Sorry, bad news. I see 35 new test failures on MacOS (only), here's the first one:

safe.test

==== safe-1.1 Safe Tk loading into an interpreter FAILED ==== Contents of test case:

safe::loadTk [safe::interpCreate a] safe::interpDelete a set x {} return $x

---- Test generated error; Return code was: 1 ---- Return code should have been one of: 0 2 ---- errorInfo: Can't find a usable tk.tcl in the following directories: {$p(:12:)}

$p(:12:)/tk.tcl: can't read "::tcl_platform(osVersion)": no such element in array can't read "::tcl_platform(osVersion)": no such element in array invoked from within "source {$p(:12:)/tk.tcl}" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $file]"

This probably means that tk wasn't installed properly.

while executing "error $msg" (procedure "tcl_findLibrary" line 161) invoked from within "tcl_findLibrary tk $tk_version $tk_patchLevel tk.tcl TK_LIBRARY tk_library" (procedure "tkInit" line 4) invoked from within "tkInit" ("interp eval" body line 8) invoked from within "load {} Tk $child" (procedure "safe::loadTk" line 61) invoked from within "safe::loadTk [safe::interpCreate a]" ("uplevel" body line 2) invoked from within "uplevel 1 $script" ---- errorCode: NONE ==== safe-1.1 FAILED

Explanation: You cannot use $::tcl_platform(osVersion) in a safe interpreter, it doesn't exist there.


nemethi (claiming to be Csaba Nemethi) added on 2026-01-09 15:33:15:

Nicolas, I must first clear with Brian O'Hagan whether we can use TTK_STATE_FOCUS rather than TTK_STATE_USER1, and I am still waiting for Marc to get some time for a review.


nab added on 2026-01-09 09:41:41:
Hi Csaba,
any chance to have this branch merged "soon" ?

best regards,
nicolas

nemethi (claiming to be Csaba Nemethi) added on 2026-01-06 13:33:33:

Kevin, many thanks for your positive feedback!

Some more progress:

With the commit [394fb431] we now have a greatly improved appearance on aqua, including more native-like open/close indicator colors and different default selection colors depending on whether the widget has the input focus or not.

And the commit [aeb8d2cb] eliminates any conflicts with the enhanced treeview implementation by Brian O'Hagan.


kevin_walzer added on 2026-01-03 17:47:41:
Csaba, this looks great! The selection color on list boxes and tree views has been a long-standing annoyance - this corrects that issue very well. I'm in favor of merging to trunk and core-9-0. Are we merging ANY fixes to 8.6 at this point? If so, and it doesn't break anything else, I'm fine with merging this to that branch as well. Thanks for your great work.

nemethi (claiming to be Csaba Nemethi) added on 2026-01-02 18:10:52:

I have just committed a significantly improved version of the file macosx/ttkMacOSXTheme.c, in which the disclosure chevrons and filled triangles for ttk::treeview widgets are drawn with the same functions, thus making sure that the right colors are used for all supported macOS versions (white if the row or cell is selected, and the text color otherwise).


nemethi (claiming to be Csaba Nemethi) added on 2025-12-30 11:06:50:

Thanks Nicolas, this confirms my positive test results.

I am still waiting for further feedback, especially from Marc, Kevin, Christopher, ...  In case the Mac experts agree with merging the branch aqua_select_colors into main, the next question is whether it may be merged also into core-9-0-branch (and core-8-6-branch).  Actually, the proposed patch fixes a very long-standing bug related to the visual appearance of the listbox and ttk::treeview widgets, present in all Tk versions.  OTOH, I think we need consent regarding the affected Tk versions.


nab added on 2025-12-30 06:08:00:
Hi Csaba,
I've tried your branch for listbox and it works fine (macOS 26.2). I can open the Preferences app and change used colour and it's responsive in my app.

bg and fg works accordingly 

best regards,
nicolas