@native-sdk/cli 0.6.1 → 0.6.3

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 (68) hide show
  1. package/build.zig +8 -0
  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/packages/core/sdk/text.ts +62 -21
  7. package/src/app_runner/root.zig +19 -0
  8. package/src/platform/linux/gtk_host.c +167 -8
  9. package/src/platform/linux/gtk_host.h +3 -2
  10. package/src/platform/linux/root.zig +198 -9
  11. package/src/platform/macos/appkit_host.h +4 -2
  12. package/src/platform/macos/appkit_host.m +137 -38
  13. package/src/platform/macos/cef_host.mm +46 -11
  14. package/src/platform/macos/root.zig +150 -6
  15. package/src/platform/null_platform.zig +32 -4
  16. package/src/platform/types.zig +31 -4
  17. package/src/platform/windows/root.zig +220 -10
  18. package/src/platform/windows/webview2_host.cpp +330 -31
  19. package/src/primitives/app_manifest/comptime_scene.zig +4 -0
  20. package/src/primitives/app_manifest/types.zig +16 -0
  21. package/src/primitives/canvas/equality.zig +3 -1
  22. package/src/primitives/canvas/events.zig +4 -0
  23. package/src/primitives/canvas/root.zig +11 -0
  24. package/src/primitives/canvas/text.zig +10 -0
  25. package/src/primitives/canvas/text_interaction.zig +164 -22
  26. package/src/primitives/canvas/text_layout.zig +107 -21
  27. package/src/primitives/canvas/text_tests.zig +86 -0
  28. package/src/primitives/canvas/ui.zig +21 -16
  29. package/src/primitives/canvas/ui_markup_reflect.zig +20 -3
  30. package/src/primitives/canvas/ui_markup_view_tests.zig +16 -0
  31. package/src/primitives/canvas/ui_tests.zig +6 -0
  32. package/src/primitives/canvas/widget_render.zig +21 -2
  33. package/src/primitives/canvas/widget_runtime.zig +1 -0
  34. package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
  35. package/src/primitives/canvas/widget_text_input.zig +23 -11
  36. package/src/runtime/api.zig +9 -0
  37. package/src/runtime/bridge_payload.zig +9 -0
  38. package/src/runtime/bridge_responses.zig +2 -0
  39. package/src/runtime/builtin_bridge.zig +10 -0
  40. package/src/runtime/canvas_frame_helpers.zig +1 -0
  41. package/src/runtime/canvas_limits.zig +7 -0
  42. package/src/runtime/canvas_widget_accessibility_tests.zig +27 -1
  43. package/src/runtime/canvas_widget_clipboard_tests.zig +16 -0
  44. package/src/runtime/canvas_widget_display.zig +15 -1
  45. package/src/runtime/canvas_widget_events.zig +43 -19
  46. package/src/runtime/canvas_widget_floating_tests.zig +3 -3
  47. package/src/runtime/canvas_widget_runtime.zig +67 -10
  48. package/src/runtime/canvas_widget_state.zig +1 -0
  49. package/src/runtime/canvas_widget_text_tests.zig +1878 -70
  50. package/src/runtime/effects.zig +5 -6
  51. package/src/runtime/flow.zig +45 -7
  52. package/src/runtime/gpu_surface_events.zig +46 -1
  53. package/src/runtime/runtime_event_tests.zig +9 -6
  54. package/src/runtime/shell_layout.zig +25 -11
  55. package/src/runtime/shell_layout_tests.zig +184 -0
  56. package/src/runtime/shell_view_tests.zig +9 -7
  57. package/src/runtime/state.zig +6 -0
  58. package/src/runtime/ui_app.zig +61 -14
  59. package/src/runtime/ui_app_window_tests.zig +107 -2
  60. package/src/runtime/view.zig +30 -0
  61. package/src/runtime/view_widget_text.zig +1048 -10
  62. package/src/runtime/view_widget_tree.zig +2 -0
  63. package/src/runtime/window_command_bridge_tests.zig +82 -6
  64. package/src/runtime/window_storage.zig +14 -3
  65. package/src/runtime/window_views.zig +12 -11
  66. package/src/tooling/manifest.zig +38 -2
  67. package/src/tooling/raw_manifest.zig +8 -0
  68. package/src/tooling/templates.zig +17 -0
