fix: calculate cell size before presenting gtk window#10459
fix: calculate cell size before presenting gtk window#10459ajbucci wants to merge 2 commits intoghostty-org:mainfrom
Conversation
|
I think that we should at least look at refactoring |
src/apprt/gtk/class/surface.zig
Outdated
| const cell = font_grid.cellSize(); | ||
|
|
||
| // Calculate size (matching recomputeInitialSize logic) | ||
| const width = @max(config.@"window-width", 10) * cell.width; |
There was a problem hiding this comment.
Definitely do not want a magic number 10 here.
src/apprt/gtk/class/surface.zig
Outdated
|
|
||
| // Calculate size (matching recomputeInitialSize logic) | ||
| const width = @max(config.@"window-width", 10) * cell.width; | ||
| const height = @max(config.@"window-height", 4) * cell.height; |
There was a problem hiding this comment.
Nor the magic number 4. These need to reference the constants in src/Surface.zig somehow.
There was a problem hiding this comment.
Thanks for the review. I'll take a look at refactoring recomputeInitialSize and adding some unit tests; then I won't have to worry about the private constants.
There was a problem hiding this comment.
On second thought, I think we can safely leave out the max() altogether because this is just our 'best guess' initial size. When the window eventually presents it will resize to the 'real' size which already has this logic baked in.
|
I took a closer look at this and I think the duplication is minimal enough that we can probably leave it as proposed. Here are the other options I explored: 1) Extract just the final window-size math (cells × cell size ÷ content scale + padding) into a shared helper.
2) Extract the entire sizing pipeline (content scale -> DPI -> DesiredSize -> DerivedConfig -> font grid lookup -> cell size -> window size)
I’m hesitant to introduce new public/static APIs solely to support an apprt quirk, especially if it increases core complexity. Let me know if you'd like me to explore further or have any suggestions! |
Fixes #7937
Added
computeInitialSizeto GTKSurfaceand call it in GTKApplicationbefore the firstpresent(), so the window manager centers the correct size on initial show.The issue occurs because the core
Surface.recomputeInitialSize()runs only after the renderer is initialized. In GTK, theGLAreaisn’t realized until afterpresent(), so the initial size arrives too late for WM centering.Limitations: when we precompute size before
present()we do not have access to padding, so the sizing will be very slightly off... but since it is only off a few pixels I was unable to tell visually that it wasn't perfectly centered.Other thoughts: I was hesitant to make changes to core
Surfacebecause the issue is Linux-specific, but it may make sense to extract a helper fromrecomputeInitialSizeto avoid duplicating the sizing math.AI Disclosure: I used AI to explore the project, help with any language / API questions (I've never used zig before and rarely use gtk), and make implementation suggestions.