@matheusbsbs / matheus-bagliano / commits / c02efc1363
Fork 0

git-gui: improve dark mode support

The colors of some ttext widgets are hard-coded. These hard-coded colors are okay with a light theme but with a dark theme some widgets are dark colored and the hard-coded ones are still light. This defeats the purpose of applying the theme and makes the UI look very awkward. Remove the hard-coded colors in ttext calls and use colors from the theme for those widgets via Text.Background and Text.Foreground from the option database. Similarly, the highlighting for the currently selected file(s) in the "Staged Files" and "Unstaged Files" sections is also hard-coded. Pull the colors for that from the current theme to make sure it is in line Signed-off-by: Serg Tereshchenko <serg.partizan@gmail.com> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>

Serg Tereshchenko committed Sep 26, 2020 at 17:54 UTC c02efc13638447f9af0be6cb158a6c1a8dd4c727
2 files changed +49 -6
git-gui.sh
+11 -6
@@ -720,7 +720,9 @@ proc rmsel_tag {text} {
720 -background [$text cget -background] \
721 -foreground [$text cget -foreground] \
722 -borderwidth 0
723 - $text tag conf in_sel -background lightgray
723 + $text tag conf in_sel\
724 + -background $color::select_bg \
725 + -foreground $color::select_fg
726 bind $text <Motion> break
727 return $text
728 }
@@ -863,6 +865,7 @@ proc apply_config {} {
865 set NS ttk
866 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
867 pave_toplevel .
868 + color::sync_with_theme
869 }
870 }
871 }
@@ -3272,7 +3275,7 @@ pack .vpane -anchor n -side top -fill both -expand 1
3275 textframe .vpane.files.workdir -height 100 -width 200
3276 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3277 -background lightsalmon -foreground black
3275 -ttext $ui_workdir -background white -foreground black \
3278 +ttext $ui_workdir \
3279 -borderwidth 0 \
3280 -width 20 -height 10 \
3281 -wrap none \
@@ -3294,7 +3297,7 @@ textframe .vpane.files.index -height 100 -width 200
3297 tlabel .vpane.files.index.title \
3298 -text [mc "Staged Changes (Will Commit)"] \
3299 -background lightgreen -foreground black
3297 -ttext $ui_index -background white -foreground black \
3300 +ttext $ui_index \
3301 -borderwidth 0 \
3302 -width 20 -height 10 \
3303 -wrap none \
@@ -3321,7 +3324,9 @@ if {!$use_ttk} {
3324
3325 foreach i [list $ui_index $ui_workdir] {
3326 rmsel_tag $i
3324 - $i tag conf in_diff -background [$i tag cget in_sel -background]
3327 + $i tag conf in_diff \
3328 + -background $color::select_bg \
3329 + -foreground $color::select_fg
3330 }
3331 unset i
3332
@@ -3429,7 +3434,7 @@ if {![is_enabled nocommit]} {
3434 }
3435
3436 textframe .vpane.lower.commarea.buffer.frame
3432 -ttext $ui_comm -background white -foreground black \
3437 +ttext $ui_comm \
3438 -borderwidth 1 \
3439 -undo true \
3440 -maxundo 20 \
@@ -3558,7 +3563,7 @@ bind .vpane.lower.diff.header.path <Button-1> {do_file_open $current_diff_path}
3563 #
3564 textframe .vpane.lower.diff.body
3565 set ui_diff .vpane.lower.diff.body.t
3561 -ttext $ui_diff -background white -foreground black \
3566 +ttext $ui_diff \
3567 -borderwidth 0 \
3568 -width 80 -height 5 -wrap none \
3569 -font font_diff \
lib/themed.tcl
+38
@@ -1,6 +1,44 @@
1 # Functions for supporting the use of themed Tk widgets in git-gui.
2 # Copyright (C) 2009 Pat Thoyts <patthoyts@users.sourceforge.net>
3
4 +
5 +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
11 +
12 + 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]
19 +
20 + set color::select_bg $select_bg
21 + set color::select_fg $select_fg
22 +
23 + proc add_option {key val} {
24 + option add $key $val widgetDefault
25 + }
26 + # Add options for plain Tk widgets
27 + # Using `option add` instead of tk_setPalette to avoid unintended
28 + # consequences.
29 + if {![is_MacOSX]} {
30 + add_option *Menu.Background $base_bg
31 + add_option *Menu.Foreground $base_fg
32 + add_option *Menu.activeBackground $select_bg
33 + add_option *Menu.activeForeground $select_fg
34 + }
35 + add_option *Text.Background $text_bg
36 + add_option *Text.Foreground $text_fg
37 + add_option *Text.HighlightBackground $base_bg
38 + add_option *Text.HighlightColor $select_bg
39 + }
40 +}
41 +
42 proc ttk_get_current_theme {} {
43 # Handle either current Tk or older versions of 8.5
44 if {[catch {set theme [ttk::style theme use]}]} {