# [PATCH 1/2] gitk: match ttk fonts to gitk fonts

8 messages from 2015-12-06 to 2015-12-19. Participants: Giuseppe Bilotta, Eric Sunshine, Paul Mackerras.
Thread: https://gitlist.dev/t/40942

## Giuseppe Bilotta, 2015-12-06 12:25

Subject: [PATCH 0/2] gitk spacing/sizing tuning for HiDPI
Message-ID: <1449404723-27177-1-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1449404723-27177-1-git-send-email-giuseppe.bilotta%40gmail.com

```
On my HiDPI monitor, most elements in gitk are correctly rendered, with two
exceptions:

* when using ttk, some elements do not use the same fonts as gitk would use
  without, and since ttk picks _unscaled_ sizes this is very noticeable (and
borderline illegible); the first patch fixes this;
* the spacing between the checkboxes on top of the diff window are a little too
  tightly-spaced; the second patch adds a little bit of breathing space.

Giuseppe Bilotta (2):
  gitk: match ttk fonts to gitk fonts
  gitk: let .bleft.mid widgets 'breathe'

 gitk | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

-- 
2.6.3.659.gfdd8f28

```

## Giuseppe Bilotta, 2015-12-06 12:25

Subject: [PATCH 1/2] gitk: match ttk fonts to gitk fonts
Message-ID: <1449404723-27177-2-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1449404723-27177-2-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <1449404723-27177-1-git-send-email-giuseppe.bilotta@gmail.com>

```
The fonts set in setoptions aren't consistently picked up by ttk, who
uses its own predefined fonts. This is noticeable when switching
between using and not using ttk with custom fonts or in HiDPI settings
(where the default TTK fonts do _not_ respect tk sclaing).

Fix by mapping the ttk fontset to the one used by gitk internally.
---
 gitk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gitk b/gitk
index fcc606e..e04264b 100755
--- a/gitk
+++ b/gitk
@@ -1943,6 +1943,8 @@ proc confirm_popup {msg {owner .}} {
 }
 
 proc setoptions {} {
+    global use_ttk
+
     if {[tk windowingsystem] ne "win32"} {
         option add *Panedwindow.showHandle 1 startupFile
         option add *Panedwindow.sashRelief raised startupFile
@@ -1965,6 +1967,18 @@ proc setoptions {} {
     option add *Listbox.font mainfont startupFile
 }
 
+proc setttkstyle {} {
+    eval font configure TkDefaultFont [fontflags mainfont]
+    eval font configure TkTextFont [fontflags textfont]
+    eval font configure TkHeadingFont [fontflags mainfont]
+    eval font configure TkCaptionFont [fontflags mainfont] -weight bold
+    eval font configure TkTooltipFont [fontflags uifont]
+    eval font configure TkFixedFont   [fontflags textfont]
+    eval font configure TkIconFont    [fontflags uifont]
+    eval font configure TkMenuFont    [fontflags uifont]
+    eval font configure TkSmallCaptionFont [fontflags uifont]
+}
+
 # Make a menu and submenus.
 # m is the window name for the menu, items is the list of menu items to add.
 # Each item is a list {mc label type description options...}
@@ -12356,6 +12370,10 @@ if {![info exists have_ttk]} {
 set use_ttk [expr {$have_ttk && $want_ttk}]
 set NS [expr {$use_ttk ? "ttk" : ""}]
 
+if {$use_ttk} {
+    setttkstyle
+}
+
 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
 
 set show_notes {}
-- 
2.6.3.659.gfdd8f28

```

## Giuseppe Bilotta, 2015-12-06 12:25

Subject: [PATCH 2/2] gitk: let .bleft.mid widgets 'breathe'
Message-ID: <1449404723-27177-3-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1449404723-27177-3-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <1449404723-27177-1-git-send-email-giuseppe.bilotta@gmail.com>

