From ff8de7607a0a5ccf88efd36521b60035572053b1 Mon Sep 17 00:00:00 2001 From: pagedown Date: Fri, 18 Feb 2022 13:50:46 +0800 Subject: [PATCH 1/3] Also handles the case where toggleFullScreen does not get called --- glfw/cocoa_window.m | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index aee7b4661..970c723fb 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -722,16 +722,29 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; } } + +- (void)windowWillEnterFullScreen:(NSNotification *)notification +{ + (void)notification; + if (window) window->ns.in_fullscreen_transition = true; +} + - (void)windowDidEnterFullScreen:(NSNotification *)notification { (void)notification; - window->ns.in_fullscreen_transition = false; + if (window) window->ns.in_fullscreen_transition = false; +} + +- (void)windowWillExitFullScreen:(NSNotification *)notification +{ + (void)notification; + if (window) window->ns.in_fullscreen_transition = true; } - (void)windowDidExitFullScreen:(NSNotification *)notification { (void)notification; - window->ns.in_fullscreen_transition = false; + if (window) window->ns.in_fullscreen_transition = false; } @end // }}} @@ -1566,10 +1579,11 @@ void _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) { - (void)toggleFullScreen:(nullable id)sender { - if (glfw_window->ns.in_fullscreen_transition) return; - if (glfw_window && glfw_window->ns.toggleFullscreenCallback && glfw_window->ns.toggleFullscreenCallback((GLFWwindow*)glfw_window) == 1) - return; - glfw_window->ns.in_fullscreen_transition = true; + if (glfw_window) { + if (glfw_window->ns.in_fullscreen_transition) return; + if (glfw_window->ns.toggleFullscreenCallback && glfw_window->ns.toggleFullscreenCallback((GLFWwindow*)glfw_window) == 1) return; + glfw_window->ns.in_fullscreen_transition = true; + } // When resizeIncrements is set, Cocoa cannot restore the original window size after returning from fullscreen. const NSSize original = [self resizeIncrements]; [self setResizeIncrements:NSMakeSize(1.0, 1.0)]; From 69c5c4909400387ed61fc1e35b99692760948996 Mon Sep 17 00:00:00 2001 From: pagedown Date: Fri, 18 Feb 2022 13:52:00 +0800 Subject: [PATCH 2/3] Disable cursor rects --- glfw/cocoa_window.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 970c723fb..d12cdbd2e 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1028,6 +1028,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)updateTrackingAreas { + if (window && [window->ns.object areCursorRectsEnabled]) + [window->ns.object disableCursorRects]; if (trackingArea != nil) { [self removeTrackingArea:trackingArea]; From 58e8609c1a651b61045b0c9178a13cdff64503bc Mon Sep 17 00:00:00 2001 From: pagedown Date: Fri, 18 Feb 2022 13:52:19 +0800 Subject: [PATCH 3/3] macOS: Ensure the cursor is updated once macOS will set the cursor to arrow after milliseconds after the switch desktop animation ends. So the cursor that was updated immediately after the focus will be changed again. This also affects toggling fullscreen. --- docs/changelog.rst | 4 ++++ glfw/cocoa_platform.h | 2 ++ glfw/cocoa_window.m | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 63f53a96d..5ffa2131c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -144,6 +144,10 @@ Detailed list of changes - Add an option :opt:`wheel_scroll_min_lines` to set the minimum number of lines for mouse wheel scrolling when using a mouse with a wheel that generates very small offsets when slow scrolling (:pull:`4710`) +- macOS: Allows to configure the toggle fullscreen shortcut in global menu. (:pull:`4714`) + +- macOS: Fix the mouse cursor being set to arrow after switching desktops or toggling fullscreen. (:pull:`4716`) + 0.24.2 [2022-02-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/cocoa_platform.h b/glfw/cocoa_platform.h index 36b318e23..6b162d7d9 100644 --- a/glfw/cocoa_platform.h +++ b/glfw/cocoa_platform.h @@ -154,6 +154,8 @@ typedef struct _GLFWwindowNS // Whether a render frame has been requested for this window bool renderFrameRequested; GLFWcocoarenderframefun renderFrameCallback; + // update cursor after switching desktops with Mission Control + bool initialCursorUpdateRequested; } _GLFWwindowNS; typedef struct _GLFWDisplayLinkNS diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index d12cdbd2e..6ef402cb2 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -582,6 +582,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; } - (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow; +- (void)requestInitialCursorUpdate:(id)sender; @end @@ -692,6 +693,9 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; _glfwPlatformGetCursorPos(window, &x, &y); _glfwInputCursorPos(window, x, y); } + // macOS will send a delayed event to update the cursor to arrow after switching desktops. + // So we need to delay and update the cursor once after that. + [self performSelector:@selector(requestInitialCursorUpdate:) withObject:nil afterDelay:0.3]; } - (void)windowDidResignKey:(NSNotification *)notification @@ -722,6 +726,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; } } +- (void)requestInitialCursorUpdate:(id)sender +{ + (void)sender; + if (window) window->ns.initialCursorUpdateRequested = true; +} - (void)windowWillEnterFullScreen:(NSNotification *)notification { @@ -733,6 +742,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; { (void)notification; if (window) window->ns.in_fullscreen_transition = false; + [self performSelector:@selector(requestInitialCursorUpdate:) withObject:nil afterDelay:0.3]; } - (void)windowWillExitFullScreen:(NSNotification *)notification @@ -745,6 +755,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; { (void)notification; if (window) window->ns.in_fullscreen_transition = false; + [self performSelector:@selector(requestInitialCursorUpdate:) withObject:nil afterDelay:0.3]; } @end // }}} @@ -929,6 +940,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; window->ns.cursorWarpDeltaX = 0; window->ns.cursorWarpDeltaY = 0; + + if (window->ns.initialCursorUpdateRequested) { + window->ns.initialCursorUpdateRequested = false; + if (cursorInContentArea(window)) updateCursorImage(window); + } } - (void)rightMouseDown:(NSEvent *)event