public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Johannes Sixt <j6t@kdbg•org>
To: Michael Rappazzo <rappazzo@gmail•com>
Cc: git@vger•kernel.org
Subject: [PATCH v2] gitk: persist position and size of the Tags and Heads window
Date: Mon, 6 Oct 2025 17:29:53 +0200	[thread overview]
Message-ID: <e999c9d2-01d2-4569-ab32-2922ded29dcf@kdbg.org> (raw)
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


      reply	other threads:[~2025-10-06 15:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28 13:54 [PATCH v3 0/2] gitk: make Tags and Heads window geometry sticky Michael Rappazzo
2025-09-28 13:54 ` [PATCH v3 1/2] Revert "gitk: Only restore window size from ~/.gitk, not position" Michael Rappazzo
2025-09-28 14:17   ` Mark Levedahl
2025-09-28 15:01     ` Mike Rappazzo
2025-10-17 16:36     ` Johannes Sixt
2025-10-17 19:27       ` Mark Levedahl
2025-09-28 15:49   ` Junio C Hamano
2025-09-28 13:54 ` [PATCH v3 2/2] gitk: make Tags and Heads window geometry sticky Michael Rappazzo
2025-09-28 15:57   ` Junio C Hamano
2025-10-04 17:36   ` Johannes Sixt
2025-10-04 22:04     ` [PATCH] gitk: persist position and size of the Tags and Heads window Johannes Sixt
2025-10-06 15:29       ` Johannes Sixt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e999c9d2-01d2-4569-ab32-2922ded29dcf@kdbg.org \
    --to=j6t@kdbg$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=rappazzo@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox