@native-sdk/cli 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/build.zig +58 -33
  2. package/native-sdk.d.ts +16 -0
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/src/app_runner/root.zig +19 -0
  7. package/src/platform/linux/gtk_host.c +167 -8
  8. package/src/platform/linux/gtk_host.h +3 -2
  9. package/src/platform/linux/root.zig +198 -9
  10. package/src/platform/macos/appkit_host.h +2 -2
  11. package/src/platform/macos/appkit_host.m +186 -36
  12. package/src/platform/macos/cef_host.mm +46 -11
  13. package/src/platform/macos/root.zig +143 -5
  14. package/src/platform/null_platform.zig +32 -4
  15. package/src/platform/types.zig +29 -4
  16. package/src/platform/windows/root.zig +220 -10
  17. package/src/platform/windows/webview2_host.cpp +330 -31
  18. package/src/primitives/app_manifest/comptime_scene.zig +4 -0
  19. package/src/primitives/app_manifest/types.zig +16 -0
  20. package/src/primitives/canvas/widget_render.zig +21 -2
  21. package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
  22. package/src/runtime/api.zig +6 -5
  23. package/src/runtime/bridge_payload.zig +9 -0
  24. package/src/runtime/bridge_responses.zig +2 -0
  25. package/src/runtime/builtin_bridge.zig +10 -0
  26. package/src/runtime/canvas_widget_events.zig +28 -2
  27. package/src/runtime/canvas_widget_floating_tests.zig +3 -3
  28. package/src/runtime/effects.zig +5 -6
  29. package/src/runtime/flow.zig +45 -7
  30. package/src/runtime/gpu_surface_events.zig +10 -3
  31. package/src/runtime/runtime_event_tests.zig +9 -6
  32. package/src/runtime/session_tests.zig +5 -4
  33. package/src/runtime/shell_layout.zig +25 -11
  34. package/src/runtime/shell_layout_tests.zig +184 -0
  35. package/src/runtime/shell_view_tests.zig +9 -7
  36. package/src/runtime/state.zig +6 -0
  37. package/src/runtime/ui_app.zig +66 -18
  38. package/src/runtime/ui_app_window_tests.zig +107 -2
  39. package/src/runtime/window_command_bridge_tests.zig +82 -6
  40. package/src/runtime/window_storage.zig +14 -3
  41. package/src/runtime/window_views.zig +12 -11
  42. package/src/tooling/manifest.zig +38 -2
  43. package/src/tooling/raw_manifest.zig +8 -0
  44. package/src/tooling/templates.zig +17 -0
@@ -415,6 +415,12 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
415
415
  @property(nonatomic, strong) CAMetalLayer *metalLayer;
416
416
  @property(nonatomic, strong) id<MTLBuffer> sampleBuffer;
417
417
  @property(nonatomic, strong) id<MTLTexture> canvasTexture;
418
+ /* Reused conversion storage for the CPU reference renderer's
419
+ * straight-alpha RGBA8 frames. A nonopaque CAMetalLayer participates in
420
+ * Core Animation's premultiplied-alpha compositing, so software
421
+ * fallbacks must enter the shared canvas texture in the same encoding
422
+ * as packet-rendered frames. */
423
+ @property(nonatomic, strong) NSMutableData *canvasPixelUploadScratch;
418
424
  @property(nonatomic, strong) id<MTLRenderPipelineState> canvasRenderPipeline;
419
425
  @property(nonatomic, strong) id<MTLSamplerState> canvasSampler;
420
426
  @property(nonatomic, assign) CGColorSpaceRef canvasColorSpace;
@@ -581,6 +587,13 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
581
587
  @property(nonatomic, assign) uint64_t lastPacketDecodeNs;
582
588
  @property(nonatomic, assign) uint64_t lastPacketDrawNs;
583
589
  @property(nonatomic, strong) NSCursor *surfaceCursor;
590
+ /* Higher-layer sibling views covering this surface, in surface
591
+ * coordinates. AppKit cursor rects are geometric rather than hit-test
592
+ * aware: one full-bounds rect here would keep winning over an embedded
593
+ * WKWebView layered above the canvas (the workbench's browser pane), so
594
+ * resetCursorRects subtracts these occluders before registering the
595
+ * retained widget cursor. */
596
+ @property(nonatomic, strong) NSArray<NSValue *> *coveredMouseRects;
584
597
  @property(nonatomic, strong) NSTrackingArea *surfaceTrackingArea;
585
598
  @property(nonatomic, copy) NSString *markedText;
586
599
  @property(nonatomic, assign) NSRange markedTextRange;
@@ -617,7 +630,7 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
617
630
  - (void)configureWithHost:(NativeSdkAppKitHost *)host windowId:(uint64_t)windowId label:(NSString *)label;
618
631
  - (BOOL)isAvailable;
619
632
  - (void)updateDrawableSize;
