@@ -6,19 +6,25 @@ namespace eval color {
66 # Variable colors
77 # Preffered way to set widget colors is using add_option.
88 # In some cases, like with tags in_diff/in_sel, we use these colors.
9- variable select_bg lightgray
10- variable select_fg black
9+ variable select_bg lightgray
10+ variable select_fg black
11+ variable inactive_select_bg lightgray
12+ variable inactive_select_fg black
1113
1214 proc sync_with_theme {} {
13- set base_bg [ttk::style lookup . -background]
14- set base_fg [ttk::style lookup . -foreground]
15- set text_bg [ttk::style lookup Treeview -background]
16- set text_fg [ttk::style lookup Treeview -foreground]
17- set select_bg [ttk::style lookup Default -selectbackground]
18- set select_fg [ttk::style lookup Default -selectforeground]
15+ set base_bg [ttk::style lookup . -background]
16+ set base_fg [ttk::style lookup . -foreground]
17+ set text_bg [ttk::style lookup Treeview -background]
18+ set text_fg [ttk::style lookup Treeview -foreground]
19+ set select_bg [ttk::style lookup Default -selectbackground]
20+ set select_fg [ttk::style lookup Default -selectforeground]
21+ set inactive_select_bg [convert_rgb_to_gray $select_bg ]
22+ set inactive_select_fg $select_fg
1923
2024 set color::select_bg $select_bg
2125 set color::select_fg $select_fg
26+ set color::inactive_select_bg $inactive_select_bg
27+ set color::inactive_select_fg $inactive_select_fg
2228
2329 proc add_option {key val} {
2430 option add $key $val widgetDefault
@@ -36,11 +42,20 @@ namespace eval color {
3642 add_option *Text.Foreground $text_fg
3743 add_option *Text.selectBackground $select_bg
3844 add_option *Text.selectForeground $select_fg
39- add_option *Text.inactiveSelectBackground $select_bg
40- add_option *Text.inactiveSelectForeground $select_fg
45+ add_option *Text.inactiveSelectBackground $inactive_select_bg
46+ add_option *Text.inactiveSelectForeground $inactive_select_fg
4147 }
4248}
4349
50+ proc convert_rgb_to_gray {rgb} {
51+ # Simply take the average of red, green and blue. This wouldn't be good
52+ # enough for, say, converting a photo to grayscale, but for this simple
53+ # purpose of approximating the brightness of a color it's good enough.
54+ lassign [winfo rgb . $rgb ] r g b
55+ set gray [expr {($r / 256 + $g / 256 + $b / 256) / 3}]
56+ return [format " #%2.2X%2.2X%2.2X" $gray $gray $gray ]
57+ }
58+
4459proc ttk_get_current_theme {} {
4560 # Handle either current Tk or older versions of 8.5
4661 if {[catch {set theme [ttk::style theme use]}]} {
0 commit comments