From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Jones Stephen <happyojones@gmail.com>
Cc: Alan Third <alan@idiocy.org>, 71912@debbugs.gnu.org
Subject: bug#71912: 30.0.50; Inaccurate window-absolute-pixel-position Values on macOS After Sleep and During Fullscreen Mode
Date: Thu, 25 Jul 2024 09:39:16 +0200 [thread overview]
Message-ID: <m2wml953a3.fsf@pro2.fritz.box> (raw)
In-Reply-To: <m21q3kqsf2.fsf@pro2.fritz.box> ("Gerd Möllmann"'s message of "Tue, 23 Jul 2024 13:06:09 +0200")
[-- Attachment #1: Type: text/plain, Size: 2840 bytes --]
Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> Jones Stephen <happyojones@gmail.com> writes:
>
>> Dear Emacs Developers,
>>
>> I am encountering an issue with window-absolute-pixel-position on macOS that leads to incorrect Y-coordinate values under specific conditions. This
>> bug appears to manifest in two scenarios: after the system resumes from sleep, and when Emacs is in fullscreen mode.
>>
>> Environment:
>>
>> Emacs Version: (30.0.50)
>> Operating System: macOS (After 14.00)
>> Issue Description:
>>
>> After Sleep: When macOS resumes from sleep, the Y-coordinate value returned by window-absolute-pixel-position is off by approximately one-fourth
>> of the screen height.
>> During Fullscreen Mode: In fullscreen mode, the Y-coordinate is incorrectly offset by the height of the navbar.
>> Steps to Reproduce:
>>
>> Open Emacs and position a window at a known pixel position.
>> Either put the system to sleep and wake it, or switch Emacs to fullscreen mode.
>> Evaluate (window-absolute-pixel-position) and note the Y-coordinate.
>> Expected Behavior:
>> The function should return accurate window positions regardless of sleep mode or fullscreen state, without any unexpected offsets.
>>
>> Actual Behavior:
>> The Y-coordinate is inaccurately calculated, showing a significant offset that seems to be influenced by system sleep and fullscreen transitions.
>>
>> This issue can be particularly disruptive in workflows that rely on precise window positioning, such as automated GUI testing or window management
>> scripts. Any insights or fixes would be greatly appreciated!
>>
>> Thank you for your attention to this matter.
>>
>> Best regards,
>> happyo
>
> I can reproduce this (only tried the fullscreen case), but I don't know
> how to fix it. In a fullscreen frame, eval
>
> (ns-frame-edges (selected-frame) 'native-edges)
> -> (566 39 2290 1107)
>
> That is, both left and top are bogus values. Also,
>
> (frame-parameter (selected-frame) 'fullscreen)
> -> fullboth
> (frame-parameter (selected-frame) 'top)
> -> 39
> (frame-parameter (selected-frame) 'left)
> -> 566
>
> which is why ns-frame-edges in its current implementation returns these
> values for left and top. Don't know what is expected here. Should top
> and left frame parameters have been set to 0 somewhere? Or is the
> implementation of ns-frame-edges wrong in using top_pos and left_pos of
> the frame?
The following patch for master addresses this at least partially. Part
of the problem is, it appears to me, is that windowDidMove is not called
when entering/exiting fullscreen mode, so that a frame's left_pos and
top_pos are not adjusted. The patch tries to fix that. I haven't found
out what to do with the frame parameters top and left.
(Alan Third CC'd)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: adjustEmacsFrameRect --]
[-- Type: text/x-patch, Size: 2294 bytes --]
From 78f81f9089b51c2de06ca0ad62f4c42c37303c4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Thu, 25 Jul 2024 09:20:04 +0200
Subject: [PATCH] macOS: adjust frame position when entering/exiting fullscreen
* src/nsterm.h ([EmacsView adjustEmacsRectRect]): Declare.
* src/nsterm.m ([EmacsView windowDidEnterFullScreen]): New method.
([EmacsView windowDidEnterFullScreen]): Call it.
([EmacsView windowDidExitFullScreen]): Call it.
---
src/nsterm.h | 1 +
src/nsterm.m | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/src/nsterm.h b/src/nsterm.h
index 3a713f8e8c9..e3f55c4e41c 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -522,6 +522,7 @@ #define NSTRACE_UNSILENCE()
- (void)copyRect:(NSRect)srcRect to:(NSPoint)dest;
/* Non-notification versions of NSView methods. Used for direct calls. */
+- (void)adjustEmacsFrameRect;
- (void)windowWillEnterFullScreen;
- (void)windowDidEnterFullScreen;
- (void)windowWillExitFullScreen;
diff --git a/src/nsterm.m b/src/nsterm.m
index 2aadada2df6..10e06b07962 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8318,6 +8318,15 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification
[self windowDidEnterFullScreen];
}
+- (void)adjustEmacsFrameRect
+{
+ struct frame *f = emacsframe;
+ NSWindow *frame_window = [FRAME_NS_VIEW (f) window];
+ NSRect r = [frame_window frame];
+ f->left_pos = NSMinX (r) - NS_PARENT_WINDOW_LEFT_POS (f);
+ f->top_pos = NS_PARENT_WINDOW_TOP_POS (f) - NSMaxY (r);
+}
+
- (void)windowDidEnterFullScreen /* provided for direct calls */
{
NSTRACE ("[EmacsView windowDidEnterFullScreen]");
@@ -8347,6 +8356,10 @@ - (void)windowDidEnterFullScreen /* provided for direct calls */
}
#endif
}
+
+ /* Do what windowDidMove does which isn't called when entering/exiting
+ fullscreen mode. */
+ [self adjustEmacsFrameRect];
}
- (void)windowWillExitFullScreen:(NSNotification *)notification
@@ -8389,6 +8402,10 @@ - (void)windowDidExitFullScreen /* provided for direct calls */
if (next_maximized != -1)
[[self window] performZoom:self];
+
+ /* Do what windowDidMove does which isn't called when entering/exiting
+ fullscreen mode. */
+ [self adjustEmacsFrameRect];
}
- (BOOL)fsIsNative
--
2.45.2
next prev parent reply other threads:[~2024-07-25 7:39 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 [this message]
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 ` bug#71912: [Gerd Möllmann] " Gerd Möllmann
[not found] ` <CAOFab0n2H3iwyAmVGV1nYrQVqcjRM=ovvJ5hTt4x_0r6rC_k3g@mail.gmail.com>
2024-08-11 11:25 ` 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=m2wml953a3.fsf@pro2.fritz.box \
--to=gerd.moellmann@gmail.com \
--cc=71912@debbugs.gnu.org \
--cc=alan@idiocy.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).