Cross-thread Window Commands

The cross-thread-window-commands feature allows non-event-loop threads to submit window control commands and wake up Flor's event loop to process them promptly.

[dependencies]
flor = { version = "0.1.0", features = ["direct2d", "cross-thread-window-commands"] }

This feature automatically enables event-loop-wakeup, so that after cross-thread window command requests are enqueued, the event loop thread can be woken up to process them.

Entry Point

After enabling, you still use the same WindowRequestApi:

use flor::platform::WindowId;
use flor::windows::WindowRequestApi;

fn resize_from_worker(window_id: WindowId) {
    window_id.request_set_size((1024, 768));
    window_id.request_show().result(|result| {
        if let Err(err) = result {
            eprintln!("show failed: {err}");
        }
    });
}

These methods do not directly call platform window APIs; instead, they enqueue commands into the event loop queue. The event loop executes the current batch of commands in FIFO order and invokes the callbacks registered via result(...) after execution.

Available Commands

MethodPurpose
request_update_window()Request synchronous window update.
request_show() / request_hide()Show or hide the window.
request_set_window_mode(mode)Set normal, minimized, maximized, or fullscreen mode.
request_set_left(left) / request_set_top(top)Set window position individually.
request_set_position((x, y))Set window position.
request_set_width(width) / request_set_height(height)Set window size individually.
request_set_size((width, height))Set window size.
request_destroy()Destroy the window.
request_drag_window()Trigger system window drag.

When to Enable

If window control only happens within the event loop thread, you can directly call the synchronous methods on WindowApi, or use request_* methods without enabling this feature.

If business threads, async tasks, background callbacks or cross-thread state synchronization logic need to control windows, you should enable cross-thread-window-commands. It uses the event-loop-wakeup wake-up capability to avoid long waits for the event loop to naturally wake up after commands are enqueued.

The request_* methods themselves are always available; this feature changes the wake-up behavior after cross-thread submission.