Skip to contentSkip to conversation

gitk: Avoid calling tk_setPalette on Windows

PATCH In review Pat Thoyts 2 participants 10 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore

Pat Thoyts

author
#0 lore raw

PATCH 1/3 gitk: Avoid calling tk_setPalette on Windows

This just messes up the system colors. Leave them alone.

---
 gitk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
gitk +1 -0
index 1f36a3e..dc9b8a8 100755
@@ -10849,6 +10849,7 @@ proc setselbg {c} {
 # radiobuttons look bad.  This chooses white for selectColor if the
 # background color is light, or black if it is dark.
 proc setui {c} {
+    if {[tk windowingsystem] eq "win32"} { return }
     set bg [winfo rgb . $c]
     set selc black
     if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
Signature · 1 line
1.6.6
author
#1 lore raw

PATCH 2/3 gitk: Add emacs editor variable block.

Help contributors use the correct indentation style.

---
 gitk |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
gitk +6 -0
index dc9b8a8..ed5f6ab 100755
@@ -11614,3 +11614,9 @@ if {[tk windowingsystem] eq "win32"} {
 }
 
 getcommits {}
+
+# Local variables:
+# mode: tcl
+# indent-tabs-mode: t
+# tab-width: 8
+# End:
Signature · 1 line
1.6.6
author
#2 lore raw

PATCH 3/3 gitk: fix display of copyright symbol

The script file uses utf-8 encoding but when sourced it will be read using the default system encoding which is never utf8 on windows. This causes the copyright symbol to display incorrectly in the about dialog. Using the unicode escape sequence avoids incorrect decoding but does require a double escape in the .po files.

Also adjusted the year range.

---
 gitk     |    2 +-
 po/de.po |    4 ++--
 po/es.po |    4 ++--
 po/fr.po |    4 ++--
 po/hu.po |    4 ++--
 po/it.po |    4 ++--
 po/ja.po |    4 ++--
 po/ru.po |    4 ++--
 po/sv.po |    4 ++--
 9 files changed, 17 insertions(+), 17 deletions(-)
gitk +1 -1
index 1f36a3e..e1f3740 100755
@@ -2782,7 +2782,7 @@ proc about {} {
     message $w.m -text [mc "
 Gitk - a commit viewer for git
 
-Copyright © 2005-2009 Paul Mackerras
+Copyright \u00a9 2005-2010 Paul Mackerras
 
 Use and redistribute under the terms of the GNU General Public License"] \
 	    -justify center -aspect 400 -border 2 -bg white -relief groove
po/de.po +2 -2
index c79aa9c..bd194a3 100644
@@ -334,14 +334,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright ©9 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - eine Visualisierung der Git-Historie\n"
 "\n"
-"Copyright © 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Benutzung und Weiterverbreitung gemäß den Bedingungen der GNU General Public License"
 
po/es.po +2 -2
index 0e19b5e..0471dd0 100644
@@ -281,14 +281,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - un visualizador de revisiones para git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Uso y redistribución permitidos según los términos de la Licencia Pública "
 "General de GNU (GNU GPL)"
po/fr.po +2 -2
index cb0e1ed..5370ddc 100644
@@ -334,14 +334,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - visualisateur de commit pour git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Utilisation et redistribution soumises aux termes de la GNU General Public "
 "License"
po/hu.po +2 -2
index 1df212e..7262b61 100644
@@ -333,14 +333,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright ©9 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - commit nézegető a githez\n"
 "\n"
-"Szerzői jog ©9 2005-2009 Paul Mackerras\n"
+"Szerzői jog \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Használd és terjeszd a GNU General Public License feltételei mellett"
 
po/it.po +2 -2
index 4818652..a730d63 100644
@@ -334,14 +334,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright © 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - un visualizzatore di revisioni per git\n"
 "\n"
-"Copyright © 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Utilizzo e redistribuzione permessi sotto i termini della GNU General Public "
 "License"
po/ja.po +2 -2
index c0c92ad..4f47051 100644
@@ -335,14 +335,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - gitコミットビューア\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "使用�よ���布� GNU General Public License �従������"
 
po/ru.po +2 -2
index 704eba8..c3d0285 100644
@@ -313,14 +313,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright © 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - программа про�мотра и�тории репозиториев Git\n"
 "\n"
-"Copyright (c) 2005-2008 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "И�пользование и ра�про�транение �огла�но у�лови�м GNU General Public License"
 
po/sv.po +2 -2
index 0f5e2fd..386763a 100644
@@ -334,14 +334,14 @@ msgid ""
 "\n"
 "Gitk - a commit viewer for git\n"
 "\n"
-"Copyright ©9 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Use and redistribute under the terms of the GNU General Public License"
 msgstr ""
 "\n"
 "Gitk - en incheckningsvisare för git\n"
 "\n"
-"Copyright © 2005-2009 Paul Mackerras\n"
+"Copyright \\u00a9 2005-2010 Paul Mackerras\n"
 "\n"
 "Använd och vidareförmedla enligt villkoren i GNU General Public License"
 
Signature · 1 line
1.6.6
#3 lore raw

PATCH 1/1 gitk: Fix display of copyright symbol in non-utf-8 locales

Unless the ‘-encoding’ option is supplied, wish interprets source files using the default system encoding, which depends on locale. This can cause the copyright symbol to display incorrectly in gitk’s about dialog.

The -encoding option was added to tcl in version 8.1.

---
Hi,

Quoted 3 lines · Pat Thoyts

The script file uses utf-8 encoding but when sourced it will be read using the default system encoding which is never utf8 on windows. This causes the copyright symbol to display incorrectly in the about dialog.

I can reproduce this in Linux with LANG=de_DE@euro ./gitk.

Quoted 2 lines

Using the unicode escape sequence avoids incorrect decoding but does require a double escape in the .po files.

When I tried applying your patch, running “make update-po” seemed to undo its effect on translations. I am also worried about what would happen in locales where ASCII is not a subset of the native character set, or other uses of non-ASCII characters in the translated messages.

Maybe the following would be safer? I haven’t looked at the effect on translations yet.

 gitk |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
gitk +1 -1
index 1f36a3e..a7c9a9a 100755
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Tcl ignores the next line -*- tcl -*- \
-exec wish "$0" -- "$@"
+exec wish -encoding utf-8 "$0" -- "$@"
 
 # Copyright © 2005-2009 Paul Mackerras.  All rights reserved.
 # This program is free software; it may be used, copied, modified
Signature · 1 line
1.7.0.2
#4 lore raw

PATCH 1/1 gitk: Update makefile to keep -encoding option for gitk-wish

Quoted 1 line · Jonathan Nieder

I can reproduce this in Linux with LANG=de_DE@euro ./gitk.

This should be squashed in to fix LANG=de_DE@euro ./gitk-wish, too. Sorry for the trouble.

 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index e1b6045..1cc922c 100644
@@ -53,7 +53,7 @@ clean::
 
 gitk-wish: gitk
 	$(QUIET_GEN)$(RM) $@ $@+ && \
-	sed -e '1,3s|^exec .* "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' <gitk >$@+ && \
+	sed -e '1,3s|^exec .* -encoding|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) -encoding|' <gitk >$@+ && \
 	chmod +x $@+ && \
 	mv -f $@+ $@
 
Signature · 1 line
1.7.0.2
author
#5 lore raw

Re: [PATCH] gitk: Fix display of copyright symbol in non-utf-8 locales

In reply to Jonathan Nieder
Quoted 48 lines · Jonathan Nieder

Unless the ‘-encoding’ option is supplied, wish interprets source files using the default system encoding, which depends on locale. This can cause the copyright symbol to display incorrectly in gitk’s about dialog.

The -encoding option was added to tcl in version 8.1.

---
Hi,

Quoted 3 lines · Pat Thoyts

The script file uses utf-8 encoding but when sourced it will be read using the default system encoding which is never utf8 on windows. This causes the copyright symbol to display incorrectly in the about dialog.

I can reproduce this in Linux with LANG=de_DE@euro ./gitk.

Quoted 2 lines

Using the unicode escape sequence avoids incorrect decoding but does require a double escape in the .po files.

When I tried applying your patch, running “make update-po” seemed to undo its effect on translations. I am also worried about what would happen in locales where ASCII is not a subset of the native character set, or other uses of non-ASCII characters in the translated messages.

Maybe the following would be safer? I haven’t looked at the effect on translations yet.

gitk | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
gitk +1 -1
index 1f36a3e..a7c9a9a 100755
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Tcl ignores the next line -*- tcl -*- \
-exec wish "$0" -- "$@"
+exec wish -encoding utf-8 "$0" -- "$@"
 
 # Copyright © 2005-2009 Paul Mackerras.  All rights reserved.
 # This program is free software; it may be used, copied, modified
Signature · 1 line
1.7.0.2

I would much rather see any fault in the makefile fixed than use source -encoding in all the various places this script might get loaded from. THere are two characters in this file that are not ASCII and one of them is in a comment. We could even just use (c) to simplify this. However, \u00a9 is the correct unicode escape sequence for tcl to get a copyright character into the script in a way that is independent of the encoding. The escape sequence should be passed through unchanged in any translations - tcl wants to see exactly \u00a9 and everyone is using a copyright glyph here.

Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
#6 lore raw

Re: [PATCH] gitk: Fix display of copyright symbol in non-utf-8 locales

Quoted 9 lines · Pat Thoyts
Quoted 7 lines · Jonathan Nieder
gitk +1 -1
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Tcl ignores the next line -*- tcl -*- \
-exec wish "$0" -- "$@"
+exec wish -encoding utf-8 "$0" -- "$@"

[...]

Quoted 3 lines

I would much rather see any fault in the makefile fixed than use source -encoding in all the various places this script might get loaded from.

Good point: git-gui.sh does not use ‘source’ but runs the moral equivalent of

set wish [info executable]
eval exec $wish gitk $revs "--" "--"

to avoid starting a shell. Is it really so expensive to start a shell? This means that, for example, if some insane person were to rewrite gitk in C, then git gui would have to be adjusted before the result could be used.

Quoted 7 lines

THere are two characters in this file that are not ASCII and one of them is in a comment. We could even just use (c) to simplify this. However, \u00a9 is the correct unicode escape sequence for tcl to get a copyright character into the script in a way that is independent of the encoding. The escape sequence should be passed through unchanged in any translations - tcl wants to see exactly \u00a9 and everyone is using a copyright glyph here.

So we should fix the Makefile. The problem is that everything Tcl-related seems to assume files it sees will be in either the current locale’s encoding or ISO-8859-1 unless told otherwise, as far as I can tell. The entire gitk source tree, on the other hand, is in UTF-8.

Ideas?
Jonathan

#7 lore raw
In reply to Pat Thoyts
Quoted 10 lines · Pat Thoyts
---
 gitk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
gitk +0 -0
index 1f36a3e..dc9b8a8 100755

gitk proc setselbg {c} { · line 10852

Quoted 8 lines
gitk +1 -0
@@ -10845,10 +10845,11 @@ proc setselbg {c} {
 
 # This sets the background color and the color scheme for the whole UI.
 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
 # if we don't specify one ourselves, which makes the checkbuttons and
 # radiobuttons look bad.  This chooses white for selectColor if the
 # background color is light, or black if it is dark.
 proc setui {c} {
+    if {[tk windowingsystem] eq "win32"} { return }

Do you know whether the situation described by the comment has been addressed for Tk? Maybe gitk could check for an appropriate Tk version to avoid this workaround on all platforms.

author
#8 lore raw
Quoted 13 lines · Jonathan Nieder
Quoted 11 lines · Pat Thoyts
---
 gitk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
gitk +0 -0
index 1f36a3e..dc9b8a8 100755
@@ -10845,10 +10845,11 @@ proc setselbg {c} {
 
Quoted 11 lines

gitk proc setselbg {c} { · line 10852

Quoted 7 lines
gitk +1 -0
 # This sets the background color and the color scheme for the whole UI.
 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
 # if we don't specify one ourselves, which makes the checkbuttons and
 # radiobuttons look bad.  This chooses white for selectColor if the
 # background color is light, or black if it is dark.
 proc setui {c} {
+    if {[tk windowingsystem] eq "win32"} { return }

Do you know whether the situation described by the comment has been addressed for Tk? Maybe gitk could check for an appropriate Tk version to avoid this workaround on all platforms.

This has never been true for Windows which has always used the native images for check and radio buttons. So the comment there is relevant only to X11. I believe in Tk 8.5 the check/radio buttons now use images by default (the ttk versions will look appropriate to the current theme - however that may be defined).

However, messing about with this on X11 would need testing that I can't do on Windows. Hence the suggested fix.

Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
#9 lore raw
Quoted 4 lines · Pat Thoyts
Quoted 4 lines
Quoted 4 lines

# For some reason, tk_setPalette chooses a nasty dark red for selectColor

 # if we don't specify one ourselves, which makes the checkbuttons and
 # radiobuttons look bad.  This chooses white for selectColor if the
 # background color is light, or black if it is dark.

[...]

Quoted 8 lines

This has never been true for Windows which has always used the native images for check and radio buttons. So the comment there is relevant only to X11. I believe in Tk 8.5 the check/radio buttons now use images by default (the ttk versions will look appropriate to the current theme - however that may be defined).

However, messing about with this on X11 would need testing that I can't do on Windows. Hence the suggested fix.

Thanks for the pointers. Sp it seems that the “interface color” setting does not have the desired effect when themed widgets are enabled. You can see some screenshots here:

http://repo.or.cz/w/git/jrn.git/commit/gitk-snapshots

The text fields, buttons, and drop-down boxes retain the traditional grey background, while the menu bar, “SHA1 ID” label, and “Lines of context” selector do change color. The effect is very strange.

When themed widgets are disabled, the tk_setPalette issue described in the comment still applies.

So I can understand better: are you saying in Windows themed widgets are always used?

Jonathan