@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.
- package/native-sdk.d.ts +16 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/src/app_runner/root.zig +19 -0
- package/src/platform/linux/gtk_host.c +167 -8
- package/src/platform/linux/gtk_host.h +3 -2
- package/src/platform/linux/root.zig +198 -9
- package/src/platform/macos/appkit_host.h +2 -2
- package/src/platform/macos/appkit_host.m +101 -28
- package/src/platform/macos/cef_host.mm +46 -11
- package/src/platform/macos/root.zig +143 -5
- package/src/platform/null_platform.zig +32 -4
- package/src/platform/types.zig +29 -4
- package/src/platform/windows/root.zig +220 -10
- package/src/platform/windows/webview2_host.cpp +330 -31
- package/src/primitives/app_manifest/comptime_scene.zig +4 -0
- package/src/primitives/app_manifest/types.zig +16 -0
- package/src/primitives/canvas/widget_render.zig +21 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
- package/src/runtime/bridge_payload.zig +9 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +10 -0
- package/src/runtime/canvas_widget_floating_tests.zig +3 -3
- package/src/runtime/effects.zig +5 -6
- package/src/runtime/flow.zig +45 -7
- package/src/runtime/gpu_surface_events.zig +8 -1
- package/src/runtime/runtime_event_tests.zig +9 -6
- package/src/runtime/shell_layout.zig +25 -11
- package/src/runtime/shell_layout_tests.zig +184 -0
- package/src/runtime/shell_view_tests.zig +9 -7
- package/src/runtime/state.zig +6 -0
- package/src/runtime/ui_app.zig +61 -14
- package/src/runtime/ui_app_window_tests.zig +107 -2
- package/src/runtime/window_command_bridge_tests.zig +82 -6
- package/src/runtime/window_storage.zig +14 -3
- package/src/runtime/window_views.zig +12 -11
- package/src/tooling/manifest.zig +38 -2
- package/src/tooling/raw_manifest.zig +8 -0
- package/src/tooling/templates.zig +17 -0
|
@@ -111,7 +111,7 @@ const shortcut_modifier_control: u32 = 1 << 2;
|
|
|
111
111
|
const shortcut_modifier_option: u32 = 1 << 3;
|
|
112
112
|
const shortcut_modifier_shift: u32 = 1 << 4;
|
|
113
113
|
|
|
114
|
-
extern fn native_sdk_gtk_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) ?*GtkHost;
|
|
114
|
+
extern fn native_sdk_gtk_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) ?*GtkHost;
|
|
115
115
|
extern fn native_sdk_gtk_destroy(host: *GtkHost) void;
|
|
116
116
|
extern fn native_sdk_gtk_run(host: *GtkHost, callback: GtkCallback, context: ?*anyopaque) void;
|
|
117
117
|
extern fn native_sdk_gtk_stop(host: *GtkHost) void;
|
|
@@ -128,13 +128,14 @@ extern fn native_sdk_gtk_emit_window_event(host: *GtkHost, window_id: u64, name:
|
|
|
128
128
|
extern fn native_sdk_gtk_set_security_policy(host: *GtkHost, allowed_origins: [*]const u8, allowed_origins_len: usize, external_urls: [*]const u8, external_urls_len: usize, external_action: c_int) void;
|
|
129
129
|
extern fn native_sdk_gtk_set_menus(host: *GtkHost, menu_titles: [*]const [*]const u8, menu_title_lens: [*]const usize, menu_count: usize, item_menu_indices: [*]const u32, item_labels: [*]const [*]const u8, item_label_lens: [*]const usize, item_commands: [*]const [*]const u8, item_command_lens: [*]const usize, item_keys: [*]const [*]const u8, item_key_lens: [*]const usize, item_modifiers: [*]const u32, item_separators: [*]const c_int, item_enabled: [*]const c_int, item_checked: [*]const c_int, item_count: usize) void;
|
|
130
130
|
extern fn native_sdk_gtk_set_shortcuts(host: *GtkHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
|
|
131
|
-
extern fn native_sdk_gtk_create_window(host: *GtkHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) c_int;
|
|
131
|
+
extern fn native_sdk_gtk_create_window(host: *GtkHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) c_int;
|
|
132
132
|
extern fn native_sdk_gtk_start_window_drag(host: *GtkHost, window_id: u64) c_int;
|
|
133
133
|
extern fn native_sdk_gtk_set_window_drag_regions(host: *GtkHost, window_id: u64, label: [*]const u8, label_len: usize, rects: [*]const f64, exclusions: [*]const c_int, count: usize) c_int;
|
|
134
134
|
extern fn native_sdk_gtk_window_chrome(host: *GtkHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
|
|
135
135
|
extern fn native_sdk_gtk_start_timer(host: *GtkHost, timer_id: u64, interval_ns: u64, repeats: c_int) void;
|
|
136
136
|
extern fn native_sdk_gtk_cancel_timer(host: *GtkHost, timer_id: u64) void;
|
|
137
137
|
extern fn native_sdk_gtk_focus_window(host: *GtkHost, window_id: u64) c_int;
|
|
138
|
+
extern fn native_sdk_gtk_show_window(host: *GtkHost, window_id: u64) c_int;
|
|
138
139
|
extern fn native_sdk_gtk_close_window(host: *GtkHost, window_id: u64) c_int;
|
|
139
140
|
extern fn native_sdk_gtk_minimize_window(host: *GtkHost, window_id: u64) c_int;
|
|
140
141
|
extern fn native_sdk_gtk_create_view(host: *GtkHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
|
|
@@ -286,7 +287,7 @@ pub const LinuxPlatform = struct {
|
|
|
286
287
|
try refuseUnsupportedMainWindowClosePolicy(window_options);
|
|
287
288
|
const window_title = window_options.resolvedTitle(app_info.app_name);
|
|
288
289
|
const frame = window_options.default_frame;
|
|
289
|
-
const host = native_sdk_gtk_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.icon_path.len, window_options.label.ptr, window_options.label.len, frame.x, frame.y, frame.width, frame.height, if (window_options.restore_state) 1 else 0, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height)) orelse return error.CreateFailed;
|
|
290
|
+
const host = native_sdk_gtk_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.icon_path.len, window_options.label.ptr, window_options.label.len, frame.x, frame.y, frame.width, frame.height, if (window_options.restore_state) 1 else 0, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
|
|
290
291
|
return .{
|
|
291
292
|
.host = host,
|
|
292
293
|
.web_engine = web_engine,
|
|
@@ -848,6 +849,22 @@ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
|
|
|
848
849
|
};
|
|
849
850
|
}
|
|
850
851
|
|
|
852
|
+
fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
|
|
853
|
+
return switch (mode) {
|
|
854
|
+
.immediate => 0,
|
|
855
|
+
.on_first_present => 1,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
fn windowFlags(options: platform_mod.WindowOptions) u32 {
|
|
860
|
+
var flags: u32 = 0;
|
|
861
|
+
if (options.transparent) flags |= 1 << 0;
|
|
862
|
+
if (options.always_on_top) flags |= 1 << 1;
|
|
863
|
+
if (options.click_through) flags |= 1 << 2;
|
|
864
|
+
if (!options.activate_on_show) flags |= 1 << 3;
|
|
865
|
+
return flags;
|
|
866
|
+
}
|
|
867
|
+
|
|
851
868
|
/// Zero/negative/non-finite floors are the "no floor" sentinel (the
|
|
852
869
|
/// host leaves that axis at its natural minimum).
|
|
853
870
|
fn minSizeFloor(value: f32) f64 {
|
|
@@ -858,7 +875,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
|
|
|
858
875
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
859
876
|
const title = options.resolvedTitle(self.app_info.app_name);
|
|
860
877
|
const frame = options.default_frame;
|
|
861
|
-
if (native_sdk_gtk_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height)) == 0) return error.CreateFailed;
|
|
878
|
+
if (native_sdk_gtk_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
|
|
862
879
|
return .{
|
|
863
880
|
.id = options.id,
|
|
864
881
|
.label = options.label,
|
|
@@ -866,7 +883,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
|
|
|
866
883
|
.frame = frame,
|
|
867
884
|
.scale_factor = 1,
|
|
868
885
|
.open = true,
|
|
869
|
-
.focused =
|
|
886
|
+
.focused = options.activate_on_show and options.show == .immediate,
|
|
870
887
|
};
|
|
871
888
|
}
|
|
872
889
|
|
|
@@ -885,12 +902,11 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
|
|
|
885
902
|
if (native_sdk_gtk_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
886
903
|
}
|
|
887
904
|
|
|
888
|
-
/// GTK has no hide-on-close
|
|
889
|
-
///
|
|
890
|
-
/// it focus — the same call the focus service makes.
|
|
905
|
+
/// GTK has no hide-on-close, but show is still distinct from explicit
|
|
906
|
+
/// focus for passive overlay windows.
|
|
891
907
|
fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
892
908
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
893
|
-
if (
|
|
909
|
+
if (native_sdk_gtk_show_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
894
910
|
}
|
|
895
911
|
|
|
896
912
|
/// The graceful quit: the same emitShutdown + g_application_quit the
|
|
@@ -1839,6 +1855,137 @@ test "linux platform module exports type" {
|
|
|
1839
1855
|
_ = LinuxPlatform;
|
|
1840
1856
|
}
|
|
1841
1857
|
|
|
1858
|
+
test "linux transparent windows clear the main webview background" {
|
|
1859
|
+
const host_source = @embedFile("gtk_host.c");
|
|
1860
|
+
const ensure_at = std.mem.indexOf(
|
|
1861
|
+
u8,
|
|
1862
|
+
host_source,
|
|
1863
|
+
"static WebKitWebView *native_sdk_ensure_main_webview",
|
|
1864
|
+
) orelse return error.TestExpectedEqual;
|
|
1865
|
+
const create_at = std.mem.indexOfPos(
|
|
1866
|
+
u8,
|
|
1867
|
+
host_source,
|
|
1868
|
+
ensure_at,
|
|
1869
|
+
"WebKitWebView *wv = WEBKIT_WEB_VIEW(",
|
|
1870
|
+
) orelse return error.TestExpectedEqual;
|
|
1871
|
+
const assign_at = std.mem.indexOfPos(
|
|
1872
|
+
u8,
|
|
1873
|
+
host_source,
|
|
1874
|
+
create_at,
|
|
1875
|
+
"win->web_view = wv;",
|
|
1876
|
+
) orelse return error.TestExpectedEqual;
|
|
1877
|
+
const create_slice = host_source[create_at..assign_at];
|
|
1878
|
+
try std.testing.expect(std.mem.indexOf(
|
|
1879
|
+
u8,
|
|
1880
|
+
create_slice,
|
|
1881
|
+
"if (win->transparent)",
|
|
1882
|
+
) != null);
|
|
1883
|
+
try std.testing.expect(std.mem.indexOf(
|
|
1884
|
+
u8,
|
|
1885
|
+
create_slice,
|
|
1886
|
+
"webkit_web_view_set_background_color(wv, &transparent_color);",
|
|
1887
|
+
) != null);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
test "linux transparent window stylesheet is host-owned and removed" {
|
|
1891
|
+
const host_source = @embedFile("gtk_host.c");
|
|
1892
|
+
try std.testing.expectEqual(
|
|
1893
|
+
@as(usize, 1),
|
|
1894
|
+
std.mem.count(u8, host_source, "gtk_style_context_add_provider_for_display("),
|
|
1895
|
+
);
|
|
1896
|
+
try std.testing.expectEqual(
|
|
1897
|
+
@as(usize, 1),
|
|
1898
|
+
std.mem.count(u8, host_source, "gtk_style_context_remove_provider_for_display("),
|
|
1899
|
+
);
|
|
1900
|
+
|
|
1901
|
+
const ensure_at = std.mem.indexOf(
|
|
1902
|
+
u8,
|
|
1903
|
+
host_source,
|
|
1904
|
+
"static void native_sdk_ensure_transparent_css",
|
|
1905
|
+
) orelse return error.TestExpectedEqual;
|
|
1906
|
+
const create_at = std.mem.indexOfPos(
|
|
1907
|
+
u8,
|
|
1908
|
+
host_source,
|
|
1909
|
+
ensure_at,
|
|
1910
|
+
"static native_sdk_gtk_window_t *native_sdk_create_window_internal",
|
|
1911
|
+
) orelse return error.TestExpectedEqual;
|
|
1912
|
+
const ensure = host_source[ensure_at..create_at];
|
|
1913
|
+
try std.testing.expect(std.mem.indexOf(
|
|
1914
|
+
u8,
|
|
1915
|
+
ensure,
|
|
1916
|
+
"if (!host || host->transparent_css_provider) return;",
|
|
1917
|
+
) != null);
|
|
1918
|
+
const create_end = std.mem.indexOfPos(
|
|
1919
|
+
u8,
|
|
1920
|
+
host_source,
|
|
1921
|
+
create_at,
|
|
1922
|
+
"static void on_activate",
|
|
1923
|
+
) orelse return error.TestExpectedEqual;
|
|
1924
|
+
const create = host_source[create_at..create_end];
|
|
1925
|
+
try std.testing.expect(std.mem.indexOf(
|
|
1926
|
+
u8,
|
|
1927
|
+
create,
|
|
1928
|
+
"native_sdk_ensure_transparent_css(host);",
|
|
1929
|
+
) != null);
|
|
1930
|
+
|
|
1931
|
+
const destroy_at = std.mem.indexOf(
|
|
1932
|
+
u8,
|
|
1933
|
+
host_source,
|
|
1934
|
+
"void native_sdk_gtk_destroy",
|
|
1935
|
+
) orelse return error.TestExpectedEqual;
|
|
1936
|
+
const destroy = host_source[destroy_at..];
|
|
1937
|
+
const remove_at = std.mem.indexOf(
|
|
1938
|
+
u8,
|
|
1939
|
+
destroy,
|
|
1940
|
+
"gtk_style_context_remove_provider_for_display(",
|
|
1941
|
+
) orelse return error.TestExpectedEqual;
|
|
1942
|
+
const provider_unref_at = std.mem.indexOf(
|
|
1943
|
+
u8,
|
|
1944
|
+
destroy,
|
|
1945
|
+
"g_object_unref(host->transparent_css_provider);",
|
|
1946
|
+
) orelse return error.TestExpectedEqual;
|
|
1947
|
+
const display_unref_at = std.mem.indexOf(
|
|
1948
|
+
u8,
|
|
1949
|
+
destroy,
|
|
1950
|
+
"g_object_unref(host->transparent_css_display);",
|
|
1951
|
+
) orelse return error.TestExpectedEqual;
|
|
1952
|
+
const app_unref_at = std.mem.indexOf(
|
|
1953
|
+
u8,
|
|
1954
|
+
destroy,
|
|
1955
|
+
"g_object_unref(host->app);",
|
|
1956
|
+
) orelse return error.TestExpectedEqual;
|
|
1957
|
+
try std.testing.expect(remove_at < provider_unref_at);
|
|
1958
|
+
try std.testing.expect(remove_at < display_unref_at);
|
|
1959
|
+
try std.testing.expect(remove_at < app_unref_at);
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
test "linux passive show restores minimized windows without presenting them" {
|
|
1963
|
+
const host_source = @embedFile("gtk_host.c");
|
|
1964
|
+
const show_at = std.mem.indexOf(
|
|
1965
|
+
u8,
|
|
1966
|
+
host_source,
|
|
1967
|
+
"int native_sdk_gtk_show_window",
|
|
1968
|
+
) orelse return error.TestExpectedEqual;
|
|
1969
|
+
const show_end = std.mem.indexOfPos(
|
|
1970
|
+
u8,
|
|
1971
|
+
host_source,
|
|
1972
|
+
show_at,
|
|
1973
|
+
"int native_sdk_gtk_minimize_window",
|
|
1974
|
+
) orelse return error.TestExpectedEqual;
|
|
1975
|
+
const show = host_source[show_at..show_end];
|
|
1976
|
+
const unminimize_at = std.mem.indexOf(
|
|
1977
|
+
u8,
|
|
1978
|
+
show,
|
|
1979
|
+
"if (!win->activate_on_show) gtk_window_unminimize(win->gtk_window);",
|
|
1980
|
+
) orelse return error.TestExpectedEqual;
|
|
1981
|
+
const present_at = std.mem.indexOf(
|
|
1982
|
+
u8,
|
|
1983
|
+
show,
|
|
1984
|
+
"native_sdk_show_window_implicit(win);",
|
|
1985
|
+
) orelse return error.TestExpectedEqual;
|
|
1986
|
+
try std.testing.expect(unminimize_at < present_at);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1842
1989
|
test "linux webview presses report the focused child label" {
|
|
1843
1990
|
// The capture-phase observer watches without claiming WebKit's
|
|
1844
1991
|
// gesture; it exists solely to mirror the focus edge into runtime
|
|
@@ -1849,6 +1996,48 @@ test "linux webview presses report the focused child label" {
|
|
|
1849
1996
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_watch_webview_pointer_focus(win, web_view);") != null);
|
|
1850
1997
|
}
|
|
1851
1998
|
|
|
1999
|
+
test "linux first-present windows stay unmapped until present with a cancellable fallback" {
|
|
2000
|
+
const host_source = @embedFile("gtk_host.c");
|
|
2001
|
+
try std.testing.expect(std.mem.indexOf(
|
|
2002
|
+
u8,
|
|
2003
|
+
host_source,
|
|
2004
|
+
"g_timeout_add(1000, native_sdk_deferred_show_timeout, win)",
|
|
2005
|
+
) != null);
|
|
2006
|
+
try std.testing.expect(std.mem.indexOf(
|
|
2007
|
+
u8,
|
|
2008
|
+
host_source,
|
|
2009
|
+
"native_sdk_cancel_deferred_show(win);",
|
|
2010
|
+
) != null);
|
|
2011
|
+
try std.testing.expect(std.mem.indexOf(
|
|
2012
|
+
u8,
|
|
2013
|
+
host_source,
|
|
2014
|
+
"gtk_widget_set_opacity(GTK_WIDGET(win->gtk_window), 0)",
|
|
2015
|
+
) == null);
|
|
2016
|
+
const first_present_at = std.mem.indexOf(
|
|
2017
|
+
u8,
|
|
2018
|
+
host_source,
|
|
2019
|
+
"if (first_present && win && !win->shown)",
|
|
2020
|
+
) orelse return error.TestExpectedEqual;
|
|
2021
|
+
const first_present_tail = host_source[first_present_at..];
|
|
2022
|
+
const cancel_at = std.mem.indexOf(
|
|
2023
|
+
u8,
|
|
2024
|
+
first_present_tail,
|
|
2025
|
+
"native_sdk_cancel_deferred_show(win);",
|
|
2026
|
+
) orelse return error.TestExpectedEqual;
|
|
2027
|
+
const show_at = std.mem.indexOf(
|
|
2028
|
+
u8,
|
|
2029
|
+
first_present_tail,
|
|
2030
|
+
"native_sdk_show_window_implicit(win);",
|
|
2031
|
+
) orelse return error.TestExpectedEqual;
|
|
2032
|
+
const queue_draw_at = std.mem.indexOf(
|
|
2033
|
+
u8,
|
|
2034
|
+
first_present_tail,
|
|
2035
|
+
"gtk_widget_queue_draw(view->widget);",
|
|
2036
|
+
) orelse return error.TestExpectedEqual;
|
|
2037
|
+
try std.testing.expect(cancel_at < show_at);
|
|
2038
|
+
try std.testing.expect(show_at < queue_draw_at);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
1852
2041
|
test "linux refuses a .hide main window at platform init instead of a silent quit-on-close" {
|
|
1853
2042
|
// The pre-created MAIN window never passes through the runtime's
|
|
1854
2043
|
// create gate, so the platform's init gate must hold the same
|
|
@@ -372,7 +372,7 @@ typedef void (*native_sdk_appkit_bridge_callback_t)(void *context, uint64_t wind
|
|
|
372
372
|
// non-empty. has_web_content declares whether the app hosts a webview;
|
|
373
373
|
// web-only default menu items (Reload, Toggle Web Inspector, Undo/Redo)
|
|
374
374
|
// exist only when it is set.
|
|
375
|
-
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);
|
|
375
|
+
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);
|
|
376
376
|
void native_sdk_appkit_destroy(native_sdk_appkit_host_t *host);
|
|
377
377
|
// Adopt pre-rendered straight-alpha RGBA8 pixels as the Dock icon (and
|
|
378
378
|
// the About panel copy). The pixels are copied before return, so the
|
|
@@ -411,7 +411,7 @@ void native_sdk_appkit_emit_window_event(native_sdk_appkit_host_t *host, uint64_
|
|
|
411
411
|
void native_sdk_appkit_set_security_policy(native_sdk_appkit_host_t *host, const char *allowed_origins, size_t allowed_origins_len, const char *external_urls, size_t external_urls_len, int external_action);
|
|
412
412
|
void native_sdk_appkit_set_menus(native_sdk_appkit_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);
|
|
413
413
|
void native_sdk_appkit_set_shortcuts(native_sdk_appkit_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);
|
|
414
|
-
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);
|
|
414
|
+
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);
|
|
415
415
|
// Content min-size floor for a created window (NSWindow contentMinSize):
|
|
416
416
|
// the user's resize stops at the floor. Values <= 0 leave that axis at
|
|
417
417
|
// AppKit's default minimum. Returns 0 when the window id is unknown.
|
|
@@ -415,6 +415,12 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
415
415
|
@property(nonatomic, strong) CAMetalLayer *metalLayer;
|
|
416
416
|
@property(nonatomic, strong) id<MTLBuffer> sampleBuffer;
|
|
417
417
|
@property(nonatomic, strong) id<MTLTexture> canvasTexture;
|
|
418
|
+
/* Reused conversion storage for the CPU reference renderer's
|
|
419
|
+
* straight-alpha RGBA8 frames. A nonopaque CAMetalLayer participates in
|
|
420
|
+
* Core Animation's premultiplied-alpha compositing, so software
|
|
421
|
+
* fallbacks must enter the shared canvas texture in the same encoding
|
|
422
|
+
* as packet-rendered frames. */
|
|
423
|
+
@property(nonatomic, strong) NSMutableData *canvasPixelUploadScratch;
|
|
418
424
|
@property(nonatomic, strong) id<MTLRenderPipelineState> canvasRenderPipeline;
|
|
419
425
|
@property(nonatomic, strong) id<MTLSamplerState> canvasSampler;
|
|
420
426
|
@property(nonatomic, assign) CGColorSpaceRef canvasColorSpace;
|
|
@@ -624,7 +630,7 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
624
630
|
- (void)configureWithHost:(NativeSdkAppKitHost *)host windowId:(uint64_t)windowId label:(NSString *)label;
|
|
625
631
|
- (BOOL)isAvailable;
|
|
626
632
|
- (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;
|
|
633
|
+
- (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects sourceIsPremultiplied:(BOOL)sourceIsPremultiplied rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength;
|
|
628
634
|
- (NSInteger)presentGpuPacketWithSurfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA requiresRender:(BOOL)requiresRender commandCount:(NSUInteger)commandCount unsupportedCommandCount:(NSUInteger)unsupportedCommandCount representable:(BOOL)representable json:(const uint8_t *)json byteLength:(NSUInteger)byteLength;
|
|
629
635
|
- (NSInteger)presentGpuPacketBinaryWithSurfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA requiresRender:(BOOL)requiresRender commandCount:(NSUInteger)commandCount unsupportedCommandCount:(NSUInteger)unsupportedCommandCount representable:(BOOL)representable packet:(const uint8_t *)packet byteLength:(NSUInteger)byteLength;
|
|
630
636
|
- (NSInteger)presentGpuPacketObject:(NSDictionary *)packet surfaceWidth:(CGFloat)surfaceWidth height:(CGFloat)surfaceHeight scale:(CGFloat)scale clearR:(uint8_t)clearR clearG:(uint8_t)clearG clearB:(uint8_t)clearB clearA:(uint8_t)clearA commandCount:(NSUInteger)commandCount;
|
|
@@ -718,6 +724,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
718
724
|
/// the delegate's windowShouldClose: consults it, so the user's close
|
|
719
725
|
/// affordance hides a .hide window instead of closing it.
|
|
720
726
|
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSNumber *> *windowClosePolicies;
|
|
727
|
+
/// Windows whose implicit reveal is passive (`activate_on_show=false`).
|
|
728
|
+
/// Explicit focusWindow bypasses this set and activates deliberately.
|
|
729
|
+
@property(nonatomic, strong) NSMutableSet<NSNumber *> *passiveShowWindows;
|
|
721
730
|
/// Windows currently hidden BY their .hide close policy — the set the
|
|
722
731
|
/// Dock reopen re-shows, and the truth emitWindowFrameForWindowId's
|
|
723
732
|
/// hidden flag reports. Ordinary orderOut/minimize states never enter
|
|
@@ -911,8 +920,9 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
911
920
|
@property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
|
|
912
921
|
@property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
|
|
913
922
|
@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;
|
|
923
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags;
|
|
924
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
925
|
+
- (void)orderWindowForImplicitShow:(uint64_t)windowId;
|
|
916
926
|
- (void)showDeferredWindowIfPending:(uint64_t)windowId reason:(const char *)reason;
|
|
917
927
|
- (void)applyWindowClearColor:(uint64_t)windowId red:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha;
|
|
918
928
|
- (void)focusWindowWithId:(uint64_t)windowId;
|
|
@@ -1223,6 +1233,7 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
|
|
|
1223
1233
|
[self.host.deferredShowWindows removeObjectForKey:key];
|
|
1224
1234
|
[self.host.windowClearColors removeObjectForKey:key];
|
|
1225
1235
|
[self.host.windowClosePolicies removeObjectForKey:key];
|
|
1236
|
+
[self.host.passiveShowWindows removeObject:key];
|
|
1226
1237
|
if (self.host.windows.count == 0) {
|
|
1227
1238
|
[self.host emitShutdown];
|
|
1228
1239
|
[self.host stop];
|
|
@@ -3513,6 +3524,18 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
|
|
|
3513
3524
|
|
|
3514
3525
|
@end
|
|
3515
3526
|
|
|
3527
|
+
static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *destination, NSUInteger pixelCount) {
|
|
3528
|
+
if (!source || !destination) return;
|
|
3529
|
+
for (NSUInteger index = 0; index < pixelCount; index += 1) {
|
|
3530
|
+
const NSUInteger offset = index * 4;
|
|
3531
|
+
const uint32_t alpha = source[offset + 3];
|
|
3532
|
+
destination[offset + 0] = (uint8_t)((source[offset + 0] * alpha + 127) / 255);
|
|
3533
|
+
destination[offset + 1] = (uint8_t)((source[offset + 1] * alpha + 127) / 255);
|
|
3534
|
+
destination[offset + 2] = (uint8_t)((source[offset + 2] * alpha + 127) / 255);
|
|
3535
|
+
destination[offset + 3] = (uint8_t)alpha;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3516
3539
|
@implementation NativeSdkMetalSurfaceView
|
|
3517
3540
|
|
|
3518
3541
|
- (instancetype)initWithFrame:(NSRect)frameRect {
|
|
@@ -3592,11 +3615,12 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
|
|
|
3592
3615
|
}
|
|
3593
3616
|
|
|
3594
3617
|
- (BOOL)isOpaque {
|
|
3595
|
-
return YES;
|
|
3618
|
+
return self.window ? self.window.opaque : YES;
|
|
3596
3619
|
}
|
|
3597
3620
|
|
|
3598
3621
|
- (void)viewDidMoveToWindow {
|
|
3599
3622
|
[super viewDidMoveToWindow];
|
|
3623
|
+
self.metalLayer.opaque = self.window ? self.window.opaque : YES;
|
|
3600
3624
|
self.window.acceptsMouseMovedEvents = YES;
|
|
3601
3625
|
[self updateDrawableSize];
|
|
3602
3626
|
[self updateSurfaceTrackingArea];
|
|
@@ -3686,11 +3710,27 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
|
|
|
3686
3710
|
}
|
|
3687
3711
|
}
|
|
3688
3712
|
|
|
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 {
|
|
3713
|
+
- (BOOL)presentPixelsWithWidth:(NSUInteger)width height:(NSUInteger)height scale:(CGFloat)scale hasDirtyRect:(BOOL)hasDirtyRect dirtyX:(CGFloat)dirtyX dirtyY:(CGFloat)dirtyY dirtyWidth:(CGFloat)dirtyWidth dirtyHeight:(CGFloat)dirtyHeight dirtyRects:(NSArray<NSValue *> *)dirtyRects sourceIsPremultiplied:(BOOL)sourceIsPremultiplied rgba8:(const uint8_t *)rgba8 byteLength:(NSUInteger)byteLength {
|
|
3690
3714
|
if (![self isAvailable] || !rgba8 || width == 0 || height == 0) return NO;
|
|
3691
3715
|
if (byteLength != width * height * 4) return NO;
|
|
3692
3716
|
if (![self ensureCanvasPresenter]) return NO;
|
|
3693
3717
|
|
|
3718
|
+
const uint8_t *presentBytes = rgba8;
|
|
3719
|
+
/* Raw runtime presents carry straight RGBA, while the packet renderer's
|
|
3720
|
+
* Core Graphics context already writes premultiplied RGBA. Metal blends
|
|
3721
|
+
* both through the same premultiplied-alpha texture contract. */
|
|
3722
|
+
if (self.window && !self.window.opaque && !sourceIsPremultiplied) {
|
|
3723
|
+
if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) {
|
|
3724
|
+
self.canvasPixelUploadScratch = [NSMutableData dataWithLength:byteLength];
|
|
3725
|
+
}
|
|
3726
|
+
if (!self.canvasPixelUploadScratch || self.canvasPixelUploadScratch.length != byteLength) return NO;
|
|
3727
|
+
NativeSdkPremultiplyStraightRgba8(
|
|
3728
|
+
rgba8,
|
|
3729
|
+
self.canvasPixelUploadScratch.mutableBytes,
|
|
3730
|
+
byteLength / 4);
|
|
3731
|
+
presentBytes = self.canvasPixelUploadScratch.bytes;
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3694
3734
|
BOOL textureChanged = NO;
|
|
3695
3735
|
if (!self.canvasTexture || self.canvasTextureWidth != width || self.canvasTextureHeight != height) {
|
|
3696
3736
|
MTLTextureDescriptor *descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:width height:height mipmapped:NO];
|
|
@@ -3764,21 +3804,21 @@ static NSDictionary *NativeSdkPacketDictionaryFromBinary(const uint8_t *bytes, N
|
|
|
3764
3804
|
return YES;
|
|
3765
3805
|
}
|
|
3766
3806
|
}
|
|
3767
|
-
const uint8_t *uploadBytes =
|
|
3807
|
+
const uint8_t *uploadBytes = presentBytes + ((uploadY * width + uploadX) * 4);
|
|
3768
3808
|
[self.canvasTexture replaceRegion:MTLRegionMake2D(uploadX, uploadY, uploadWidth, uploadHeight)
|
|
3769
3809
|
mipmapLevel:0
|
|
3770
3810
|
withBytes:uploadBytes
|
|
3771
3811
|
bytesPerRow:width * 4];
|
|
3772
3812
|
if (backingBytes) {
|
|
3773
3813
|
if (uploadFullTexture) {
|
|
3774
|
-
memcpy(backingBytes,
|
|
3814
|
+
memcpy(backingBytes, presentBytes, byteLength);
|
|
3775
3815
|
/* A full foreign upload (raw-pixels present) makes the
|
|
3776
3816
|
* backing match the glass byte-for-byte again. */
|
|
3777
3817
|
self.canvasPacketPixelsValid = YES;
|
|
3778
3818
|
} else {
|
|
3779
3819
|
for (NSUInteger row = 0; row < uploadHeight; row++) {
|
|
3780
3820
|
const NSUInteger rowOffset = ((uploadY + row) * width + uploadX) * 4;
|
|
3781
|
-
memcpy((uint8_t *)backingBytes + rowOffset,
|
|
3821
|
+
memcpy((uint8_t *)backingBytes + rowOffset, presentBytes + rowOffset, uploadWidth * 4);
|
|
3782
3822
|
}
|
|
3783
3823
|
}
|
|
3784
3824
|
}
|
|
@@ -5302,7 +5342,7 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5302
5342
|
}
|
|
5303
5343
|
|
|
5304
5344
|
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];
|
|
5345
|
+
BOOL presented = [self presentPixelsWithWidth:pixelWidth height:pixelHeight scale:normalizedScale hasDirtyRect:uploadDirtyRect dirtyX:scissorRect.origin.x dirtyY:scissorRect.origin.y dirtyWidth:scissorRect.size.width dirtyHeight:scissorRect.size.height dirtyRects:(uploadDirtyRect ? dirtyRects : nil) sourceIsPremultiplied:YES rgba8:(const uint8_t *)pixels.bytes byteLength:pixels.length];
|
|
5306
5346
|
if (getenv("NATIVE_SDK_GPU_DRAW_TRACE")) {
|
|
5307
5347
|
/* Per-present phase split (draw vs texture upload + Metal present),
|
|
5308
5348
|
* NATIVE_SDK_WINDOW_TIMING-style stderr diagnostics. */
|
|
@@ -5823,12 +5863,22 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5823
5863
|
const double red = self.hasCanvasTexture ? 0.965 : 0.10 + 0.08 * sin(phase * 6.283185307179586);
|
|
5824
5864
|
const double green = self.hasCanvasTexture ? 0.973 : 0.18 + 0.10 * sin((phase + 0.33) * 6.283185307179586);
|
|
5825
5865
|
const double blue = self.hasCanvasTexture ? 0.988 : 0.34 + 0.16 * sin((phase + 0.66) * 6.283185307179586);
|
|
5866
|
+
const BOOL transparentWindow = window != nil && !window.opaque;
|
|
5826
5867
|
|
|
5827
5868
|
MTLRenderPassDescriptor *descriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
|
5828
5869
|
descriptor.colorAttachments[0].texture = drawable.texture;
|
|
5829
5870
|
descriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
|
5830
5871
|
descriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
|
5831
|
-
|
|
5872
|
+
// The clear remains visible when the renderer has not supplied a
|
|
5873
|
+
// canvas texture yet, and briefly while a resize's retained texture
|
|
5874
|
+
// does not match the new drawable. An opaque placeholder is useful
|
|
5875
|
+
// for an ordinary window, but it defeats a transparent overlay's
|
|
5876
|
+
// contract exactly when the late-reveal fallback exposes that state.
|
|
5877
|
+
// Clear transparent glass to transparent black (valid premultiplied
|
|
5878
|
+
// alpha); a matching canvas texture still draws over the whole pass.
|
|
5879
|
+
descriptor.colorAttachments[0].clearColor = transparentWindow
|
|
5880
|
+
? MTLClearColorMake(0.0, 0.0, 0.0, 0.0)
|
|
5881
|
+
: MTLClearColorMake(red, green, blue, 1.0);
|
|
5832
5882
|
|
|
5833
5883
|
id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
|
|
5834
5884
|
if (!commandBuffer) return;
|
|
@@ -7133,7 +7183,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7133
7183
|
|
|
7134
7184
|
@implementation NativeSdkAppKitHost
|
|
7135
7185
|
|
|
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 {
|
|
7186
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags {
|
|
7137
7187
|
self = [super init];
|
|
7138
7188
|
if (!self) {
|
|
7139
7189
|
return nil;
|
|
@@ -7162,6 +7212,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7162
7212
|
self.deferredShowWindows = [[NSMutableDictionary alloc] init];
|
|
7163
7213
|
self.windowClearColors = [[NSMutableDictionary alloc] init];
|
|
7164
7214
|
self.windowClosePolicies = [[NSMutableDictionary alloc] init];
|
|
7215
|
+
self.passiveShowWindows = [[NSMutableSet alloc] init];
|
|
7165
7216
|
self.policyHiddenWindows = [[NSMutableSet alloc] init];
|
|
7166
7217
|
self.childWebViews = [[NSMutableDictionary alloc] init];
|
|
7167
7218
|
self.nativeViews = [[NSMutableDictionary alloc] init];
|
|
@@ -7178,7 +7229,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7178
7229
|
[self configureApplication];
|
|
7179
7230
|
NativeSdkLaunchLap("app_configured");
|
|
7180
7231
|
|
|
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];
|
|
7232
|
+
[self createWindowWithId:1 title:(windowTitle.length > 0 ? windowTitle : self.appName) label:self.windowLabel x:x y:y width:width height:height restoreFrame:restoreFrame resizable:resizable titlebarStyle:titlebarStyle showPolicy:showPolicy windowFlags:windowFlags makeMain:YES];
|
|
7182
7233
|
self.didShutdown = NO;
|
|
7183
7234
|
self.pendingPreRunStop = NO;
|
|
7184
7235
|
self.observesApplicationActivation = NO;
|
|
@@ -7186,7 +7237,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7186
7237
|
return self;
|
|
7187
7238
|
}
|
|
7188
7239
|
|
|
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 {
|
|
7240
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
7190
7241
|
NSNumber *key = @(windowId);
|
|
7191
7242
|
if (self.windows[key]) {
|
|
7192
7243
|
return NO;
|
|
@@ -7243,6 +7294,15 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7243
7294
|
// next autorelease-pool drain; the main window only ever closes at
|
|
7244
7295
|
// shutdown, which is why this stayed hidden until windows_fn).
|
|
7245
7296
|
window.releasedWhenClosed = NO;
|
|
7297
|
+
// Overlay behavior is installed before the first order-front so no
|
|
7298
|
+
// opaque, focus-taking, or interactive intermediate window can flash.
|
|
7299
|
+
if ((windowFlags & (1u << 0)) != 0) {
|
|
7300
|
+
window.opaque = NO;
|
|
7301
|
+
window.backgroundColor = NSColor.clearColor;
|
|
7302
|
+
}
|
|
7303
|
+
if ((windowFlags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
|
|
7304
|
+
if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
|
|
7305
|
+
if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
|
|
7246
7306
|
[window setTitle:(title.length > 0 ? title : self.appName)];
|
|
7247
7307
|
if (titlebarStyle == 1 || titlebarStyle == 2) {
|
|
7248
7308
|
window.titlebarAppearsTransparent = YES;
|
|
@@ -7314,12 +7374,27 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7314
7374
|
self.delegate = delegate;
|
|
7315
7375
|
self.windowLabel = label.length > 0 ? label : @"main";
|
|
7316
7376
|
} else if (showPolicy != 1) {
|
|
7317
|
-
[
|
|
7318
|
-
[NSApp activate];
|
|
7377
|
+
[self orderWindowForImplicitShow:windowId];
|
|
7319
7378
|
}
|
|
7320
7379
|
return YES;
|
|
7321
7380
|
}
|
|
7322
7381
|
|
|
7382
|
+
// Implicit shows honor `activate_on_show`: passive overlays are ordered
|
|
7383
|
+
// front without changing the active app or key window. Explicit focus
|
|
7384
|
+
// continues to activate and makeKeyAndOrderFront. Activation comes
|
|
7385
|
+
// first: a first-present window can reveal while the app is inactive,
|
|
7386
|
+
// and asking that inactive app to make a window key is only best effort.
|
|
7387
|
+
- (void)orderWindowForImplicitShow:(uint64_t)windowId {
|
|
7388
|
+
NSWindow *window = self.windows[@(windowId)];
|
|
7389
|
+
if (!window) return;
|
|
7390
|
+
if ([self.passiveShowWindows containsObject:@(windowId)]) {
|
|
7391
|
+
[window orderFront:nil];
|
|
7392
|
+
} else {
|
|
7393
|
+
[NSApp activate];
|
|
7394
|
+
[window makeKeyAndOrderFront:nil];
|
|
7395
|
+
}
|
|
7396
|
+
}
|
|
7397
|
+
|
|
7323
7398
|
// Order a deferred-show window front exactly once — from the first
|
|
7324
7399
|
// gpu-surface present (the contract), or from the fallback deadline.
|
|
7325
7400
|
// `NATIVE_SDK_WINDOW_TIMING=1` logs the create→show latency.
|
|
@@ -7334,8 +7409,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7334
7409
|
const double elapsedMs = (double)(NativeSdkTimestampNanoseconds() - createdNs.unsignedLongLongValue) / 1e6;
|
|
7335
7410
|
fprintf(stderr, "native-sdk: window %llu shown (%s) %.1f ms after create wall_ns=%llu\n", (unsigned long long)windowId, reason, elapsedMs, (unsigned long long)clock_gettime_nsec_np(CLOCK_REALTIME));
|
|
7336
7411
|
}
|
|
7337
|
-
[
|
|
7338
|
-
[NSApp activate];
|
|
7412
|
+
[self orderWindowForImplicitShow:windowId];
|
|
7339
7413
|
[self emitWindowFrameForWindowId:windowId open:YES];
|
|
7340
7414
|
[self scheduleFrame];
|
|
7341
7415
|
}
|
|
@@ -7386,8 +7460,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7386
7460
|
// An explicit focus overrides a pending present-before-show defer:
|
|
7387
7461
|
// the runtime asked for the window NOW.
|
|
7388
7462
|
[self.deferredShowWindows removeObjectForKey:@(windowId)];
|
|
7389
|
-
[window makeKeyAndOrderFront:nil];
|
|
7390
7463
|
[NSApp activate];
|
|
7464
|
+
[window makeKeyAndOrderFront:nil];
|
|
7391
7465
|
[self emitWindowFrameForWindowId:windowId open:YES];
|
|
7392
7466
|
[self scheduleFrame];
|
|
7393
7467
|
}
|
|
@@ -7430,7 +7504,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7430
7504
|
}
|
|
7431
7505
|
|
|
7432
7506
|
// The counterpart show verb: bring a hidden (or merely unfocused)
|
|
7433
|
-
// window back to the glass
|
|
7507
|
+
// window back to the glass, activating unless its creation-time
|
|
7508
|
+
// presentation policy is passive — the tray-menu
|
|
7434
7509
|
// "Open" consequence and the Dock reopen both land here. Also clears a
|
|
7435
7510
|
// pending present-before-show defer and a minimize, for the same
|
|
7436
7511
|
// reason focusWindowWithId: does: the runtime asked for the window NOW.
|
|
@@ -7440,8 +7515,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7440
7515
|
[self.policyHiddenWindows removeObject:@(windowId)];
|
|
7441
7516
|
[self.deferredShowWindows removeObjectForKey:@(windowId)];
|
|
7442
7517
|
if (window.miniaturized) [window deminiaturize:nil];
|
|
7443
|
-
[
|
|
7444
|
-
[NSApp activate];
|
|
7518
|
+
[self orderWindowForImplicitShow:windowId];
|
|
7445
7519
|
[self emitWindowFrameForWindowId:windowId open:YES];
|
|
7446
7520
|
[self scheduleFrame];
|
|
7447
7521
|
}
|
|
@@ -7975,7 +8049,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7975
8049
|
* resync. (The packet path calls presentPixelsWithWidth internally,
|
|
7976
8050
|
* so the invalidation lives here at the raw entry, not inside it.) */
|
|
7977
8051
|
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];
|
|
8052
|
+
const BOOL presented = [surface presentPixelsWithWidth:width height:height scale:scale hasDirtyRect:hasDirtyRect dirtyX:dirtyX dirtyY:dirtyY dirtyWidth:dirtyWidth dirtyHeight:dirtyHeight dirtyRects:nil sourceIsPremultiplied:NO rgba8:rgba8 byteLength:byteLength];
|
|
7979
8053
|
if (presented) [self showDeferredWindowIfPending:windowId reason:"first-present"];
|
|
7980
8054
|
return presented;
|
|
7981
8055
|
}
|
|
@@ -9064,9 +9138,8 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
|
|
|
9064
9138
|
// here and appears when its first canvas present lands (or the
|
|
9065
9139
|
// create-time fallback deadline fires).
|
|
9066
9140
|
if (!self.deferredShowWindows[@1]) {
|
|
9067
|
-
[self
|
|
9141
|
+
[self orderWindowForImplicitShow:1];
|
|
9068
9142
|
}
|
|
9069
|
-
[NSApp activate];
|
|
9070
9143
|
if (!self.shortcutEventMonitor) {
|
|
9071
9144
|
__weak NativeSdkAppKitHost *weakSelf = self;
|
|
9072
9145
|
self.shortcutEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
|
|
@@ -11434,7 +11507,7 @@ static BOOL NativeSdkPolicyListMatches(NSArray<NSString *> *values, NSURL *url)
|
|
|
11434
11507
|
return NO;
|
|
11435
11508
|
}
|
|
11436
11509
|
|
|
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) {
|
|
11510
|
+
native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
11438
11511
|
@autoreleasepool {
|
|
11439
11512
|
NSString *appNameString = [[NSString alloc] initWithBytes:app_name length:app_name_len encoding:NSUTF8StringEncoding] ?: @"native-sdk";
|
|
11440
11513
|
NSString *displayNameString = [[NSString alloc] initWithBytes:display_name length:display_name_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
@@ -11444,7 +11517,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
11444
11517
|
NSString *bundleIdString = [[NSString alloc] initWithBytes:bundle_id length:bundle_id_len encoding:NSUTF8StringEncoding] ?: @"dev.native_sdk.app";
|
|
11445
11518
|
NSString *iconPathString = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
11446
11519
|
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];
|
|
11520
|
+
NativeSdkAppKitHost *host = [[NativeSdkAppKitHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString hasWebContent:(has_web_content != 0) windowTitle:windowTitleString bundleIdentifier:bundleIdString iconPath:iconPathString windowLabel:windowLabelString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags];
|
|
11448
11521
|
return (__bridge_retained native_sdk_appkit_host_t *)host;
|
|
11449
11522
|
}
|
|
11450
11523
|
}
|
|
@@ -11742,11 +11815,11 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
|
|
|
11742
11815
|
[object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
|
|
11743
11816
|
}
|
|
11744
11817
|
|
|
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) {
|
|
11818
|
+
int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
11746
11819
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
11747
11820
|
NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"";
|
|
11748
11821
|
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;
|
|
11822
|
+
return [object createWindowWithId:window_id title:titleString ?: @"" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags makeMain:NO] ? 1 : 0;
|
|
11750
11823
|
}
|
|
11751
11824
|
|
|
11752
11825
|
int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host, uint64_t window_id, double min_width, double min_height) {
|