mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Initialize PipeWire lazily
This helps with: - System setups starting PipeWire late (after niri startup, but before any screencast). - Tests which don't even want to start PipeWire.
This commit is contained in:
+1
-3
@@ -83,7 +83,7 @@ impl DBusServers {
|
|||||||
dbus.conn_introspect = try_start(introspect);
|
dbus.conn_introspect = try_start(introspect);
|
||||||
|
|
||||||
#[cfg(feature = "xdp-gnome-screencast")]
|
#[cfg(feature = "xdp-gnome-screencast")]
|
||||||
if niri.pipewire.is_some() {
|
{
|
||||||
let (to_niri, from_screen_cast) = calloop::channel::channel();
|
let (to_niri, from_screen_cast) = calloop::channel::channel();
|
||||||
niri.event_loop
|
niri.event_loop
|
||||||
.insert_source(from_screen_cast, {
|
.insert_source(from_screen_cast, {
|
||||||
@@ -95,8 +95,6 @@ impl DBusServers {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri);
|
let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri);
|
||||||
dbus.conn_screen_cast = try_start(screen_cast);
|
dbus.conn_screen_cast = try_start(screen_cast);
|
||||||
} else {
|
|
||||||
warn!("disabling screencast support because we couldn't start PipeWire");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -1,4 +1,4 @@
|
|||||||
use std::cell::{Cell, OnceCell, RefCell};
|
use std::cell::{Cell, LazyCell, OnceCell, RefCell};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -327,7 +327,7 @@ pub struct Niri {
|
|||||||
|
|
||||||
// Casts are dropped before PipeWire to prevent a double-free (yay).
|
// Casts are dropped before PipeWire to prevent a double-free (yay).
|
||||||
pub casts: Vec<Cast>,
|
pub casts: Vec<Cast>,
|
||||||
pub pipewire: Option<PipeWire>,
|
pub pipewire: LazyCell<Option<PipeWire>, Box<dyn FnOnce() -> Option<PipeWire>>>,
|
||||||
|
|
||||||
// Screencast output for each mapped window.
|
// Screencast output for each mapped window.
|
||||||
#[cfg(feature = "xdp-gnome-screencast")]
|
#[cfg(feature = "xdp-gnome-screencast")]
|
||||||
@@ -1504,13 +1504,15 @@ impl State {
|
|||||||
let gbm = match self.backend.gbm_device() {
|
let gbm = match self.backend.gbm_device() {
|
||||||
Some(gbm) => gbm,
|
Some(gbm) => gbm,
|
||||||
None => {
|
None => {
|
||||||
debug!("no GBM device available");
|
warn!("error starting screencast: no GBM device available");
|
||||||
|
self.niri.stop_cast(session_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(pw) = &self.niri.pipewire else {
|
let Some(pw) = &*self.niri.pipewire else {
|
||||||
error!("screencasting must be disabled if PipeWire is missing");
|
warn!("error starting screencast: PipeWire failed to initialize");
|
||||||
|
self.niri.stop_cast(session_id);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1882,13 +1884,14 @@ impl Niri {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let pipewire = match PipeWire::new(&event_loop) {
|
let loop_handle = event_loop.clone();
|
||||||
|
let pipewire = LazyCell::new(Box::new(move || match PipeWire::new(&loop_handle) {
|
||||||
Ok(pipewire) => Some(pipewire),
|
Ok(pipewire) => Some(pipewire),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("error connecting to PipeWire, screencasting will not work: {err:?}");
|
warn!("error connecting to PipeWire, screencasting will not work: {err:?}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
}) as _);
|
||||||
|
|
||||||
let display_source = Generic::new(display, Interest::READ, Mode::Level);
|
let display_source = Generic::new(display, Interest::READ, Mode::Level);
|
||||||
event_loop
|
event_loop
|
||||||
|
|||||||
Reference in New Issue
Block a user