@@ -405,6 +405,8 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
405
405
  @property(nonatomic, assign) NativeSdkMetalSurfaceView *surfaceView;
406
406
  @property(nonatomic, assign) uint64_t widgetId;
407
407
  @property(nonatomic, assign) uint32_t actionFlags;
408
+ @property(nonatomic, assign) BOOL canUndo;
409
+ @property(nonatomic, assign) BOOL canRedo;
408
410
  - (BOOL)emitSetTextAccessibilityValue:(id)value;
409
411
  - (BOOL)emitSetSelectionAccessibilityValue:(id)value;
410
412
  @end
@@ -415,6 +417,12 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
415
417
  @property(nonatomic, strong) CAMetalLayer *metalLayer;
416
418
  @property(nonatomic, strong) id<MTLBuffer> sampleBuffer;
417
419
  @property(nonatomic, strong) id<MTLTexture> canvasTexture;
420
+ /* Reused conversion storage for the CPU reference renderer's
421
+ * straight-alpha RGBA8 frames. A nonopaque CAMetalLayer participates in
422
+ * Core Animation's premultiplied-alpha compositing, so software
423
+ * fallbacks must enter the shared canvas texture in the same encoding
424
+ * as packet-rendered frames. */
425
+ @property(nonatomic, strong) NSMutableData *canvasPixelUploadScratch;
418
426
  @property(nonatomic, strong) id<MTLRenderPipelineState> canvasRenderPipeline;
419
427
  @property(nonatomic, strong) id<MTLSamplerState> canvasSampler;
420
428
  @property(nonatomic, assign) CGColorSpaceRef canvasColorSpace;
@@ -624,7 +632,7 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
624
632
  - (void)configureWithHost:(NativeSdkAppKitHost *)host windowId:(uint64_t)windowId label:(NSString *)label;
625
633
  - (BOOL)isAvailable;
626
634
  - (void)updateDrawableSize;
