unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: 71912@debbugs.gnu.org
Cc: Jones Stephen <happyojones@gmail.com>
Subject: bug#71912: [Gerd Möllmann] Re: bug#71912: 30.0.50; Inaccurate window-absolute-pixel-position Values on macOS After Sleep and During Fullscreen Mode
Date: Sun, 11 Aug 2024 08:49:13 +0200	[thread overview]
Message-ID: <m2msljpn9y.fsf@pro2.fritz.box> (raw)
In-Reply-To: <CAOFab0=gs1aChbEoe=rX2b2AobWkZzki72FEYBsteSwY3rzmSA@mail.gmail.com>

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

Forwarded to bug list to keep it informed.

-------------------- Start of forwarded message --------------------
From: Gerd Möllmann <gerd.moellmann@gmail.com>
To: Jones Stephen <happyojones@gmail.com>
Subject: Re: bug#71912: 30.0.50; Inaccurate window-absolute-pixel-position
 Values on macOS After Sleep and During Fullscreen Mode
Date: Sun, 11 Aug 2024 08:41:49 +0200


[-- Attachment #2.1: Type: text/plain, Size: 1545 bytes --]

Jones Stephen <happyojones@gmail.com> writes:

> Thank you for the recent patch. I wanted to let you know that after
> using the latest version of Emacs, I found that the fullscreen issue
> has been resolved, which is great news—thank you for that!
>
> However, I’m still encountering an issue with the frame position after
> the system wakes from sleep. Here’s how to reproduce it:
>
> 1. Open Emacs.
> 2. Use a window management tool like Rectangle to position Emacs on one side of the screen.
> 3. Put macOS to sleep.
> 4. Wait for a while, approximately 30 minutes.
> 5. Wake up macOS, enter the login password, and then focus back on Emacs.
>
> At this point, the frame position seems to be incorrect.

I can reproduce this here.

> Interestingly, when I use Rectangle to move Emacs to the other side of
> the screen, the position issue is resolved.
>
> I believe this could be related to missing a system wake notification.
> Perhaps adding something like:
>
> ```swift
> NotificationCenter.default.addObserver(
>     self,
>     selector: #selector(systemDidWake),
>     name: NSWorkspace.didWakeNotification,
>     object: nil
> )
> ```
>
> and calling `adjustEmacsFrameRect` in the callback could address this
> issue. Alternatively, calling `adjustEmacsFrameRect` whenever
> `windowDidBecomeKey` is triggered might also work.
>

Indeed, that seems to work, although I find it strage that something
like that is necessary. But what do I know.

Could you please try the attached patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.2: 0001-macOS-Wrong-frame-rectangle-after-wake-bug-71912.patch --]
[-- Type: text/x-patch, Size: 2258 bytes --]

> From 1e095fd07bf91cdccf4fe1ecdbcdd9855773e787 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Sun, 11 Aug 2024 08:35:23 +0200
Subject: [PATCH] macOS: Wrong frame rectangle after wake (bug#71912)

* src/nsterm.h ([EmacsView workspaceDidWake:]: New method.
* src/nsterm.m ([EmacsView dealloc])
([EmacsView initFrameFromEmacs:]): Register and deregister view as
observer for NSWorkspaceDidWakeNotification.
---
 src/nsterm.h |  1 +
 src/nsterm.m | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/src/nsterm.h b/src/nsterm.h
index 6c67653705e..0833745616e 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -523,6 +523,7 @@ #define NSTRACE_UNSILENCE()

 /* Non-notification versions of NSView methods. Used for direct calls.  */
 - (void)adjustEmacsFrameRect;
+- (void)workspaceDidWake: (NSNotification *) notification;
 - (void)windowWillEnterFullScreen;
 - (void)windowDidEnterFullScreen;
 - (void)windowWillExitFullScreen;
diff --git a/src/nsterm.m b/src/nsterm.m
index 905707dace4..b60c38b742a 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6689,6 +6689,13 @@ - (void)dealloc
               name:NSViewFrameDidChangeNotification
             object:nil];

+#ifdef NS_IMPL_COCOA
+  [[[NSWorkspace sharedWorkspace] notificationCenter]
+    removeObserver: self
+	      name: NSWorkspaceDidWakeNotification
+	    object: nil];
+#endif
+
   if (fs_state == FULLSCREEN_BOTH)
     [nonfs_window release];
   [super dealloc];
@@ -8039,6 +8046,11 @@ - (BOOL)isOpaque
   return NO;
 }

+- (void)workspaceDidWake: (NSNotification *) notification
+{
+  if (emacsframe)
+    [self adjustEmacsFrameRect];
+}

 - (instancetype) initFrameFromEmacs: (struct frame *)f
 {
@@ -8051,6 +8063,15 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
   fs_state = FULLSCREEN_NONE;
   fs_before_fs = next_maximized = -1;

+#ifdef NS_IMPL_COCOA
+  /* Wrong frame rectangle after wake (bug#71912).  */
+  [[[NSWorkspace sharedWorkspace] notificationCenter]
+    addObserver: self
+       selector: @selector (workspaceDidWake:)
+	   name: NSWorkspaceDidWakeNotification
+	 object: nil];
+#endif
+
   fs_is_native = NO;
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
--
2.46.0


[-- Attachment #3: Type: text/plain, Size: 67 bytes --]

-------------------- End of forwarded message --------------------

  parent reply	other threads:[~2024-08-11  6:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03  2:38 bug#71912: 30.0.50; Inaccurate window-absolute-pixel-position Values on macOS After Sleep and During Fullscreen Mode Jones Stephen
2024-07-23 11:06 ` Gerd Möllmann
2024-07-25  7:39   ` Gerd Möllmann
2024-07-26 19:24     ` Alan Third
2024-07-26 19:27       ` Gerd Möllmann
2024-07-26 20:32         ` Gerd Möllmann
2024-07-30  4:06     ` Gerd Möllmann
2024-08-11  6:49 ` Gerd Möllmann [this message]
     [not found]   ` <CAOFab0n2H3iwyAmVGV1nYrQVqcjRM=ovvJ5hTt4x_0r6rC_k3g@mail.gmail.com>
2024-08-11 11:25     ` bug#71912: [Gerd Möllmann] " Gerd Möllmann
     [not found]       ` <CAOFab0mKnZbku1bq3Y0uyZAr6hb1Pkc7gmV7xuxt1pMJq_AFXw@mail.gmail.com>
2024-08-12  3:16         ` Gerd Möllmann

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=m2msljpn9y.fsf@pro2.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=71912@debbugs.gnu.org \
    --cc=happyojones@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).