From f7e77ca94cdce63b861b6d483cd16ec74681ccb1 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 3 Jul 2022 00:20:48 +0200 Subject: [PATCH] wayland: register most singletons before starting async work --- src/compositor.rs | 2 +- src/globals.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/compositor.rs b/src/compositor.rs index 6894f49d..0adc3f11 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -227,7 +227,7 @@ async fn start_compositor3(state: Rc, test_future: Option) { } }; state.backend.set(backend.clone()); - state.globals.add_singletons(&backend); + state.globals.add_backend_singletons(&backend); if backend.import_environment() { if let Some(acc) = state.acceptor.get() { diff --git a/src/globals.rs b/src/globals.rs index f5503dc9..09e19400 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -109,12 +109,14 @@ pub struct Globals { impl Globals { pub fn new() -> Self { - Self { + let slf = Self { next_name: NumCell::new(1), registry: CopyHashMap::new(), outputs: Default::default(), seats: Default::default(), - } + }; + slf.add_singletons(); + slf } pub fn clear(&self) { @@ -123,7 +125,7 @@ impl Globals { self.seats.clear(); } - pub fn add_singletons(&self, backend: &Rc) { + fn add_singletons(&self) { macro_rules! add_singleton { ($name:ident) => { self.add_global_no_broadcast(&Rc::new($name::new(self.name()))); @@ -145,11 +147,17 @@ impl Globals { add_singleton!(ExtSessionLockManagerV1Global); add_singleton!(WpViewporterGlobal); add_singleton!(WpFractionalScaleManagerV1Global); + } + pub fn add_backend_singletons(&self, backend: &Rc) { + macro_rules! add_singleton { + ($name:ident) => { + self.add_global_no_broadcast(&Rc::new($name::new(self.name()))); + }; + } if backend.supports_idle() { add_singleton!(ZwpIdleInhibitManagerV1Global); } - if backend.supports_presentation_feedback() { add_singleton!(WpPresentationGlobal); }