627
- - (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;
635
+ - (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;
628
636
  - (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;
629
637
  - (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;
630
638
  - (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;
@@ -718,6 +726,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
718
726
  /// the delegate's windowShouldClose: consults it, so the user's close
719
727
  /// affordance hides a .hide window instead of closing it.
720
728
  @property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSNumber *> *windowClosePolicies;
729
+ /// Windows whose implicit reveal is passive (`activate_on_show=false`).
730
+ /// Explicit focusWindow bypasses this set and activates deliberately.
731
+ @property(nonatomic, strong) NSMutableSet<NSNumber *> *passiveShowWindows;
721
732
  /// Windows currently hidden BY their .hide close policy — the set the
722
733
  /// Dock reopen re-shows, and the truth emitWindowFrameForWindowId's
723
734
  /// hidden flag reports. Ordinary orderOut/minimize states never enter
@@ -911,8 +922,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
911
922
  @property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
912
923
  @property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
913
924
  @property(nonatomic, assign) NSInteger externalLinkAction;
914
- - (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;
915
- - (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;
925
+ - (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;
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 titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
927
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId;
916
928
  - (void)showDeferredWindowIfPending:(uint64_t)windowId reason:(const char *)reason;
917
929
  - (void)applyWindowClearColor:(uint64_t)windowId red:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha;
918
930
  - (void)focusWindowWithId:(uint64_t)windowId;
@@ -1223,6 +1235,7 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
1223
1235
  [self.host.deferredShowWindows removeObjectForKey:key];
1224
1236
  [self.host.windowClearColors removeObjectForKey:key];
1225
1237
  [self.host.windowClosePolicies removeObjectForKey:key];
1238
+ [self.host.passiveShowWindows removeObject:key];
1226
1239
  if (self.host.windows.count == 0) {
1227
1240
  [self.host emitShutdown];
1228
1241
  [self.host stop];
@@ -3513,6 +3526,18 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3513
3526
 
3514
3527
  @end
3515
3528
 
3529
+ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *destination, NSUInteger pixelCount) {
3530
+ if (!source || !destination) return;
3531
+ for (NSUInteger index = 0; index < pixelCount; index += 1) {
3532
+ const NSUInteger offset = index * 4;
3533
+ const uint32_t alpha = source[offset + 3];
3534
+ destination[offset + 0] = (uint8_t)((source[offset + 0] * alpha + 127) / 255);
3535
+ destination[offset + 1] = (uint8_t)((source[offset + 1] * alpha + 127) / 255);
3536
+ destination[offset + 2] = (uint8_t)((source[offset + 2] * alpha + 127) / 255);
3537
+ destination[offset + 3] = (uint8_t)alpha;
3538
+ }
3539
+ }
3540
+
3516
3541
  @implementation NativeSdkMetalSurfaceView
3517
3542
 
3518
3543
  - (instancetype)initWithFrame:(NSRect)frameRect {
@@ -3592,11 +3617,12 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3592
3617
  }
3593
3618
 
3594
3619
  - (BOOL)isOpaque {
3595
- return YES;
3620
+ return self.window ? self.window.opaque : YES;
3596
3621
  }
3597
3622
 
3598
3623
  - (void)viewDidMoveToWindow {
3599
3624
  [super viewDidMoveToWindow];
3625
+ self.metalLayer.opaque = self.window ? self.window.opaque : YES;
3600
3626
  self.window.acceptsMouseMovedEvents = YES;
3601
3627
  [self updateDrawableSize];
3602
3628
  [self updateSurfaceTrackingArea];
@@ -3686,11 +3712,27 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3686
3712
  }
3687
3713
  }
3688
3714
 
3689
- - (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 {
3715
+ - (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 {
3690
3716
  if (![self isAvailable] || !rgba8 || width == 0 || height == 0) return NO;
3691
3717
  if (byteLength != width * height * 4) return NO;
3692
3718
  if (![self ensureCanvasPresenter]) return NO;
3693
3719
 
3720
+ const uint8_t *presentBytes = rgba8;
3721
+ /* Raw runtime presents carry straight RGBA, while the packet renderer's
3722
+ * Core Graphics context already writes premultiplied RGBA. Metal blends
3723
+ * both through the same premultiplied-alpha texture contract. */
3724
+ if (self.window && !self.window.opaque && !sourceIsPremultiplied) {
3725
+ if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) {
3726
+ self.canvasPixelUploadScratch = [NSMutableData dataWithLength:byteLength];
3727
+ }
3728
+ if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) return NO;
3729
+ NativeSdkPremultiplyStraightRgba8(
3730
+ rgba8,
3731
+ self.canvasPixelUploadScratch.mutableBytes,
3732
+ byteLength / 4);
3733
+ presentBytes = self.canvasPixelUploadScratch.bytes;
3734
+ }
3735
+
3694
3736
  BOOL textureChanged = NO;
3695
3737
  if (!self.canvasTexture || self.canvasTextureWidth != width || self.canvasTextureHeight != height) {
3696
3738
  MTLTextureDescriptor *descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:width height:height mipmapped:NO];
@@ -3764,21 +3806,21 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
3764
3806
  return YES;
3765
3807
  }
3766
3808
  }
3767
- const uint8_t *uploadBytes = rgba8 + ((uploadY * width + uploadX) * 4);
3809
+ const uint8_t *uploadBytes = presentBytes + ((uploadY * width + uploadX) * 4);
3768
3810
  [self.canvasTexture replaceRegion:MTLRegionMake2D(uploadX, uploadY, uploadWidth, uploadHeight)
3769
3811
  mipmapLevel:0
3770
3812
  withBytes:uploadBytes
3771
3813
  bytesPerRow:width * 4];
3772
3814
  if (backingBytes) {
3773
3815
  if (uploadFullTexture) {
3774
- memcpy(backingBytes, rgba8, byteLength);
3816
+ memcpy(backingBytes, presentBytes, byteLength);
3775
3817
  /* A full foreign upload (raw-pixels present) makes the
3776
3818
  * backing match the glass byte-for-byte again. */
3777
3819
  self.canvasPacketPixelsValid = YES;
3778
3820
  } else {
3779
3821
  for (NSUInteger row = 0; row < uploadHeight; row++) {
3780
3822
  const NSUInteger rowOffset = ((uploadY + row) * width + uploadX) * 4;
3781
- memcpy((uint8_t *)backingBytes + rowOffset, rgba8 + rowOffset, uploadWidth * 4);
3823
+ memcpy((uint8_t *)backingBytes + rowOffset, presentBytes + rowOffset, uploadWidth * 4);
3782
3824
  }
3783
3825
  }
3784
3826
  }
@@ -5302,7 +5344,7 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5302
5344
  }
5303
5345
 
5304
5346
  BOOL uploadDirtyRect = directRetainedDirtyUpdate;
5305
- 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];
5347
+ 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];
5306
5348
  if (getenv("NATIVE_SDK_GPU_DRAW_TRACE")) {
5307
5349
  /* Per-present phase split (draw vs texture upload + Metal present),
5308
5350
  * NATIVE_SDK_WINDOW_TIMING-style stderr diagnostics. */
@@ -5498,6 +5540,8 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5498
5540
  element.accessibilityEnabled = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_ENABLED) != 0;
5499
5541
  element.accessibilityFocused = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_FOCUSED) != 0;
5500
5542
  element.accessibilitySelected = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_SELECTED) != 0;
5543
+ element.canUndo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_UNDO) != 0;
5544
+ element.canRedo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_REDO) != 0;
5501
5545
  if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_EXPANDED) != 0) {
5502
5546
  element.accessibilityExpanded = YES;
5503
5547
  } else if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_COLLAPSED) != 0) {
@@ -5823,12 +5867,22 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5823
5867
  const double red = self.hasCanvasTexture ? 0.965 : 0.10 + 0.08 * sin(phase * 6.283185307179586);
5824
5868
  const double green = self.hasCanvasTexture ? 0.973 : 0.18 + 0.10 * sin((phase + 0.33) * 6.283185307179586);
5825
5869
  const double blue = self.hasCanvasTexture ? 0.988 : 0.34 + 0.16 * sin((phase + 0.66) * 6.283185307179586);
5870
+ const BOOL transparentWindow = window != nil && !window.opaque;
5826
5871
 
5827
5872
  MTLRenderPassDescriptor *descriptor = [MTLRenderPassDescriptor renderPassDescriptor];
5828
5873
  descriptor.colorAttachments[0].texture = drawable.texture;
5829
5874
  descriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
5830
5875
  descriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
5831
- descriptor.colorAttachments[0].clearColor = MTLClearColorMake(red, green, blue, 1.0);
5876
+ // The clear remains visible when the renderer has not supplied a
5877
+ // canvas texture yet, and briefly while a resize's retained texture
5878
+ // does not match the new drawable. An opaque placeholder is useful
5879
+ // for an ordinary window, but it defeats a transparent overlay's
5880
+ // contract exactly when the late-reveal fallback exposes that state.
5881
+ // Clear transparent glass to transparent black (valid premultiplied
5882
+ // alpha); a matching canvas texture still draws over the whole pass.
5883
+ descriptor.colorAttachments[0].clearColor = transparentWindow
5884
+ ? MTLClearColorMake(0.0, 0.0, 0.0, 0.0)
5885
+ : MTLClearColorMake(red, green, blue, 1.0);
5832
5886
 
5833
5887
  id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
5834
5888
  if (!commandBuffer) return;
@@ -6964,6 +7018,20 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
6964
7018
  [self emitSelectAllTextInputCommand];
6965
7019
  }
