public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Michael Rappazzo <rappazzo@gmail•com>
To: git@vger•kernel.org
Cc: j6t@kdbg•org, Michael Rappazzo <rappazzo@gmail•com>
Subject: [PATCH v2 2/2] gitk: make Tags and Heads window geometry sticky
Date: Sat, 20 Sep 2025 14:40:07 -0400	[thread overview]
Message-ID: <20250920184007.26183-3-rappazzo@gmail.com> (raw)
In-Reply-To: <20250920184007.26183-1-rappazzo@gmail.com>

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 | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/gitk b/gitk
index 95469a8fae..0393241c85 100755
--- a/gitk
+++ b/gitk
@@ -3116,6 +3116,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 {}
@@ -10209,11 +10214,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" \
@@ -10239,8 +10246,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
@@ -10249,6 +10256,8 @@ proc showrefs {} {
     bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
     set reflist {}
     refill_reflist
+    after idle [list manage_showrefs_geometry $top restore]
+    bind $top <Configure> [list manage_showrefs_geometry $top save]
 }
 
 proc sel_reflist {w x y} {
@@ -10281,6 +10290,28 @@ proc reflistfilter_change {n1 n2 op} {
     after 200 refill_reflist
 }
 
+proc manage_showrefs_geometry {top action} {
+    global geometry
+    switch $action {
+        save {
+            if {[winfo exists $top]} {
+                set geometry(showrefs) [wm geometry $top]
+            }
+        }
+        restore {
+            if {[info exists geometry(showrefs)] && [winfo exists $top]} {
+                after 1 [list wm geometry $top $geometry(showrefs)]
+            }
+        }
+    }
+}
+
+proc destroy_showrefs {top} {
+    manage_showrefs_geometry $top save
+    savestuff .
+    destroy $top
+}
+
 proc refill_reflist {} {
     global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype
     global curview upstreamofref
-- 
2.51.0


  parent reply	other threads:[~2025-09-20 18:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20 18:40 [PATCH v2 0/2] gitk: make the 'Tags and Heads' window geometry sticky Michael Rappazzo
2025-09-20 18:40 ` [PATCH v2 1/2] gitk: fix the position of the main main window on initialize Michael Rappazzo
2025-09-22  6:00   ` Johannes Sixt
2025-09-22 10:16     ` Mark Levedahl
2025-09-20 18:40 ` Michael Rappazzo [this message]
2025-09-22  6:34   ` [PATCH v2 2/2] gitk: make Tags and Heads window geometry sticky Johannes Sixt
2025-09-25 12:45     ` Mike Rappazzo
2025-09-28 13:30       ` Mike Rappazzo

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=20250920184007.26183-3-rappazzo@gmail.com \
    --to=rappazzo@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=j6t@kdbg$(echo .)org \
    /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