diff --git a/main.go b/main.go index 5c09802..90c2bf4 100644 --- a/main.go +++ b/main.go @@ -238,8 +238,7 @@ func repaint(name string, data tk.Opt) { } else { tk.App.WmTitle("why") } - // causes weird behavior on macOS 26 where the window re-renders during the move - // tk.App.Center() + center() } func menuSelect() { @@ -375,6 +374,31 @@ func main() { repaint("", tk.Data(noise)) tk.Pack(img) - tk.App.Center() + center() tk.App.Wait() } + +func center() { + // Force Tk to flush pending events so geometry info is accurate + tk.Update() + + w := tk.App + + // Get screen dimensions + sw, _ := strconv.Atoi(tk.WinfoScreenWidth(w)) + sh, _ := strconv.Atoi(tk.WinfoScreenHeight(w)) + + // Get current window dimensions + // Note: If testing at startup before the window is visible, + // you might need WinfoReqWidth(w) instead. + width, _ := strconv.Atoi(tk.WinfoWidth(w)) + height, _ := strconv.Atoi(tk.WinfoHeight(w)) + + // Calculate center + x := (sw - width) / 2 + y := (sh - height) / 2 + + // Apply geometry directly without hiding the window + // This moves the window to x,y while preserving current width/height + tk.WmGeometry(w, fmt.Sprintf("+%d+%d", x, y)) +}