threads / patch / 64220

v3, 2 partsgitk: make Tags and Heads window geometry sticky

Subject: [PATCH v3 0/2] gitk: make Tags and Heads window geometry sticky

## tl;dr

12 messages between Sep 28, 2025 and Oct 17, 2025. Diffs are folded; open one to read it.

replies: 11people: 4as markdown or json

Michael Rappazzo· Sep 28, 2025, 13:54 UTC · lore
Changes since v2:
 - replaced my commit to restore the window size and position with the
   commit that was already floating around from Hannes's repository.  I
   included this because the next commit relies on it to work correctly
   in some environments.
 - split the manage_showrefs_geometry function into 2 functions.
Johannes Sixt (1):
  Revert "gitk: Only restore window size from ~/.gitk, not position"
Michael Rappazzo (1):
  gitk: make Tags and Heads window geometry sticky
 gitk | 51 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 12 deletions(-)
-- 
2.51.0
Michael Rappazzo· Sep 28, 2025, 13:54 UTC · re: Michael Rappazzo · lore

[PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

From: Johannes Sixt <johannes.sixt@telecom.at>
This reverts commit b9bee11526ec23541ddbbd75716bfd1acc241463.

The commit catered to an unsupportable port of the Windows Tcl/Tk stuck at 8.4.1 that was used by Cygwin. 8.4.1 has some bad bugs in its layout engine, and forced changes in Gitk to be compatible. All this became irrelevant around 2011 after Cygwin gained an X11 server and switched to a supportable port of the Unix/X11 Tcl/Tk (it is now on the current 8.6 code base).

Helped-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 gitk | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
Show changes to gitk +2 −10
diff --git a/gitk b/gitk
index 6e4d71d585..275f353811 100755
--- a/gitk
+++ b/gitk
@@ -2764,17 +2764,9 @@ proc makewindow {} {
     .pwbottom add .bright
     .ctop add .pwbottom
 
-    # restore window width & height if known
+    # restore window position if known
     if {[info exists geometry(main)]} {
-        if {[scan $geometry(main) "%dx%d" w h] >= 2} {
-            if {$w > [winfo screenwidth .]} {
-                set w [winfo screenwidth .]
-            }
-            if {$h > [winfo screenheight .]} {
-                set h [winfo screenheight .]
-            }
-            wm geometry . "${w}x$h"
-        }
+        wm geometry . "$geometry(main)"
     }
 
     if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
-- 
2.51.0
Mark Levedahl· Sep 28, 2025, 14:17 UTC · re: Michael Rappazzo · lore

Re: [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

On 9/28/25 9:54 AM, Michael Rappazzo wrote:
Show 41 quoted lines
> From: Johannes Sixt <johannes.sixt@telecom.at>
>
> This reverts commit b9bee11526ec23541ddbbd75716bfd1acc241463.
>
> The commit catered to an unsupportable port of the Windows Tcl/Tk
> stuck at 8.4.1 that was used by Cygwin. 8.4.1 has some bad bugs in its
> layout engine, and forced changes in Gitk to be compatible. All this
> became irrelevant around 2011 after Cygwin gained an X11 server and
> switched to a supportable port of the Unix/X11 Tcl/Tk (it is now on the
> current 8.6 code base).
>
> Helped-by: Mark Levedahl <mlevedahl@gmail.com>
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
>  gitk | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/gitk b/gitk
> index 6e4d71d585..275f353811 100755
> --- a/gitk
> +++ b/gitk
> @@ -2764,17 +2764,9 @@ proc makewindow {} {
>      .pwbottom add .bright
>      .ctop add .pwbottom
>  
> -    # restore window width & height if known
> +    # restore window position if known
>      if {[info exists geometry(main)]} {
> -        if {[scan $geometry(main) "%dx%d" w h] >= 2} {
> -            if {$w > [winfo screenwidth .]} {
> -                set w [winfo screenwidth .]
> -            }
> -            if {$h > [winfo screenheight .]} {
> -                set h [winfo screenheight .]
> -            }
> -            wm geometry . "${w}x$h"
> -        }
> +        wm geometry . "$geometry(main)"
>      }
>  
>      if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {

I mis-interpreted an earlier inquiry about the patch being reverted here. Patch e9937d2a03 actually addressed the issues of Cygwin's 8.4.1 Tcl/Tk. Part of that was fixing the window geometry being restored, as sometimes the window manager would size the main window in a manner causing 8.4.1 to fail. But, this override of the main window manager on all platforms raised complaints on the mailing list, and commit b9bee11526 was the response: it was only the SIZE of the Window that mattered on Cygwin, not its location, so allowing window managers to set the location was ok.

Personally, I'm fine with gitk remembering / restoring the full window geometry (I wrote it that way in e9937d2a03).

Mark
Mike Rappazzo· Sep 28, 2025, 15:01 UTC · re: Mark Levedahl · lore

Re: [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

On Sun, Sep 28, 2025 at 10:17 AM Mark Levedahl <mlevedahl@gmail.com> wrote:
Show 53 quoted lines
>
> On 9/28/25 9:54 AM, Michael Rappazzo wrote:
> > From: Johannes Sixt <johannes.sixt@telecom.at>
> >
> > This reverts commit b9bee11526ec23541ddbbd75716bfd1acc241463.
> >
> > The commit catered to an unsupportable port of the Windows Tcl/Tk
> > stuck at 8.4.1 that was used by Cygwin. 8.4.1 has some bad bugs in its
> > layout engine, and forced changes in Gitk to be compatible. All this
> > became irrelevant around 2011 after Cygwin gained an X11 server and
> > switched to a supportable port of the Unix/X11 Tcl/Tk (it is now on the
> > current 8.6 code base).
> >
> > Helped-by: Mark Levedahl <mlevedahl@gmail.com>
> > Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> > ---
> >  gitk | 12 ++----------
> >  1 file changed, 2 insertions(+), 10 deletions(-)
> >
> > diff --git a/gitk b/gitk
> > index 6e4d71d585..275f353811 100755
> > --- a/gitk
> > +++ b/gitk
> > @@ -2764,17 +2764,9 @@ proc makewindow {} {
> >      .pwbottom add .bright
> >      .ctop add .pwbottom
> >
> > -    # restore window width & height if known
> > +    # restore window position if known
> >      if {[info exists geometry(main)]} {
> > -        if {[scan $geometry(main) "%dx%d" w h] >= 2} {
> > -            if {$w > [winfo screenwidth .]} {
> > -                set w [winfo screenwidth .]
> > -            }
> > -            if {$h > [winfo screenheight .]} {
> > -                set h [winfo screenheight .]
> > -            }
> > -            wm geometry . "${w}x$h"
> > -        }
> > +        wm geometry . "$geometry(main)"
> >      }
> >
> >      if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
> I mis-interpreted an earlier inquiry about the patch being reverted here. Patch e9937d2a03
> actually addressed the issues of Cygwin's 8.4.1 Tcl/Tk. Part of that was fixing the window
> geometry being restored, as sometimes the window manager would size the main window in a
> manner causing 8.4.1 to fail. But, this override of the main window manager on all
> platforms raised complaints on the mailing list, and commit b9bee11526 was the response:
> it was only the SIZE of the Window that mattered on Cygwin, not its location, so allowing
> window managers to set the location was ok.
>
> Personally, I'm fine with gitk remembering / restoring the full window geometry (I wrote
> it that way in e9937d2a03).
In my v2 version there is a slight difference:
+        after idle [list wm geometry . $geometry(main)]

This seems likely related to my second patch changes where I use `after idle` due to the timing concerns which I reported on in my latest email from that series[1].

[1] https://lore.kernel.org/git/CANoM8SXnxxF6UMSfQ06ANfEv7HFCEEMCVoGgod1-DuFeHp6tXg@mail.gmail.com/T/#e1fc2a76267e3077c0de40ad8902e2158c00164e1
>
> Mark
Johannes Sixt· Oct 17, 2025, 16:36 UTC · re: Mark Levedahl · lore

Re: [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

Am 28.09.25 um 16:17 schrieb Mark Levedahl:
Show 52 quoted lines
> On 9/28/25 9:54 AM, Michael Rappazzo wrote:
>> From: Johannes Sixt <johannes.sixt@telecom.at>
>>
>> This reverts commit b9bee11526ec23541ddbbd75716bfd1acc241463.
>>
>> The commit catered to an unsupportable port of the Windows Tcl/Tk
>> stuck at 8.4.1 that was used by Cygwin. 8.4.1 has some bad bugs in its
>> layout engine, and forced changes in Gitk to be compatible. All this
>> became irrelevant around 2011 after Cygwin gained an X11 server and
>> switched to a supportable port of the Unix/X11 Tcl/Tk (it is now on the
>> current 8.6 code base).
>>
>> Helped-by: Mark Levedahl <mlevedahl@gmail.com>
>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>> ---
>>  gitk | 12 ++----------
>>  1 file changed, 2 insertions(+), 10 deletions(-)
>>
>> diff --git a/gitk b/gitk
>> index 6e4d71d585..275f353811 100755
>> --- a/gitk
>> +++ b/gitk
>> @@ -2764,17 +2764,9 @@ proc makewindow {} {
>>      .pwbottom add .bright
>>      .ctop add .pwbottom
>>  
>> -    # restore window width & height if known
>> +    # restore window position if known
>>      if {[info exists geometry(main)]} {
>> -        if {[scan $geometry(main) "%dx%d" w h] >= 2} {
>> -            if {$w > [winfo screenwidth .]} {
>> -                set w [winfo screenwidth .]
>> -            }
>> -            if {$h > [winfo screenheight .]} {
>> -                set h [winfo screenheight .]
>> -            }
>> -            wm geometry . "${w}x$h"
>> -        }
>> +        wm geometry . "$geometry(main)"
>>      }
>>  
>>      if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
> I mis-interpreted an earlier inquiry about the patch being reverted here. Patch e9937d2a03
> actually addressed the issues of Cygwin's 8.4.1 Tcl/Tk. Part of that was fixing the window
> geometry being restored, as sometimes the window manager would size the main window in a
> manner causing 8.4.1 to fail. But, this override of the main window manager on all
> platforms raised complaints on the mailing list, and commit b9bee11526 was the response:
> it was only the SIZE of the Window that mattered on Cygwin, not its location, so allowing
> window managers to set the location was ok.
> 
> Personally, I'm fine with gitk remembering / restoring the full window geometry (I wrote
> it that way in e9937d2a03).

Thank you for the hint. I found the thread, and after reading it I notice that the opposition is based on that restoring the position doesn't put the window on the desired monitor. I can't test this right now. I've rewritten the commit message as follows. Whether or not the position should be restored seems to be a personal preference, and the patch applies my and your preference, but obviously not everyone's. Please let me know whether I understood the situation correctly or not.

    Revert "gitk: Only restore window size from ~/.gitk, not position"
    
    This reverts commit b9bee11526ec (gitk: Only restore window size from
    ~/.gitk, not position, 2008-03-10).
    
    The earlier commit e9937d2a03a4 (Make gitk work reasonably well on
    Cygwin, 2007-02-01) reworked the window layout considerably. Much of
    this became irrelevant around 2011 after Cygwin gained an X11 server
    and switched to a supportable port of the Unix/X11 Tcl/Tk (it is now
    on the current 8.6 code base).
    
    Part of the necessary change was to restore the window size across
    sessions, but the position was also restored. This raised complaints
    on the mailing list[*], because Gitk was opened on the wrong monitor.
    b9bee11526ec was the compromise, because it was only the size that
    mattered for the Cygwin layout engine to work.
    
    I personally, find it annoying when Gitk pops up on a random location
    on the screen, in particular, since many other applications restore
    the window positions across sessions, so why not Gitk as well? (I do
    not operate multi-monitor setups, so I cannot test the case.)
    
    [*] https://lore.kernel.org/git/47AAA254.2020008@thorn.ws/
-- Hannes
Mark Levedahl· Oct 17, 2025, 19:27 UTC · re: Johannes Sixt · lore

Re: [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

On 10/17/25 12:36 PM, Johannes Sixt wrote:
Show 10 quoted lines
> Thank you for the hint. I found the thread, and after reading it I
> notice that the opposition is based on that restoring the position
> doesn't put the window on the desired monitor. I can't test this right
> now. I've rewritten the commit message as follows. Whether or not the
> position should be restored seems to be a personal preference, and the
> patch applies my and your preference, but obviously not everyone's.
> Please let me know whether I understood the situation correctly or not.
>
> -- Hannes
>

Your commit message accurately captures the issues as I understand them. I also cannot contribute on the multi-monitor setup, nor about the broader context wanting this patch.

Mark
Junio C Hamano· Sep 28, 2025, 15:49 UTC · re: Michael Rappazzo · lore

Re: [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position"

Michael Rappazzo <rappazzo@gmail.com> writes:
> From: Johannes Sixt <johannes.sixt@telecom.at>
>
> This reverts commit b9bee11526ec23541ddbbd75716bfd1acc241463.
If you wrote it like
    Revert b9bee115 (gitk: Only restore window size from ~/.gitk,
    not position, 2008-03-10).

it would make it obvious that this is not a revert of a recent screwup, but historical wart carried from long time ago.

Show 10 quoted lines
> The commit catered to an unsupportable port of the Windows Tcl/Tk
> stuck at 8.4.1 that was used by Cygwin. 8.4.1 has some bad bugs in its
> layout engine, and forced changes in Gitk to be compatible. All this
> became irrelevant around 2011 after Cygwin gained an X11 server and
> switched to a supportable port of the Unix/X11 Tcl/Tk (it is now on the
> current 8.6 code base).
>
> Helped-by: Mark Levedahl <mlevedahl@gmail.com>
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
Very nice to see such a clean-up.
Michael Rappazzo· Sep 28, 2025, 13:54 UTC · re: Michael Rappazzo · lore

[PATCH v3 2/2] gitk: make Tags and Heads window geometry sticky

Currently, the Tags and Heads window always opens at a default position and size, requiring users to reposition it each time. This patch makes the window remember its geometry between sessions.

This change saves and restores the Tags and Heads window size and position relative to the main gitk window. The geometry is stored in the config file as `geometry(showrefs)` and persists between gitk sessions. The window position is stored relative to the main window, so it maintains the same spatial relationship when the main window is moved or when gitk is restarted on different monitors.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
 gitk | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
Show changes to gitk +37 −2
diff --git a/gitk b/gitk
index 275f353811..79a6dcdb4c 100755
--- a/gitk
+++ b/gitk
@@ -3106,6 +3106,11 @@ proc savestuff {w} {
         puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
         puts $f "set geometry(botwidth) [winfo width .bleft]"
         puts $f "set geometry(botheight) [winfo height .bleft]"
+        if {[winfo exists .showrefs]} {
+            puts $f "set geometry(showrefs) \"[wm geometry .showrefs]\""
+        } elseif {[info exists geometry(showrefs)]} {
+            puts $f "set geometry(showrefs) \"$geometry(showrefs)\""
+        }
 
         array set view_save {}
         array set views {}
@@ -10199,11 +10204,13 @@ proc showrefs {} {
     if {[winfo exists $top]} {
         raise $top
         refill_reflist
+        wm protocol $top WM_DELETE_WINDOW [list destroy_showrefs $top]
         return
     }
     ttk_toplevel $top
     wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
     make_transient $top .
+    wm protocol $top WM_DELETE_WINDOW [list destroy_showrefs $top]
     text $top.list -background $bgcolor -foreground $fgcolor \
         -selectbackground $selectbgcolor -font mainfont \
         -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
@@ -10229,8 +10236,8 @@ proc showrefs {} {
     ttk::checkbutton $top.sort -text [mc "Sort refs by type"] \
         -variable sortrefsbytype -command {refill_reflist}
     grid $top.sort - -sticky w -pady 2
-    ttk::button $top.close -command [list destroy $top] -text [mc "Close"]
-    bind $top <Key-Escape> [list destroy $top]
+    ttk::button $top.close -command [list destroy_showrefs $top] -text [mc "Close"]
+    bind $top <Key-Escape> [list destroy_showrefs $top]
     grid $top.close -
     grid columnconfigure $top 0 -weight 1
     grid rowconfigure $top 0 -weight 1
@@ -10239,6 +10246,9 @@ proc showrefs {} {
     bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
     set reflist {}
     refill_reflist
+    # Restore geometry after the window is fully created and mapped
+    # Delay Configure binding to avoid overwriting restored geometry
+    bind $top <Map> [list after idle [list setup_showrefs_geometry_tracking $top]]
 }
 
 proc sel_reflist {w x y} {
@@ -10271,6 +10281,31 @@ proc reflistfilter_change {n1 n2 op} {
     after 200 refill_reflist
 }
 
+proc save_showrefs_geometry {top} {
+    global geometry
+    if {[winfo exists $top]} {
+        set geometry(showrefs) [wm geometry $top]
+    }
+}
+
+proc restore_showrefs_geometry {top} {
+    global geometry
+    if {[info exists geometry(showrefs)] && [winfo exists $top]} {
+        wm geometry $top $geometry(showrefs)
+    }
+}
+
+proc setup_showrefs_geometry_tracking {top} {
+    restore_showrefs_geometry $top
+    bind $top <Configure> [list save_showrefs_geometry $top]
+}
+
+proc destroy_showrefs {top} {
+    save_showrefs_geometry $top
+    savestuff .
+    destroy $top
+}
+
 proc refill_reflist {} {
     global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype
     global curview upstreamofref
-- 
2.51.0
Junio C Hamano· Sep 28, 2025, 15:57 UTC · re: Michael Rappazzo · lore

Re: [PATCH v3 2/2] gitk: make Tags and Heads window geometry sticky

Michael Rappazzo <rappazzo@gmail.com> writes:
> Currently, the Tags and Heads window always opens at a default position
> and size, requiring users to reposition it each time. This patch makes
> the window remember its geometry between sessions.

As the second patch in two-patch series, whose first step is a revert we just saw, it is unclear what state of the code "Currently" above refers to. Has it been that way even before the revert (in other words, even with the ancient Tcl/Tk 8.4.1 workaround), or have we briefly regressed with the previous step to fix it correctly and this is the right fix suitable for Tcl/Tk of the modern times?

Show 11 quoted lines
> This change saves and restores the Tags and Heads window size and position
> relative to the main gitk window. The geometry is stored in the config file
> as `geometry(showrefs)` and persists between gitk sessions. The window
> position is stored relative to the main window, so it maintains the same
> spatial relationship when the main window is moved or when gitk is restarted
> on different monitors.
>
> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
> ---
>  gitk | 39 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)

Nice. Very well written explanation that tells why this is a good thing to do to those who do not even use gitk very often.

As a pair of patches to an area with an official submaintainer, I won't touch them and instead expect them to be fed via a pull request once the reviews are done on them, but it still is appreciated to see patches sent here for reviews even when the submaintainer is part of the team that authored them.

Thanks.
Johannes Sixt· Oct 4, 2025, 17:36 UTC · re: Michael Rappazzo · lore

Re: [PATCH v3 2/2] gitk: make Tags and Heads window geometry sticky

Am 28.09.25 um 15:54 schrieb Michael Rappazzo:
Show 99 quoted lines
> Currently, the Tags and Heads window always opens at a default position
> and size, requiring users to reposition it each time. This patch makes
> the window remember its geometry between sessions.
> 
> This change saves and restores the Tags and Heads window size and position
> relative to the main gitk window. The geometry is stored in the config file
> as `geometry(showrefs)` and persists between gitk sessions. The window
> position is stored relative to the main window, so it maintains the same
> spatial relationship when the main window is moved or when gitk is restarted
> on different monitors.
> 
> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
> ---
>  gitk | 39 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/gitk b/gitk
> index 275f353811..79a6dcdb4c 100755
> --- a/gitk
> +++ b/gitk
> @@ -3106,6 +3106,11 @@ proc savestuff {w} {
>          puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
>          puts $f "set geometry(botwidth) [winfo width .bleft]"
>          puts $f "set geometry(botheight) [winfo height .bleft]"
> +        if {[winfo exists .showrefs]} {
> +            puts $f "set geometry(showrefs) \"[wm geometry .showrefs]\""
> +        } elseif {[info exists geometry(showrefs)]} {
> +            puts $f "set geometry(showrefs) \"$geometry(showrefs)\""
> +        }
>  
>          array set view_save {}
>          array set views {}
> @@ -10199,11 +10204,13 @@ proc showrefs {} {
>      if {[winfo exists $top]} {
>          raise $top
>          refill_reflist
> +        wm protocol $top WM_DELETE_WINDOW [list destroy_showrefs $top]
>          return
>      }
>      ttk_toplevel $top
>      wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
>      make_transient $top .
> +    wm protocol $top WM_DELETE_WINDOW [list destroy_showrefs $top]
>      text $top.list -background $bgcolor -foreground $fgcolor \
>          -selectbackground $selectbgcolor -font mainfont \
>          -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
> @@ -10229,8 +10236,8 @@ proc showrefs {} {
>      ttk::checkbutton $top.sort -text [mc "Sort refs by type"] \
>          -variable sortrefsbytype -command {refill_reflist}
>      grid $top.sort - -sticky w -pady 2
> -    ttk::button $top.close -command [list destroy $top] -text [mc "Close"]
> -    bind $top <Key-Escape> [list destroy $top]
> +    ttk::button $top.close -command [list destroy_showrefs $top] -text [mc "Close"]
> +    bind $top <Key-Escape> [list destroy_showrefs $top]
>      grid $top.close -
>      grid columnconfigure $top 0 -weight 1
>      grid rowconfigure $top 0 -weight 1
> @@ -10239,6 +10246,9 @@ proc showrefs {} {
>      bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
>      set reflist {}
>      refill_reflist
> +    # Restore geometry after the window is fully created and mapped
> +    # Delay Configure binding to avoid overwriting restored geometry
> +    bind $top <Map> [list after idle [list setup_showrefs_geometry_tracking $top]]
>  }
>  
>  proc sel_reflist {w x y} {
> @@ -10271,6 +10281,31 @@ proc reflistfilter_change {n1 n2 op} {
>      after 200 refill_reflist
>  }
>  
> +proc save_showrefs_geometry {top} {
> +    global geometry
> +    if {[winfo exists $top]} {
> +        set geometry(showrefs) [wm geometry $top]
> +    }
> +}
> +
> +proc restore_showrefs_geometry {top} {
> +    global geometry
> +    if {[info exists geometry(showrefs)] && [winfo exists $top]} {
> +        wm geometry $top $geometry(showrefs)
> +    }
> +}
> +
> +proc setup_showrefs_geometry_tracking {top} {
> +    restore_showrefs_geometry $top
> +    bind $top <Configure> [list save_showrefs_geometry $top]
> +}
> +
> +proc destroy_showrefs {top} {
> +    save_showrefs_geometry $top
> +    savestuff .
> +    destroy $top
> +}
> +
>  proc refill_reflist {} {
>      global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype
>      global curview upstreamofref

A patch should be much smaller than this. I was thinking along the lines of the below diff. However, it doesn't work for some reason: the variable that is updated from the Configure handler is not the same that is serialized in proc savestuff, and I don't know why. Nevertheless, within a session, the window geometry *is* preserved, just not across sessions.

Show changes to gitk +11 −1
diff --git a/gitk b/gitk
index 275f353..77d5acc 100755
--- a/gitk
+++ b/gitk
@@ -3058,7 +3058,7 @@ proc config_variable_change_cb {name name2 op} {
 }

 proc savestuff {w} {
-    global stuffsaved
+    global stuffsaved geometry
     global config_file config_file_tmp
     global config_variables config_variable_changed
     global viewchanged
@@ -3106,6 +3106,9 @@ proc savestuff {w} {
         puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos
1] 1\""
         puts $f "set geometry(botwidth) [winfo width .bleft]"
         puts $f "set geometry(botheight) [winfo height .bleft]"
+        if {[info exists geometry(showrefs)]} {
+            puts $f "set geometry(showrefs) \"$geometry(showrefs)\""
+        }

         array set view_save {}
         array set views {}
@@ -10193,6 +10196,7 @@ proc rmbranch {} {
 proc showrefs {} {
     global showrefstop bgcolor fgcolor selectbgcolor
     global bglist fglist reflistfilter reflist maincursor
+    global geometry

     set top .showrefs
     set showrefstop $top
@@ -10239,6 +10243,12 @@ proc showrefs {} {
     bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
     set reflist {}
     refill_reflist
+    if {[info exists geometry(showrefs)]} {
+        after idle [list wm geometry $top $geometry(showrefs)]
+    }
+    # avoid <Configure> being bound to child windows
+    bindtags $top [linsert [bindtags $top] 1 bind$top]
+    bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
 }

 proc sel_reflist {w x y} {
Johannes Sixt· Oct 4, 2025, 22:04 UTC · re: Johannes Sixt · lore

[PATCH] gitk: persist position and size of the Tags and Heads window

The Tags and Heads window always opens at a default position and size, requiring users to reposition it each time. Remember its geometry between sessions in the config file as `geometry(showrefs)`.

Note that the existing configuration is sourced in proc savestuff right before new settings are written. This makes the old settings available as local variables(!) and does not overwrite the current settings. Since we need access to the global geometry(showrefs), it is necessary to unset the local variable.

Helped-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Am 04.10.25 um 19:36 schrieb Johannes Sixt:
> ... it doesn't work for some reason: the
> variable that is updated from the Configure handler is not the same that
> is serialized in proc savestuff, and I don't know why.

Very simple: the old settings are sourced before being written out again and overwrite the current setting. But things turn out to be more sutle than that. See above and below.

 gitk | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Show changes to gitk +12 −0
diff --git a/gitk b/gitk
index 275f353..6deaa3a 100755
--- a/gitk
+++ b/gitk
@@ -3106,6 +3106,11 @@ proc savestuff {w} {
         puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
         puts $f "set geometry(botwidth) [winfo width .bleft]"
         puts $f "set geometry(botheight) [winfo height .bleft]"
+        unset -nocomplain geometry
+        global geometry
+        if {[info exists geometry(showrefs)]} {
+            puts $f "set geometry(showrefs) $geometry(showrefs)"
+        }
 
         array set view_save {}
         array set views {}
@@ -10193,6 +10198,7 @@ proc rmbranch {} {
 proc showrefs {} {
     global showrefstop bgcolor fgcolor selectbgcolor
     global bglist fglist reflistfilter reflist maincursor
+    global geometry
 
     set top .showrefs
     set showrefstop $top
@@ -10239,6 +10245,12 @@ proc showrefs {} {
     bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
     set reflist {}
     refill_reflist
+    if {[info exists geometry(showrefs)]} {
+        after idle [list wm geometry $top $geometry(showrefs)]
+    }
+    # avoid <Configure> being bound to child windows
+    bindtags $top [linsert [bindtags $top] 1 bind$top]
+    bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
 }
 
 proc sel_reflist {w x y} {
-- 
2.51.0.427.g504992c71c
Johannes Sixt· Oct 6, 2025, 15:29 UTC · re: Johannes Sixt · lore

[PATCH v2] gitk: persist position and size of the Tags and Heads window

The Tags and Heads window always opens at a default position and size, requiring users to reposition it each time. Remember its geometry between sessions in the config file as `geometry(showrefs)`.

Note that the existing configuration is sourced in proc savestuff right before new settings are written. This makes the old settings available as local variables(!) and does not overwrite the current settings. Since we need access to the global geometry(showrefs), it is necessary to unset the local variable.

Helped-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Changes since v1:
- On Windows, only the size was restored, but not the position. There is
  special logic for Windows that positions popup windows. Now we take
  this into account.
 gitk | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
Show changes to gitk +20 −5
diff --git a/gitk b/gitk
index 275f353..ed61661 100755
--- a/gitk
+++ b/gitk
@@ -2131,12 +2131,14 @@ proc ttk_toplevel {w args} {
     return $w
 }
 
-proc make_transient {window origin} {
+proc make_transient {window origin {geometry ""}} {
     wm transient $window $origin
 
-    # Windows fails to place transient windows normally, so
-    # schedule a callback to center them on the parent.
-    if {[tk windowingsystem] eq {win32}} {
+    if {$geometry ne ""} {
+        after idle [list wm geometry $window $geometry]
+    } elseif {[tk windowingsystem] eq {win32}} {
+        # Windows fails to place transient windows normally, so
+        # schedule a callback to center them on the parent.
         after idle [list tk::PlaceWindow $window widget $origin]
     }
 }
@@ -3106,6 +3108,11 @@ proc savestuff {w} {
         puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
         puts $f "set geometry(botwidth) [winfo width .bleft]"
         puts $f "set geometry(botheight) [winfo height .bleft]"
+        unset -nocomplain geometry
+        global geometry
+        if {[info exists geometry(showrefs)]} {
+            puts $f "set geometry(showrefs) $geometry(showrefs)"
+        }
 
         array set view_save {}
         array set views {}
@@ -10193,6 +10200,7 @@ proc rmbranch {} {
 proc showrefs {} {
     global showrefstop bgcolor fgcolor selectbgcolor
     global bglist fglist reflistfilter reflist maincursor
+    global geometry
 
     set top .showrefs
     set showrefstop $top
@@ -10203,7 +10211,11 @@ proc showrefs {} {
     }
     ttk_toplevel $top
     wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
-    make_transient $top .
+    if {[info exists geometry(showrefs)]} {
+        make_transient $top . $geometry(showrefs)
+    } else {
+        make_transient $top .
+    }
     text $top.list -background $bgcolor -foreground $fgcolor \
         -selectbackground $selectbgcolor -font mainfont \
         -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
@@ -10239,6 +10251,9 @@ proc showrefs {} {
     bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
     set reflist {}
     refill_reflist
+    # avoid <Configure> being bound to child windows
+    bindtags $top [linsert [bindtags $top] 1 bind$top]
+    bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
 }
 
 proc sel_reflist {w x y} {
-- 
2.51.0.431.g0f99086cdf

← back to recent threads