git-gui: use gray background for inactive text widgets
This makes it easier to see at a glance which of the four main views has the keyboard focus. Signed-off-by: Stefan Haller <stefan@haller-berlin.de> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
Stefan Haller committed
Dec 18, 2020 at 10:43 UTC
da4d86da97a316413cf25bef99332525dbfb4d59
2 files changed
+37
-16
git-gui.sh
+12
-6
@@ -720,9 +720,6 @@ proc rmsel_tag {text} {
720
-background [$text cget -background] \
721
-foreground [$text cget -foreground] \
722
-borderwidth 0
723
- $text tag conf in_sel\
724
- -background $color::select_bg \
725
- -foreground $color::select_fg
723
bind $text <Motion> break
724
return $text
725
}
@@ -3328,11 +3325,20 @@ if {!$use_ttk} {
3325
.vpane.files paneconfigure .vpane.files.index -sticky news
3326
}
3327
3328
+proc set_selection_colors {w has_focus} {
3329
+ foreach tag [list in_diff in_sel] {
3330
+ $w tag conf $tag \
3331
+ -background [expr {$has_focus ? $color::select_bg : $color::inactive_select_bg}] \
3332
+ -foreground [expr {$has_focus ? $color::select_fg : $color::inactive_select_fg}]
3333
+ }
3334
+}
3335
+
3336
foreach i [list $ui_index $ui_workdir] {
3337
rmsel_tag $i
3333
- $i tag conf in_diff \
3334
- -background $color::select_bg \
3335
- -foreground $color::select_fg
3338
+
3339
+ set_selection_colors $i 0
3340
+ bind $i <FocusIn> { set_selection_colors %W 1 }
3341
+ bind $i <FocusOut> { set_selection_colors %W 0 }
3342
}
3343
unset i
3344
lib/themed.tcl
+25
-10
@@ -6,19 +6,25 @@ namespace eval color {
6
# Variable colors
7
# Preffered way to set widget colors is using add_option.
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
13
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
23
24
set color::select_bg $select_bg
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
28
29
proc add_option {key val} {
30
option add $key $val widgetDefault
@@ -36,11 +42,20 @@ namespace eval color {
42
add_option *Text.Foreground $text_fg
43
add_option *Text.selectBackground $select_bg
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
47
}
48
}
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
+
59
proc ttk_get_current_theme {} {
60
# Handle either current Tk or older versions of 8.5
61
if {[catch {set theme [ttk::style theme use]}]} {