@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
package/build.zig CHANGED
@@ -1140,6 +1140,10 @@ pub fn build(b: *std.Build) void {
1140
1140
  // An assistive client's AXFocused WRITE must move the app's
1141
1141
  // real focus, not just flip a flag on the snapshot element.
1142
1142
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "setAccessibilityFocused" },
1143
+ // Native Edit-menu validation follows the retained editor's actual
1144
+ // history directions instead of merely checking text focus.
1145
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canUndo" },
1146
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canRedo" },
1143
1147
  });
1144
1148
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-text-ranges", "Verify AppKit GPU widget accessibility publishes text selection ranges", &.{
1145
1149
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilitySelectedTextRange" },
@@ -1198,6 +1202,10 @@ pub fn build(b: *std.Build) void {
1198
1202
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
1199
1203
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
1200
1204
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1205
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)undo:(id)sender" },
1206
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)redo:(id)sender" },
1207
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1208
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)" },
1201
1209
  // Modified horizontal navigation must bypass AppKit's selector
1202
1210
  // rewrite: the shared editor consumes the raw modifiers, and a
1203
1211
  // terminal translates them to its shell/protocol bindings.
package/native-sdk.d.ts CHANGED
@@ -34,6 +34,12 @@ export interface NativeSdkWindowInfo {
34
34
  scale: number;
35
35
  }
36
36
 
