create event system
This commit is contained in:
parent
21819e27d2
commit
18a0c78657
9 changed files with 65 additions and 5 deletions
|
|
@ -29,6 +29,7 @@ use {
|
|||
clonecell::CloneCell,
|
||||
double_click_state::DoubleClickState,
|
||||
errorfmt::ErrorFmt,
|
||||
event_listener::LazyEventSource,
|
||||
hash_map_ext::HashMapExt,
|
||||
linkedlist::{LinkedList, LinkedNode, NodeRef},
|
||||
numcell::NumCell,
|
||||
|
|
@ -140,6 +141,10 @@ pub struct ContainerNode {
|
|||
attention_requests: ThresholdCounter,
|
||||
pending_layout_damage: Cell<bool>,
|
||||
layout_damage_timeout: Cell<Option<SpawnedFuture<()>>>,
|
||||
pub layout_complete: Rc<LazyEventSource>,
|
||||
pub child_added: Rc<LazyEventSource>,
|
||||
pub child_removed: Rc<LazyEventSource>,
|
||||
pub all_children_resized: Rc<LazyEventSource>,
|
||||
}
|
||||
|
||||
impl Debug for ContainerNode {
|
||||
|
|
@ -258,6 +263,10 @@ impl ContainerNode {
|
|||
attention_requests: Default::default(),
|
||||
pending_layout_damage: Cell::new(false),
|
||||
layout_damage_timeout: Cell::new(None),
|
||||
layout_complete: state.post_layout_event_sources.create_source(),
|
||||
child_added: state.lazy_event_sources.create_source(),
|
||||
child_removed: state.lazy_event_sources.create_source(),
|
||||
all_children_resized: state.post_layout_event_sources.create_source(),
|
||||
});
|
||||
child.tl_set_parent(slf.clone());
|
||||
slf.pull_child_properties(&child_node_ref);
|
||||
|
|
@ -368,6 +377,7 @@ impl ContainerNode {
|
|||
// log::info!("add_child");
|
||||
self.schedule_layout();
|
||||
self.cancel_seat_ops();
|
||||
self.child_added.trigger();
|
||||
}
|
||||
|
||||
fn cancel_seat_ops(&self) {
|
||||
|
|
@ -461,6 +471,22 @@ impl ContainerNode {
|
|||
}
|
||||
}
|
||||
|
||||
fn all_children_match_body(&self) -> bool {
|
||||
if let Some(mono) = self.mono_child.get() {
|
||||
let body = self.mono_body.get();
|
||||
let content = mono.content.get();
|
||||
return content.width() == body.width() && content.height() == body.height();
|
||||
}
|
||||
for child in self.children.iter() {
|
||||
let body = child.body.get();
|
||||
let content = child.content.get();
|
||||
if content.width() != body.width() || content.height() != body.height() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn perform_layout(self: &Rc<Self>) {
|
||||
if self.num_children.get() == 0 {
|
||||
return;
|
||||
|
|
@ -475,6 +501,7 @@ impl ContainerNode {
|
|||
// log::info!("perform_layout");
|
||||
self.schedule_render_titles();
|
||||
self.schedule_compute_render_positions();
|
||||
self.layout_complete.trigger();
|
||||
if self.pending_layout_damage.get() {
|
||||
let slf = self.clone();
|
||||
let timeout = self.state.eng.spawn("layout damage timeout", async move {
|
||||
|
|
@ -1832,6 +1859,9 @@ impl Node for ContainerNode {
|
|||
if let Some(node) = cn.get(&child.node_id()) {
|
||||
self.update_child_size(node, width, height);
|
||||
}
|
||||
if self.pending_layout_damage.get() && self.all_children_match_body() {
|
||||
self.all_children_resized.trigger();
|
||||
}
|
||||
self.flush_layout_damage();
|
||||
}
|
||||
|
||||
|
|
@ -2115,6 +2145,7 @@ impl ContainingNode for ContainerNode {
|
|||
// log::info!("cnode_remove_child2");
|
||||
self.schedule_layout();
|
||||
self.cancel_seat_ops();
|
||||
self.child_removed.trigger();
|
||||
}
|
||||
|
||||
fn cnode_accepts_child(&self, _node: &dyn Node) -> bool {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ use {
|
|||
},
|
||||
utils::{
|
||||
asyncevent::AsyncEvent, clonecell::CloneCell, double_click_state::DoubleClickState,
|
||||
errorfmt::ErrorFmt, linkedlist::LinkedNode, on_drop_event::OnDropEvent,
|
||||
smallmap::SmallMapMut,
|
||||
errorfmt::ErrorFmt, event_listener::LazyEventSource, linkedlist::LinkedNode,
|
||||
on_drop_event::OnDropEvent, smallmap::SmallMapMut,
|
||||
},
|
||||
},
|
||||
ahash::AHashMap,
|
||||
|
|
@ -56,6 +56,7 @@ pub struct FloatNode {
|
|||
pub title_textures: RefCell<SmallMapMut<Scale, TextTexture, 2>>,
|
||||
cursors: RefCell<AHashMap<CursorType, CursorState>>,
|
||||
pub attention_requested: Cell<bool>,
|
||||
pub layout_complete: Rc<LazyEventSource>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
|
|
@ -136,6 +137,7 @@ impl FloatNode {
|
|||
title_textures: Default::default(),
|
||||
cursors: Default::default(),
|
||||
attention_requested: Cell::new(false),
|
||||
layout_complete: state.post_layout_event_sources.create_source(),
|
||||
});
|
||||
floater.pull_child_properties();
|
||||
*floater.display_link.borrow_mut() = Some(state.root.stacked.add_last(floater.clone()));
|
||||
|
|
@ -190,6 +192,7 @@ impl FloatNode {
|
|||
self.title_rect.set(tr);
|
||||
self.layout_scheduled.set(false);
|
||||
self.schedule_render_titles();
|
||||
self.layout_complete.trigger();
|
||||
}
|
||||
|
||||
pub fn schedule_render_titles(self: &Rc<Self>) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ use {
|
|||
clonecell::CloneCell,
|
||||
copyhashmap::CopyHashMap,
|
||||
errorfmt::ErrorFmt,
|
||||
event_listener::EventSource,
|
||||
event_listener::{EventSource, LazyEventSource},
|
||||
hash_map_ext::HashMapExt,
|
||||
linkedlist::{LinkedList, NodeRef},
|
||||
on_drop_event::OnDropEvent,
|
||||
|
|
@ -127,6 +127,7 @@ pub struct OutputNode {
|
|||
pub pinned: LinkedList<Rc<dyn PinnedNode>>,
|
||||
pub tearing: Cell<bool>,
|
||||
pub active_zwlr_gamma_control: CloneCell<Option<Rc<ZwlrGammaControlV1>>>,
|
||||
pub workspace_switched: Rc<LazyEventSource>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -415,6 +415,8 @@ pub struct ToplevelData {
|
|||
pub seat_foci: CopyHashMap<SeatId, ()>,
|
||||
pub content_type: Cell<Option<ContentType>>,
|
||||
pub property_changed_source: OnceCell<Rc<LazyEventSource>>,
|
||||
pub mapped_source: Rc<LazyEventSource>,
|
||||
pub unmapped_source: Rc<LazyEventSource>,
|
||||
}
|
||||
|
||||
impl ToplevelData {
|
||||
|
|
@ -469,6 +471,8 @@ impl ToplevelData {
|
|||
seat_foci: Default::default(),
|
||||
content_type: Default::default(),
|
||||
property_changed_source: Default::default(),
|
||||
mapped_source: state.lazy_event_sources.create_source(),
|
||||
unmapped_source: state.lazy_event_sources.create_source(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue