A frameless desktop window whose page is HTML: a WebView2 window on Windows and a WebKitGTK window on Linux. The page draws everything, including its own background. Where the platform can, the window itself is see-through, so the page can be a transparent layer over the desktop.
The library is meant to be used as a submodule. The host application:
- calls
setApplicationNameandinitializeWindowingat startup, andsetApplicationIconif it has a PNG icon to show, - subclasses
WebViewWindow, overridinghtml()(ordevUrl()) andtitle(), - defines
showErrorfor each platform it runs on, the one desktop function the library leaves to the host. Theexamples/Host.*files have the Windows, Linux and macOS versions.
- A window is hidden until its page reports that it's ready, so it never shows as an empty frame. A
showorpresentthat comes before then takes effect once the page is ready. The page reports it by posting{id, method: 'ready', args: []}to the host, once it has subscribed to the events it needs. Until then, host events wait for it. - Events queue until the page is ready, and replies from a page that has since been reloaded are dropped.
- On Windows, if the page doesn't report ready within
WindowOptions::startupTimeout(30 seconds by default), or the web view fails, the window callsonWebViewFailure. Linux has no startup timeout yet. The default shows the error and closes the window. A page can report its own failure by posting{id, method: 'frontendError', args: [message]}.reload()recreates the web view and loads the page again. WindowOptions::webViewDataFoldersets where WebView2 keeps its profile. Empty means a folder beside the executable.hidefrees the window's web view after two minutes, unless the window is shown again first. The nextshoworpresentopens the window again.- When the user closes a window,
allowClosedecides. If it returns true, the window is destroyed. A window that should stay reusable returns false and hides itself, as it would throughhide. WindowOptions::resizeEdgesdraws strips along the window's edges, after each page load, and a press on one starts a resize from that edge. The page doesn't need to draw them. It applies whenresizableis set and the window isn't autosize.
- When a page asks for the microphone, camera or notifications, the host's
onPermissionRequestanswers. Return true to allow, false to deny, or nothing to leave the platform's default: WebKitGTK denies the request, and WebView2 asks the user. The answer comes fromdecidePermission, which the platform calls with the page's address. - On Linux, notifications are decided once for the window's own page origin (its
devUrl) when the window opens, since WebKitGTK otherwise denies them. A page at another origin is asked when it asks. - Other permission kinds reach
onPermissionRequestasPagePermission::Otheron Windows and are left to the platform on Linux.
include/: the public headers.WebViewWindow.his the window;Messages.his the page-to-host message dispatch.src/: the parts shared by both platforms.platform/windows/: the Win32 window, WebView2 callbacks, and DirectComposition for see-through windows.platform/linux/: the GTK and WebKitGTK window. GTK is loaded at runtime, so only the headers inthird_party/gtkare needed.platform/macos/: the AppKit and WebKit window, in Objective-C++. A skeleton for now; see Status.third_party/: WebView2 headers and loader, GTK headers, and nlohmann/json.
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw-w64.cmake
cmake --build build
The Windows build uses MinGW-w64. The example is built with WEBVIEW_WINDOW_BUILD_EXAMPLE (on by default). Set it to OFF
when the library is used as a submodule. The WebView2 runtime must be installed on the machine that runs the program.
- Windows: built and run with the example. The permission hook compiles with MinGW but hasn't been run on Windows yet.
- Linux: built and run with the example.
tests/linux_example_test.shandtests/linux_permission_test.shcheck it. - macOS: in progress.
platform/macos/builds and links, but the window and web view are still stubs, so the example doesn't show a window yet. A GitHub Actions workflow (.github/workflows/macos.yml) builds it on a macOS runner.