@@ -6,19 +6,25 @@ namespace eval color {
6
6
# Variable colors
7
7
# Preffered way to set widget colors is using add_option.
8
8
# 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
11
13
12
14
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
19
23
20
24
set color::select_bg $select_bg
21
25
set color::select_fg $select_fg
26
+ set color::inactive_select_bg $inactive_select_bg
27
+ set color::inactive_select_fg $inactive_select_fg
22
28
23
29
proc add_option {key val} {
24
30
option add $key $val widgetDefault
@@ -36,11 +42,20 @@ namespace eval color {
36
42
add_option *Text.Foreground $text_fg
37
43
add_option *Text.selectBackground $select_bg
38
44
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
41
47
}
42
48
}
43
49
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
+
44
59
proc ttk_get_current_theme {} {
45
60
# Handle either current Tk or older versions of 8.5
46
61
if {[catch {set theme [ttk::style theme use]}]} {
0 commit comments