Skip to content

Commit af94549

Browse files
committed
Added documentation
1 parent 993e197 commit af94549

28 files changed

Lines changed: 292 additions & 11 deletions

src/backends/linux_browser_host.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub const LaunchResult = struct {
66
is_child_process: bool = true,
77
};
88

9+
/// Launches a browser process and returns tracked process metadata when successful.
910
pub fn launchTracked(
1011
allocator: std.mem.Allocator,
1112
browser_path: []const u8,
@@ -30,6 +31,7 @@ pub fn launchTracked(
3031
};
3132
}
3233

34+
/// Opens a URL using an existing browser installation path.
3335
pub fn openUrlInExistingInstall(
3436
allocator: std.mem.Allocator,
3537
browser_path: []const u8,
@@ -39,13 +41,15 @@ pub fn openUrlInExistingInstall(
3941
return launched != null;
4042
}
4143

44+
/// Terminates a tracked browser process on Linux.
4245
pub fn terminateProcess(_: std.mem.Allocator, pid_value: i64) void {
4346
if (pid_value <= 0) return;
4447
const pid: std.posix.pid_t = @intCast(pid_value);
4548
std.posix.kill(pid, std.posix.SIG.TERM) catch {};
4649
std.posix.kill(pid, std.posix.SIG.KILL) catch {};
4750
}
4851

52+
/// Returns whether the tracked browser process is still alive.
4953
pub fn isProcessAlive(_: std.mem.Allocator, pid_value: i64) bool {
5054
if (pid_value <= 0) return false;
5155

@@ -60,6 +64,7 @@ pub fn isProcessAlive(_: std.mem.Allocator, pid_value: i64) bool {
6064
return !isZombieProcessLinux(pid);
6165
}
6266

67+
/// Applies a coarse native window control action to the launched browser process.
6368
pub fn controlWindow(allocator: std.mem.Allocator, pid: i64, cmd: window_style_types.WindowControl) bool {
6469
if (pid <= 0) return false;
6570

src/backends/linux_webview/rounded_shape.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const std = @import("std");
22
const common = @import("common.zig");
33
const symbols_mod = @import("symbols.zig");
44

5+
/// Applies a rounded clip region to a GTK toplevel window when the runtime supports it.
56
pub fn applyRoundedWindowShape(
67
symbols: *const symbols_mod.Symbols,
78
corner_radius: ?u16,

src/backends/linux_webview/symbols.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub const Symbols = struct {
147147
cairo_fill: ?*const fn (*common.cairo_t) callconv(.c) void = null,
148148
cairo_region_destroy: ?*const fn (*common.cairo_region_t) callconv(.c) void = null,
149149

150+
/// \Uload for.
150151
pub fn loadFor(target: RuntimeTarget) !Symbols {
151152
var syms: Symbols = undefined;
152153
try syms.loadDynLibs(target);
@@ -155,6 +156,7 @@ pub const Symbols = struct {
155156
return syms;
156157
}
157158

159+
/// Releases resources owned by this value.
158160
pub fn deinit(self: *Symbols) void {
159161
_ = self;
160162
// Intentionally do not dlclose GTK/WebKit/GLib stacks at runtime.
@@ -165,6 +167,7 @@ pub const Symbols = struct {
165167
// Process-exit cleanup is sufficient for this host runtime.
166168
}
167169

170+
/// Returns init toolkit.
168171
pub fn initToolkit(self: *const Symbols) void {
169172
if (self.gtk_api == .gtk4) {
170173
if (self.gtk_init_gtk4) |init| {
@@ -175,13 +178,15 @@ pub const Symbols = struct {
175178
if (self.gtk_init_gtk3) |init| init(null, null);
176179
}
177180

181+
/// Returns new top level window.
178182
pub fn newTopLevelWindow(self: *const Symbols) ?*common.GtkWidget {
179183
return switch (self.gtk_api) {
180184
.gtk3 => if (self.gtk_window_new_gtk3) |create| create(common.GTK_WINDOW_TOPLEVEL) else null,
181185
.gtk4 => if (self.gtk_window_new_gtk4) |create| create() else null,
182186
};
183187
}
184188

189+
/// Returns add window child.
185190
pub fn addWindowChild(self: *const Symbols, window_widget: *common.GtkWidget, child_widget: *common.GtkWidget) ?*common.GtkWidget {
186191
switch (self.gtk_api) {
187192
.gtk3 => {
@@ -212,15 +217,18 @@ pub const Symbols = struct {
212217
}
213218
}
214219

220+
/// \Ushow window.
215221
pub fn showWindow(self: *const Symbols, window_widget: *common.GtkWidget, child_widget: *common.GtkWidget) void {
216222
self.gtk_widget_show(child_widget);
217223
self.gtk_widget_show(window_widget);
218224
}
219225

226+
/// \Uqueue widget draw.
220227
pub fn queueWidgetDraw(self: *const Symbols, widget: *common.GtkWidget) void {
221228
if (self.gtk_widget_queue_draw) |queue_draw| queue_draw(widget);
222229
}
223230

231+
/// \Udestroy window.
224232
pub fn destroyWindow(self: *const Symbols, window_widget: *common.GtkWidget) void {
225233
switch (self.gtk_api) {
226234
.gtk3 => {
@@ -241,14 +249,17 @@ pub const Symbols = struct {
241249
}
242250
}
243251

252+
/// \Uset window position center.
244253
pub fn setWindowPositionCenter(self: *const Symbols, window: *common.GtkWindow) void {
245254
if (self.gtk_window_set_position) |set_pos| set_pos(window, common.GTK_WIN_POS_CENTER);
246255
}
247256

257+
/// \Uset window position.
248258
pub fn setWindowPosition(self: *const Symbols, window: *common.GtkWindow, x: c_int, y: c_int) void {
249259
if (self.gtk_window_move) |move| move(window, x, y);
250260
}
251261

262+
/// \Uapply transparent visual.
252263
pub fn applyTransparentVisual(self: *const Symbols, window_widget: *common.GtkWidget) void {
253264
switch (self.gtk_api) {
254265
.gtk3 => {
@@ -269,6 +280,7 @@ pub const Symbols = struct {
269280
}
270281
}
271282

283+
/// \Uapply gtk4 window style.
272284
pub fn applyGtk4WindowStyle(
273285
self: *const Symbols,
274286
window_widget: *common.GtkWidget,
@@ -318,6 +330,7 @@ pub const Symbols = struct {
318330
}
319331
}
320332

333+
/// \Uminimize window.
321334
pub fn minimizeWindow(self: *const Symbols, window: *common.GtkWindow) void {
322335
if (self.gtk_window_iconify) |iconify| {
323336
iconify(window);
@@ -326,6 +339,7 @@ pub const Symbols = struct {
326339
if (self.gtk_window_minimize) |minimize| minimize(window);
327340
}
328341

342+
/// \Uset window min size.
329343
pub fn setWindowMinSize(self: *const Symbols, window_widget: *common.GtkWidget, min_size: ?common.Size) void {
330344
const set_size = self.gtk_widget_set_size_request orelse return;
331345
if (min_size) |size| {
@@ -335,6 +349,7 @@ pub const Symbols = struct {
335349
}
336350
}
337351

352+
/// \Uset window kiosk.
338353
pub fn setWindowKiosk(self: *const Symbols, window: *common.GtkWindow, enabled: bool) void {
339354
if (enabled) {
340355
if (self.gtk_window_fullscreen) |fullscreen| fullscreen(window);
@@ -343,6 +358,7 @@ pub const Symbols = struct {
343358
}
344359
}
345360

361+
/// \Uset window high contrast.
346362
pub fn setWindowHighContrast(
347363
self: *const Symbols,
348364
window_widget: *common.GtkWidget,
@@ -380,6 +396,7 @@ pub const Symbols = struct {
380396
}
381397
}
382398

399+
/// \Uset window icon from path.
383400
pub fn setWindowIconFromPath(self: *const Symbols, window_widget: *common.GtkWidget, path_z: [*:0]const u8) void {
384401
const window: *common.GtkWindow = @ptrCast(window_widget);
385402

@@ -421,6 +438,7 @@ pub const Symbols = struct {
421438
set_icon_list(@ptrCast(surface), list);
422439
}
423440

441+
/// \Uclear window icon.
424442
pub fn clearWindowIcon(self: *const Symbols, window_widget: *common.GtkWidget) void {
425443
const window: *common.GtkWindow = @ptrCast(window_widget);
426444

@@ -440,6 +458,7 @@ pub const Symbols = struct {
440458
set_icon_list(@ptrCast(surface), null);
441459
}
442460

461+
/// Returns whether the rounded shape.
443462
pub fn supportsRoundedShape(self: *const Symbols) bool {
444463
return self.gtk_widget_shape_combine_region != null and
445464
self.gtk_widget_input_shape_combine_region != null and
@@ -458,6 +477,7 @@ pub const Symbols = struct {
458477
self.cairo_region_destroy != null;
459478
}
460479

480+
/// \Uset rounded region.
461481
pub fn setRoundedRegion(self: *const Symbols, window_widget: *common.GtkWidget, region: ?*common.cairo_region_t) void {
462482
if (self.gtk_widget_shape_combine_region) |shape| shape(window_widget, region);
463483
if (self.gtk_widget_input_shape_combine_region) |input_shape| input_shape(window_widget, region);

src/backends/linux_webview_host.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub const Host = struct {
5353
closed: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
5454
shutdown_requested: bool = false,
5555

56+
/// \Ustart.
5657
pub fn start(
5758
allocator: std.mem.Allocator,
5859
title: []const u8,
@@ -79,6 +80,7 @@ pub const Host = struct {
7980
return host;
8081
}
8182

83+
/// Releases resources owned by this value.
8284
pub fn deinit(self: *Host) void {
8385
_ = self.enqueue(.shutdown) catch {};
8486

@@ -129,30 +131,36 @@ pub const Host = struct {
129131
self.allocator.destroy(self);
130132
}
131133

134+
/// Returns whether the ready.
132135
pub fn isReady(self: *Host) bool {
133136
self.mutex.lock();
134137
defer self.mutex.unlock();
135138
return self.ui_ready and !self.closed.load(.acquire);
136139
}
137140

141+
/// Returns whether the closed.
138142
pub fn isClosed(self: *Host) bool {
139143
return self.closed.load(.acquire);
140144
}
141145

146+
/// \Unavigate.
142147
pub fn navigate(self: *Host, url: []const u8) !void {
143148
const duped = try self.allocator.dupe(u8, url);
144149
errdefer self.allocator.free(duped);
145150
try self.enqueue(.{ .navigate = duped });
146151
}
147152

153+
/// \Uapply style.
148154
pub fn applyStyle(self: *Host, style: WindowStyle) !void {
149155
try self.enqueue(.{ .apply_style = style });
150156
}
151157

158+
/// \Ucontrol.
152159
pub fn control(self: *Host, cmd: WindowControl) !void {
153160
try self.enqueue(.{ .control = cmd });
154161
}
155162

163+
/// Returns pump.
156164
pub fn pump(self: *Host) void {
157165
drainCommandsUiThread(self);
158166

@@ -237,6 +245,7 @@ fn initOnCurrentThread(host: *Host) !void {
237245
should_destroy_window = false;
238246
}
239247

248+
/// Returns runtime available for.
240249
pub fn runtimeAvailableFor(target: RuntimeTarget) bool {
241250
const cache_ptr = switch (target) {
242251
.webview => &probe_cache_webview,

src/backends/macos_browser_host.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub const LaunchResult = struct {
66
is_child_process: bool = true,
77
};
88

9+
/// Launches a browser process and returns tracked process metadata when successful.
910
pub fn launchTracked(
1011
allocator: std.mem.Allocator,
1112
browser_path: []const u8,
@@ -27,6 +28,7 @@ pub fn launchTracked(
2728
return .{ .pid = @as(i64, @intCast(child.id)), .is_child_process = true };
2829
}
2930

31+
/// Opens a URL using an existing browser installation path.
3032
pub fn openUrlInExistingInstall(
3133
allocator: std.mem.Allocator,
3234
browser_path: []const u8,
@@ -36,13 +38,15 @@ pub fn openUrlInExistingInstall(
3638
return launched != null;
3739
}
3840

41+
/// Terminates a tracked browser process on macOS.
3942
pub fn terminateProcess(_: std.mem.Allocator, pid_value: i64) void {
4043
if (pid_value <= 0) return;
4144
const pid: std.posix.pid_t = @intCast(pid_value);
4245
std.posix.kill(pid, std.posix.SIG.TERM) catch {};
4346
std.posix.kill(pid, std.posix.SIG.KILL) catch {};
4447
}
4548

49+
/// Returns whether the tracked browser process is still alive.
4650
pub fn isProcessAlive(_: std.mem.Allocator, pid_value: i64) bool {
4751
if (pid_value <= 0) return false;
4852

@@ -56,6 +60,7 @@ pub fn isProcessAlive(_: std.mem.Allocator, pid_value: i64) bool {
5660
return true;
5761
}
5862

63+
/// Applies a coarse native window control action to the launched browser process.
5964
pub fn controlWindow(allocator: std.mem.Allocator, pid: i64, cmd: window_style_types.WindowControl) bool {
6065
if (pid <= 0) return false;
6166

src/backends/macos_webview/bindings.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub const Symbols = struct {
1818
autorelease_pool_push: ObjcAutoreleasePoolPushFn,
1919
autorelease_pool_pop: ObjcAutoreleasePoolPopFn,
2020

21+
/// \Uload.
2122
pub fn load() !Symbols {
2223
var objc = try std.DynLib.open("/usr/lib/libobjc.A.dylib");
2324
errdefer objc.close();
@@ -46,6 +47,7 @@ pub const Symbols = struct {
4647
};
4748
}
4849

50+
/// Releases resources owned by this value.
4951
pub fn deinit(self: *Symbols) void {
5052
self.webkit.close();
5153
self.appkit.close();

src/backends/macos_webview_host.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub const Host = struct {
7979

8080
explicit_hidden: bool = false,
8181

82+
/// \Ustart.
8283
pub fn start(allocator: std.mem.Allocator, title: []const u8, style: WindowStyle) !*Host {
8384
if (!runtimeAvailable()) return error.NativeBackendUnavailable;
8485

@@ -116,6 +117,7 @@ pub const Host = struct {
116117
return host;
117118
}
118119

120+
/// Releases resources owned by this value.
119121
pub fn deinit(self: *Host) void {
120122
self.enqueue(.shutdown) catch {};
121123

@@ -134,26 +136,31 @@ pub const Host = struct {
134136
self.allocator.destroy(self);
135137
}
136138

139+
/// Returns whether the ready.
137140
pub fn isReady(self: *Host) bool {
138141
self.mutex.lock();
139142
defer self.mutex.unlock();
140143
return self.ui_ready and !self.closed.load(.acquire);
141144
}
142145

146+
/// Returns whether the closed.
143147
pub fn isClosed(self: *Host) bool {
144148
return self.closed.load(.acquire);
145149
}
146150

151+
/// \Unavigate.
147152
pub fn navigate(self: *Host, url: []const u8) !void {
148153
const duped = try self.allocator.dupe(u8, url);
149154
errdefer self.allocator.free(duped);
150155
try self.enqueue(.{ .navigate = duped });
151156
}
152157

158+
/// \Uapply style.
153159
pub fn applyStyle(self: *Host, style: WindowStyle) !void {
154160
try self.enqueue(.{ .apply_style = style });
155161
}
156162

163+
/// \Ucontrol.
157164
pub fn control(self: *Host, cmd: WindowControl) !void {
158165
try self.enqueue(.{ .control = cmd });
159166
}
@@ -173,6 +180,7 @@ pub const Host = struct {
173180
}
174181
};
175182

183+
/// Returns runtime available.
176184
pub fn runtimeAvailable() bool {
177185
if (builtin.os.tag != .macos) return false;
178186
var symbols = objc.Symbols.load() catch return false;

0 commit comments

Comments
 (0)