```
The widgets on top of the diff window are very tightly packed. Make
them breathe a little by adding an 'i'-spaced padding between them.
---
 gitk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gitk b/gitk
index e04264b..b621762 100755
--- a/gitk
+++ b/gitk
@@ -2361,6 +2361,9 @@ proc makewindow {} {
     ${NS}::frame .bleft.mid
     ${NS}::frame .bleft.bottom
 
+    # gap between sub-widgets
+    set wgap [font measure uifont "i"]
+
     ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
@@ -2375,8 +2378,9 @@ proc makewindow {} {
 	-command changediffdisp -variable diffelide -value {0 1}
     ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
 	-command changediffdisp -variable diffelide -value {1 0}
+
     ${NS}::label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
-    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
+    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
     spinbox .bleft.mid.diffcontext -width 5 \
 	-from 0 -increment 1 -to 10000000 \
 	-validate all -validatecommand "diffcontextvalidate %P" \
@@ -2384,7 +2388,7 @@ proc makewindow {} {
     .bleft.mid.diffcontext set $diffcontext
     trace add variable diffcontextstring write diffcontextchange
     lappend entries .bleft.mid.diffcontext
-    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
+    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
 	-command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
-- 
2.6.3.659.gfdd8f28

```

## Eric Sunshine, 2015-12-07 04:09

Subject: Re: [PATCH 0/2] gitk spacing/sizing tuning for HiDPI
Message-ID: <CAPig+cSwWxLMRh7e231svhtiJQH-5WuMO+3Y5x-e9tEOyHtqDg@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcSwWxLMRh7e231svhtiJQH-5WuMO%2B3Y5x-e9tEOyHtqDg%40mail.gmail.com
In-Reply-To: <1449404723-27177-1-git-send-email-giuseppe.bilotta@gmail.com>

```
On Sun, Dec 6, 2015 at 7:25 AM, Giuseppe Bilotta
<giuseppe.bilotta@gmail.com> wrote:
> On my HiDPI monitor, most elements in gitk are correctly rendered, with two
> exceptions:
>
> * when using ttk, some elements do not use the same fonts as gitk would use
>   without, and since ttk picks _unscaled_ sizes this is very noticeable (and
> borderline illegible); the first patch fixes this;
> * the spacing between the checkboxes on top of the diff window are a little too
>   tightly-spaced; the second patch adds a little bit of breathing space.

Both patches are missing your Signed-off-by:.

```

## Giuseppe Bilotta, 2015-12-08 07:05

Subject: [PATCH 1/2] gitk: match ttk fonts to gitk fonts
Message-ID: <1449558351-15038-1-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1449558351-15038-1-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <CAPig+cSwWxLMRh7e231svhtiJQH-5WuMO+3Y5x-e9tEOyHtqDg@mail.gmail.com>

```
The fonts set in setoptions aren't consistently picked up by ttk, who
uses its own predefined fonts. This is noticeable when switching
between using and not using ttk with custom fonts or in HiDPI settings
(where the default TTK fonts do _not_ respect tk sclaing).

Fix by mapping the ttk fontset to the one used by gitk internally.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gitk b/gitk
index fcc606e..e04264b 100755
--- a/gitk
+++ b/gitk
@@ -1943,6 +1943,8 @@ proc confirm_popup {msg {owner .}} {
 }
 
 proc setoptions {} {
+    global use_ttk
+
     if {[tk windowingsystem] ne "win32"} {
         option add *Panedwindow.showHandle 1 startupFile
         option add *Panedwindow.sashRelief raised startupFile
@@ -1965,6 +1967,18 @@ proc setoptions {} {
     option add *Listbox.font mainfont startupFile
 }
 
+proc setttkstyle {} {
+    eval font configure TkDefaultFont [fontflags mainfont]
+    eval font configure TkTextFont [fontflags textfont]
+    eval font configure TkHeadingFont [fontflags mainfont]
+    eval font configure TkCaptionFont [fontflags mainfont] -weight bold
+    eval font configure TkTooltipFont [fontflags uifont]
+    eval font configure TkFixedFont   [fontflags textfont]
+    eval font configure TkIconFont    [fontflags uifont]
+    eval font configure TkMenuFont    [fontflags uifont]
+    eval font configure TkSmallCaptionFont [fontflags uifont]
+}
+
 # Make a menu and submenus.
 # m is the window name for the menu, items is the list of menu items to add.
 # Each item is a list {mc label type description options...}
@@ -12356,6 +12370,10 @@ if {![info exists have_ttk]} {
 set use_ttk [expr {$have_ttk && $want_ttk}]
 set NS [expr {$use_ttk ? "ttk" : ""}]
 
+if {$use_ttk} {
+    setttkstyle
+}
+
 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
 
 set show_notes {}
-- 
2.6.3.659.gfdd8f28

```

