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>
Johannes Sixt committed
Oct 17, 2025 at 18:38 UTC
bf5a55ac5eaef91e87470d704613e6942500a810
1 file changed
+20
-5
gitk
+20
-5
@@ -2131,12 +2131,14 @@ proc ttk_toplevel {w args} {
2131
return $w
2132
}
2133
2134
-proc make_transient {window origin} {
2134
+proc make_transient {window origin {geometry ""}} {
2135
wm transient $window $origin
2136
2137
- # Windows fails to place transient windows normally, so
2138
- # schedule a callback to center them on the parent.
2139
- if {[tk windowingsystem] eq {win32}} {
2137
+ if {$geometry ne ""} {
2138
+ after idle [list wm geometry $window $geometry]
2139
+ } elseif {[tk windowingsystem] eq {win32}} {
2140
+ # Windows fails to place transient windows normally, so
2141
+ # schedule a callback to center them on the parent.
2142
after idle [list tk::PlaceWindow $window widget $origin]
2143
}
2144
}
@@ -3106,6 +3108,11 @@ proc savestuff {w} {
3108
puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
3109
puts $f "set geometry(botwidth) [winfo width .bleft]"
3110
puts $f "set geometry(botheight) [winfo height .bleft]"
3111
+ unset -nocomplain geometry
3112
+ global geometry
3113
+ if {[info exists geometry(showrefs)]} {
3114
+ puts $f "set geometry(showrefs) $geometry(showrefs)"
3115
+ }
3116
3117
array set view_save {}
3118
array set views {}
@@ -10193,6 +10200,7 @@ proc rmbranch {} {
10200
proc showrefs {} {
10201
global showrefstop bgcolor fgcolor selectbgcolor
10202
global bglist fglist reflistfilter reflist maincursor
10203
+ global geometry
10204
10205
set top .showrefs
10206
set showrefstop $top
@@ -10203,7 +10211,11 @@ proc showrefs {} {
10211
}
10212
ttk_toplevel $top
10213
wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
10206
- make_transient $top .
10214
+ if {[info exists geometry(showrefs)]} {
10215
+ make_transient $top . $geometry(showrefs)
10216
+ } else {
10217
+ make_transient $top .
10218
+ }
10219
text $top.list -background $bgcolor -foreground $fgcolor \
10220
-selectbackground $selectbgcolor -font mainfont \
10221
-xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
@@ -10239,6 +10251,9 @@ proc showrefs {} {
10251
bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
10252
set reflist {}
10253
refill_reflist
10254
+ # avoid <Configure> being bound to child windows
10255
+ bindtags $top [linsert [bindtags $top] 1 bind$top]
10256
+ bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
10257
}
10258
10259
proc sel_reflist {w x y} {