{"thread":{"id":"25632","subject":"[PATCH] gitk: improve dark background support","startedAt":"2010-11-04T00:35:24Z","lastAt":"2010-11-11T04:59:18Z","messageCount":3,"participants":["David Fries","Matthijs Kooijman"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"155100","messageId":"20101104003524.GI7835@spacedout.fries.net","threadId":"25632","inReplyTo":null,"subject":"[PATCH] gitk: improve dark background support","fromName":"David Fries","fromEmail":"david@fries.net","sentAt":"2010-11-04T00:35:24Z","receivedAt":"2010-11-04T00:35:24Z","isPatch":true,"sender":{"key":"david@fries.net","avatar":"https://avatars.githubusercontent.com/u/2767875?v=4"},"body":"Replace most uses of black with $fgcolor as items such as a black\noutline on the tag or tag lines with a black background doesn't show\nup.  Use $fgcolor instead to make it contrast with the background.\n\nUse diffcolor 2 for link as blue on a black background might as well\nlook like dark blue on black and is very difficult to read.  The\n\"Diff: hunk header\" keeps the colors more consistent and both default\nto blue.\n\nIf the foreground color is dark use light tags, branches, and\nremote fill colors.  If it is light use darker versions so the\ntext is readable.\n\nSigned-off-by: David Fries <David@Fries.net>\n---\n gitk-git/gitk |   40 ++++++++++++++++++++++++++++++++--------\n 1 files changed, 32 insertions(+), 8 deletions(-)\n\ndiff --git a/gitk-git/gitk b/gitk-git/gitk\nindex 1b0e09a..ca9244f 100644\n--- a/gitk-git/gitk\n+++ b/gitk-git/gitk\n@@ -6233,6 +6233,7 @@ proc drawtags {id x xt y1} {\n     global idtags idheads idotherrefs mainhead\n     global linespc lthickness\n     global canv rowtextx curview fgcolor bgcolor ctxbut\n+    global tagcolor branchcolor remotecolor\n \n     set marks {}\n     set ntags 0\n@@ -6270,7 +6271,7 @@ proc drawtags {id x xt y1} {\n \tset xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]\n     }\n     set t [$canv create line $x $y1 [lindex $xvals end] $y1 \\\n-\t       -width $lthickness -fill black -tags tag.$id]\n+\t       -width $lthickness -fill $fgcolor -tags tag.$id]\n     $canv lower $t\n     foreach tag $marks x $xvals wid $wvals {\n \tset xl [expr {$x + $delta}]\n@@ -6280,13 +6281,13 @@ proc drawtags {id x xt y1} {\n \t    # draw a tag\n \t    set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \\\n \t\t       $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \\\n-\t\t       -width 1 -outline black -fill yellow -tags tag.$id]\n+\t\t       -width 1 -outline $fgcolor -fill $tagcolor -tags tag.$id]\n \t    $canv bind $t <1> [list showtag $tag 1]\n \t    set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]\n \t} else {\n \t    # draw a head or other ref\n \t    if {[incr nheads -1] >= 0} {\n-\t\tset col green\n+\t\tset col $branchcolor\n \t\tif {$tag eq $mainhead} {\n \t\t    set font mainfontbold\n \t\t}\n@@ -6295,14 +6296,14 @@ proc drawtags {id x xt y1} {\n \t    }\n \t    set xl [expr {$xl - $delta/2}]\n \t    $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \\\n-\t\t-width 1 -outline black -fill $col -tags tag.$id\n+\t\t-width 1 -outline $fgcolor -fill $col -tags tag.$id\n \t    if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {\n \t        set rwid [font measure mainfont $remoteprefix]\n \t\tset xi [expr {$x + 1}]\n \t\tset yti [expr {$yt + 1}]\n \t\tset xri [expr {$x + $rwid}]\n \t\t$canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \\\n-\t\t\t-width 0 -fill \"#ffddaa\" -tags tag.$id\n+\t\t\t-width 0 -fill $remotecolor -tags tag.$id\n \t    }\n \t}\n \tset t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \\\n@@ -6673,7 +6674,7 @@ proc appendwithlinks {text tags} {\n }\n \n proc setlink {id lk} {\n-    global curview ctext pendinglinks\n+    global curview ctext pendinglinks diffcolors\n \n     set known 0\n     if {[string length $id] < 40} {\n@@ -6687,7 +6688,7 @@ proc setlink {id lk} {\n \tset known [commitinview $id $curview]\n     }\n     if {$known} {\n-\t$ctext tag conf $lk -foreground blue -underline 1\n+\t$ctext tag conf $lk -foreground [lindex $diffcolors 2] -underline 1\n \t$ctext tag bind $lk <1> [list selbyid $id]\n \t$ctext tag bind $lk <Enter> {linkcursor %W 1}\n \t$ctext tag bind $lk <Leave> {linkcursor %W -1}\n@@ -8215,6 +8216,7 @@ proc linehover {} {\n     global hoverx hovery hoverid hovertimer\n     global canv linespc lthickness\n     global commitinfo\n+    global fgcolor\n \n     set text [lindex $commitinfo($hoverid) 0]\n     set ymax [lindex [$canv cget -scrollregion] 3]\n@@ -8227,7 +8229,7 @@ proc linehover {} {\n     set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]\n     set y1 [expr {$y + $linespc + 2 * $lthickness}]\n     set t [$canv create rectangle $x0 $y0 $x1 $y1 \\\n-\t       -fill \\#ffff80 -outline black -width 1 -tags hover]\n+\t       -fill \\#ffff80 -outline $fgcolor -width 1 -tags hover]\n     $canv raise $t\n     set t [$canv create text $x $y -anchor nw -text $text -tags hover \\\n \t       -font mainfont]\n@@ -10877,6 +10879,23 @@ proc setbg {c} {\n     }\n }\n \n+proc setfill {c} {\n+    global tagcolor branchcolor remotecolor\n+\n+    set fg [winfo rgb . $c]\n+    if {[lindex $fg 0] + 1.5 * [lindex $fg 1] + 0.5 * [lindex $fg 2] > 100000} {\n+\t# dark fill to read a light foreground font\n+\tset tagcolor yellow4\n+\tset branchcolor green4\n+\tset remotecolor \"#806F55\"\n+    } else {\n+\t# light fill to read a dark foreground font\n+        set tagcolor yellow\n+        set branchcolor green\n+        set remotecolor \"#ffddaa\"\n+    }\n+}\n+\n proc setfg {c} {\n     global fglist canv\n \n@@ -10886,6 +10905,8 @@ proc setfg {c} {\n     allcanvs itemconf text -fill $c\n     $canv itemconf circle -outline $c\n     $canv itemconf markid -outline $c\n+\n+    setfill $c\n }\n \n proc prefscan {} {\n@@ -11381,11 +11402,13 @@ if {[tk windowingsystem] eq \"win32\"} {\n     set uicolor SystemButtonFace\n     set bgcolor SystemWindow\n     set fgcolor SystemButtonText\n+    setfill $fgcolor\n     set selectbgcolor SystemHighlight\n } else {\n     set uicolor grey85\n     set bgcolor white\n     set fgcolor black\n+    setfill $fgcolor\n     set selectbgcolor gray85\n }\n set diffcolors {red \"#00a000\" blue}\n@@ -11422,6 +11445,7 @@ namespace import ::msgcat::mc\n ::msgcat::mcload $gitk_msgsdir\n \n catch {source ~/.gitk}\n+setfill $fgcolor\n \n parsefont mainfont $mainfont\n eval font create mainfont [fontflags mainfont]\n-- \n1.7.1\n"},{"id":"155377","messageId":"20101108131412.GE22067@login.drsnuggles.stderr.nl","threadId":"25632","inReplyTo":"20101104003524.GI7835@spacedout.fries.net","subject":"Re: [PATCH] gitk: improve dark background support","fromName":"Matthijs Kooijman","fromEmail":"matthijs@stdin.nl","sentAt":"2010-11-08T13:14:12Z","receivedAt":"2010-11-08T13:14:12Z","isPatch":true,"sender":{"key":"matthijs@stdin.nl","avatar":"https://avatars.githubusercontent.com/u/194491?v=4"},"body":"Hi David,\n\nI've been using gitk with a gray-on-black color-scheme for a while now,\nso I've given your patch a test drive. It seems to work as expected and\nindeed makes gitk a bit more pleasant to use with a dark color scheme.\n\nI've reviewed the code a bit and it looks ok as well (though I'm hardly\nfamiliar with git internals, and not at all in this area).\n\nI did encounter one minor issue, though: If you change the foreground\ncolor, the current view is not updated until you restart or switch views\n(or otherwise trigger a redraw, I guess). A quick look at the code shows\nthat the \"setfg\" function contains some code that updates all canvases\nand all contexts in $fglist with the new fg color. I guess that\nsomething similar should be done for these tag colors to get them\nupdated right away (though perhaps that should be a second patch)?\n\nA final note: There are still some other problems with working with\ngrey-on-black color scheme. In case your interested in working on those,\nI've listed them at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=568470\n\nGr.\n\nMatthijs\n"},{"id":"155646","messageId":"20101111045918.GA7572@spacedout.fries.net","threadId":"25632","inReplyTo":"20101108131412.GE22067@login.drsnuggles.stderr.nl","subject":"Re: [PATCH] gitk: improve dark background support","fromName":"David Fries","fromEmail":"david@fries.net","sentAt":"2010-11-11T04:59:18Z","receivedAt":"2010-11-11T04:59:18Z","isPatch":true,"sender":{"key":"david@fries.net","avatar":"https://avatars.githubusercontent.com/u/2767875?v=4"},"body":"On Mon, Nov 08, 2010 at 02:14:12PM +0100, Matthijs Kooijman wrote:\n> Hi David,\n> \n> I've been using gitk with a gray-on-black color-scheme for a while now,\n> so I've given your patch a test drive. It seems to work as expected and\n> indeed makes gitk a bit more pleasant to use with a dark color scheme.\n> \n> I've reviewed the code a bit and it looks ok as well (though I'm hardly\n> familiar with git internals, and not at all in this area).\n> \n> I did encounter one minor issue, though: If you change the foreground\n> color, the current view is not updated until you restart or switch views\n> (or otherwise trigger a redraw, I guess). A quick look at the code shows\n> that the \"setfg\" function contains some code that updates all canvases\n> and all contexts in $fglist with the new fg color. I guess that\n> something similar should be done for these tag colors to get them\n> updated right away (though perhaps that should be a second patch)?\n\nAfter much work and document searching I now know more about tk/tcl\nthan ever before and have figured out how to make the colors\ndynamically update when the preferences change.  Have a look if you\nwill, and if it looks good I'll post it to the maintainer for\ninclusion.  I'm also posting a new patch series to the list.\n\nbranch gitk_colors\ngit://gitorious.org/~dfries/git/dfriess-git-mainline.git\n\nand the more disorganized work in progress branch is gitk_colors_PreSquash\n\n\n\n> A final note: There are still some other problems with working with\n> grey-on-black color scheme. In case your interested in working on those,\n> I've listed them at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=568470\n\nAnything left in that list worth going over?  In terms of the .gitk\nconfig colors what are you using and what isn't working?\n\nmy relevant .gitk config file settings,\nset mainfont {Helvetica 8}\nset textfont {Courier 8}\nset uifont {Helvetica 9 bold}\nset uicolor grey85\nset bgcolor black\nset fgcolor white\nset colors {green red blue magenta darkgrey brown orange}\nset diffcolors {red green cyan}\nset markbgcolor #404060\nset selectbgcolor gray50\n\n-- \nDavid Fries <david@fries.net>\nhttp://fries.net/~david/ (PGP encryption key available)\n"}]}