Racket FFI Interface for rktwebview_qt
1 Overview
The module racket-webview-qt.rkt provides a Racket FFI wrapper around the native rktwebview_qt library. It loads the shared library, initializes the native runtime, and exposes Racket functions for creating and controlling webview windows.
The wrapper translates the low-level C interface into a Racket-oriented API based on structures, callbacks, and ordinary Racket values.
The module provides:
creation of HTTP(S) contexts
creation and management of webview windows
navigation and HTML loading
JavaScript execution
window geometry and visibility control
native dialogs
asynchronous event delivery
version and cleanup utilities
2 Requirements
The native backend requires Qt version 6.10.2 or newer.
The shared library rktwebview_qt must therefore be built against Qt 6.10.2 or a compatible later release.
Earlier Qt versions are not supported.
3 Module Initialization
Loading the module performs several initialization steps automatically.
determines the operating system and architecture
sets Qt runtime environment variables
loads the rktwebview_qt shared library
initializes the native runtime
starts a background thread that processes native events
Currently the wrapper supports the following platforms:
’linux
’windows
If the current system is unsupported, loading the module raises an error.
4 Data Model
4.1 The rkt-wv Structure
Each webview window is represented by a transparent Racket structure.
struct
(struct rkt-wv (win evt-queue callback valid close-callback))
win : exact-integer? evt-queue : any/c callback : procedure? valid : boolean? close-callback : procedure?
Fields:
win: the native integer window handle
evt-queue: internal queue of pending event strings
callback: user event callback
valid: mutable flag indicating whether the wrapper considers the window active
close-callback: procedure invoked when the window is closed
Although the structure is transparent, user code should normally treat it as an opaque handle.
procedure
(rkt-wv-win wv) → exact-integer?
wv : rkt-wv?
5 HTTP(S) Contexts
A context represents the shared HTTP(S) environment used by webviews.
Contexts correspond to native WebEngine profiles and determine properties such as:
cookies and cache
injected JavaScript
trusted certificates
procedure
(rkt-webview-new-context boilerplate-js server-cert) → exact-integer? boilerplate-js : string? server-cert : bytes?
Arguments:
boilerplate-js: JavaScript source injected into pages
server-cert: optional certificate data
The returned context identifier can be passed to rkt-webview-create to create webviews within that context.
6 Creating Webviews
procedure
(rkt-webview-create context parent evt-callback close-callback) → rkt-wv? context : exact-integer? parent : (or/c #f rkt-wv?) evt-callback : (-> rkt-wv? string? any) close-callback : (-> any)
Arguments:
context: context identifier returned by rkt-webview-new-context
parent: optional parent webview
evt-callback: procedure invoked for each event
close-callback: procedure invoked when the window is closed
The result is a new rkt-wv structure.
Events generated by the native layer are delivered asynchronously through evt-callback.
7 Window Lifecycle
procedure
(rkt-webview-close wv) → boolean?
wv : rkt-wv?
The wrapper forwards the request to the native backend and schedules cleanup of the event-processing loop.
Returns #t.
procedure
(rkt-webview-valid? wv) → boolean?
wv : rkt-wv?
The wrapper first checks its internal validity flag and then queries the native runtime.
procedure
(rkt-webview-exit) → void?
This function is also registered with the Racket plumber so that cleanup occurs automatically when the process exits.
8 Window Configuration
procedure
(rkt-webview-set-title! wv title) → symbol?
wv : rkt-wv? title : string?
Returns a result symbol such as:
'oke
'failed
procedure
(rkt-webview-set-ou-token wv token) → boolean?
wv : rkt-wv? token : string?
This token may be used by the native layer when accepting certain self-signed certificates.
9 Navigation
procedure
(rkt-webview-set-url! wv url) → symbol?
wv : rkt-wv? url : string?
Returns a result symbol such as:
'oke
'set_navigate_failed
procedure
(rkt-webview-set-html! wv html) → symbol?
wv : rkt-wv? html : string?
Returns a result symbol such as:
'oke
'set_html_failed
10 JavaScript Execution
procedure
(rkt-webview-run-js wv js) → symbol?
wv : rkt-wv? js : string?
Returns a result symbol such as:
'oke
'eval_js_failed
procedure
(rkt-webview-call-js wv js) → (list/c symbol? string?)
wv : rkt-wv? js : string?
(list result value)
where:
result is the native result code
value is a JSON string containing the returned data
The JSON structure is generated by the native backend.
11 Window Geometry
procedure
(rkt-webview-move wv x y) → symbol?
wv : rkt-wv? x : exact-integer? y : exact-integer?
procedure
(rkt-webview-resize wv width height) → symbol?
wv : rkt-wv? width : exact-integer? height : exact-integer?
procedure
(rkt-webview-show wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-hide wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-show-normal wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-maximize wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-minimize wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-present wv) → symbol?
wv : rkt-wv?
procedure
(rkt-webview-window-state wv) → symbol?
wv : rkt-wv?
Possible results include:
'normal
'minimized
'maximized
'hidden
12 Developer Tools
procedure
(rkt-webview-open-devtools wv) → symbol?
wv : rkt-wv?
13 Native Dialogs
Dialog functions return immediately with a status code. The user’s choice is delivered asynchronously through the event callback.
procedure
(rkt-webview-choose-dir wv title base-dir) → symbol?
wv : rkt-wv? title : string? base-dir : string?
procedure
(rkt-webview-file-open wv title base-dir extensions) → symbol? wv : rkt-wv? title : string? base-dir : string? extensions : string?
procedure
(rkt-webview-file-save wv title base-dir extensions) → symbol? wv : rkt-wv? title : string? base-dir : string? extensions : string?
procedure
(rkt-webview-messagebox wv title message submessage type) → symbol? wv : rkt-wv? title : string? message : string? submessage : string? type : symbol?
14 Event Delivery
Each webview has an associated event callback.
The callback has the form:
(λ (wv event-json) ...)
Arguments:
wv: the webview handle
event-json: JSON event string from the native backend
Typical event types include:
"show"
"hide"
"move"
"resize"
"closed"
"page-loaded"
"navigation-request"
"js-evt"
The wrapper does not parse the JSON payload.
15 Version Information
procedure
(rkt-webview-version) → (list/c list? list?)
Example result:
(list (list 'webview-c-api 1 0 0) (list 'qt 6 10 2))
16 Example
(define ctx (rkt-webview-new-context "" #"")) (define wv (rkt-webview-create ctx #f (λ (wv evt) (displayln evt)) (λ () (displayln "closed")))) (rkt-webview-set-title! wv "Example") (rkt-webview-set-url! wv "https://example.org")
17 Summary
The FFI module provides a thin Racket interface to the native rktwebview_qt backend.
Key characteristics:
thin wrapper around the native C API
asynchronous event delivery
JSON-based event payloads
simple Racket structures for webviews