Skip to content

Commit 01121d6

Browse files
committed
Merge branch 'st/dark-mode' into master
Improve dark mode support. Do not hard-code widget colors and instead pull them from the current theme and update them in the options database. * st/dark-mode: git-gui: improve dark mode support
2 parents 95bfc6c + c02efc1 commit 01121d6

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

git-gui.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ proc rmsel_tag {text} {
720720
-background [$text cget -background] \
721721
-foreground [$text cget -foreground] \
722722
-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
724726
bind $text <Motion> break
725727
return $text
726728
}
@@ -863,6 +865,7 @@ proc apply_config {} {
863865
set NS ttk
864866
bind [winfo class .] <<ThemeChanged>> [list InitTheme]
865867
pave_toplevel .
868+
color::sync_with_theme
866869
}
867870
}
868871
}
@@ -3272,7 +3275,7 @@ pack .vpane -anchor n -side top -fill both -expand 1
32723275
textframe .vpane.files.workdir -height 100 -width 200
32733276
tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
32743277
-background lightsalmon -foreground black
3275-
ttext $ui_workdir -background white -foreground black \
3278+
ttext $ui_workdir \
32763279
-borderwidth 0 \
32773280
-width 20 -height 10 \
32783281
-wrap none \
@@ -3294,7 +3297,7 @@ textframe .vpane.files.index -height 100 -width 200
32943297
tlabel .vpane.files.index.title \
32953298
-text [mc "Staged Changes (Will Commit)"] \
32963299
-background lightgreen -foreground black
3297-
ttext $ui_index -background white -foreground black \
3300+
ttext $ui_index \
32983301
-borderwidth 0 \
32993302
-width 20 -height 10 \
33003303
-wrap none \
@@ -3321,7 +3324,9 @@ if {!$use_ttk} {
33213324
33223325
foreach i [list $ui_index $ui_workdir] {
33233326
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
33253330
}
33263331
unset i
33273332
@@ -3429,7 +3434,7 @@ if {![is_enabled nocommit]} {
34293434
}
34303435
34313436
textframe .vpane.lower.commarea.buffer.frame
3432-
ttext $ui_comm -background white -foreground black \
3437+
ttext $ui_comm \
34333438
-borderwidth 1 \
34343439
-undo true \
34353440
-maxundo 20 \
@@ -3558,7 +3563,7 @@ bind .vpane.lower.diff.header.path <Button-1> {do_file_open $current_diff_path}
35583563
#
35593564
textframe .vpane.lower.diff.body
35603565
set ui_diff .vpane.lower.diff.body.t
3561-
ttext $ui_diff -background white -foreground black \
3566+
ttext $ui_diff \
35623567
-borderwidth 0 \
35633568
-width 80 -height 5 -wrap none \
35643569
-font font_diff \

lib/themed.tcl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
# Functions for supporting the use of themed Tk widgets in git-gui.
22
# Copyright (C) 2009 Pat Thoyts <[email protected]>
33

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+
442
proc ttk_get_current_theme {} {
543
# Handle either current Tk or older versions of 8.5
644
if {[catch {set theme [ttk::style theme use]}]} {

0 commit comments

Comments
 (0)