forge
Explore
Log in

Don't you dare go Hollow

Initialize PipeWire lazily

Browse files at this commit

8dcc41a54d2606bab2d0e950f4b67668b48d9750Ivan MolodetskikhParent: ba3d2e3
This helps with:
- System setups starting PipeWire late (after niri startup, but before any
  screencast).
- Tests which don't even want to start PipeWire.
src/dbus/mod.rsmodified+1 -3
@@ -83,7 +83,7 @@ impl DBusServers {
83 dbus.conn_introspect = try_start(introspect);83 dbus.conn_introspect = try_start(introspect);
84 84
85 #[cfg(feature = "xdp-gnome-screencast")]85 #[cfg(feature = "xdp-gnome-screencast")]
86- if niri.pipewire.is_some() {86+ {
87 let (to_niri, from_screen_cast) = calloop::channel::channel();87 let (to_niri, from_screen_cast) = calloop::channel::channel();
88 niri.event_loop88 niri.event_loop
89 .insert_source(from_screen_cast, {89 .insert_source(from_screen_cast, {
@@ -95,8 +95,6 @@ impl DBusServers {
95 .unwrap();95 .unwrap();
96 let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri);96 let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri);
97 dbus.conn_screen_cast = try_start(screen_cast);97 dbus.conn_screen_cast = try_start(screen_cast);
98- } else {
99- warn!("disabling screencast support because we couldn't start PipeWire");
100 }98 }
101 }99 }
102 100
src/niri.rsmodified+10 -7
@@ -1,4 +1,4 @@
1-use std::cell::{Cell, OnceCell, RefCell};1+use std::cell::{Cell, LazyCell, OnceCell, RefCell};
2 use std::collections::{HashMap, HashSet};2 use std::collections::{HashMap, HashSet};
3 use std::ffi::OsString;3 use std::ffi::OsString;
4 use std::path::PathBuf;4 use std::path::PathBuf;
@@ -327,7 +327,7 @@ pub struct Niri {
327 327
328 // Casts are dropped before PipeWire to prevent a double-free (yay).328 // Casts are dropped before PipeWire to prevent a double-free (yay).
329 pub casts: Vec<Cast>,329 pub casts: Vec<Cast>,
330- pub pipewire: Option<PipeWire>,330+ pub pipewire: LazyCell<Option<PipeWire>, Box<dyn FnOnce() -> Option<PipeWire>>>,
331 331
332 // Screencast output for each mapped window.332 // Screencast output for each mapped window.
333 #[cfg(feature = "xdp-gnome-screencast")]333 #[cfg(feature = "xdp-gnome-screencast")]
@@ -1504,13 +1504,15 @@ impl State {
1504 let gbm = match self.backend.gbm_device() {1504 let gbm = match self.backend.gbm_device() {
1505 Some(gbm) => gbm,1505 Some(gbm) => gbm,
1506 None => {1506 None => {
1507- debug!("no GBM device available");1507+ warn!("error starting screencast: no GBM device available");
1508+ self.niri.stop_cast(session_id);
1508 return;1509 return;
1509 }1510 }
1510 };1511 };
1511 1512
1512- let Some(pw) = &self.niri.pipewire else {1513+ let Some(pw) = &*self.niri.pipewire else {
1513- error!("screencasting must be disabled if PipeWire is missing");1514+ warn!("error starting screencast: PipeWire failed to initialize");
1515+ self.niri.stop_cast(session_id);
1514 return;1516 return;
1515 };1517 };
1516 1518
@@ -1882,13 +1884,14 @@ impl Niri {
1882 }1884 }
1883 };1885 };
1884 1886
1885- let pipewire = match PipeWire::new(&event_loop) {1887+ let loop_handle = event_loop.clone();
1888+ let pipewire = LazyCell::new(Box::new(move || match PipeWire::new(&loop_handle) {
1886 Ok(pipewire) => Some(pipewire),1889 Ok(pipewire) => Some(pipewire),
1887 Err(err) => {1890 Err(err) => {
1888 warn!("error connecting to PipeWire, screencasting will not work: {err:?}");1891 warn!("error connecting to PipeWire, screencasting will not work: {err:?}");
1889 None1892 None
1890 }1893 }
1891- };1894+ }) as _);
1892 1895
1893 let display_source = Generic::new(display, Interest::READ, Mode::Level);1896 let display_source = Generic::new(display, Interest::READ, Mode::Level);
1894 event_loop1897 event_loop