Skip to content

Commit 30b5a6a

Browse files
authored
feat(webui): add focus and async wait bindings (#116)
Add `webui_focus()` to bring windows to front, and `webui_wait_async()` for non-blocking window closure checks. Update to latest webui beta.
1 parent fa9d191 commit 30b5a6a

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.minimum_zig_version = "0.14.0",
66
.dependencies = .{
77
.webui = .{
8-
.hash = "webui-2.5.0-beta.4-pxqD5Rb7NwBVEwKyEzxwKAprzUIYjN20Y_Wffl_SWVdg",
9-
.url = "https://github.com/webui-dev/webui/archive/8d7c13895935f821f01d62dfc7e0243a99668925.tar.gz",
8+
.hash = "webui-2.5.0-beta.4-pxqD5a53OADNensyGsjVC_i_ksZ_G1enGSSsVD6p2dgg",
9+
.url = "https://github.com/webui-dev/webui/archive/62bed203df456cb150bc088ed4f1b173526e9776.tar.gz",
1010
},
1111
},
1212
.paths = .{

src/c.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ pub extern fn webui_show_wv(window: usize, content: [*:0]const u8) callconv(.c)
170170
/// @example webui_set_kiosk(my_window, true);
171171
pub extern fn webui_set_kiosk(window: usize, status: bool) callconv(.c) void;
172172

173+
/// @brief Bring a window to the front and focus it.
174+
///
175+
/// @param window The window number
176+
///
177+
/// @example webui_focus(myWindow);
178+
pub extern fn webui_focus(window: usize) callconv(.c) void;
179+
173180
/// @brief Add a user-defined web browser's CLI parameters.
174181
///
175182
/// @param window The window number
@@ -215,6 +222,16 @@ pub extern fn webui_browser_exist(browser: Browser) callconv(.c) bool;
215222
/// @example webui_wait();
216223
pub extern fn webui_wait() callconv(.c) void;
217224

225+
/// @brief Wait asynchronously until all opened windows get closed.
226+
/// Note: In WebView mode, you need to call this from the main thread.
227+
///
228+
/// @return Returns True if more windows are still opened, False otherwise.
229+
///
230+
/// @example while (webui_wait_async()) {
231+
/// // Your main thread code here
232+
/// }
233+
pub extern fn webui_wait_async() callconv(.c) bool;
234+
218235
/// @brief Close a specific window only. The window object will still exist.
219236
/// All clients.
220237
///

src/webui.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ pub fn setKiosk(self: webui, status: bool) void {
165165
c.webui_set_kiosk(self.window_handle, status);
166166
}
167167

168+
/// Bring a window to the front and focus it.
169+
pub fn focus(self: webui) void {
170+
c.webui_focus(self.window_handle);
171+
}
172+
168173
/// Add a user-defined web browser's CLI parameters.
169174
pub fn setCustomParameters(self: webui, params: [:0]const u8) void {
170175
c.webui_set_custom_parameters(self.window_handle, params.ptr);
@@ -196,6 +201,12 @@ pub fn wait() void {
196201
c.webui_wait();
197202
}
198203

204+
/// Wait asynchronously until all opened windows get closed.
205+
/// Returns `true` while there are still windows open.
206+
pub fn waitAsync() bool {
207+
return c.webui_wait_async();
208+
}
209+
199210
/// Set a custom logger function.
200211
/// The logger callback receives the log level, message, and optional user data.
201212
pub fn setLogger(comptime logger: fn (level: LoggerLevel, log: []const u8, user_data: ?*anyopaque) void, user_data: ?*anyopaque) void {

0 commit comments

Comments
 (0)