portal: make pipewire optional
This commit is contained in:
parent
21916017c1
commit
b359b2648d
2 changed files with 22 additions and 10 deletions
|
|
@ -14,7 +14,7 @@ use {
|
|||
forker::ForkerError,
|
||||
io_uring::IoUring,
|
||||
logger::Logger,
|
||||
pipewire::pw_con::{PwCon, PwConHolder, PwConOwner},
|
||||
pipewire::pw_con::{PwConHolder, PwConOwner},
|
||||
portal::{
|
||||
ptl_display::{watch_displays, PortalDisplay, PortalDisplayId},
|
||||
ptl_render_ctx::PortalRenderCtx,
|
||||
|
|
@ -181,9 +181,10 @@ async fn run_async(
|
|||
}
|
||||
};
|
||||
let pw_con = match PwConHolder::new(&eng, &ring).await {
|
||||
Ok(p) => p,
|
||||
Ok(p) => Some(p),
|
||||
Err(e) => {
|
||||
fatal!("Could not connect to pipewire: {}", ErrorFmt(e));
|
||||
log::error!("Could not connect to pipewire: {}", ErrorFmt(e));
|
||||
None
|
||||
}
|
||||
};
|
||||
let state = Rc::new(PortalState {
|
||||
|
|
@ -191,7 +192,6 @@ async fn run_async(
|
|||
ring,
|
||||
eng,
|
||||
wheel,
|
||||
pw_con: pw_con.con.clone(),
|
||||
displays: Default::default(),
|
||||
dbus,
|
||||
screencasts: Default::default(),
|
||||
|
|
@ -199,15 +199,19 @@ async fn run_async(
|
|||
render_ctxs: Default::default(),
|
||||
dma_buf_ids: Default::default(),
|
||||
});
|
||||
if let Some(pw_con) = &pw_con {
|
||||
pw_con.con.owner.set(Some(state.clone()));
|
||||
}
|
||||
let _root = {
|
||||
let obj = state
|
||||
.dbus
|
||||
.add_object("/org/freedesktop/portal/desktop")
|
||||
.unwrap();
|
||||
add_screencast_dbus_members(&state, &obj);
|
||||
if let Some(pw_con) = &pw_con {
|
||||
add_screencast_dbus_members(&state, &pw_con.con, &obj);
|
||||
}
|
||||
obj
|
||||
};
|
||||
state.pw_con.owner.set(Some(state.clone()));
|
||||
watch_displays(state.clone()).await;
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +285,6 @@ struct PortalState {
|
|||
ring: Rc<IoUring>,
|
||||
eng: Rc<AsyncEngine>,
|
||||
wheel: Rc<Wheel>,
|
||||
pw_con: Rc<PwCon>,
|
||||
displays: CopyHashMap<PortalDisplayId, Rc<PortalDisplay>>,
|
||||
dbus: Rc<DbusSocket>,
|
||||
screencasts: CopyHashMap<String, Rc<ScreencastSession>>,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use {
|
|||
crate::{
|
||||
dbus::{prelude::Variant, DbusObject, DictEntry, DynamicType, PendingReply},
|
||||
pipewire::{
|
||||
pw_con::PwCon,
|
||||
pw_ifs::pw_client_node::{
|
||||
PwClientNode, PwClientNodeBufferConfig, PwClientNodeOwner, PwClientNodePort,
|
||||
PwClientNodePortSupportedFormats, SUPPORTED_META_VIDEO_CROP,
|
||||
|
|
@ -56,6 +57,7 @@ shared_ids!(ScreencastSessionId);
|
|||
pub struct ScreencastSession {
|
||||
_id: ScreencastSessionId,
|
||||
state: Rc<PortalState>,
|
||||
pw_con: Rc<PwCon>,
|
||||
pub app: String,
|
||||
session_obj: DbusObject,
|
||||
pub phase: CloneCell<ScreencastPhase>,
|
||||
|
|
@ -234,7 +236,7 @@ impl PwClientNodeOwner for StartedScreencast {
|
|||
|
||||
impl SelectingScreencastCore {
|
||||
pub fn starting(&self, dpy: &Rc<PortalDisplay>, target: ScreencastTarget) {
|
||||
let node = dpy.state.pw_con.create_client_node(&[
|
||||
let node = self.session.pw_con.create_client_node(&[
|
||||
("media.class".to_string(), "Video/Source".to_string()),
|
||||
("node.name".to_string(), "jay-desktop-portal".to_string()),
|
||||
("node.driver".to_string(), "true".to_string()),
|
||||
|
|
@ -462,11 +464,16 @@ impl UsrJayScreencastOwner for StartedScreencast {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn add_screencast_dbus_members(state_: &Rc<PortalState>, object: &DbusObject) {
|
||||
pub(super) fn add_screencast_dbus_members(
|
||||
state_: &Rc<PortalState>,
|
||||
pw_con: &Rc<PwCon>,
|
||||
object: &DbusObject,
|
||||
) {
|
||||
use org::freedesktop::impl_::portal::screen_cast::*;
|
||||
let state = state_.clone();
|
||||
let pw_con = pw_con.clone();
|
||||
object.add_method::<CreateSession, _>(move |req, pr| {
|
||||
dbus_create_session(&state, req, pr);
|
||||
dbus_create_session(&state, &pw_con, req, pr);
|
||||
});
|
||||
let state = state_.clone();
|
||||
object.add_method::<SelectSources, _>(move |req, pr| {
|
||||
|
|
@ -483,6 +490,7 @@ pub(super) fn add_screencast_dbus_members(state_: &Rc<PortalState>, object: &Dbu
|
|||
|
||||
fn dbus_create_session(
|
||||
state: &Rc<PortalState>,
|
||||
pw_con: &Rc<PwCon>,
|
||||
req: CreateSession,
|
||||
reply: PendingReply<CreateSessionReply<'static>>,
|
||||
) {
|
||||
|
|
@ -501,6 +509,7 @@ fn dbus_create_session(
|
|||
let session = Rc::new(ScreencastSession {
|
||||
_id: state.id(),
|
||||
state: state.clone(),
|
||||
pw_con: pw_con.clone(),
|
||||
app: req.app_id.to_string(),
|
||||
session_obj: obj,
|
||||
phase: CloneCell::new(ScreencastPhase::Init),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue