unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: charles@aurox.ch (Charles A. Roelli)
To: Anders Lindgren <andlind@gmail.com>
Cc: 25818@debbugs.gnu.org
Subject: bug#25818: 25.2; frame moved off display does not return (OS X)
Date: Sat, 08 Apr 2017 22:40:31 +0200	[thread overview]
Message-ID: <m2efx21vls.fsf@aurox.ch> (raw)
In-Reply-To: <CABr8ebZNxKUo6057EM0-y4UYyebTaYDBtkUasmv7TSgPBjuk+A@mail.gmail.com> (Anders Lindgren's message of "Mon, 3 Apr 2017 10:33:04 +0200")

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

Hi Anders,

Following your idea, here's an updated patch that works equivalently.
Please let me know what you think.

> Anyway, I think that we're on the right track and I appreciate that you
> have taken time to work on this!

My pleasure!

> PS. I just found another, unrelated, problem, when comparing the NS and X11
> versions. When passing a negative value to `set-frame-position' it is
> supposed to place the frame relative to the right/bottom border of the
> display, but in the NS version it doesn't. (The X11 version gets the Y
> placement wrong with 48 pixels, but that is another story.)

Hm... but what if a second display is in the negative coordinate space?
How would you place a frame on it programmatically?  In any case I'll
try to build the X11 version and see how it does it -- I wasn't aware
that it still works on Mac OS.

Cheers,
Charles

>> A quick test on 10.6:
>>
>> (setq ns-auto-hide-menu-bar t)
>>
>> ;; Places the frame just above the top of the screen.
>> (set-frame-position (selected-frame) 0 -20)
>>
>> ;; Frame would be completely offscreen; so it's constrained and brought
>> ;; back.
>> (set-frame-position (selected-frame) 0 -10000)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Constrain-frames-to-visible-area-of-screens-in-OS-X-revised.patch --]
[-- Type: text/x-patch, Size: 2206 bytes --]

From 2b95b86f8c50665bbbb62b5faae0d8d610019594 Mon Sep 17 00:00:00 2001
From: Charles A. Roelli <charles@aurox.ch>
Date: Sat, 8 Apr 2017 22:15:17 +0200
Subject: [PATCH] Constrain frames to visible area of screens in OS X

* nsterm.m (constrainFrameRect:toScreen:): Constrain
  frames in OS X, if they would otherwise go offscreen.

Fixes: debbugs:25818
---
 src/nsterm.m |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index ebe29e4..b1429f4 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7846,21 +7846,52 @@ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
   // If separate spaces is on, it is like each screen is independent.  There is
   // no spanning of frames across screens.
   if ([NSScreen screensHaveSeparateSpaces])
     {
       NSTRACE_MSG ("Screens have separate spaces");
       frameRect = [super constrainFrameRect:frameRect toScreen:screen];
       NSTRACE_RETURN_RECT (frameRect);
       return frameRect;
     }
-#endif
+  else
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 */
+    // Check that the proposed frameRect intersects at least one
+    // screen rectangle.  If it does not, constrain the frame and
+    // return it.  See bug #25818.
+    {
+      NSArray *screens = [NSScreen screens];
+      NSUInteger nr_screens = [screens count];
+
+      int i;
+      BOOL frame_on_screen = NO;
+
+      for (i = 0; i < nr_screens; ++i)
+	{
+	  NSScreen *s = [screens objectAtIndex: i];
+	  NSRect scrRect = [s frame];
+
+	  if (NSIntersectsRect(frameRect, scrRect))
+	    {
+	      frame_on_screen = YES;
+	      break;
+	    }
+	}
+
+      if (!frame_on_screen)
+	{
+	  NSTRACE_MSG ("Frame outside screens; constraining");
+	  frameRect = [super constrainFrameRect:frameRect toScreen:screen];
+	  NSTRACE_RETURN_RECT (frameRect);
+	  return frameRect;
+	}
+    }
 #endif
 
   return constrain_frame_rect(frameRect,
                               [(EmacsView *)[self delegate] isFullscreen]);
 }
 
 
 - (void)performZoom:(id)sender
 {
   NSTRACE ("[EmacsWindow performZoom:]");
-- 
1.7.4.4


  reply	other threads:[~2017-04-08 20:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 20:04 bug#25818: 25.2; frame moved off display does not return (OS X) Charles A. Roelli
2017-02-23  8:49 ` martin rudalics
2017-02-26 11:26   ` Charles A. Roelli
2017-02-26 15:40     ` Charles A. Roelli
2017-02-26 16:45       ` martin rudalics
2017-02-26 19:42         ` Charles A. Roelli
2017-02-27  8:05           ` martin rudalics
2017-02-27 10:34             ` Charles A. Roelli
2017-02-27 20:47             ` Charles A. Roelli
2017-02-28 10:12               ` Charles A. Roelli
2017-02-28 13:20               ` Anders Lindgren
2017-02-28 15:05                 ` Charles A. Roelli
2017-02-28 20:35                   ` Anders Lindgren
2017-02-28 22:05                     ` Drew Adams
2017-03-01 10:48                       ` Anders Lindgren
2017-03-01 16:10                         ` Drew Adams
2017-03-19 19:38                     ` Charles A. Roelli
2017-03-27 18:22                       ` Anders Lindgren
2017-04-02 14:14                         ` Charles A. Roelli
2017-04-03  8:33                           ` Anders Lindgren
2017-04-08 20:40                             ` Charles A. Roelli [this message]
2017-04-09 19:13                               ` Anders Lindgren
2017-04-10 19:54                                 ` Charles A. Roelli
2017-04-11 18:35                                   ` Anders Lindgren
2017-04-27 19:14                                     ` Charles A. Roelli
2017-04-27 20:05                                       ` Alan Third
2017-04-28 17:33                                         ` Charles A. Roelli
2017-05-02 20:33                                           ` Alan Third
2017-05-05 18:30                                             ` Charles A. Roelli
2017-04-29 10:30                                       ` martin rudalics
2017-04-29 11:15                                         ` Charles A. Roelli
2017-04-29 14:51                                           ` Alan Third
2017-04-29 17:23                                           ` Anders Lindgren
2017-04-30  8:32                                           ` martin rudalics

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=m2efx21vls.fsf@aurox.ch \
    --to=charles@aurox.ch \
    --cc=25818@debbugs.gnu.org \
    --cc=andlind@gmail.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).