unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Jiege Chen <jiegec@qq.com>
Cc: 29953@debbugs.gnu.org
Subject: bug#29953: 26.0.90; Moving a child frame before making it visible makes the child frame not showing any more on macOS
Date: Wed, 3 Jan 2018 14:07:04 +0000	[thread overview]
Message-ID: <20180103140704.GA98841@breton.holly.idiocy.org> (raw)
In-Reply-To: <5a4c1c86.0ac7df0a.a769a.93cbSMTPIN_ADDED_BROKEN@mx.google.com>

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

On Wed, Jan 03, 2018 at 07:55:12AM +0800, Jiege Chen wrote:
> 
> Snippet:
> 
> This code uses `oddp', which might not be available from `emacs -Q'.

You can replace it with (= 1 (mod count 2))

> On my macOS Sierra, the frame only shows once and never shows again.

There were two issues interacting here: invisible child frames lose
track of their parents in NS, and frames that are off‐screen don’t
have an associated screen but our positioning code will only position
a frame if it knows it’s screen.

I’ve fixed the first issue so that we look up the parent through the
Emacs frame structs, and the second by positioning according to the
main screen if the frame doesn’t have a screen.

I also fixed what I think is a bug when child frames are positioned
with negative values. On X it looks as though a negative value always
results in positioning according to the bottom‐right of the parent
frame, but on NS it would be positioned to the left and above the
parent frame. NS now behaves like X.

Patch attached.

> Related issue: https://github.com/emacs-lsp/lsp-ui/issues/21 .

Are you using threads? GUI calls and threads don’t mix well yet,
unfortunately.
-- 
Alan Third

[-- Attachment #2: 0001-Fix-child-frame-placement-issues-bug-29953.patch --]
[-- Type: text/plain, Size: 4497 bytes --]

From b54c5c18df91cbf887d653846edddeb1c853c141 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Wed, 3 Jan 2018 13:45:03 +0000
Subject: [PATCH] Fix child frame placement issues (bug#29953)

* src/nsterm.h (NS_PARENT_WINDOW_LEFT_POS):
(NS_PARENT_WINDOW_TOP_POS): Get the parent frame through the frame
struct as invisible child windows are detached from their parents in
NS.
* src/nsterm.m (x_set_offset): Offscreen frames have `nil' screen
value, so handle that gracefully.  Child frames with negative left and
top should be positioned relative to the bottom right of the parent
frame.
---
 src/nsterm.h |  6 +++---
 src/nsterm.m | 46 ++++++++++++++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/nsterm.h b/src/nsterm.h
index c40ddf3284..588b9fc644 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -1073,11 +1073,11 @@ struct x_output
    window or, if there is no parent window, the screen. */
 #define NS_PARENT_WINDOW_LEFT_POS(f)                                    \
   (FRAME_PARENT_FRAME (f) != NULL                                       \
-   ? [[FRAME_NS_VIEW (f) window] parentWindow].frame.origin.x : 0)
+   ? [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.x : 0)
 #define NS_PARENT_WINDOW_TOP_POS(f)                                     \
   (FRAME_PARENT_FRAME (f) != NULL                                       \
-   ? ([[FRAME_NS_VIEW (f) window] parentWindow].frame.origin.y          \
-      + [[FRAME_NS_VIEW (f) window] parentWindow].frame.size.height     \
+   ? ([FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.y    \
+      + [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.size.height \
       - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f)))              \
    : [[[NSScreen screens] objectAtIndex: 0] frame].size.height)
 
diff --git a/src/nsterm.m b/src/nsterm.m
index 5798f4fd0b..419a37033f 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1736,7 +1736,6 @@ -(void)remove
 {
   NSView *view = FRAME_NS_VIEW (f);
   NSArray *screens = [NSScreen screens];
-  NSScreen *fscreen = [screens objectAtIndex: 0];
   NSScreen *screen = [[view window] screen];
 
   NSTRACE ("x_set_offset");
@@ -1746,26 +1745,41 @@ -(void)remove
   f->left_pos = xoff;
   f->top_pos = yoff;
 
-  if (view != nil && screen && fscreen)
+  if (view != nil)
     {
-      f->left_pos = f->size_hint_flags & XNegative
-        ? [screen visibleFrame].size.width + f->left_pos - FRAME_PIXEL_WIDTH (f)
-        : f->left_pos;
-      /* We use visibleFrame here to take menu bar into account.
-	 Ideally we should also adjust left/top with visibleFrame.origin.  */
-
-      f->top_pos = f->size_hint_flags & YNegative
-        ? ([screen visibleFrame].size.height + f->top_pos
-           - FRAME_PIXEL_HEIGHT (f) - FRAME_NS_TITLEBAR_HEIGHT (f)
-           - FRAME_TOOLBAR_HEIGHT (f))
-        : f->top_pos;
+      if (FRAME_PARENT_FRAME (f) == NULL && screen)
+        {
+          f->left_pos = f->size_hint_flags & XNegative
+            ? [screen visibleFrame].size.width + f->left_pos - FRAME_PIXEL_WIDTH (f)
+            : f->left_pos;
+          /* We use visibleFrame here to take menu bar into account.
+             Ideally we should also adjust left/top with visibleFrame.origin.  */
+
+          f->top_pos = f->size_hint_flags & YNegative
+            ? ([screen visibleFrame].size.height + f->top_pos
+               - FRAME_PIXEL_HEIGHT (f) - FRAME_NS_TITLEBAR_HEIGHT (f)
+               - FRAME_TOOLBAR_HEIGHT (f))
+            : f->top_pos;
 #ifdef NS_IMPL_GNUSTEP
-      if (FRAME_PARENT_FRAME (f) == NULL)
-	{
 	  if (f->left_pos < 100)
 	    f->left_pos = 100;  /* don't overlap menu */
-	}
 #endif
+        }
+      else if (FRAME_PARENT_FRAME (f) != NULL)
+        {
+          struct frame *parent = FRAME_PARENT_FRAME (f);
+
+          /* On X negative values for child frames always result in
+             positioning relative to the bottom right corner of the
+             parent frame.  */
+          if (f->left_pos < 0)
+            f->left_pos = FRAME_PIXEL_WIDTH (parent) - FRAME_PIXEL_WIDTH (f) + f->left_pos;
+
+          if (f->top_pos < 0)
+            f->top_pos = FRAME_PIXEL_HEIGHT (parent) + FRAME_TOOLBAR_HEIGHT (parent)
+              - FRAME_PIXEL_HEIGHT (f) + f->top_pos;
+        }
+
       /* Constrain the setFrameTopLeftPoint so we don't move behind the
          menu bar.  */
       NSPoint pt = NSMakePoint (SCREENMAXBOUND (f->left_pos
-- 
2.14.3


       reply	other threads:[~2018-01-03 14:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5a4c1c86.0ac7df0a.a769a.93cbSMTPIN_ADDED_BROKEN@mx.google.com>
2018-01-03 14:07 ` Alan Third [this message]
2018-01-04  8:38   ` bug#29953: 26.0.90; Moving a child frame before making it visible makes the child frame not showing any more on macOS jiegec
     [not found]   ` <5a4de826.cdaddf0a.a4a57.beeeSMTPIN_ADDED_BROKEN@mx.google.com>
2018-01-04 19:37     ` Alan Third
2018-01-06 23:22       ` Alan Third
2018-01-02 23:55 Jiege Chen

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=20180103140704.GA98841@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=29953@debbugs.gnu.org \
    --cc=jiegec@qq.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).