flux_tui/window/
event_queue.rs1use std::sync::{OnceLock, mpsc::*};
2
3use crossterm::event::Event;
4
5use super::*;
6
7pub(super) struct ChangedProperty {
9 pub(super) uid: WindowUID,
10 pub(super) property: WindowProperty,
11}
12
13impl ChangedProperty {
14 fn new(uid: WindowUID, property: WindowProperty) -> Self {
15 Self { property, uid }
16 }
17}
18
19#[derive(Debug, Copy, Clone, PartialEq, Hash)]
21pub enum WindowProperty {
22 Focus,
23 Children,
24 Alignment,
25 Size,
26 Margin,
27 Border,
28 IsVisible,
29}
30
31pub(super) struct TreeUpdate {
32 pub win: WindowRef,
33 pub depth: u8,
34 pub rect: Rect,
35}
36
37pub(super) struct FocusUpdate {
38 pub win: WindowRef,
39 pub depth: u8,
40}
41
42static SENDER: OnceLock<SyncSender<ChangedProperty>> = OnceLock::new();
43
44pub struct WindowEventQueue {
46 pub(super) recv: Receiver<ChangedProperty>,
47}
48
49impl WindowEventQueue {
50 pub(super) fn initialize() -> Self {
51 let (send, recv) = sync_channel(32);
52 SENDER.set(send).unwrap();
53 Self { recv }
54 }
55
56 pub fn provoke_changed_property(uid: WindowUID, property: WindowProperty) {
58 if let Some(sender) = SENDER.get() {
59 let change = ChangedProperty::new(uid, property);
60 sender.send(change).unwrap();
61 }
62 }
63}
64
65#[derive(Debug)]
66pub struct WindowEvent {
68 event: Event,
69 pub handled: bool,
70}
71
72impl WindowEvent {
73 pub(crate) fn new(event: Event) -> Self {
74 Self {
75 event,
76 handled: false,
77 }
78 }
79
80 pub fn raw(&self) -> &Event {
82 &self.event
83 }
84}