From 58e8609c1a651b61045b0c9178a13cdff64503bc Mon Sep 17 00:00:00 2001 From: pagedown Date: Fri, 18 Feb 2022 13:52:19 +0800 Subject: [PATCH] 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