37
+ export type NativeSdkWindowTitlebarStyle =
38
+ | "standard"
39
+ | "hidden_inset"
40
+ | "hidden_inset_tall"
41
+ | "chromeless";
42
+
37
43
  export interface NativeSdkCreateWindowOptions {
38
44
  label?: string;
39
45
  title?: string;
@@ -42,6 +48,16 @@ export interface NativeSdkCreateWindowOptions {
42
48
  x?: number;
43
49
  y?: number;
44
50
  restoreState?: boolean;
51
+ /** Native titlebar treatment. Transparent Windows windows require "chromeless". */
52
+ titlebar?: NativeSdkWindowTitlebarStyle;
53
+ /** Make the top-level window alpha-capable. */
54
+ transparent?: boolean;
55
+ /** Keep the window above ordinary application windows. */
56
+ alwaysOnTop?: boolean;
57
+ /** Pass all pointer input through to the window underneath. */
58
+ clickThrough?: boolean;
59
+ /** Set false to show without activating the app or taking focus. */
60
+ activateOnShow?: boolean;
45
61
  url?: string;
46
62
  }
47
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.6.1",
36
- "@native-sdk/cli-darwin-x64": "0.6.1",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.6.1",
38
- "@native-sdk/cli-linux-arm64-musl": "0.6.1",
39
- "@native-sdk/cli-linux-x64-gnu": "0.6.1",
40
- "@native-sdk/cli-linux-x64-musl": "0.6.1",
41
- "@native-sdk/cli-win32-arm64": "0.6.1",
42
- "@native-sdk/cli-win32-x64": "0.6.1"
35
+ "@native-sdk/cli-darwin-arm64": "0.6.3",
36
+ "@native-sdk/cli-darwin-x64": "0.6.3",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.6.3",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.6.3",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.6.3",
40
+ "@native-sdk/cli-linux-x64-musl": "0.6.3",
41
+ "@native-sdk/cli-win32-arm64": "0.6.3",
42
+ "@native-sdk/cli-win32-x64": "0.6.3"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.6.1",
9
+ "version": "0.6.3",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,8 @@
14
14
  // call returns a new state and never touches its inputs.
15
15
  //
16
16
  // Offsets are BYTE offsets, always snapped to UTF-8 sequence boundaries
17
- // before use, so a caret can never land inside a multi-byte character.
17
+ // before use, so a caret can never land inside a multi-byte character or
18
+ // between the two bytes of a CRLF hard-line boundary.
18
19
  // Capacity is the caller's fixed byte budget (mirror your runtime
19
20
  // TextBuffer's): an edit whose result would not fit returns null — the
20
21
  // refuse-whole contract — and `clampedInsertEvent` recovers the one case
@@ -128,6 +129,42 @@ function nextTextOffset(text: Uint8Array, offset: number): number {
128
129
  return next;
129
130
  }
130
131
 
132
+ // Caret editing treats CRLF as one hard-line boundary. Raw text ranges
133
+ // continue to use snapTextOffset so they may address either delimiter byte.
134
+ function snapTextCaretOffset(text: Uint8Array, offset: number): number {
135
+ const cursor = snapTextOffset(text, offset);
136
+ if (
137
+ cursor > 0 &&
138
+ cursor < text.length &&
139
+ text[cursor] === 0x0a &&
140
+ text[cursor - 1] === 0x0d
141
+ ) {
142
+ return cursor - 1;
143
+ }
144
+ return cursor;
145
+ }
146
+
147
+ function previousTextCaretOffset(text: Uint8Array, offset: number): number {
148
+ const previous = previousTextOffset(text, offset);
149
+ if (previous > 0 && text[previous] === 0x0a && text[previous - 1] === 0x0d) {
150
+ return previous - 1;
151
+ }
152
+ return previous;
153
+ }
154
+
155
+ function nextTextCaretOffset(text: Uint8Array, offset: number): number {
156
+ const cursor = snapTextOffset(text, offset);
157
+ if (
158
+ cursor < text.length &&
159
+ text[cursor] === 0x0d &&
160
+ cursor + 1 < text.length &&
161
+ text[cursor + 1] === 0x0a
162
+ ) {
163
+ return cursor + 2;
164
+ }
165
+ return nextTextOffset(text, cursor);
166
+ }
167
+
131
168
  function isAsciiAlphanumeric(b: number): boolean {
132
169
  return (b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5a) || (b >= 0x61 && b <= 0x7a);
133
170
  }
@@ -179,10 +216,10 @@ function nextTextWordOffset(text: Uint8Array, offset: number): number {
179
216
  return cursor;
180
217
  }
181
218
 
182
- function snapTextSelection(text: Uint8Array, selection: TextSelection): TextSelection {
219
+ function snapTextCaretSelection(text: Uint8Array, selection: TextSelection): TextSelection {
183
220
  return {
184
- anchor: snapTextOffset(text, selection.anchor),
185
- focus: snapTextOffset(text, selection.focus),
221
+ anchor: snapTextCaretOffset(text, selection.anchor),
222
+ focus: snapTextCaretOffset(text, selection.focus),
186
223
  };
187
224
  }
188
225
 
@@ -226,8 +263,9 @@ function replaceTextRange(
226
263
  function normalizeTextEditState(state: TextEditState): TextEditState {
227
264
  return {
228
265
  text: state.text,
229
- selection: snapTextSelection(state.text, state.selection),
230
- composition: state.composition !== null ? snapTextRange(state.text, state.composition) : null,
266
+ selection: snapTextCaretSelection(state.text, state.selection),
267
+ composition:
268
+ state.composition !== null ? snapTextRange(state.text, state.composition) : null,
231
269
  };
232
270
  }
233
271
 
@@ -246,7 +284,7 @@ function replaceTextEditRange(
246
284
  ): TextEditState | null {
247
285
  const result = replaceTextRange(state.text, range, replacement, capacity);
248
286
  if (result === null) return null;
249
- const cursor = snapTextOffset(
287
+ const cursor = snapTextCaretOffset(
250
288
  result.text,
251
289
  result.insertedStart + Math.min(cursorOffset, replacement.length),
252
290
  );
@@ -264,10 +302,10 @@ function setTextComposition(
264
302
  capacity: number,
265
303
  ): TextEditState | null {
266
304
  const range = activeTextReplaceRange(state);
267
- const cursor = snapTextOffset(text, cursorIn === null ? text.length : cursorIn);
305
+ const cursor = snapTextCaretOffset(text, cursorIn === null ? text.length : cursorIn);
268
306
  const result = replaceTextRange(state.text, range, text, capacity);
269
307
  if (result === null) return null;
270
- const absoluteCursor = snapTextOffset(result.text, result.insertedStart + cursor);
308
+ const absoluteCursor = snapTextCaretOffset(result.text, result.insertedStart + cursor);
271
309
  return {
272
310
  text: result.text,
273
311
  selection: { anchor: absoluteCursor, focus: absoluteCursor },
@@ -282,7 +320,10 @@ function cancelTextComposition(state: TextEditState, capacity: number): TextEdit
282
320
  if (result === null) return null;
283
321
  return {
284
322
  text: result.text,
285
- selection: { anchor: result.insertedStart, focus: result.insertedStart },
323
+ selection: snapTextCaretSelection(result.text, {
324
+ anchor: result.insertedStart,
325
+ focus: result.insertedStart,
326
+ }),
286
327
  composition: null,
287
328
  };
288
329
  }
@@ -292,13 +333,13 @@ function deleteBackwardTextEdit(state: TextEditState, capacity: number): TextEdi
292
333
  if (!rangeIsCollapsed(range, state.text.length)) {
293
334
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
294
335
  }
295
- const caret = snapTextOffset(state.text, state.selection.focus);
336
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
296
337
  if (caret === 0) {
297
338
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
298
339
  }
299
340
  return replaceTextEditRange(
300
341
  state,
301
- { start: previousTextOffset(state.text, caret), end: caret },
342
+ { start: previousTextCaretOffset(state.text, caret), end: caret },
302
343
  new Uint8Array(0),
303
344
  capacity,
304
345
  null,
@@ -311,14 +352,14 @@ function deleteForwardTextEdit(state: TextEditState, capacity: number): TextEdit
311
352
  if (!rangeIsCollapsed(range, state.text.length)) {
312
353
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
313
354
  }
314
- const caret = snapTextOffset(state.text, state.selection.focus);
355
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
315
356
  if (caret >= state.text.length) {
316
357
  const len = state.text.length;
317
358
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
318
359
  }
319
360
  return replaceTextEditRange(
320
361
  state,
321
- { start: caret, end: nextTextOffset(state.text, caret) },
362
+ { start: caret, end: nextTextCaretOffset(state.text, caret) },
322
363
  new Uint8Array(0),
323
364
  capacity,
324
365
  null,
@@ -331,7 +372,7 @@ function deleteWordBackwardTextEdit(state: TextEditState, capacity: number): Tex
331
372
  if (!rangeIsCollapsed(range, state.text.length)) {
332
373
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
333
374
  }
334
- const caret = snapTextOffset(state.text, state.selection.focus);
375
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
335
376
  if (caret === 0) {
336
377
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
337
378
  }
@@ -350,7 +391,7 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
350
391
  if (!rangeIsCollapsed(range, state.text.length)) {
351
392
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
352
393
  }
353
- const caret = snapTextOffset(state.text, state.selection.focus);
394
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
354
395
  if (caret >= state.text.length) {
355
396
  const len = state.text.length;
356
397
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
@@ -367,13 +408,13 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
367
408
 
368
409
  function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState {
369
410
  const range = selectionRange(state.selection, state.text.length);
370
- const focus = snapTextOffset(state.text, state.selection.focus);
411
+ const focus = snapTextCaretOffset(state.text, state.selection.focus);
371
412
  const collapsed = rangeIsCollapsed(range, state.text.length);
372
413
  let target: number;
373
414
  if (move.direction === "previous") {
374
- target = !move.extend && !collapsed ? range.start : previousTextOffset(state.text, focus);
415
+ target = !move.extend && !collapsed ? range.start : previousTextCaretOffset(state.text, focus);
375
416
  } else if (move.direction === "next") {
376
- target = !move.extend && !collapsed ? range.end : nextTextOffset(state.text, focus);
417
+ target = !move.extend && !collapsed ? range.end : nextTextCaretOffset(state.text, focus);
377
418
  } else if (move.direction === "previous_word") {
378
419
  target = !move.extend && !collapsed ? range.start : previousTextWordOffset(state.text, focus);
379
420
  } else if (move.direction === "next_word") {
@@ -388,7 +429,7 @@ function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState
388
429
  : { anchor: target, focus: target };
389
430
  return {
390
431
  text: state.text,
391
- selection: snapTextSelection(state.text, selection),
432
+ selection: snapTextCaretSelection(state.text, selection),
392
433
  composition: null,
393
434
  };
394
435
  }
@@ -427,7 +468,7 @@ export function applyTextInputEvent(
427
468
  case "set_selection":
428
469
  return {
429
470
  text: normalized.text,
430
- selection: snapTextSelection(normalized.text, event.selection),
471
+ selection: snapTextCaretSelection(normalized.text, event.selection),
431
472
  composition: null,
432
473
  };
433
474
  case "set_composition":
@@ -92,6 +92,10 @@ pub const RunOptions = struct {
92
92
  info.main_window.titlebar = manifestShellStartupTitlebar();
93
93
  info.main_window.resizable = manifestShellStartupResizable();
94
94
  info.main_window.show = manifestShellStartupShowMode();
95
+ info.main_window.transparent = manifestShellStartupBool("transparent", false);
96
+ info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
97
+ info.main_window.click_through = manifestShellStartupBool("click_through", false);
98
+ info.main_window.activate_on_show = manifestShellStartupBool("activate_on_show", true);
95
99
  // Min-size floors ride the create call like the titlebar:
96
100
  // the scene re-applies size/title later, but the window's
97
101
  // enforced floor is host state from the first frame on.
@@ -158,6 +162,10 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
158
162
  .restore_state = windowBool(window, "restore_state", true),
159
163
  .restore_policy = windowRestorePolicy(window),
160
164
  .titlebar = windowTitlebarStyle(window),
165
+ .transparent = windowBool(window, "transparent", false),
166
+ .always_on_top = windowBool(window, "always_on_top", false),
167
+ .click_through = windowBool(window, "click_through", false),
168
+ .activate_on_show = windowBool(window, "activate_on_show", true),
161
169
  .min_width = windowMinSize(window, "min_width"),
162
170
  .min_height = windowMinSize(window, "min_height"),
163
171
  .close_policy = windowClosePolicy(window),
@@ -207,6 +215,17 @@ fn manifestShellStartupResizable() bool {
207
215
  return windowBool(shell.windows[0], "resizable", true);
208
216
  }
209
217
 
218
+ /// One creation-time boolean from app.zon's first shell window. Overlay
219
+ /// presentation must reach the host before the startup window is shown;
220
+ /// applying it after scene load would allow a focus/opaque flash.
221
+ fn manifestShellStartupBool(comptime field: []const u8, comptime default_value: bool) bool {
222
+ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return default_value;
223
+ const shell = app_manifest.shell;
224
+ if (comptime !@hasField(@TypeOf(shell), "windows")) return default_value;
225
+ if (comptime shell.windows.len == 0) return default_value;
226
+ return windowBool(shell.windows[0], field, default_value);
227
+ }
228
+
210
229
  /// The startup window's close policy for scene-first apps: app.zon's
211
230
  /// `.shell.windows[0].close_policy`. Like the titlebar, close handling
212
231
  /// is host window state fixed at create time.
@@ -353,6 +353,15 @@ typedef struct native_sdk_gtk_window {
353
353
  double emitted_width;
354
354
  double emitted_height;
355
355
  double emitted_scale;
356
+ int transparent;
357
+ int always_on_top;
358
+ int click_through;
359
+ int activate_on_show;
360
+ int show_on_first_present;
361
+ int shown;
362
+ /* One-second safety reveal for a canvas window whose first present
363
+ * never arrives. Zero once cancelled/fired. */
364
+ guint deferred_show_source;
356
365
  /* The window WebView's z-position among the overlay children. 0 is
357
366
  * the classic bottom-most main child; apps that layer native views
358
367
  * UNDER the WebView (or the WebView over a canvas) set it through
@@ -375,6 +384,12 @@ typedef struct native_sdk_gtk_window {
375
384
 
376
385
  struct native_sdk_gtk_host {
377
386
  GtkApplication *app;
387
+ /* Display providers are global and the display retains them until
388
+ * explicitly removed. Keep the transparent-window stylesheet once
389
+ * per host, rather than registering one immortal provider for every
390
+ * transparent window created over the process lifetime. */
391
+ GdkDisplay *transparent_css_display;
392
+ GtkCssProvider *transparent_css_provider;
378
393
  char *app_name;
379
394
  char *window_title;
380
395
  char *bundle_id;
@@ -388,6 +403,8 @@ struct native_sdk_gtk_host {
388
403
  int init_titlebar_style;
389
404
  double init_min_width;
390
405
  double init_min_height;
406
+ int init_show_policy;
407
+ uint32_t init_window_flags;
391
408
 
392
409
  native_sdk_gtk_event_callback_t callback;
393
410
  void *callback_context;
@@ -1855,6 +1872,10 @@ static void native_sdk_clear_webviews(native_sdk_gtk_window_t *win) {
1855
1872
 
1856
1873
  static void native_sdk_clear_window(native_sdk_gtk_window_t *win) {
1857
1874
  if (!win) return;
1875
+ if (win->deferred_show_source) {
1876
+ g_source_remove(win->deferred_show_source);
1877
+ win->deferred_show_source = 0;
1878
+ }
1858
1879
  native_sdk_clear_native_views(win);
1859
1880
  native_sdk_clear_webviews(win);
1860
1881
  native_sdk_clear_window_source(win);
@@ -2917,6 +2938,10 @@ static WebKitWebView *native_sdk_ensure_main_webview(native_sdk_gtk_window_t *wi
2917
2938
  g_object_new(WEBKIT_TYPE_WEB_VIEW,
2918
2939
  "user-content-manager", win->content_manager,
2919
2940
  NULL));
2941
+ if (win->transparent) {
2942
+ GdkRGBA transparent_color = {0, 0, 0, 0};
2943
+ webkit_web_view_set_background_color(wv, &transparent_color);
2944
+ }
2920
2945
  win->web_view = wv;
2921
2946
  native_sdk_register_zero_scheme(win->host, wv);
2922
2947
  native_sdk_setup_bridge(win);
@@ -2935,7 +2960,95 @@ static WebKitWebView *native_sdk_ensure_main_webview(native_sdk_gtk_window_t *wi
2935
2960
  }
2936
2961
  #endif /* NATIVE_SDK_HAS_WEBKITGTK */
2937
2962
 
2938
- static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk_host_t *host, uint64_t window_id, const char *title, const char *label, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, double min_width, double min_height) {
2963
+ static void native_sdk_apply_overlay_surface_options(native_sdk_gtk_window_t *win) {
2964
+ if (!win || !win->gtk_window) return;
2965
+ GtkWidget *widget = GTK_WIDGET(win->gtk_window);
2966
+ gtk_widget_realize(widget);
2967
+ GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(widget));
2968
+ if (!surface) return;
2969
+
2970
+ if (win->click_through) {
2971
+ cairo_region_t *empty = cairo_region_create();
2972
+ gdk_surface_set_input_region(surface, empty);
2973
+ cairo_region_destroy(empty);
2974
+ }
2975
+
2976
+ if (win->always_on_top) {
2977
+ /* GTK4 intentionally exposes no cross-compositor keep-above API.
2978
+ * Honor it on X11 through the standard EWMH state set before
2979
+ * map; Wayland compositors do not permit clients to demand this
2980
+ * level, so the diagnostic is explicit rather than a silent lie. */
2981
+ typedef unsigned long (*gdk_x11_surface_get_xid_fn)(GdkSurface *);
2982
+ typedef void *(*gdk_x11_display_get_xdisplay_fn)(GdkDisplay *);
2983
+ typedef unsigned long (*x_intern_atom_fn)(void *, const char *, int);
2984
+ typedef int (*x_change_property_fn)(void *, unsigned long, unsigned long, unsigned long, int, int, const unsigned char *, int);
2985
+ typedef int (*x_flush_fn)(void *);
2986
+ gdk_x11_surface_get_xid_fn get_xid = (gdk_x11_surface_get_xid_fn)dlsym(RTLD_DEFAULT, "gdk_x11_surface_get_xid");
2987
+ gdk_x11_display_get_xdisplay_fn get_xdisplay = (gdk_x11_display_get_xdisplay_fn)dlsym(RTLD_DEFAULT, "gdk_x11_display_get_xdisplay");
2988
+ x_intern_atom_fn intern_atom = (x_intern_atom_fn)dlsym(RTLD_DEFAULT, "XInternAtom");
2989
+ x_change_property_fn change_property = (x_change_property_fn)dlsym(RTLD_DEFAULT, "XChangeProperty");
2990
+ x_flush_fn flush = (x_flush_fn)dlsym(RTLD_DEFAULT, "XFlush");
2991
+ GdkDisplay *gdk_display = gdk_surface_get_display(surface);
2992
+ const char *display_type = G_OBJECT_TYPE_NAME(gdk_display);
2993
+ const int is_x11 = display_type && strstr(display_type, "X11") != NULL;
2994
+ if (is_x11 && get_xid && get_xdisplay && intern_atom && change_property && flush) {
2995
+ void *display = get_xdisplay(gdk_display);
2996
+ const unsigned long xid = get_xid(surface);
2997
+ const unsigned long state = intern_atom(display, "_NET_WM_STATE", 0);
2998
+ const unsigned long above = intern_atom(display, "_NET_WM_STATE_ABOVE", 0);
2999
+ change_property(display, xid, state, 4 /* XA_ATOM */, 32, 0 /* PropModeReplace */, (const unsigned char *)&above, 1);
3000
+ flush(display);
3001
+ } else {
3002
+ fprintf(stderr, "native-sdk: always_on_top is unavailable on this Linux compositor (Wayland does not expose a reliable client-controlled topmost window level)\n");
3003
+ }
3004
+ }
3005
+ }
3006
+
3007
+ static void native_sdk_show_window_implicit(native_sdk_gtk_window_t *win) {
3008
+ if (!win || !win->gtk_window) return;
3009
+ if (win->activate_on_show) {
3010
+ gtk_window_present(win->gtk_window);
3011
+ } else {
3012
+ gtk_widget_set_visible(GTK_WIDGET(win->gtk_window), TRUE);
3013
+ }
3014
+ win->shown = 1;
3015
+ }
3016
+
3017
+ static void native_sdk_cancel_deferred_show(native_sdk_gtk_window_t *win) {
3018
+ if (!win || !win->deferred_show_source) return;
3019
+ g_source_remove(win->deferred_show_source);
3020
+ win->deferred_show_source = 0;
3021
+ }
3022
+
3023
+ static gboolean native_sdk_deferred_show_timeout(gpointer data) {
3024
+ native_sdk_gtk_window_t *win = data;
3025
+ if (!win) return G_SOURCE_REMOVE;
3026
+ win->deferred_show_source = 0;
3027
+ if (!win->gtk_window || win->shown) return G_SOURCE_REMOVE;
3028
+ /* This is the wedged-renderer safety path: map the GTK window even
3029
+ * though the first canvas present never arrived. */
3030
+ native_sdk_show_window_implicit(win);
3031
+ native_sdk_emit_window_frame(win->host, win, 1);
3032
+ return G_SOURCE_REMOVE;
3033
+ }
3034
+
3035
+ static void native_sdk_ensure_transparent_css(native_sdk_gtk_host_t *host) {
3036
+ if (!host || host->transparent_css_provider) return;
3037
+ GdkDisplay *display = gdk_display_get_default();
3038
+ if (!display) return;
3039
+
3040
+ GtkCssProvider *provider = gtk_css_provider_new();
3041
+ #if GTK_CHECK_VERSION(4, 12, 0)
3042
+ gtk_css_provider_load_from_string(provider, ".native-sdk-transparent { background-color: transparent; }");
3043
+ #else
3044
+ gtk_css_provider_load_from_data(provider, ".native-sdk-transparent { background-color: transparent; }", -1);
3045
+ #endif
3046
+ gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
3047
+ host->transparent_css_display = g_object_ref(display);
3048
+ host->transparent_css_provider = provider;
3049
+ }
3050
+
3051
+ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk_host_t *host, uint64_t window_id, const char *title, const char *label, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, double min_width, double min_height, int show_policy, uint32_t window_flags) {
2939
3052
  if (native_sdk_find_window(host, window_id)) return NULL;
2940
3053
 
2941
3054
  int slot = -1;
@@ -2958,6 +3071,11 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
2958
3071
  win->y = restore_frame ? y : 0;
2959
3072
  win->label = native_sdk_strndup(label && label[0] ? label : "main", strlen(label && label[0] ? label : "main"));
2960
3073
  win->title = native_sdk_strndup(title && title[0] ? title : host->app_name, strlen(title && title[0] ? title : host->app_name));
3074
+ win->transparent = (window_flags & (1u << 0)) != 0;
3075
+ win->always_on_top = (window_flags & (1u << 1)) != 0;
3076
+ win->click_through = (window_flags & (1u << 2)) != 0;
3077
+ win->activate_on_show = (window_flags & (1u << 3)) == 0;
3078
+ win->show_on_first_present = show_policy == 1;
2961
3079
  if (!win->label || !win->title) {
2962
3080
  free(win->label);
2963
3081
  free(win->title);
@@ -2966,6 +3084,10 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
2966
3084
  }
2967
3085
 
2968
3086
  win->gtk_window = GTK_WINDOW(gtk_application_window_new(host->app));
3087
+ if (win->transparent) {
3088
+ native_sdk_ensure_transparent_css(host);
3089
+ gtk_widget_add_css_class(GTK_WIDGET(win->gtk_window), "native-sdk-transparent");
3090
+ }
2969
3091
  gtk_window_set_title(win->gtk_window, win->title);
2970
3092
  gtk_window_set_default_size(win->gtk_window, (int)width, (int)height);
2971
3093
  gtk_window_set_resizable(win->gtk_window, resizable ? TRUE : FALSE);
@@ -3057,6 +3179,11 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
3057
3179
  g_signal_connect(shortcut_controller, "key-pressed", G_CALLBACK(on_shortcut_key_pressed), win);
3058
3180
  gtk_widget_add_controller(GTK_WIDGET(win->gtk_window), shortcut_controller);
3059
3181
 
3182
+ native_sdk_apply_overlay_surface_options(win);
3183
+ if (win->show_on_first_present) {
3184
+ win->deferred_show_source = g_timeout_add(1000, native_sdk_deferred_show_timeout, win);
3185
+ }
3186
+
3060
3187
  return win;
3061
3188
  }
3062
3189
 
@@ -3070,10 +3197,11 @@ static void on_activate(GtkApplication *app, gpointer data) {
3070
3197
  host->init_width > 0 ? host->init_width : 720,
3071
3198
  host->init_height > 0 ? host->init_height : 480,
3072
3199
  host->restore_frame, host->init_resizable, host->init_titlebar_style,
3073
- host->init_min_width, host->init_min_height);
3200
+ host->init_min_width, host->init_min_height,
3201
+ host->init_show_policy, host->init_window_flags);
3074
3202
  if (!win) return;
3075
3203
 
3076
- gtk_window_present(win->gtk_window);
3204
+ if (!win->show_on_first_present) native_sdk_show_window_implicit(win);
3077
3205
  native_sdk_emit_app_active_if_changed(host);
3078
3206
 
3079
3207
  native_sdk_emit(host, (native_sdk_gtk_event_t){ .kind = NATIVE_SDK_GTK_EVENT_START });
@@ -3093,7 +3221,8 @@ native_sdk_gtk_host_t *native_sdk_gtk_create(
3093
3221
  const char *window_label, size_t window_label_len,
3094
3222
  double x, double y, double width, double height,
3095
3223
  int restore_frame, int resizable, int titlebar_style,
3096
- double min_width, double min_height)
3224
+ double min_width, double min_height, int show_policy,
3225
+ uint32_t window_flags)
3097
3226
  {
3098
3227
  native_sdk_gtk_host_t *host = calloc(1, sizeof(native_sdk_gtk_host_t));
3099
3228
  if (!host) return NULL;
@@ -3112,6 +3241,8 @@ native_sdk_gtk_host_t *native_sdk_gtk_create(
3112
3241
  host->init_titlebar_style = titlebar_style;
3113
3242
  host->init_min_width = min_width;
3114
3243
  host->init_min_height = min_height;
3244
+ host->init_show_policy = show_policy;
3245
+ host->init_window_flags = window_flags;
3115
3246
 
3116
3247
  host->allowed_origins = NULL;
3117
3248
  host->allowed_origins_count = 0;
@@ -3154,6 +3285,13 @@ void native_sdk_gtk_destroy(native_sdk_gtk_host_t *host) {
3154
3285
  for (int i = 0; i < host->window_count; i++) {
3155
3286
  native_sdk_clear_window(&host->windows[i]);
3156
3287
  }
3288
+ if (host->transparent_css_provider) {
3289
+ gtk_style_context_remove_provider_for_display(
3290
+ host->transparent_css_display,
3291
+ GTK_STYLE_PROVIDER(host->transparent_css_provider));
3292
+ g_object_unref(host->transparent_css_provider);
3293
+ g_object_unref(host->transparent_css_display);
3294
+ }
3157
3295
  g_object_unref(host->app);
3158
3296
  free(host->app_name);
3159
3297
  free(host->window_title);
@@ -3626,15 +3764,15 @@ void native_sdk_gtk_set_shortcuts(native_sdk_gtk_host_t *host, const char *const
3626
3764
  }
3627
3765
  }
3628
3766
 
3629
- int native_sdk_gtk_create_window(native_sdk_gtk_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, double min_width, double min_height) {
3767
+ int native_sdk_gtk_create_window(native_sdk_gtk_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, double min_width, double min_height, int show_policy, uint32_t window_flags) {
3630
3768
  char *title = window_title_len > 0 ? native_sdk_strndup(window_title, window_title_len) : NULL;
3631
3769
  char *label = window_label_len > 0 ? native_sdk_strndup(window_label, window_label_len) : NULL;
3632
- native_sdk_gtk_window_t *win = native_sdk_create_window_internal(host, window_id, title, label, x, y, width, height, restore_frame, resizable, titlebar_style, min_width, min_height);
3770
+ native_sdk_gtk_window_t *win = native_sdk_create_window_internal(host, window_id, title, label, x, y, width, height, restore_frame, resizable, titlebar_style, min_width, min_height, show_policy, window_flags);
3633
3771
  free(title);
3634
3772
  free(label);
3635
3773
  if (!win) return 0;
3636
3774
 
3637
- gtk_window_present(win->gtk_window);
3775
+ if (!win->show_on_first_present) native_sdk_show_window_implicit(win);
3638
3776
  return 1;
3639
3777
  }
3640
3778
 
@@ -3804,7 +3942,19 @@ int native_sdk_gtk_window_chrome(native_sdk_gtk_host_t *host, uint64_t window_id
3804
3942
  int native_sdk_gtk_focus_window(native_sdk_gtk_host_t *host, uint64_t window_id) {
3805
3943
  native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
3806
3944
  if (!win || !win->gtk_window) return 0;
3945
+ native_sdk_cancel_deferred_show(win);
3807
3946
  gtk_window_present(win->gtk_window);
3947
+ win->shown = 1;
3948
+ native_sdk_emit_window_frame(host, win, 1);
3949
+ return 1;
3950
+ }
3951
+
3952
+ int native_sdk_gtk_show_window(native_sdk_gtk_host_t *host, uint64_t window_id) {
3953
+ native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
3954
+ if (!win || !win->gtk_window) return 0;
3955
+ native_sdk_cancel_deferred_show(win);
3956
+ if (!win->activate_on_show) gtk_window_unminimize(win->gtk_window);
3957
+ native_sdk_show_window_implicit(win);
3808
3958
  native_sdk_emit_window_frame(host, win, 1);
3809
3959
  return 1;
3810
3960
  }
@@ -4224,13 +4374,22 @@ int native_sdk_gtk_present_gpu_surface_pixels(native_sdk_gtk_host_t *host, uint6
4224
4374
  view->gpu_sample_color = ((uint32_t)sa << 24) | ((uint32_t)sr << 16) | ((uint32_t)sg << 8) | (uint32_t)sb;
4225
4375
  }
4226
4376
 
4227
- gtk_widget_queue_draw(view->widget);
4228
4377
  /* A present is the completion producer on the surface's single
4229
4378
  * frame-event scheduler: the completion event it arms is what
4230
4379
  * drives the runtime's frame loop (an armed animation presents,
4231
4380
  * this echo steps it again). The first present also retires the
4232
4381
  * placeholder pump — from here on frames exist only on demand. */
4382
+ const int first_present = !view->gpu_presented;
4233
4383
  view->gpu_presented = 1;
4384
+ if (first_present && win && !win->shown) {
4385
+ native_sdk_cancel_deferred_show(win);
4386
+ native_sdk_show_window_implicit(win);
4387
+ native_sdk_emit_window_frame(host, win, 1);
4388
+ }
4389
+ /* GTK discards queue_draw while a widget is unmapped. Map a deferred
4390
+ * first-present window above, then queue the draw that consumes the
4391
+ * newly installed canvas buffer. */
4392
+ gtk_widget_queue_draw(view->widget);
4234
4393
  native_sdk_gpu_surface_schedule_frame_emission(view);
4235
4394
  return 1;
4236
4395
  }