浏览代码

Added support for resizing windows on visionOS

Sam Lantinga 3 周之前
父节点
当前提交
b144c79da2
共有 3 个文件被更改,包括 20 次插入0 次删除
  1. 1 0
      src/video/uikit/SDL_uikitvideo.m
  2. 1 0
      src/video/uikit/SDL_uikitwindow.h
  3. 18 0
      src/video/uikit/SDL_uikitwindow.m

+ 1 - 0
src/video/uikit/SDL_uikitvideo.m

@@ -87,6 +87,7 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
         device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
         device->CreateSDLWindow = UIKit_CreateWindow;
         device->SetWindowTitle = UIKit_SetWindowTitle;
+        device->SetWindowSize = UIKit_SetWindowSize;
         device->ShowWindow = UIKit_ShowWindow;
         device->HideWindow = UIKit_HideWindow;
         device->RaiseWindow = UIKit_RaiseWindow;

+ 1 - 0
src/video/uikit/SDL_uikitwindow.h

@@ -28,6 +28,7 @@
 
 extern bool UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
 extern void UIKit_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
+extern void UIKit_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
 extern void UIKit_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
 extern void UIKit_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
 extern void UIKit_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window);

+ 18 - 0
src/video/uikit/SDL_uikitwindow.m

@@ -247,6 +247,24 @@ void UIKit_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
     }
 }
 
+void UIKit_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
+{
+#ifdef SDL_PLATFORM_VISIONOS
+    @autoreleasepool {
+        SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->internal;
+        UIWindowScene *scene = data.uiwindow.windowScene;
+        CGSize size = { window->pending.w, window->pending.h };
+        UIWindowSceneGeometryPreferences *preferences = [[UIWindowSceneGeometryPreferencesVision alloc] initWithSize:size];
+        [scene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) {
+            // Request failed, no worries
+        }];
+    }
+    return true;
+#else
+    return SDL_Unsupported();
+#endif
+}
+
 void UIKit_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
 {
     @autoreleasepool {