Skip to content

Commit 408a7ae

Browse files
committed
Child window support for macOS
1 parent c290766 commit 408a7ae

7 files changed

Lines changed: 178 additions & 108 deletions

File tree

include/brisk/graphics/NativeWindowHandle.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,30 @@ struct NativeWindowHandle {
6363
#ifdef BRISK_APPLE
6464
#if defined(__OBJC__)
6565
NSWindow* nsWindow() const noexcept {
66-
return (__bridge NSWindow*)ptr;
66+
if (ptr == nullptr)
67+
return nullptr;
68+
if (isNsWindow())
69+
return (__bridge NSWindow*)ptr;
70+
return [(__bridge NSView*)ptr window];
71+
}
72+
73+
NSView* nsView() const noexcept {
74+
if (ptr == nullptr)
75+
return nullptr;
76+
return (__bridge NSView*)ptr;
77+
}
78+
79+
bool isNsWindow() const noexcept {
80+
return ptr != nullptr && [((__bridge id)ptr) isKindOfClass:[NSWindow class]];
81+
}
82+
83+
bool isNsView() const noexcept {
84+
return ptr != nullptr && [((__bridge id)ptr) isKindOfClass:[NSView class]];
6785
}
6886

6987
explicit NativeWindowHandle(NSWindow* nsWindow) noexcept : ptr((__bridge void*)nsWindow) {}
88+
89+
explicit NativeWindowHandle(NSView* nsView) noexcept : ptr((__bridge void*)nsView) {}
7090
#endif
7191
#endif
7292

src/graphics/WebGpuRenderer/WindowRenderTarget_Darwin.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@
3030
ensureOnRenderThread();
3131
@autoreleasepool {
3232
NativeWindowHandle handle = window->getHandle();
33-
NSWindow* nsWindow = handle.nsWindow();
34-
NSView* view = [nsWindow contentView];
33+
NSWindow* nsWindow;
34+
NSView* view;
35+
if (handle.isNsWindow()) {
36+
nsWindow = handle.nsWindow();
37+
view = [nsWindow contentView];
38+
} else {
39+
nsWindow = handle.nsWindow();
40+
view = handle.nsView();
41+
}
3542

3643
[view setWantsLayer:YES];
3744
[view setLayer:[CAMetalLayer layer]];

src/window/PlatformWindow.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PlatformWindow {
108108

109109
Bytes placement() const;
110110
void setPlacement(BytesView data);
111-
explicit PlatformWindow(Window* window, Size windowSize, Point position, WindowStyle style);
111+
explicit PlatformWindow(Window* window, Size windowSize, Point position, WindowStyle style, NativeWindowHandle parent);
112112
bool createWindow();
113113

114114
void setTitle(std::string_view title);
@@ -117,7 +117,6 @@ class PlatformWindow {
117117
void setSizeLimits(Size minSize, Size maxSize);
118118
void setStyle(WindowStyle style);
119119
void setOwner(Rc<Window> window);
120-
void setParent(NativeWindowHandle parent);
121120
void releaseButtonsAndKeys();
122121

123122
NativeWindowHandle getHandle() const;

0 commit comments

Comments
 (0)