@native-sdk/cli 0.6.1 → 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 (40) hide show
  1. package/native-sdk.d.ts +16 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/src/app_runner/root.zig +19 -0
  6. package/src/platform/linux/gtk_host.c +167 -8
  7. package/src/platform/linux/gtk_host.h +3 -2
  8. package/src/platform/linux/root.zig +198 -9
  9. package/src/platform/macos/appkit_host.h +2 -2
  10. package/src/platform/macos/appkit_host.m +101 -28
  11. package/src/platform/macos/cef_host.mm +46 -11
  12. package/src/platform/macos/root.zig +143 -5
  13. package/src/platform/null_platform.zig +32 -4
  14. package/src/platform/types.zig +29 -4
  15. package/src/platform/windows/root.zig +220 -10
  16. package/src/platform/windows/webview2_host.cpp +330 -31
  17. package/src/primitives/app_manifest/comptime_scene.zig +4 -0
  18. package/src/primitives/app_manifest/types.zig +16 -0
  19. package/src/primitives/canvas/widget_render.zig +21 -2
  20. package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
  21. package/src/runtime/bridge_payload.zig +9 -0
  22. package/src/runtime/bridge_responses.zig +2 -0
  23. package/src/runtime/builtin_bridge.zig +10 -0
  24. package/src/runtime/canvas_widget_floating_tests.zig +3 -3
  25. package/src/runtime/effects.zig +5 -6
  26. package/src/runtime/flow.zig +45 -7
  27. package/src/runtime/gpu_surface_events.zig +8 -1
  28. package/src/runtime/runtime_event_tests.zig +9 -6
  29. package/src/runtime/shell_layout.zig +25 -11
  30. package/src/runtime/shell_layout_tests.zig +184 -0
  31. package/src/runtime/shell_view_tests.zig +9 -7
  32. package/src/runtime/state.zig +6 -0
  33. package/src/runtime/ui_app.zig +61 -14
  34. package/src/runtime/ui_app_window_tests.zig +107 -2
  35. package/src/runtime/window_command_bridge_tests.zig +82 -6
  36. package/src/runtime/window_storage.zig +14 -3
  37. package/src/runtime/window_views.zig +12 -11
  38. package/src/tooling/manifest.zig +38 -2
  39. package/src/tooling/raw_manifest.zig +8 -0
  40. package/src/tooling/templates.zig +17 -0
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.2",
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.2",
36
+ "@native-sdk/cli-darwin-x64": "0.6.2",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.6.2",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.6.2",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.6.2",
40
+ "@native-sdk/cli-linux-x64-musl": "0.6.2",
41
+ "@native-sdk/cli-win32-arm64": "0.6.2",
42
+ "@native-sdk/cli-win32-x64": "0.6.2"
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.2",
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.2",
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.2",
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",
@@ -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
  }
@@ -160,7 +160,7 @@ typedef struct {
160
160
  * window with client-side decorations — a header bar carrying the
161
161
  * desktop-themed window controls and system drag behavior, no title
162
162
  * text); min_width/min_height <= 0 leave that axis unfloored. */
163
- native_sdk_gtk_host_t *native_sdk_gtk_create(const char *app_name, size_t app_name_len, 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, double min_width, double min_height);
163
+ native_sdk_gtk_host_t *native_sdk_gtk_create(const char *app_name, size_t app_name_len, 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, double min_width, double min_height, int show_policy, uint32_t window_flags);
164
164
  void native_sdk_gtk_destroy(native_sdk_gtk_host_t *host);
165
165
  void native_sdk_gtk_run(native_sdk_gtk_host_t *host, native_sdk_gtk_event_callback_t callback, void *context);
166
166
  void native_sdk_gtk_stop(native_sdk_gtk_host_t *host);
@@ -188,7 +188,7 @@ void native_sdk_gtk_emit_window_event(native_sdk_gtk_host_t *host, uint64_t wind
188
188
  void native_sdk_gtk_set_security_policy(native_sdk_gtk_host_t *host, const char *allowed_origins, size_t allowed_origins_len, const char *external_urls, size_t external_urls_len, int external_action);
189
189
  void native_sdk_gtk_set_menus(native_sdk_gtk_host_t *host, const char *const *menu_titles, const size_t *menu_title_lens, size_t menu_count, const uint32_t *item_menu_indices, const char *const *item_labels, const size_t *item_label_lens, const char *const *item_commands, const size_t *item_command_lens, const char *const *item_keys, const size_t *item_key_lens, const uint32_t *item_modifiers, const int *item_separators, const int *item_enabled, const int *item_checked, size_t item_count);
190
190
  void native_sdk_gtk_set_shortcuts(native_sdk_gtk_host_t *host, const char *const *ids, const size_t *id_lens, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count);
191
- 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);
191
+ 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);
192
192
  /* Ask the windowing system to start an interactive move from the last
193
193
  * pointer press (the widget `window_drag` channel). Returns 0 when the
194
194
  * window is unknown or no press has been recorded yet. */
@@ -216,6 +216,7 @@ int native_sdk_gtk_window_chrome(native_sdk_gtk_host_t *host, uint64_t window_id
216
216
  void native_sdk_gtk_start_timer(native_sdk_gtk_host_t *host, uint64_t timer_id, uint64_t interval_ns, int repeats);
217
217
  void native_sdk_gtk_cancel_timer(native_sdk_gtk_host_t *host, uint64_t timer_id);
218
218
  int native_sdk_gtk_focus_window(native_sdk_gtk_host_t *host, uint64_t window_id);
219
+ int native_sdk_gtk_show_window(native_sdk_gtk_host_t *host, uint64_t window_id);
219
220
  int native_sdk_gtk_close_window(native_sdk_gtk_host_t *host, uint64_t window_id);
220
221
  /* The real OS minimize verb (gtk_window_minimize), for app-drawn window
221
222
  * controls on chromeless windows. Returns 0 when the window id is