## Giuseppe Bilotta, 2015-12-08 07:05

Subject: [PATCH 2/2] gitk: let .bleft.mid widgets 'breathe'
Message-ID: <1449558351-15038-2-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1449558351-15038-2-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <1449558351-15038-1-git-send-email-giuseppe.bilotta@gmail.com>

```
The widgets on top of the diff window are very tightly packed. Make
them breathe a little by adding an 'i'-spaced padding between them.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gitk b/gitk
index e04264b..b621762 100755
--- a/gitk
+++ b/gitk
@@ -2361,6 +2361,9 @@ proc makewindow {} {
     ${NS}::frame .bleft.mid
     ${NS}::frame .bleft.bottom
 
+    # gap between sub-widgets
+    set wgap [font measure uifont "i"]
+
     ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
@@ -2375,8 +2378,9 @@ proc makewindow {} {
 	-command changediffdisp -variable diffelide -value {0 1}
     ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
 	-command changediffdisp -variable diffelide -value {1 0}
+
     ${NS}::label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
-    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
+    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
     spinbox .bleft.mid.diffcontext -width 5 \
 	-from 0 -increment 1 -to 10000000 \
 	-validate all -validatecommand "diffcontextvalidate %P" \
@@ -2384,7 +2388,7 @@ proc makewindow {} {
     .bleft.mid.diffcontext set $diffcontext
     trace add variable diffcontextstring write diffcontextchange
     lappend entries .bleft.mid.diffcontext
-    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
+    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
 	-command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
-- 
2.6.3.659.gfdd8f28

```

## Giuseppe Bilotta, 2015-12-08 07:08

Subject: Re: [PATCH 0/2] gitk spacing/sizing tuning for HiDPI
Message-ID: <CAOxFTcyXcm0b-44j_TwR8giBeWkvugmTT=3bm4DQQvz_5kzP4A@mail.gmail.com>
URL: https://gitlist.dev/e/CAOxFTcyXcm0b-44j_TwR8giBeWkvugmTT%3D3bm4DQQvz_5kzP4A%40mail.gmail.com
In-Reply-To: <CAPig+cSwWxLMRh7e231svhtiJQH-5WuMO+3Y5x-e9tEOyHtqDg@mail.gmail.com>

```
On Mon, Dec 7, 2015 at 5:09 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> Both patches are missing your Signed-off-by:.

Doh sorry, resending now.


-- 
Giuseppe "Oblomov" Bilotta

```

## Paul Mackerras, 2015-12-19 02:26

Subject: Re: [PATCH 1/2] gitk: match ttk fonts to gitk fonts
Message-ID: <20151219022640.GC422@fergus.ozlabs.ibm.com>
URL: https://gitlist.dev/e/20151219022640.GC422%40fergus.ozlabs.ibm.com
In-Reply-To: <1449558351-15038-1-git-send-email-giuseppe.bilotta@gmail.com>

```
On Tue, Dec 08, 2015 at 08:05:50AM +0100, Giuseppe Bilotta wrote:
> The fonts set in setoptions aren't consistently picked up by ttk, who
> uses its own predefined fonts. This is noticeable when switching
> between using and not using ttk with custom fonts or in HiDPI settings
> (where the default TTK fonts do _not_ respect tk sclaing).
> 
> Fix by mapping the ttk fontset to the one used by gitk internally.
> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>

Thanks, applied both this and the following patch.

Paul.

```
