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-24 12:56:38 -04:00
|
|
|
use tokio::sync::{mpsc::unbounded_channel, oneshot};
|
2022-06-24 11:43:48 -04:00
|
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
|
|
2022-06-24 12:56:38 -04:00
|
|
|
pub async fn run_compositor(token: CancellationToken, wayland_socket_tx: oneshot::Sender<String>) {
|
|
|
|
|
let mut wayland_socket_tx = Some(wayland_socket_tx);
|
2022-06-24 11:43:48 -04:00
|
|
|
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
2022-06-24 14:46:14 -04:00
|
|
|
ProcessHandler::new(tx, &token).run("cosmic-comp", vec![], vec![]);
|
2022-06-24 11:43:48 -04:00
|
|
|
let span = info_span!("cosmic-comp");
|
|
|
|
|
let _enter = span.enter();
|
|
|
|
|
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"
|
|
|
|
|
if let Some(tx) = wayland_socket_tx.take() {
|
|
|
|
|
let socket_name = line
|
|
|
|
|
.split('"')
|
|
|
|
|
.nth(1)
|
|
|
|
|
.expect("failed to get WAYLAND_SOCKET");
|
|
|
|
|
tx.send(socket_name.to_string())
|
|
|
|
|
.expect("failed to send WAYLAND_SOCKET back to main app");
|
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|