ReviewOS

also looking at this

craft-native/craft

feat: add Linux and Windows named-window routing

#325
Merged glennmichael123 wants to merge codex/multi-window-linux-windows into main
29 files +2250 -200

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/zig/src/linux.zigmodified+10-1
Changes to packages/zig/src/linux.zig
@@ -793,6 +793,14 @@ pub fn createWindow(title: []const u8, width: u32, height: u32, html: []const u8
793793}
794794
795795pub fn createWindowWithURL(title: []const u8, width: u32, height: u32, url: []const u8, style: WindowStyle) !*anyopaque {
796 return createStyledWindow(title, width, height, url, style, true);
797}
798
799pub fn createWindowWithHTML(title: []const u8, width: u32, height: u32, html: []const u8, style: WindowStyle) !*anyopaque {
800 return createStyledWindow(title, width, height, html, style, false);
801}
802
803fn createStyledWindow(title: []const u8, width: u32, height: u32, content: []const u8, style: WindowStyle, comptime is_url: bool) !*anyopaque {
796804 var window = try Window.create(.{
797805 .title = title,
798806 .width = width,
@@ -811,7 +819,8 @@ pub fn createWindowWithURL(title: []const u8, width: u32, height: u32, url: []co
811819 .allow_notifications = style.allow_notifications,
812820 .allow_clipboard = style.allow_clipboard,
813821 });
814 try window.loadURL(url);
822 errdefer window.close();
823 if (is_url) try window.loadURL(content) else try window.loadHTML(content);
815824 window.show();
816825 return window.gtk_window;
817826}
packages/zig/src/main.zigmodified+57-2
Changes to packages/zig/src/main.zig
@@ -170,6 +170,9 @@ pub const Window = struct {
170170 }
171171
172172 pub fn show(self: *Self) !void {
173 // Styled URL/HTML constructors already created and showed their native
174 // window. Creating it again here would duplicate the first page.
175 if (self.native_handle != null) return;
173176 switch (builtin.os.tag) {
174177 .macos => try self.showMacOS(),
175178 .linux => try self.showLinux(),
@@ -314,7 +317,7 @@ pub const App = struct {
314317 try self.windows.append(self.allocator, window);
315318 return window;
316319 } else {
317 return error.UnsupportedPlatform;
320 return self.createPortableWindow(title, width, height, html, style, false);
318321 }
319322 }
320323
@@ -328,8 +331,60 @@ pub const App = struct {
328331 try self.windows.append(self.allocator, window);
329332 return window;
330333 } else {
331 return error.UnsupportedPlatform;
334 return self.createPortableWindow(title, width, height, url, style, true);
335 }
336 }
337
338 fn createPortableWindow(self: *Self, title: []const u8, width: u32, height: u32, content: []const u8, style: WindowStyle, comptime is_url: bool) !*Window {
339 if (builtin.os.tag == .linux) {
340 const linux = ;
341 const native_style: linux.WindowStyle = .{
342 .frameless = style.frameless,
343 .transparent = style.transparent,
344 .always_on_top = style.always_on_top,
345 .resizable = style.resizable,
346 .fullscreen = style.fullscreen,
347 .x = style.x,
348 .y = style.y,
349 .dark_mode = style.dark_mode,
350 .dev_tools = style.dev_tools,
351 };
352 const native = if (is_url)
353 try linux.createWindowWithURL(title, width, height, content, native_style)
354 else
355 try linux.createWindowWithHTML(title, width, height, content, native_style);
356 errdefer linux.gtk_window_close(native);
357 return self.rememberPortableWindow(title, width, height, if (is_url) "" else content, native);
358 } else if (builtin.os.tag == .windows) {
359 const windows = ;
360 const native_style: windows.WindowStyle = .{
361 .frameless = style.frameless,
362 .transparent = style.transparent,
363 .always_on_top = style.always_on_top,
364 .resizable = style.resizable,
365 .fullscreen = style.fullscreen,
366 .x = style.x,
367 .y = style.y,
368 .dark_mode = style.dark_mode,
369 .dev_tools = style.dev_tools,
370 };
371 const native = if (is_url)
372 try windows.createWindowWithURL(title, width, height, content, native_style)
373 else
374 try windows.createWindowWithHTML(title, width, height, content, native_style);
375 errdefer _ = windows.DestroyWindow(native);
376 return self.rememberPortableWindow(title, width, height, if (is_url) "" else content, native);
332377 }
378 return error.UnsupportedPlatform;
379 }
380
381 fn rememberPortableWindow(self: *Self, title: []const u8, width: u32, height: u32, html: []const u8, native: *anyopaque) !*Window {
382 const window = try self.allocator.create(Window);
383 errdefer self.allocator.destroy(window);
384 window.* = Window.init(title, width, height, html);
385 window.native_handle = native;
386 try self.windows.append(self.allocator, window);
387 return window;
333388 }
334389
335390 /// Create a window with a native macOS sidebar (Finder-style with vibrancy) - HTML mode
packages/zig/src/windows.zigmodified+11-1
Changes to packages/zig/src/windows.zig
@@ -1549,6 +1549,14 @@ pub fn createWindow(title: []const u8, width: u32, height: u32, html: []const u8
15491549}
15501550
15511551pub fn createWindowWithURL(title: []const u8, width: u32, height: u32, url: []const u8, style: WindowStyle) !*anyopaque {
1552 return createStyledWindow(title, width, height, url, style, true);
1553}
1554
1555pub fn createWindowWithHTML(title: []const u8, width: u32, height: u32, html: []const u8, style: WindowStyle) !*anyopaque {
1556 return createStyledWindow(title, width, height, html, style, false);
1557}
1558
1559fn createStyledWindow(title: []const u8, width: u32, height: u32, content: []const u8, style: WindowStyle, comptime is_url: bool) !*anyopaque {
15521560 var window = try Window.create(.{
15531561 .title = title,
15541562 .width = width,
@@ -1558,11 +1566,13 @@ pub fn createWindowWithURL(title: []const u8, width: u32, height: u32, url: []co
15581566 .resizable = style.resizable,
15591567 .frameless = style.frameless,
15601568 .transparent = style.transparent,
1569 .always_on_top = style.always_on_top,
15611570 .fullscreen = style.fullscreen,
15621571 .dark_mode = style.dark_mode,
15631572 .dev_tools = style.dev_tools,
15641573 });
1565 try window.loadURL(url);
1574 errdefer window.close();
1575 if (is_url) try window.loadURL(content) else try window.loadHTML(content);
15661576 window.show();
15671577 return window.hwnd;
15681578}