6966
7020
 
7021
+ // The runtime owns canvas-editor history, so Edit-menu actions take the
7022
+ // same Command+Z / Command+Shift+Z route as physical keyboard events.
7023
+ - (void)undo:(id)sender {
7024
+ (void)sender;
7025
+ if (![self focusedTextAccessibilityElement]) return;
7026
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)];
7027
+ }
7028
+
7029
+ - (void)redo:(id)sender {
7030
+ (void)sender;
7031
+ if (![self focusedTextAccessibilityElement]) return;
7032
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)];
7033
+ }
7034
+
6967
7035
  // Edit-menu clipboard actions on the canvas: the runtime already
6968
7036
  // resolves cmd+C/X/V key events against the focused editable widget or
6969
7037
  // the view's text selection, so the menu items ride the same path as
@@ -6989,8 +7057,18 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
6989
7057
  }
6990
7058
 
6991
7059
  - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
6992
- if (menuItem.action == @selector(cut:) || menuItem.action == @selector(paste:) || menuItem.action == @selector(selectAll:)) {
6993
- return [self focusedTextAccessibilityElement] != nil;
7060
+ NativeSdkWidgetAccessibilityElement *focusedText =
7061
+ (NativeSdkWidgetAccessibilityElement *)[self focusedTextAccessibilityElement];
7062
+ if (menuItem.action == @selector(undo:)) {
7063
+ return focusedText != nil && focusedText.canUndo;
7064
+ }
7065
+ if (menuItem.action == @selector(redo:)) {
7066
+ return focusedText != nil && focusedText.canRedo;
7067
+ }
7068
+ if (menuItem.action == @selector(cut:) ||
7069
+ menuItem.action == @selector(paste:) ||
7070
+ menuItem.action == @selector(selectAll:)) {
7071
+ return focusedText != nil;
6994
7072
  }
6995
7073
  return YES;
6996
7074
  }
