create event system
This commit is contained in:
parent
21819e27d2
commit
18a0c78657
9 changed files with 65 additions and 5 deletions
|
|
@ -68,7 +68,7 @@ use {
|
|||
clone3::ensure_reaper,
|
||||
clonecell::CloneCell,
|
||||
errorfmt::ErrorFmt,
|
||||
event_listener::handle_lazy_event_sources,
|
||||
event_listener::{handle_lazy_event_sources, handle_post_layout_event_sources},
|
||||
fdcloser::FdCloser,
|
||||
nice::{did_elevate_scheduler, elevate_scheduler},
|
||||
numcell::NumCell,
|
||||
|
|
@ -393,6 +393,7 @@ fn start_compositor2(
|
|||
supports_presentation_feedback: Default::default(),
|
||||
eventfd_cache,
|
||||
lazy_event_sources: Default::default(),
|
||||
post_layout_event_sources: Default::default(),
|
||||
bo_drop_queue: Rc::new(ObjectDropQueue::new(&ring)),
|
||||
virtual_outputs: Default::default(),
|
||||
clean_logs_older_than: Default::default(),
|
||||
|
|
@ -602,6 +603,11 @@ fn start_global_event_handlers(state: &Rc<State>) -> Vec<SpawnedFuture<()>> {
|
|||
"lazy event sources",
|
||||
handle_lazy_event_sources(state.clone()),
|
||||
),
|
||||
eng.spawn2(
|
||||
"post layout event sources",
|
||||
Phase::PostLayout,
|
||||
handle_post_layout_event_sources(state.clone()),
|
||||
),
|
||||
eng.spawn(
|
||||
"warp mouse to focus",
|
||||
handle_warp_mouse_to_focus(state.clone()),
|
||||
|
|
@ -799,6 +805,7 @@ fn create_dummy_output(state: &Rc<State>) {
|
|||
pinned: Default::default(),
|
||||
tearing: Default::default(),
|
||||
active_zwlr_gamma_control: Default::default(),
|
||||
workspace_switched: state.lazy_event_sources.create_source(),
|
||||
});
|
||||
let dummy_workspace = WorkspaceNode::new(&dummy_output, "dummy", true);
|
||||
dummy_workspace.may_capture.set(false);
|
||||
|
|
|
|||
|
|
@ -536,6 +536,7 @@ impl XdgToplevel {
|
|||
}
|
||||
}
|
||||
self.state.tree_changed();
|
||||
self.toplevel_data.unmapped_source.trigger();
|
||||
} else {
|
||||
self.map(self.parent.get().as_deref(), pos);
|
||||
self.extents_changed();
|
||||
|
|
@ -550,6 +551,7 @@ impl XdgToplevel {
|
|||
// }
|
||||
// }
|
||||
self.state.tree_changed();
|
||||
self.toplevel_data.mapped_source.trigger();
|
||||
self.toplevel_data.broadcast(self.clone());
|
||||
}
|
||||
self.toplevel_data
|
||||
|
|
|
|||
|
|
@ -298,6 +298,7 @@ pub struct State {
|
|||
pub supports_presentation_feedback: Cell<bool>,
|
||||
pub eventfd_cache: Rc<EventfdCache>,
|
||||
pub lazy_event_sources: Rc<LazyEventSources>,
|
||||
pub post_layout_event_sources: Rc<LazyEventSources>,
|
||||
pub bo_drop_queue: Rc<ObjectDropQueue<Rc<dyn BufferObject>>>,
|
||||
pub virtual_outputs: VirtualOutputs,
|
||||
pub clean_logs_older_than: Cell<Option<SystemTime>>,
|
||||
|
|
@ -936,6 +937,7 @@ impl State {
|
|||
if !output.is_dummy {
|
||||
output.schedule_update_render_data();
|
||||
self.tree_changed();
|
||||
output.workspace_switched.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1169,6 +1171,7 @@ impl State {
|
|||
self.wait_for_syncobj.clear();
|
||||
self.xdg_surface_configure_events.clear();
|
||||
self.lazy_event_sources.clear();
|
||||
self.post_layout_event_sources.clear();
|
||||
self.bo_drop_queue.kill();
|
||||
self.virtual_outputs.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ impl ConnectorHandler {
|
|||
pinned: Default::default(),
|
||||
tearing: Default::default(),
|
||||
active_zwlr_gamma_control: Default::default(),
|
||||
workspace_switched: self.state.lazy_event_sources.create_source(),
|
||||
});
|
||||
on.update_visible();
|
||||
on.update_rects();
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,16 @@ use {
|
|||
};
|
||||
|
||||
pub async fn handle_lazy_event_sources(state: Rc<State>) {
|
||||
handle_lazy_event_sources_of(&state.lazy_event_sources).await;
|
||||
}
|
||||
|
||||
pub async fn handle_post_layout_event_sources(state: Rc<State>) {
|
||||
handle_lazy_event_sources_of(&state.post_layout_event_sources).await;
|
||||
}
|
||||
|
||||
async fn handle_lazy_event_sources_of(sources: &LazyEventSources) {
|
||||
loop {
|
||||
let source = state.lazy_event_sources.queue.pop().await;
|
||||
let source = sources.queue.pop().await;
|
||||
source.queued.set(false);
|
||||
for listener in source.listeners.iter() {
|
||||
listener.triggered();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue