Skip to main content

crepuscularity_lite/
host_queue.rs

1//! Deferred work that must run on the GPUI thread with a live window (e.g. native title APIs).
2
3use std::sync::{Arc, Mutex};
4
5#[derive(Debug, Clone)]
6pub enum HostDeferred {
7    SetWindowTitle(String),
8    /// Content size in **logical pixels** (GPUI `px`).
9    SetContentSize {
10        width: f32,
11        height: f32,
12    },
13    ToggleFullscreen,
14    Minimize,
15    Zoom,
16    /// [`gpui::Window::show_character_palette`].
17    ShowCharacterPalette,
18    /// macOS “document edited” dot; maps to [`gpui::Window::set_window_edited`].
19    SetWindowEdited(bool),
20    /// [`gpui::Window::start_window_move`].
21    StartWindowMove,
22    /// [`gpui::Window::refresh`].
23    RefreshWindow,
24    /// [`gpui::Window::request_decorations`].
25    RequestDecorations(DeferredWindowDecorations),
26}
27
28/// Decoration style for [`HostDeferred::RequestDecorations`].
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum DeferredWindowDecorations {
31    Server,
32    Client,
33}
34
35pub struct HostCommandQueue {
36    inner: Mutex<Vec<HostDeferred>>,
37}
38
39impl HostCommandQueue {
40    pub fn new() -> Arc<Self> {
41        Arc::new(Self {
42            inner: Mutex::new(Vec::new()),
43        })
44    }
45
46    pub fn push(&self, cmd: HostDeferred) {
47        self.inner
48            .lock()
49            .expect("HostCommandQueue mutex poisoned")
50            .push(cmd);
51    }
52
53    pub fn drain(&self) -> Vec<HostDeferred> {
54        let mut g = self.inner.lock().expect("HostCommandQueue mutex poisoned");
55        std::mem::take(&mut *g)
56    }
57}