webview_sys/
lib.rs

1//! Raw FFI bindings to [webview].
2//!
3//! To use a custom version of webview, define an environment variable `WEBVIEW_DIR` with the path
4//! to its source directory.
5//!
6//! [webview]: https://github.com/zserge/webview
7
8#[cfg(all(target_family = "unix", not(target_os = "macos")))]
9mod gtk;
10
11use std::os::raw::*;
12
13pub enum CWebView {} // opaque type, only used in ffi pointers
14
15type ErasedExternalInvokeFn = extern "C" fn(webview: *mut CWebView, arg: *const c_char);
16type ErasedDispatchFn = extern "C" fn(webview: *mut CWebView, arg: *mut c_void);
17
18extern "C" {
19    pub fn webview_free(this: *mut CWebView);
20    pub fn webview_new(
21        title: *const c_char,
22        url: *const c_char,
23        width: c_int,
24        height: c_int,
25        resizable: c_int,
26        debug: c_int,
27        frameless: c_int,
28        visible: c_int,
29        min_width: c_int,
30        min_height: c_int,
31        external_invoke_cb: Option<ErasedExternalInvokeFn>,
32        userdata: *mut c_void,
33    ) -> *mut CWebView;
34    pub fn webview_loop(this: *mut CWebView, blocking: c_int) -> c_int;
35    pub fn webview_exit(this: *mut CWebView);
36    pub fn webview_get_user_data(this: *mut CWebView) -> *mut c_void;
37    pub fn webview_get_window_handle(this: *mut CWebView) -> *mut c_void;
38    pub fn webview_dispatch(this: *mut CWebView, f: Option<ErasedDispatchFn>, arg: *mut c_void);
39    pub fn webview_eval(this: *mut CWebView, js: *const c_char) -> c_int;
40    pub fn webview_set_title(this: *mut CWebView, title: *const c_char);
41    pub fn webview_set_fullscreen(this: *mut CWebView, fullscreen: c_int);
42    pub fn webview_set_maximized(this: *mut CWebView, maximize: c_int);
43    pub fn webview_set_minimized(this: *mut CWebView, minimize: c_int);
44    pub fn webview_set_visible(this: *mut CWebView, visible: c_int);
45    pub fn webview_set_color(this: *mut CWebView, red: u8, green: u8, blue: u8, alpha: u8);
46    pub fn webview_set_zoom_level(this: *mut CWebView, percentage: c_double);
47    pub fn webview_set_html(this: *mut CWebView, html: *const c_char);
48}