@@ -7133,7 +7211,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7133
7211
 
7134
7212
  @implementation NativeSdkAppKitHost
7135
7213
 
7136
- - (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 {
7214
+ - (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 {
7137
7215
  self = [super init];
7138
7216
  if (!self) {
7139
7217
  return nil;
@@ -7162,6 +7240,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7162
7240
  self.deferredShowWindows = [[NSMutableDictionary alloc] init];
7163
7241
  self.windowClearColors = [[NSMutableDictionary alloc] init];
7164
7242
  self.windowClosePolicies = [[NSMutableDictionary alloc] init];
7243
+ self.passiveShowWindows = [[NSMutableSet alloc] init];
7165
7244
  self.policyHiddenWindows = [[NSMutableSet alloc] init];
7166
7245
  self.childWebViews = [[NSMutableDictionary alloc] init];
7167
7246
  self.nativeViews = [[NSMutableDictionary alloc] init];
@@ -7178,7 +7257,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7178
7257
  [self configureApplication];
7179
7258
  NativeSdkLaunchLap("app_configured");
7180
7259
 
7181
- [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];
7260
+ [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];
7182
7261
  self.didShutdown = NO;
7183
7262
  self.pendingPreRunStop = NO;
7184
7263
  self.observesApplicationActivation = NO;
@@ -7186,7 +7265,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7186
7265
  return self;
7187
7266
  }
7188
7267
 
7189
- - (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 {
7268
+ - (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 {
7190
7269
  NSNumber *key = @(windowId);
7191
7270
  if (self.windows[key]) {
7192
7271
  return NO;
@@ -7243,6 +7322,15 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7243
7322
  // next autorelease-pool drain; the main window only ever closes at
7244
7323
  // shutdown, which is why this stayed hidden until windows_fn).
7245
7324
  window.releasedWhenClosed = NO;
7325
+ // Overlay behavior is installed before the first order-front so no
7326
+ // opaque, focus-taking, or interactive intermediate window can flash.
7327
+ if ((windowFlags & (1u << 0)) != 0) {
7328
+ window.opaque = NO;
7329
+ window.backgroundColor = NSColor.clearColor;
7330
+ }
7331
+ if ((windowFlags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
7332
+ if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
7333
+ if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
7246
7334
  [window setTitle:(title.length > 0 ? title : self.appName)];
7247
7335
  if (titlebarStyle == 1 || titlebarStyle == 2) {
7248
7336
  window.titlebarAppearsTransparent = YES;
@@ -7314,12 +7402,27 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7314
7402
  self.delegate = delegate;
7315
7403
  self.windowLabel = label.length > 0 ? label : @"main";
7316
7404
  } else if (showPolicy != 1) {
7317
- [window makeKeyAndOrderFront:nil];
7318
- [NSApp activate];
7405
+ [self orderWindowForImplicitShow:windowId];
7319
7406
  }
7320
7407
  return YES;
7321
7408
  }
7322
7409
 
7410
+ // Implicit shows honor `activate_on_show`: passive overlays are ordered
7411
+ // front without changing the active app or key window. Explicit focus
7412
+ // continues to activate and makeKeyAndOrderFront. Activation comes
7413
+ // first: a first-present window can reveal while the app is inactive,
7414
+ // and asking that inactive app to make a window key is only best effort.
7415
+ - (void)orderWindowForImplicitShow:(uint64_t)windowId {
7416
+ NSWindow *window = self.windows[@(windowId)];
7417
+ if (!window) return;
7418
+ if ([self.passiveShowWindows containsObject:@(windowId)]) {
7419
+ [window orderFront:nil];
7420
+ } else {
7421
+ [NSApp activate];
7422
+ [window makeKeyAndOrderFront:nil];
7423
+ }
7424
+ }
7425
+
7323
7426
  // Order a deferred-show window front exactly once — from the first
7324
7427
  // gpu-surface present (the contract), or from the fallback deadline.
7325
7428
  // `NATIVE_SDK_WINDOW_TIMING=1` logs the create→show latency.
@@ -7334,8 +7437,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7334
7437
  const double elapsedMs = (double)(NativeSdkTimestampNanoseconds() - createdNs.unsignedLongLongValue) / 1e6;
7335
7438
  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));
7336
7439
  }
7337
- [window makeKeyAndOrderFront:nil];
7338
- [NSApp activate];
7440
+ [self orderWindowForImplicitShow:windowId];
7339
7441
  [self emitWindowFrameForWindowId:windowId open:YES];
7340
7442
  [self scheduleFrame];
7341
7443
  }
@@ -7386,8 +7488,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7386
7488
  // An explicit focus overrides a pending present-before-show defer:
7387
7489
  // the runtime asked for the window NOW.
7388
7490
  [self.deferredShowWindows removeObjectForKey:@(windowId)];
7389
- [window makeKeyAndOrderFront:nil];
7390
7491
  [NSApp activate];
7492
+ [window makeKeyAndOrderFront:nil];
7391
7493
  [self emitWindowFrameForWindowId:windowId open:YES];
7392
7494
  [self scheduleFrame];
7393
7495
  }
@@ -7430,7 +7532,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7430
7532
  }
7431
7533
 
7432
7534
  // The counterpart show verb: bring a hidden (or merely unfocused)
7433
- // window back to the glass and activate the app — the tray-menu
7535
+ // window back to the glass, activating unless its creation-time
7536
+ // presentation policy is passive — the tray-menu
7434
7537
  // "Open" consequence and the Dock reopen both land here. Also clears a
7435
7538
  // pending present-before-show defer and a minimize, for the same
7436
7539
  // reason focusWindowWithId: does: the runtime asked for the window NOW.
@@ -7440,8 +7543,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7440
7543
  [self.policyHiddenWindows removeObject:@(windowId)];
7441
7544
  [self.deferredShowWindows removeObjectForKey:@(windowId)];
7442
7545
  if (window.miniaturized) [window deminiaturize:nil];
7443
- [window makeKeyAndOrderFront:nil];
7444
- [NSApp activate];
7546
+ [self orderWindowForImplicitShow:windowId];
7445
7547
  [self emitWindowFrameForWindowId:windowId open:YES];
7446
7548
  [self scheduleFrame];
7447
7549
  }
@@ -7975,7 +8077,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7975
8077
  * resync. (The packet path calls presentPixelsWithWidth internally,
7976
8078
  * so the invalidation lives here at the raw entry, not inside it.) */
7977
8079
  surface.hasCanvasRetainedState = NO;
7978
- 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];
8080
+ 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];
7979
8081
  if (presented) [self showDeferredWindowIfPending:windowId reason:"first-present"];
7980
8082
  return presented;
7981
8083
  }
