git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 6, 2025, 15:29 UTC
Message-ID
<e999c9d2-01d2-4569-ab32-2922ded29dcf@kdbg.org>
In-Reply-To
<941180e0-d8a1-4f2b-a0d8-2128428b36d8@kdbg.org>

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(-)
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
Previous: Johannes Sixt
Message 12 of 12 in “gitk: make Tags and Heads window geometry sticky”
  1. 0/2 gitk: make Tags and Heads window geometry stickyMichael Rappazzo, Sep 28, 2025
  2. 1/2 Revert "gitk: Only restore window size from ~/.gitk, not position"Michael Rappazzo, Sep 28, 2025
  3. Mark LevedahlSep 28, 2025
  4. Mike RappazzoSep 28, 2025
  5. Johannes SixtOct 17, 2025
  6. Mark LevedahlOct 17, 2025
  7. Junio C HamanoSep 28, 2025
  8. 2/2 gitk: make Tags and Heads window geometry stickyMichael Rappazzo, Sep 28, 2025
  9. Junio C HamanoSep 28, 2025
  10. Johannes SixtOct 4, 2025
  11. gitk: persist position and size of the Tags and Heads windowJohannes Sixt, Oct 4, 2025
  12. gitk: persist position and size of the Tags and Heads windowJohannes Sixt, Oct 6, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.