crepuscularity_lite/
host_queue.rs1use std::sync::{Arc, Mutex};
4
5#[derive(Debug, Clone)]
6pub enum HostDeferred {
7 SetWindowTitle(String),
8 SetContentSize {
10 width: f32,
11 height: f32,
12 },
13 ToggleFullscreen,
14 Minimize,
15 Zoom,
16 ShowCharacterPalette,
18 SetWindowEdited(bool),
20 StartWindowMove,
22 RefreshWindow,
24 RequestDecorations(DeferredWindowDecorations),
26}
27
28#[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}