Skip to main content

nifty_rt/
window.rs

1//! `open_window(…)` and `close_window(…)` in compiled apps, which ask for the window by
2//! its position among the app's windows.
3
4use nifty_runtime::{WindowAction, WindowRequest};
5
6use crate::abi::borrow_context;
7use crate::context::Context;
8
9/// Asks for `action` on the app's window at position `window`, done once the current
10/// event finishes.
11///
12/// # Safety
13/// See the `abi` module's contract; `window` is the position of one of the program's
14/// windows.
15#[unsafe(no_mangle)]
16pub(crate) unsafe extern "C" fn nf_window(
17    context: *const Context,
18    action: WindowAction,
19    window: u32,
20) {
21    // SAFETY: by the caller's contract.
22    let context = unsafe { borrow_context(context) };
23    context.request_window(WindowRequest {
24        action,
25        window: usize::try_from(window).expect("window positions fit in usize"),
26    });
27}