diff options
author | Brian Norris <[email protected]> | 2024-02-15 16:10:30 -0800 |
---|---|---|
committer | raveit65 <[email protected]> | 2024-02-18 14:14:57 +0100 |
commit | 62578331bfcbd1e4b8fd804676c737e7890bbd1f (patch) | |
tree | f0581d022d6bd2766ddbf0b78caa96c93e893a63 | |
parent | 44b230796268177ab00dc8d82b3b937d66f77bbb (diff) | |
download | mate-terminal-1.26.tar.bz2 mate-terminal-1.26.tar.xz |
terminal-window: Factor CSDs into geometry hints1.26
It seems Wayland-based window managers provide additional decorations
that we're not tracking in our "preferred size" computations. This means
every geometry update shrinks the window by a bit.
Factor in the allocated dimensions, not just the preferred ones.
Borrows some ideas from
https://bugzilla.gnome.org/show_bug.cgi?id=769898
I also drop a few unused values leftover from gnome-terminal.
Fixes #350
-rw-r--r-- | src/terminal-window.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/terminal-window.c b/src/terminal-window.c index 3fabc6b..3f5421d 100644 --- a/src/terminal-window.c +++ b/src/terminal-window.c @@ -3366,10 +3366,11 @@ terminal_window_update_geometry (TerminalWindow *window) GtkWidget *widget; GdkGeometry hints; GtkBorder padding; - GtkRequisition toplevel_request, vbox_request, widget_request; + GtkRequisition vbox_request; int grid_width, grid_height; int char_width, char_height; int chrome_width, chrome_height; + int csd_width = 0, csd_height = 0; if (priv->active_screen == NULL) return; @@ -3400,20 +3401,41 @@ terminal_window_update_geometry (TerminalWindow *window) _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "content area requests %dx%d px\n", vbox_request.width, vbox_request.height); - gtk_widget_get_preferred_size (GTK_WIDGET (window), NULL, &toplevel_request); - _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "window requests %dx%d px\n", - toplevel_request.width, toplevel_request.height); - chrome_width = vbox_request.width - (char_width * grid_width); chrome_height = vbox_request.height - (char_height * grid_height); _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "chrome: %dx%d px\n", chrome_width, chrome_height); - gtk_widget_get_preferred_size (widget, NULL, &widget_request); - _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "terminal widget requests %dx%d px\n", - widget_request.width, widget_request.height); + if (gtk_widget_get_realized (GTK_WIDGET (window))) { + GtkAllocation toplevel_allocation, vbox_allocation; + + gtk_widget_get_allocation (priv->main_vbox, &vbox_allocation); + _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, + "terminal widget allocation %dx%d px\n", + vbox_allocation.width, vbox_allocation.height); - if (char_width != priv->old_char_width || + gtk_widget_get_allocation (GTK_WIDGET (window), &toplevel_allocation); + _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "window allocation %dx%d px\n", + toplevel_allocation.width, toplevel_allocation.height); + + csd_width = toplevel_allocation.width - vbox_allocation.width; + csd_height = toplevel_allocation.height - vbox_allocation.height; + _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "CSDs: %dx%d px\n", + csd_width, csd_height); + } + + if (!gtk_widget_get_realized (GTK_WIDGET (window))) + { + /* Don't actually set the geometry hints until we have been realized, + * because we don't know how large the client-side decorations are going + * to be. + * + * Similarly, the size request doesn't seem to include the padding + * until we've been redrawn at least once. Don't resize the window + * until we've done that. */ + _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, "not realized yet\n"); + } + else if (char_width != priv->old_char_width || char_height != priv->old_char_height || padding.left + padding.right != priv->old_padding_width || padding.top + padding.bottom != priv->old_padding_height || @@ -3421,8 +3443,8 @@ terminal_window_update_geometry (TerminalWindow *window) chrome_height != priv->old_chrome_height || widget != GTK_WIDGET (priv->old_geometry_widget)) { - hints.base_width = chrome_width; - hints.base_height = chrome_height; + hints.base_width = chrome_width + csd_width; + hints.base_height = chrome_height + csd_height; #define MIN_WIDTH_CHARS 4 #define MIN_HEIGHT_CHARS 1 |