Browse Source

Added a workaround for fullscreen mouse position on macOS 26

Sam Lantinga 1 week ago
parent
commit
c39d772a07
1 changed files with 13 additions and 0 deletions
  1. 13 0
      src/video/cocoa/SDL_cocoawindow.m

+ 13 - 0
src/video/cocoa/SDL_cocoawindow.m

@@ -1862,6 +1862,19 @@ static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL
     x = point.x;
     x = point.x;
     y = (window->h - point.y);
     y = (window->h - point.y);
 
 
+    // On macOS 26 if you move away from a space and then back, mouse motion events will have incorrect
+    // values at the top of the screen. The global mouse position query is still correct, so we'll fall
+    // back to that until this is fixed by Apple. Mouse button events are interestingly not affected.
+    if (@available(macOS 26.0, *)) {
+        if ([_data.listener isInFullscreenSpace]) {
+            int posx = 0, posy = 0;
+            SDL_GetWindowPosition(window, &posx, &posy);
+            SDL_GetGlobalMouseState(&x, &y);
+            x -= posx;
+            y -= posy;
+        }
+    }
+
     if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) {
     if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) {
         // Mouse grab is taken care of by the confinement rect
         // Mouse grab is taken care of by the confinement rect
     } else {
     } else {