diff --git a/src/gtkutil.c b/src/gtkutil.c index a6bba096a4..167329ccb8 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1174,6 +1182,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) int outer_width = width + FRAME_TOOLBAR_WIDTH (f); bool was_visible = false; bool hide_child_frame; + int scale = xg_get_scale (f); #ifndef HAVE_PGTK gtk_window_get_size (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), @@ -1196,8 +1206,42 @@ xg_frame_set_char_size (struct frame *f, int width, int height) /* Do this before resize, as we don't know yet if we will be resized. */ FRAME_RIF (f)->clear_under_internal_border (f); - outer_height /= xg_get_scale (f); - outer_width /= xg_get_scale (f); + outer_height /= scale; + outer_width /= scale; + + if (scale != 1 && !frame_resize_pixelwise) + { + int base_width_unscaled = (FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 1) + + FRAME_TOOLBAR_WIDTH (f)); + int base_width_scaled = base_width_unscaled / scale; + int base_height_unscaled = (FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 1) + + FRAME_MENUBAR_HEIGHT (f) + + FRAME_TOOLBAR_HEIGHT (f)); + int base_height_scaled = base_height_unscaled / scale; + int width_inc = FRAME_COLUMN_WIDTH (f) / scale; + int height_inc = FRAME_LINE_HEIGHT (f) / scale; + int width_rest, height_rest; + + if (width_inc < 1) + width_inc = 1; + + if (height_inc < 1) + height_inc = 1; + + if (outer_width < base_width_scaled) + outer_width = base_width_scaled; + + if (outer_height < base_height_scaled) + outer_height = base_height_scaled; + + width_rest = (outer_width - base_width_scaled) % width_inc; + height_rest = (outer_height - base_height_scaled) % height_inc; + + if (width_rest > 0 || (base_width_unscaled % scale) > 0) + outer_width = outer_width + width_inc - width_rest; + if (height_rest > 0 || (base_height_unscaled % scale) > 0) + outer_height = outer_height + height_inc - height_rest; + } xg_wm_set_size_hint (f, 0, 0);