From: Robert Pluim Date: Wed, 24 Jan 2018 07:55:34 +0000 (+0100) Subject: Use scaled coordinates when calling into GTK X-Git-Tag: emacs-26.1-rc1~326 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=59db8dca030ba6a34d143c3cc6715f02beba1068;p=emacs.git Use scaled coordinates when calling into GTK This is part two of a two part fix for the GTK scaling problems. See the thread starting at http://lists.gnu.org/archive/html/emacs-devel/2018-01/msg00372.html for an explanation of why it has been added to Emacs 26. * src/gtkutil.c (xg_set_geometry): Scale down the coordinates that we pass to gtk_window_move and to gtk_window_parse_geometry. * src/xterm.c (x_set_offset): Likewise. --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 123236f5f08..83b306a730a 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -823,6 +823,7 @@ xg_set_geometry (struct frame *f) { if (f->size_hint_flags & (USPosition | PPosition)) { + int scale = xg_get_scale (f); #if ! GTK_CHECK_VERSION (3, 22, 0) if (x_gtk_use_window_move) { @@ -838,8 +839,9 @@ xg_set_geometry (struct frame *f) f->top_pos = (x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - FRAME_PIXEL_HEIGHT (f) + f->top_pos); + /* GTK works in scaled pixels, so convert from X pixels. */ gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - f->left_pos, f->top_pos); + f->left_pos / scale, f->top_pos / scale); /* Reset size hint flags. */ f->size_hint_flags &= ~ (XNegative | YNegative); @@ -847,9 +849,10 @@ xg_set_geometry (struct frame *f) } else { - int left = f->left_pos; + /* GTK works in scaled pixels, so convert from X pixels. */ + int left = f->left_pos / scale; int xneg = f->size_hint_flags & XNegative; - int top = f->top_pos; + int top = f->top_pos / scale; int yneg = f->size_hint_flags & YNegative; char geom_str[sizeof "=x--" + 4 * INT_STRLEN_BOUND (int)]; guint id; diff --git a/src/xterm.c b/src/xterm.c index f771631dafa..f05ac6147eb 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10310,6 +10310,7 @@ void x_set_offset (struct frame *f, register int xoff, register int yoff, int change_gravity) { int modified_top, modified_left; + int scale = xg_get_scale (f); if (change_gravity > 0) { @@ -10332,11 +10333,12 @@ x_set_offset (struct frame *f, register int xoff, register int yoff, int change_ if (x_gtk_use_window_move) { /* When a position change was requested and the outer GTK widget - has been realized already, leave it to gtk_window_move to DTRT - and return. Used for Bug#25851 and Bug#25943. */ + has been realized already, leave it to gtk_window_move to + DTRT and return. Used for Bug#25851 and Bug#25943. Convert + from X pixels to GTK scaled pixels. */ if (change_gravity != 0 && FRAME_GTK_OUTER_WIDGET (f)) gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - f->left_pos, f->top_pos); + f->left_pos / scale, f->top_pos / scale); unblock_input (); return; } @@ -10355,8 +10357,9 @@ x_set_offset (struct frame *f, register int xoff, register int yoff, int change_ } #ifdef USE_GTK + /* Make sure we adjust for possible scaling. */ gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - modified_left, modified_top); + modified_left / scale, modified_top / scale); #else XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), modified_left, modified_top);