Skip to main content

windows_composition/
stack.rs

1use super::*;
2
3/// Owns a dispatcher queue on the current thread.
4///
5/// Keep it alive and pump the thread's message loop while using a
6/// [`Compositor`](crate::Compositor) created on that thread.
7pub struct DispatcherQueueController(
8    #[expect(
9        dead_code,
10        reason = "held only to keep the dispatcher queue alive on this thread"
11    )]
12    bindings::DispatcherQueueController,
13);
14
15impl DispatcherQueueController {
16    /// Creates a dispatcher queue on the current thread. Fails if the thread
17    /// already has one.
18    pub fn create_on_current_thread() -> Result<Self> {
19        let options = bindings::DispatcherQueueOptions {
20            dwSize: size_of::<bindings::DispatcherQueueOptions>() as u32,
21            threadType: bindings::DQTYPE_THREAD_CURRENT,
22            apartmentType: bindings::DQTAT_COM_ASTA,
23        };
24
25        unsafe {
26            let mut controller = core::ptr::null_mut();
27            bindings::CreateDispatcherQueueController(options, &mut controller).ok()?;
28            Ok(Self(bindings::DispatcherQueueController::from_raw(
29                controller,
30            )))
31        }
32    }
33}