@@ -8915,14 +9017,12 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
8915
9017
  [mainMenu addItem:editMenuItem];
8916
9018
  NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
8917
9019
  [editMenuItem setSubmenu:editMenu];
8918
- if (self.hasWebContent) {
8919
- // Undo/Redo answer only inside web content (the webview's own
8920
- // editing stack); the canvas text editor has no undo stack, so
8921
- // canvas-only apps do not show items nothing can perform.
8922
- [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
8923
- [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
8924
- [editMenu addItem:[NSMenuItem separatorItem]];
8925
- }
9020
+ // Web content answers through its native responder. A focused canvas
9021
+ // editor answers through NativeSdkGpuSurfaceView's synthetic-key
9022
+ // bridge into the runtime's per-editor history.
9023
+ [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
9024
+ [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
9025
+ [editMenu addItem:[NSMenuItem separatorItem]];
8926
9026
  [editMenu addItem:[self menuItem:@"Cut" action:@selector(cut:) key:@"x" modifiers:NSEventModifierFlagCommand]];
8927
9027
  [editMenu addItem:[self menuItem:@"Copy" action:@selector(copy:) key:@"c" modifiers:NSEventModifierFlagCommand]];
8928
9028
  [editMenu addItem:[self menuItem:@"Paste" action:@selector(paste:) key:@"v" modifiers:NSEventModifierFlagCommand]];
@@ -9064,9 +9164,8 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
9064
9164
  // here and appears when its first canvas present lands (or the
9065
9165
  // create-time fallback deadline fires).
9066
9166
  if (!self.deferredShowWindows[@1]) {
9067
- [self.window makeKeyAndOrderFront:nil];
9167
+ [self orderWindowForImplicitShow:1];
9068
9168
  }
9069
- [NSApp activate];
9070
9169
  if (!self.shortcutEventMonitor) {
9071
9170
  __weak NativeSdkAppKitHost *weakSelf = self;
9072
9171
  self.shortcutEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
@@ -11434,7 +11533,7 @@ static BOOL NativeSdkPolicyListMatches(NSArray<NSString *> *values, NSURL *url)
11434
11533
  return NO;
11435
11534
  }
11436
11535
 
11437
- 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) {
11536
+ 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) {
11438
11537
  @autoreleasepool {
11439
11538
  NSString *appNameString = [[NSString alloc] initWithBytes:app_name length:app_name_len encoding:NSUTF8StringEncoding] ?: @"native-sdk";
11440
11539
  NSString *displayNameString = [[NSString alloc] initWithBytes:display_name length:display_name_len encoding:NSUTF8StringEncoding] ?: @"";
@@ -11444,7 +11543,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
11444
11543
  NSString *bundleIdString = [[NSString alloc] initWithBytes:bundle_id length:bundle_id_len encoding:NSUTF8StringEncoding] ?: @"dev.native_sdk.app";
11445
11544
  NSString *iconPathString = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding] ?: @"";
11446
11545
  NSString *windowLabelString = [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] ?: @"main";
11447
- 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];
11546
+ 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];
11448
11547
  return (__bridge_retained native_sdk_appkit_host_t *)host;
11449
11548
  }
11450
11549
  }
@@ -11742,11 +11841,11 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
11742
11841
  [object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
11743
11842
  }
11744
11843
 
11745
- 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) {
11844
+ 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) {
11746
11845
  NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
11747
11846
  NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"";
11748
11847
  NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
11749
- 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;
11848
+ 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;
11750
11849
  }
11751
11850
 
11752
11851
  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