620
- - (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength;
633
+ - (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects sourceIsPremultiplied:(BOOL)sourceIsPremultiplied rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength;
621
634
  - (NSInteger)presentGpuPacketWithSurfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA requiresRender:(BOOL)requiresRender commandCount:(NSUInteger)commandCount unsupportedCommandCount:(NSUInteger)unsupportedCommandCount representable:(BOOL)representable json:(const uint8_t *)json byteLength:(NSUInteger)byteLength;
622
635
  - (NSInteger)presentGpuPacketBinaryWithSurfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA requiresRender:(BOOL)requiresRender commandCount:(NSUInteger)commandCount unsupportedCommandCount:(NSUInteger)unsupportedCommandCount representable:(BOOL)representable packet:(const uint8_t *)packet byteLength:(NSUInteger)byteLength;
623
636
  - (NSInteger)presentGpuPacketObject:(NSDictionary *)packet surfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA commandCount:(NSUInteger)commandCount;
@@ -711,6 +724,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
711
724
  /// the delegate's windowShouldClose: consults it, so the user's close
712
725
  /// affordance hides a .hide window instead of closing it.
713
726
  @property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSNumber *> *windowClosePolicies;
727
+ /// Windows whose implicit reveal is passive (`activate_on_show=false`).
728
+ /// Explicit focusWindow bypasses this set and activates deliberately.
729
+ @property(nonatomic, strong) NSMutableSet<NSNumber *> *passiveShowWindows;
714
730
  /// Windows currently hidden BY their .hide close policy — the set the
715
731
  /// Dock reopen re-shows, and the truth emitWindowFrameForWindowId's
716
732
  /// hidden flag reports. Ordinary orderOut/minimize states never enter
@@ -904,8 +920,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
904
920
  @property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
905
921
  @property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
906
922
  @property(nonatomic, assign) NSInteger externalLinkAction;
907
- - (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy;
908
- - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy makeMain:(BOOL)makeMain;
923
+ - (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags;
924
+ - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
925
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId;
909
926
  - (void)showDeferredWindowIfPending:(uint64_t)windowId reason:(const char *)reason;
910
927
  - (void)applyWindowClearColor:(uint64_t)windowId red:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha;
911
928
  - (void)focusWindowWithId:(uint64_t)windowId;
@@ -1216,6 +1233,7 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
1216
1233
  [self.host.deferredShowWindows removeObjectForKey:key];
1217
1234
  [self.host.windowClearColors removeObjectForKey:key];
1218
1235
  [self.host.windowClosePolicies removeObjectForKey:key];
1236
+ [self.host.passiveShowWindows removeObject:key];
1219
1237
  if (self.host.windows.count == 0) {
1220
1238
  [self.host emitShutdown];
1221
1239
  [self.host stop];
@@ -3506,6 +3524,18 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3506
3524
 
3507
3525
  @end
3508
3526
 
3527
+ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *destination, NSUInteger pixelCount) {
3528
+ if (!source || !destination) return;
3529
+ for (NSUInteger index = 0; index < pixelCount; index += 1) {
3530
+ const NSUInteger offset = index * 4;
3531
+ const uint32_t alpha = source[offset + 3];
3532
+ destination[offset + 0] = (uint8_t)((source[offset + 0] * alpha + 127) / 255);
3533
+ destination[offset + 1] = (uint8_t)((source[offset + 1] * alpha + 127) / 255);
3534
+ destination[offset + 2] = (uint8_t)((source[offset + 2] * alpha + 127) / 255);
3535
+ destination[offset + 3] = (uint8_t)alpha;
3536
+ }
3537
+ }
3538
+
3509
3539
  @implementation NativeSdkMetalSurfaceView
3510
3540
 
3511
3541
  - (instancetype)initWithFrame:(NSRect)frameRect {
@@ -3585,11 +3615,12 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3585
3615
  }
3586
3616
 
3587
3617
  - (BOOL)isOpaque {
3588
- return YES;
3618
+ return self.window ? self.window.opaque : YES;
3589
3619
  }
3590
3620
 
3591
3621
  - (void)viewDidMoveToWindow {
3592
3622
  [super viewDidMoveToWindow];
3623
+ self.metalLayer.opaque = self.window ? self.window.opaque : YES;
3593
3624
  self.window.acceptsMouseMovedEvents = YES;
3594
3625
  [self updateDrawableSize];
3595
3626
  [self updateSurfaceTrackingArea];
@@ -3679,11 +3710,27 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3679
3710
  }
3680
3711
  }
3681
3712
 
3682
- - (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength {
3713
+ - (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects sourceIsPremultiplied:(BOOL)sourceIsPremultiplied rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength {
3683
3714
  if (![self isAvailable] || !rgba8 || width == 0 || height == 0) return NO;
3684
3715
  if (byteLength != width * height * 4) return NO;
3685
3716
  if (![self ensureCanvasPresenter]) return NO;
3686
3717
 
3718
+ const uint8_t *presentBytes = rgba8;
3719
+ /* Raw runtime presents carry straight RGBA, while the packet renderer's
3720
+ * Core Graphics context already writes premultiplied RGBA. Metal blends
3721
+ * both through the same premultiplied-alpha texture contract. */
3722
+ if (self.window && !self.window.opaque && !sourceIsPremultiplied) {
3723
+ if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) {
3724
+ self.canvasPixelUploadScratch = [NSMutableData dataWithLength:byteLength];
3725
+ }
3726
+ if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) return NO;
3727
+ NativeSdkPremultiplyStraightRgba8(
3728
+ rgba8,
3729
+ self.canvasPixelUploadScratch.mutableBytes,
3730
+ byteLength / 4);
3731
+ presentBytes = self.canvasPixelUploadScratch.bytes;
3732
+ }
3733
+
3687
3734
  BOOL textureChanged = NO;
3688
3735
  if (!self.canvasTexture || self.canvasTextureWidth != width || self.canvasTextureHeight != height) {
3689
3736
  MTLTextureDescriptor *descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:width height:height mipmapped:NO];
@@ -3757,21 +3804,21 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3757
3804
  return YES;
3758
3805
  }
3759
3806
  }
3760
- const uint8_t *uploadBytes = rgba8 + ((uploadY * width + uploadX) * 4);
3807
+ const uint8_t *uploadBytes = presentBytes + ((uploadY * width + uploadX) * 4);
3761
3808
  [self.canvasTexture replaceRegion:MTLRegionMake2D(uploadX, uploadY, uploadWidth, uploadHeight)
3762
3809
  mipmapLevel:0
3763
3810
  withBytes:uploadBytes
3764
3811
  bytesPerRow:width * 4];
3765
3812
  if (backingBytes) {
3766
3813
  if (uploadFullTexture) {
3767
- memcpy(backingBytes, rgba8, byteLength);
3814
+ memcpy(backingBytes, presentBytes, byteLength);
3768
3815
  /* A full foreign upload (raw-pixels present) makes the
3769
3816
  * backing match the glass byte-for-byte again. */
3770
3817
  self.canvasPacketPixelsValid = YES;
3771
3818
  } else {
3772
3819
  for (NSUInteger row = 0; row < uploadHeight; row++) {
3773
3820
  const NSUInteger rowOffset = ((uploadY + row) * width + uploadX) * 4;
3774
- memcpy((uint8_t *)backingBytes + rowOffset, rgba8 + rowOffset, uploadWidth * 4);
3821
+ memcpy((uint8_t *)backingBytes + rowOffset, presentBytes + rowOffset, uploadWidth * 4);
3775
3822
  }
3776
3823
  }
3777
3824
  }
@@ -5295,7 +5342,7 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5295
5342
  }
5296
5343
 
5297
5344
  BOOL uploadDirtyRect = directRetainedDirtyUpdate;
5298
- BOOL presented = [self presentPixelsWithWidth:pixelWidth height:pixelHeight scale:normalizedScale hasDirtyRect:uploadDirtyRect dirtyX:scissorRect.origin.x dirtyY:scissorRect.origin.y dirtyWidth:scissorRect.size.width dirtyHeight:scissorRect.size.height dirtyRects:(uploadDirtyRect ? dirtyRects : nil) rgba8:(const uint8_t *)pixels.bytes byteLength:pixels.length];
5345
+ BOOL presented = [self presentPixelsWithWidth:pixelWidth height:pixelHeight scale:normalizedScale hasDirtyRect:uploadDirtyRect dirtyX:scissorRect.origin.x dirtyY:scissorRect.origin.y dirtyWidth:scissorRect.size.width dirtyHeight:scissorRect.size.height dirtyRects:(uploadDirtyRect ? dirtyRects : nil) sourceIsPremultiplied:YES rgba8:(const uint8_t *)pixels.bytes byteLength:pixels.length];
5299
5346
  if (getenv("NATIVE_SDK_GPU_DRAW_TRACE")) {
5300
5347
  /* Per-present phase split (draw vs texture upload + Metal present),
5301
5348
  * NATIVE_SDK_WINDOW_TIMING-style stderr diagnostics. */
@@ -5816,12 +5863,22 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5816
5863
  const double red = self.hasCanvasTexture ? 0.965 : 0.10 + 0.08 * sin(phase * 6.283185307179586);
5817
5864
  const double green = self.hasCanvasTexture ? 0.973 : 0.18 + 0.10 * sin((phase + 0.33) * 6.283185307179586);
5818
5865
  const double blue = self.hasCanvasTexture ? 0.988 : 0.34 + 0.16 * sin((phase + 0.66) * 6.283185307179586);
5866
+ const BOOL transparentWindow = window != nil && !window.opaque;
5819
5867
 
5820
5868
  MTLRenderPassDescriptor *descriptor = [MTLRenderPassDescriptor renderPassDescriptor];
5821
5869
  descriptor.colorAttachments[0].texture = drawable.texture;
5822
5870
  descriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
5823
5871
  descriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
5824
- descriptor.colorAttachments[0].clearColor = MTLClearColorMake(red, green, blue, 1.0);
5872
+ // The clear remains visible when the renderer has not supplied a
5873
+ // canvas texture yet, and briefly while a resize's retained texture
5874
+ // does not match the new drawable. An opaque placeholder is useful
5875
+ // for an ordinary window, but it defeats a transparent overlay's
5876
+ // contract exactly when the late-reveal fallback exposes that state.
5877
+ // Clear transparent glass to transparent black (valid premultiplied
5878
+ // alpha); a matching canvas texture still draws over the whole pass.
5879
+ descriptor.colorAttachments[0].clearColor = transparentWindow
5880
+ ? MTLClearColorMake(0.0, 0.0, 0.0, 0.0)
5881
+ : MTLClearColorMake(red, green, blue, 1.0);
5825
5882
 
5826
5883
  id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
5827
5884
  if (!commandBuffer) return;
@@ -5908,13 +5965,74 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5908
5965
 
5909
5966
  - (void)resetCursorRects {
5910
5967
  [super resetCursorRects];
5911
- [self addCursorRect:self.bounds cursor:self.surfaceCursor ?: [NSCursor arrowCursor]];
5968
+ // Cursor rects do not honor sibling occlusion. Register the canvas
5969
+ // cursor only on the visible fragments left after higher-layer
5970
+ // native/web views are subtracted, so an overlaid WKWebView keeps
5971
+ // authority over its own link/text CSS cursors.
5972
+ NSMutableArray<NSValue *> *visibleCursorRects = [NSMutableArray arrayWithObject:[NSValue valueWithRect:self.bounds]];
5973
+ for (NSValue *coveredValue in self.coveredMouseRects) {
5974
+ NSRect covered = coveredValue.rectValue;
5975
+ NSMutableArray<NSValue *> *nextVisibleRects = [[NSMutableArray alloc] init];
5976
+ for (NSValue *visibleValue in visibleCursorRects) {
5977
+ NSRect visible = visibleValue.rectValue;
5978
+ NSRect intersection = NSIntersectionRect(visible, covered);
5979
+ if (NSIsEmptyRect(intersection)) {
5980
+ [nextVisibleRects addObject:visibleValue];
5981
+ continue;
5982
+ }
5983
+
5984
+ const CGFloat visibleMinX = NSMinX(visible);
5985
+ const CGFloat visibleMaxX = NSMaxX(visible);
5986
+ const CGFloat visibleMinY = NSMinY(visible);
5987
+ const CGFloat visibleMaxY = NSMaxY(visible);
5988
+ const CGFloat coveredMinX = NSMinX(intersection);
5989
+ const CGFloat coveredMaxX = NSMaxX(intersection);
5990
+ const CGFloat coveredMinY = NSMinY(intersection);
5991
+ const CGFloat coveredMaxY = NSMaxY(intersection);
5992
+
5993
+ if (coveredMinY > visibleMinY) {
5994
+ [nextVisibleRects addObject:[NSValue valueWithRect:NSMakeRect(
5995
+ visibleMinX, visibleMinY, visible.size.width, coveredMinY - visibleMinY)]];
5996
+ }
5997
+ if (coveredMaxY < visibleMaxY) {
5998
+ [nextVisibleRects addObject:[NSValue valueWithRect:NSMakeRect(
5999
+ visibleMinX, coveredMaxY, visible.size.width, visibleMaxY - coveredMaxY)]];
6000
+ }
6001
+ if (coveredMinX > visibleMinX) {
6002
+ [nextVisibleRects addObject:[NSValue valueWithRect:NSMakeRect(
6003
+ visibleMinX, coveredMinY, coveredMinX - visibleMinX, intersection.size.height)]];
6004
+ }
6005
+ if (coveredMaxX < visibleMaxX) {
6006
+ [nextVisibleRects addObject:[NSValue valueWithRect:NSMakeRect(
6007
+ coveredMaxX, coveredMinY, visibleMaxX - coveredMaxX, intersection.size.height)]];
6008
+ }
6009
+ }
6010
+ visibleCursorRects = nextVisibleRects;
6011
+ }
6012
+
6013
+ NSCursor *cursor = self.surfaceCursor ?: [NSCursor arrowCursor];
6014
+ for (NSValue *visibleValue in visibleCursorRects) {
6015
+ [self addCursorRect:visibleValue.rectValue cursor:cursor];
6016
+ }
5912
6017
  }
5913
6018
 
5914
6019
  - (void)setSurfaceCursor:(NSCursor *)cursor {
5915
6020
  _surfaceCursor = cursor ?: [NSCursor arrowCursor];
5916
6021
  [self.window invalidateCursorRectsForView:self];
5917
- [_surfaceCursor set];
6022
+ // The runtime changes cursor intent from mouseMoved:. Its tracking
6023
+ // area spans the geometric surface even where a sibling webview is
6024
+ // layered above it, so never let that immediate update clobber the
6025
+ // higher view's cursor. The visible cursor rect takes over again as
6026
+ // soon as the pointer returns to the canvas.
6027
+ NSPoint mousePoint = [self convertPoint:self.window.mouseLocationOutsideOfEventStream fromView:nil];
6028
+ BOOL covered = NO;
6029
+ for (NSValue *coveredValue in self.coveredMouseRects) {
6030
+ if (NSPointInRect(mousePoint, coveredValue.rectValue)) {
6031
+ covered = YES;
6032
+ break;
6033
+ }
6034
+ }
6035
+ if (!covered && NSPointInRect(mousePoint, self.bounds)) [_surfaceCursor set];
5918
6036
  }
5919
6037
 
5920
6038
  - (void)mouseDown:(NSEvent *)event {
@@ -7065,7 +7183,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7065
7183
 
7066
7184
  @implementation NativeSdkAppKitHost
7067
7185
 
7068
- - (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy {
7186
+ - (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags {
7069
7187
  self = [super init];
7070
7188
  if (!self) {
7071
7189
  return nil;
@@ -7094,6 +7212,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7094
7212
  self.deferredShowWindows = [[NSMutableDictionary alloc] init];
7095
7213
  self.windowClearColors = [[NSMutableDictionary alloc] init];
7096
7214
  self.windowClosePolicies = [[NSMutableDictionary alloc] init];
7215
+ self.passiveShowWindows = [[NSMutableSet alloc] init];
7097
7216
  self.policyHiddenWindows = [[NSMutableSet alloc] init];
7098
7217
  self.childWebViews = [[NSMutableDictionary alloc] init];
7099
7218
  self.nativeViews = [[NSMutableDictionary alloc] init];
@@ -7110,7 +7229,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7110
7229
  [self configureApplication];
7111
7230
  NativeSdkLaunchLap("app_configured");
7112
7231
 
7113
- [self createWindowWithId:1 title:(windowTitle.length > 0 ? windowTitle : self.appName) label:self.windowLabel x:x y:y width:width height:height restoreFrame:restoreFrame resizable:resizable titlebarStyle:titlebarStyle showPolicy:showPolicy makeMain:YES];
7232
+ [self createWindowWithId:1 title:(windowTitle.length > 0 ? windowTitle : self.appName) label:self.windowLabel x:x y:y width:width height:height restoreFrame:restoreFrame resizable:resizable titlebarStyle:titlebarStyle showPolicy:showPolicy windowFlags:windowFlags makeMain:YES];
7114
7233
  self.didShutdown = NO;
7115
7234
  self.pendingPreRunStop = NO;
7116
7235
  self.observesApplicationActivation = NO;
@@ -7118,7 +7237,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7118
7237
  return self;
7119
7238
  }
7120
7239
 
7121
- - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy makeMain:(BOOL)makeMain {
7240
+ - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
7122
7241
  NSNumber *key = @(windowId);
7123
7242
  if (self.windows[key]) {
7124
7243
  return NO;
@@ -7175,6 +7294,15 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7175
7294
  // next autorelease-pool drain; the main window only ever closes at
7176
7295
  // shutdown, which is why this stayed hidden until windows_fn).
7177
7296
  window.releasedWhenClosed = NO;
7297
+ // Overlay behavior is installed before the first order-front so no
7298
+ // opaque, focus-taking, or interactive intermediate window can flash.
7299
+ if ((windowFlags & (1u << 0)) != 0) {
7300
+ window.opaque = NO;
7301
+ window.backgroundColor = NSColor.clearColor;
7302
+ }
7303
+ if ((windowFlags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
7304
+ if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
7305
+ if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
7178
7306
  [window setTitle:(title.length > 0 ? title : self.appName)];
7179
7307
  if (titlebarStyle == 1 || titlebarStyle == 2) {
7180
7308
  window.titlebarAppearsTransparent = YES;
@@ -7246,12 +7374,27 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7246
7374
  self.delegate = delegate;
7247
7375
  self.windowLabel = label.length > 0 ? label : @"main";
7248
7376
  } else if (showPolicy != 1) {
7249
- [window makeKeyAndOrderFront:nil];
7250
- [NSApp activate];
7377
+ [self orderWindowForImplicitShow:windowId];
7251
7378
  }
7252
7379
  return YES;
7253
7380
  }
7254
7381
 
7382
+ // Implicit shows honor `activate_on_show`: passive overlays are ordered
7383
+ // front without changing the active app or key window. Explicit focus
7384
+ // continues to activate and makeKeyAndOrderFront. Activation comes
7385
+ // first: a first-present window can reveal while the app is inactive,
7386
+ // and asking that inactive app to make a window key is only best effort.
7387
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId {
7388
+ NSWindow *window = self.windows[@(windowId)];
7389
+ if (!window) return;
7390
+ if ([self.passiveShowWindows containsObject:@(windowId)]) {
7391
+ [window orderFront:nil];
7392
+ } else {
7393
+ [NSApp activate];
7394
+ [window makeKeyAndOrderFront:nil];
7395
+ }
7396
+ }
7397
+
7255
7398
  // Order a deferred-show window front exactly once — from the first
7256
7399
  // gpu-surface present (the contract), or from the fallback deadline.
7257
7400
  // `NATIVE_SDK_WINDOW_TIMING=1` logs the create→show latency.
@@ -7266,8 +7409,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7266
7409
  const double elapsedMs = (double)(NativeSdkTimestampNanoseconds() - createdNs.unsignedLongLongValue) / 1e6;
7267
7410
  fprintf(stderr, "native-sdk: window %llu shown (%s) %.1f ms after create wall_ns=%llu\n", (unsigned long long)windowId, reason, elapsedMs, (unsigned long long)clock_gettime_nsec_np(CLOCK_REALTIME));
7268
7411
  }
7269
- [window makeKeyAndOrderFront:nil];
7270
- [NSApp activate];
7412
+ [self orderWindowForImplicitShow:windowId];
7271
7413
  [self emitWindowFrameForWindowId:windowId open:YES];
7272
7414
  [self scheduleFrame];
7273
7415
  }
@@ -7318,8 +7460,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7318
7460
  // An explicit focus overrides a pending present-before-show defer:
7319
7461
  // the runtime asked for the window NOW.
7320
7462
  [self.deferredShowWindows removeObjectForKey:@(windowId)];
7321
- [window makeKeyAndOrderFront:nil];
7322
7463
  [NSApp activate];
7464
+ [window makeKeyAndOrderFront:nil];
7323
7465
  [self emitWindowFrameForWindowId:windowId open:YES];
7324
7466
  [self scheduleFrame];
7325
7467
  }
@@ -7362,7 +7504,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7362
7504
  }
7363
7505
 
7364
7506
  // The counterpart show verb: bring a hidden (or merely unfocused)
7365
- // window back to the glass and activate the app — the tray-menu
7507
+ // window back to the glass, activating unless its creation-time
7508
+ // presentation policy is passive — the tray-menu
7366
7509
  // "Open" consequence and the Dock reopen both land here. Also clears a
7367
7510
  // pending present-before-show defer and a minimize, for the same
7368
7511
  // reason focusWindowWithId: does: the runtime asked for the window NOW.
@@ -7372,8 +7515,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7372
7515
  [self.policyHiddenWindows removeObject:@(windowId)];
7373
7516
  [self.deferredShowWindows removeObjectForKey:@(windowId)];
7374
7517
  if (window.miniaturized) [window deminiaturize:nil];
7375
- [window makeKeyAndOrderFront:nil];
7376
- [NSApp activate];
7518
+ [self orderWindowForImplicitShow:windowId];
7377
7519
  [self emitWindowFrameForWindowId:windowId open:YES];
7378
7520
  [self scheduleFrame];
7379
7521
  }
@@ -7907,7 +8049,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7907
8049
  * resync. (The packet path calls presentPixelsWithWidth internally,
7908
8050
  * so the invalidation lives here at the raw entry, not inside it.) */
7909
8051
  surface.hasCanvasRetainedState = NO;
7910
- const BOOL presented = [surface presentPixelsWithWidth:width height:height scale:scale hasDirtyRect:hasDirtyRect dirtyX:dirtyX dirtyY:dirtyY dirtyWidth:dirtyWidth dirtyHeight:dirtyHeight dirtyRects:nil rgba8:rgba8 byteLength:byteLength];
8052
+ const BOOL presented = [surface presentPixelsWithWidth:width height:height scale:scale hasDirtyRect:hasDirtyRect dirtyX:dirtyX dirtyY:dirtyY dirtyWidth:dirtyWidth dirtyHeight:dirtyHeight dirtyRects:nil sourceIsPremultiplied:NO rgba8:rgba8 byteLength:byteLength];
7911
8053
  if (presented) [self showDeferredWindowIfPending:windowId reason:"first-present"];
7912
8054
  return presented;
7913
8055
  }
@@ -8412,18 +8554,27 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
8412
8554
  }];
8413
8555
 
8414
8556
  for (NSUInteger index = 0; index < views.count; index++) {
8415
- if (![views[index] isKindOfClass:[NativeSdkWebView class]]) continue;
8416
- NativeSdkWebView *webView = (NativeSdkWebView *)views[index];
8557
+ NSView *coveredView = views[index];
8558
+ const BOOL isWebView = [coveredView isKindOfClass:[NativeSdkWebView class]];
8559
+ const BOOL isMetalSurface = [coveredView isKindOfClass:[NativeSdkMetalSurfaceView class]];
8560
+ if (!isWebView && !isMetalSurface) continue;
8417
8561
  NSMutableArray<NSValue *> *coveredRects = [[NSMutableArray alloc] init];
8418
8562
  for (NSUInteger coverIndex = index + 1; coverIndex < views.count; coverIndex++) {
8419
8563
  NSView *coveringView = views[coverIndex];
8420
8564
  if (coveringView.hidden) continue;
8421
- NSRect intersection = NSIntersectionRect(webView.frame, coveringView.frame);
8565
+ NSRect intersection = NSIntersectionRect(coveredView.frame, coveringView.frame);
8422
8566
  if (NSIsEmptyRect(intersection)) continue;
8423
- [coveredRects addObject:[NSValue valueWithRect:[webView convertRect:intersection fromView:contentView]]];
8567
+ [coveredRects addObject:[NSValue valueWithRect:[coveredView convertRect:intersection fromView:contentView]]];
8568
+ }
8569
+ if (isWebView) {
8570
+ NativeSdkWebView *webView = (NativeSdkWebView *)coveredView;
8571
+ webView.coveredMouseRects = coveredRects;
8572
+ [self applyCoveredMouseRects:coveredRects toWebView:webView];
8573
+ } else {
8574
+ NativeSdkMetalSurfaceView *surfaceView = (NativeSdkMetalSurfaceView *)coveredView;
8575
+ surfaceView.coveredMouseRects = coveredRects;
8576
+ [surfaceView.window invalidateCursorRectsForView:surfaceView];
8424
8577
  }
8425
- webView.coveredMouseRects = coveredRects;
8426
- [self applyCoveredMouseRects:coveredRects toWebView:webView];
8427
8578
  }
8428
8579
  }
8429
8580
 
@@ -8987,9 +9138,8 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
8987
9138
  // here and appears when its first canvas present lands (or the
8988
9139
  // create-time fallback deadline fires).
8989
9140
  if (!self.deferredShowWindows[@1]) {
8990
- [self.window makeKeyAndOrderFront:nil];
9141
+ [self orderWindowForImplicitShow:1];
8991
9142
  }
8992
- [NSApp activate];
8993
9143
  if (!self.shortcutEventMonitor) {
8994
9144
  __weak NativeSdkAppKitHost *weakSelf = self;
8995
9145
  self.shortcutEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
@@ -11357,7 +11507,7 @@ static BOOL NativeSdkPolicyListMatches(NSArray<NSString *> *values, NSURL *url)
11357
11507
  return NO;
11358
11508
  }
11359
11509
 
11360
- native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy) {
11510
+ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
11361
11511
  @autoreleasepool {
11362
11512
  NSString *appNameString = [[NSString alloc] initWithBytes:app_name length:app_name_len encoding:NSUTF8StringEncoding] ?: @"native-sdk";
11363
11513
  NSString *displayNameString = [[NSString alloc] initWithBytes:display_name length:display_name_len encoding:NSUTF8StringEncoding] ?: @"";
@@ -11367,7 +11517,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
11367
11517
  NSString *bundleIdString = [[NSString alloc] initWithBytes:bundle_id length:bundle_id_len encoding:NSUTF8StringEncoding] ?: @"dev.native_sdk.app";
11368
11518
  NSString *iconPathString = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding] ?: @"";
11369
11519
  NSString *windowLabelString = [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] ?: @"main";
11370
- NativeSdkAppKitHost *host = [[NativeSdkAppKitHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString hasWebContent:(has_web_content != 0) windowTitle:windowTitleString bundleIdentifier:bundleIdString iconPath:iconPathString windowLabel:windowLabelString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy];
11520
+ NativeSdkAppKitHost *host = [[NativeSdkAppKitHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString hasWebContent:(has_web_content != 0) windowTitle:windowTitleString bundleIdentifier:bundleIdString iconPath:iconPathString windowLabel:windowLabelString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags];
11371
11521
  return (__bridge_retained native_sdk_appkit_host_t *)host;
11372
11522
  }
11373
11523
  }
@@ -11665,11 +11815,11 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
11665
11815
  [object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
11666
11816
  }
11667
11817
 
11668
- int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy) {
11818
+ int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
11669
11819
  NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
11670
11820
  NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"";
11671
11821
  NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
11672
- return [object createWindowWithId:window_id title:titleString ?: @"" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy makeMain:NO] ? 1 : 0;
11822
+ return [object createWindowWithId:window_id title:titleString ?: @"" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags makeMain:NO] ? 1 : 0;
11673
11823
  }
11674
11824
 
11675
11825
  int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host, uint64_t window_id, double min_width, double min_height) {
@@ -530,6 +530,7 @@ static const char *NativeSdkCefBridgeScript() {
530
530
  /// policy currently hides — mirrors the AppKit host's bookkeeping.
531
531
  @property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSNumber *> *windowClosePolicies;
532
532
  @property(nonatomic, strong) NSMutableSet<NSNumber *> *policyHiddenWindows;
533
+ @property(nonatomic, strong) NSMutableSet<NSNumber *> *passiveShowWindows;
533
534
  @property(nonatomic, strong) id reopenDelegate;
534
535
  @property(nonatomic, strong) NSMutableDictionary<NSString *, NSView *> *webviewViews;
535
536
  @property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *webviewPendingURLs;
@@ -577,7 +578,8 @@ static const char *NativeSdkCefBridgeScript() {
577
578
  - (void)configureApplication;
578
579
  - (void)buildMenuBar;
579
580
  - (NSMenuItem *)menuItem:(NSString *)title action:(SEL)action key:(NSString *)key modifiers:(NSEventModifierFlags)modifiers;
580
- - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable makeMain:(BOOL)makeMain;
581
+ - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
582
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId;
581
583
  - (void)focusWindowWithId:(uint64_t)windowId;
582
584
  - (void)closeWindowWithId:(uint64_t)windowId;
583
585
  - (void)hideWindowWithId:(uint64_t)windowId;
@@ -730,6 +732,7 @@ static const char *NativeSdkCefBridgeScript() {
730
732
  [self.host closeWebViewsInWindow:self.windowId];
731
733
  NSNumber *key = @(self.windowId);
732
734
  [self.host.windowClosePolicies removeObjectForKey:key];
735
+ [self.host.passiveShowWindows removeObject:key];
733
736
  [self.host.windows removeObjectForKey:key];
734
737
  [self.host.browserContainers removeObjectForKey:key];
735
738
  [self.host.delegates removeObjectForKey:key];
@@ -788,6 +791,7 @@ static const char *NativeSdkCefBridgeScript() {
788
791
  self.fallbackURLs = [[NSMutableDictionary alloc] init];
789
792
  self.windowClosePolicies = [[NSMutableDictionary alloc] init];
790
793
  self.policyHiddenWindows = [[NSMutableSet alloc] init];
794
+ self.passiveShowWindows = [[NSMutableSet alloc] init];
791
795
  self.webviewViews = [[NSMutableDictionary alloc] init];
792
796
  self.webviewPendingURLs = [[NSMutableDictionary alloc] init];
793
797
  self.webviewPendingZooms = [[NSMutableDictionary alloc] init];
@@ -804,7 +808,7 @@ static const char *NativeSdkCefBridgeScript() {
804
808
  self.externalLinkAction = 0;
805
809
  self.shortcuts = @[];
806
810
 
807
- [self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:0 y:0 width:width height:height restoreFrame:NO resizable:YES makeMain:YES];
811
+ [self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:0 y:0 width:width height:height restoreFrame:NO resizable:YES windowFlags:0 makeMain:YES];
808
812
  self.didShutdown = NO;
809
813
  self.pendingPreRunStop = NO;
810
814
  self.observesApplicationActivation = NO;
@@ -919,7 +923,7 @@ static const char *NativeSdkCefBridgeScript() {
919
923
  delete self.browsers;
920
924
  }
921
925
 
922
- - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable makeMain:(BOOL)makeMain {
926
+ - (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
923
927
  NSNumber *key = @(windowId);
924
928
  if (self.windows[key]) return NO;
925
929
 
@@ -934,6 +938,13 @@ static const char *NativeSdkCefBridgeScript() {
934
938
  styleMask:styleMask
935
939
  backing:NSBackingStoreBuffered
936
940
  defer:NO];
941
+ if ((windowFlags & (1u << 0)) != 0) {
942
+ window.opaque = NO;
943
+ window.backgroundColor = NSColor.clearColor;
944
+ }
945
+ if ((windowFlags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
946
+ if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
947
+ if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
937
948
  [window setTitle:title.length > 0 ? title : @"native-sdk"];
938
949
  if (!restoreFrame) [window center];
939
950
 
@@ -963,11 +974,19 @@ static const char *NativeSdkCefBridgeScript() {
963
974
  self.browserContainer = browserContainer;
964
975
  self.delegate = delegate;
965
976
  self.cefClient = client;
977
+ }
978
+ return YES;
979
+ }
980
+
981
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId {
982
+ NSWindow *window = self.windows[@(windowId)];
983
+ if (!window) return;
984
+ if ([self.passiveShowWindows containsObject:@(windowId)]) {
985
+ [window orderFront:nil];
966
986
  } else {
967
987
  [window makeKeyAndOrderFront:nil];
968
988
  [NSApp activateIgnoringOtherApps:YES];
969
989
  }
970
- return YES;
971
990
  }
972
991
 
973
992
  - (void)focusWindowWithId:(uint64_t)windowId {
@@ -1009,8 +1028,7 @@ static const char *NativeSdkCefBridgeScript() {
1009
1028
  if (!window) return;
1010
1029
  [self.policyHiddenWindows removeObject:@(windowId)];
1011
1030
  if (window.miniaturized) [window deminiaturize:nil];
1012
- [window makeKeyAndOrderFront:nil];
1013
- [NSApp activateIgnoringOtherApps:YES];
1031
+ [self orderWindowForImplicitShow:windowId];
1014
1032
  [self emitWindowFrameForWindowId:windowId open:YES];
1015
1033
  };
1016
1034
  if ([NSThread isMainThread]) {
@@ -1098,8 +1116,7 @@ static const char *NativeSdkCefBridgeScript() {
1098
1116
  NSApp.delegate = reopenDelegate;
1099
1117
  }
1100
1118
 
1101
- [self.window makeKeyAndOrderFront:nil];
1102
- [NSApp activateIgnoringOtherApps:YES];
1119
+ [self orderWindowForImplicitShow:1];
1103
1120
  if (!self.shortcutEventMonitor) {
1104
1121
  __weak NativeSdkChromiumHost *weakSelf = self;
1105
1122
  self.shortcutEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
@@ -2102,8 +2119,21 @@ static void NativeSdkApplyHiddenInsetTitlebar(NSWindow *window, int titlebar_sty
2102
2119
  }
2103
2120
  }
2104
2121
 
2105
- native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy) {
2122
+ static void NativeSdkApplyOverlayWindowFlags(NativeSdkChromiumHost *host, uint64_t window_id, uint32_t window_flags) {
2123
+ NSWindow *window = host.windows[@(window_id)];
2124
+ if (!window) return;
2125
+ if ((window_flags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
2126
+ if ((window_flags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
2127
+ if ((window_flags & (1u << 3)) != 0) [host.passiveShowWindows addObject:@(window_id)];
2128
+ }
2129
+
2130
+ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
2106
2131
  @autoreleasepool {
2132
+ // A windowed CEF child cannot paint transparent pixels into its
2133
+ // parent NSWindow. Refuse instead of accepting a flag that leaves
2134
+ // the browser surface opaque; the Zig platform seam returns the
2135
+ // more specific UnsupportedWindowTransparency before this call.
2136
+ if ((window_flags & (1u << 0)) != 0) return nullptr;
2107
2137
  // Present-before-show is a canvas contract; the Chromium host
2108
2138
  // hosts webviews only (gpu-surface presents are unsupported on
2109
2139
  // this engine), so the policy is accepted for ABI parity and
@@ -2131,6 +2161,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
2131
2161
  host.window.styleMask &= ~NSWindowStyleMaskResizable;
2132
2162
  }
2133
2163
  NativeSdkApplyHiddenInsetTitlebar(host.window, titlebar_style, host.delegates[@1]);
2164
+ NativeSdkApplyOverlayWindowFlags(host, 1, window_flags);
2134
2165
  return (__bridge_retained native_sdk_appkit_host_t *)host;
2135
2166
  }
2136
2167
  }
@@ -2376,14 +2407,18 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
2376
2407
  [object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
2377
2408
  }
2378
2409
 
2379
- int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy) {
2410
+ int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
2380
2411
  // Accepted for ABI parity; see native_sdk_appkit_create.
2381
2412
  (void)show_policy;
2413
+ if ((window_flags & (1u << 0)) != 0) return 0;
2382
2414
  NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
2383
2415
  NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"native-sdk";
2384
2416
  NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
2385
- if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) makeMain:NO]) return 0;
2417
+ if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) windowFlags:window_flags makeMain:NO]) return 0;
2386
2418
  NativeSdkApplyHiddenInsetTitlebar(object.windows[@(window_id)], titlebar_style, object.delegates[@(window_id)]);
2419
+ // Apply chrome and overlay presentation while still hidden, then
2420
+ // reveal once so a secondary window cannot flash its default frame.
2421
+ [object orderWindowForImplicitShow:window_id];
2387
2422
  return 1;
2388
2423
  }
2389
2424