2022-06-27 13:54:24 -04:00
|
|
|
use std::os::unix::prelude::IntoRawFd;
|
|
|
|
|
|
2022-06-24 12:56:38 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-06-24 11:43:48 -04:00
|
|
|
use crate::process::{ProcessEvent, ProcessHandler};
|
2022-06-27 13:54:24 -04:00
|
|
|
use tokio::{
|
|
|
|
|
net::UnixStream,
|
|
|
|
|
sync::{mpsc::unbounded_channel, oneshot},
|
|
|
|
|
};
|
2022-06-24 11:43:48 -04:00
|
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
|
|
2022-06-24 20:36:49 -04:00
|
|
|
pub async fn run_compositor(token: CancellationToken, wayland_display_tx: oneshot::Sender<String>) {
|
|
|
|
|
let mut wayland_display_tx = Some(wayland_display_tx);
|
2022-06-24 11:43:48 -04:00
|
|
|
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
2022-06-27 13:54:24 -04:00
|
|
|
let (session, comp) = UnixStream::pair().expect("failed to create pair of unix sockets");
|
|
|
|
|
let comp = comp.into_std().unwrap().into_raw_fd();
|
|
|
|
|
ProcessHandler::new(tx, &token).run("cosmic-comp", vec![], vec![(
|
|
|
|
|
"COSMIC_SESSION_SOCK".into(),
|
|
|
|
|
comp.to_string(),
|
|
|
|
|
)]);
|
2022-06-24 11:43:48 -04:00
|
|
|
while let Some(event) = rx.recv().await {
|
|
|
|
|
match event {
|
|
|
|
|
ProcessEvent::Started => {
|
|
|
|
|
info!("started");
|
|
|
|
|
}
|
2022-06-24 12:56:38 -04:00
|
|
|
// cosmic-comp outputs everything to stderr because slog
|
|
|
|
|
ProcessEvent::Stdout(line) | ProcessEvent::Stderr(line) => {
|
|
|
|
|
if line.contains("Listening on \"") {
|
|
|
|
|
// Message format: Listening on "wayland-0"
|
2022-06-24 20:36:49 -04:00
|
|
|
if let Some(tx) = wayland_display_tx.take() {
|
2022-06-24 12:56:38 -04:00
|
|
|
let socket_name = line
|
|
|
|
|
.split('"')
|
|
|
|
|
.nth(1)
|
2022-06-24 20:36:49 -04:00
|
|
|
.expect("failed to get WAYLAND_DISPLAY");
|
2022-06-24 12:56:38 -04:00
|
|
|
tx.send(socket_name.to_string())
|
2022-06-24 20:36:49 -04:00
|
|
|
.expect("failed to send WAYLAND_DISPLAY back to main app");
|
2022-06-24 12:56:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 11:43:48 -04:00
|
|
|
info!("{}", line);
|
|
|
|
|
}
|
|
|
|
|
ProcessEvent::Ended(Some(status)) => {
|
|
|
|
|
error!("exited with status {}", status);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ProcessEvent::Ended(None) => {
|
|
|
|
|
error!("exited");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|