unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: martin rudalics <rudalics@gmx.at>,
	emacs-devel@gnu.org, Feng Shu <tumashu@163.com>
Subject: Re: set-frame-parameter a child-frame's 'parent-frame error on macOS ?
Date: Mon, 22 Jan 2018 12:11:26 +0100	[thread overview]
Message-ID: <87k1wakv1d.fsf@gmail.com> (raw)
In-Reply-To: <87d12agitl.fsf@gmail.com> (Robert Pluim's message of "Tue, 16 Jan 2018 12:10:46 +0100")

[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]

Robert Pluim <rpluim@gmail.com> writes:

> Dmitry Gutov <dgutov@yandex.ru> writes:
>
>> That is the description of my experience with Robert's patch
>> applied. Without it applied, the "bad frame" appears last (at position
>> 40-100, approximately).
>>
>> Feng Shu has changed his code since to call set-frame-position much
>> less often, and it seems to work correctly *without* Robert's
>> patch. Quite weird.
>
> Yes. I have an improved version of the patch on the way, which should
> also fix `frameset-restore' and a few other cases of incorrect frame
> positioning. Hopefully by the end of the week.

frameset-restore turned out to be a completely separate fix.

The attached fixes the cases that I could track down where we weren't
applying scaling properly. All Emacs pixel coordinates remain unscaled
after this, the values are just scaled when passing them into GTK. The
xwidget code almost certainly requires the same type of adjustments.

Strongly recommended for emacs-26. People who don't use scaling will
see no side-effects.

Robert


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-scaled-coordinates-when-calling-into-GTK.patch --]
[-- Type: text/x-diff, Size: 3297 bytes --]

From 3324e5b4d94d5432a13d0d2828f342a8cf3c1398 Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Fri, 19 Jan 2018 11:38:07 +0100
Subject: [PATCH] Use scaled coordinates when calling into GTK

* 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.
---
 src/gtkutil.c |  9 ++++++---
 src/xterm.c   | 11 +++++++----
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/gtkutil.c b/src/gtkutil.c
index 123236f5f0..83b306a730 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 f771631daf..f05ac6147e 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);
-- 
2.16.0.rc1


  reply	other threads:[~2018-01-22 11:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12  3:02 set-frame-parameter a child-frame's 'parent-frame error on macOS ? tumashu
2018-01-12  8:49 ` martin rudalics
2018-01-12 12:13   ` Feng Shu
2018-01-12 18:47     ` martin rudalics
2018-01-12 19:31       ` Alan Third
2018-01-13  8:49         ` martin rudalics
2018-01-13  3:01       ` tumashu
2018-01-13  8:50         ` martin rudalics
2018-01-13 10:36           ` Feng Shu
2018-01-13 11:58             ` martin rudalics
2018-01-13 12:11               ` Dmitry Gutov
2018-01-13 12:29                 ` martin rudalics
2018-01-14  1:07                   ` Dmitry Gutov
2018-01-14  9:05                     ` martin rudalics
2018-01-14 10:34                       ` Dmitry Gutov
2018-01-14 11:19                         ` martin rudalics
2018-01-13 23:57               ` Feng Shu
2018-01-14  9:05                 ` martin rudalics
2018-01-14 10:35                   ` Dmitry Gutov
2018-01-14 11:19                     ` martin rudalics
2018-01-15  0:29                     ` Dmitry Gutov
2018-01-15  8:49                       ` Robert Pluim
2018-01-15  9:38                       ` martin rudalics
2018-01-15 11:59                         ` Feng Shu
2018-01-16  9:08                           ` martin rudalics
2018-01-16 10:33                             ` Feng Shu
2018-01-19 18:54                               ` martin rudalics
2018-01-20  0:11                                 ` Feng Shu
2018-01-20 10:34                                   ` martin rudalics
2018-01-20 13:26                                     ` Feng Shu
2018-01-15 17:07                         ` Dmitry Gutov
2018-01-16  9:07                           ` martin rudalics
2018-01-16 10:37                             ` Feng Shu
2018-01-16 11:10                           ` Robert Pluim
2018-01-22 11:11                             ` Robert Pluim [this message]
2018-01-22 16:01                               ` Eli Zaretskii
2018-01-22 16:12                                 ` Robert Pluim
2018-01-22 16:17                                   ` Eli Zaretskii
2018-01-22 16:25                                     ` Robert Pluim
2018-01-22 16:31                                       ` Eli Zaretskii
2018-01-22 16:55                                         ` Paul Eggert
2018-01-22 16:59                                           ` Eli Zaretskii
2018-01-22 18:59                                             ` martin rudalics
2018-01-23  1:12                                               ` Dmitry Gutov
2018-01-23  3:36                                                 ` Eli Zaretskii
2018-01-24  8:38                                                   ` martin rudalics
2018-01-24  8:47                                                     ` Robert Pluim
2018-01-13 23:59               ` Feng Shu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k1wakv1d.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=rudalics@gmx.at \
    --cc=tumashu@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).