✨ Get WAYLAND_SOCKET from comp; run cosmic-panel
This commit is contained in:
parent
8bf6567a91
commit
fb1a832916
3 changed files with 60 additions and 8 deletions
23
src/comp.rs
23
src/comp.rs
|
|
@ -1,8 +1,10 @@
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
use crate::process::{ProcessEvent, ProcessHandler};
|
use crate::process::{ProcessEvent, ProcessHandler};
|
||||||
use tokio::sync::mpsc::unbounded_channel;
|
use tokio::sync::{mpsc::unbounded_channel, oneshot};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
pub async fn run_compositor(token: CancellationToken) {
|
pub async fn run_compositor(token: CancellationToken, wayland_socket_tx: oneshot::Sender<String>) {
|
||||||
|
let mut wayland_socket_tx = Some(wayland_socket_tx);
|
||||||
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
||||||
ProcessHandler::new(tx, &token).run("cosmic-comp", vec![]);
|
ProcessHandler::new(tx, &token).run("cosmic-comp", vec![]);
|
||||||
let span = info_span!("cosmic-comp");
|
let span = info_span!("cosmic-comp");
|
||||||
|
|
@ -12,12 +14,21 @@ pub async fn run_compositor(token: CancellationToken) {
|
||||||
ProcessEvent::Started => {
|
ProcessEvent::Started => {
|
||||||
info!("started");
|
info!("started");
|
||||||
}
|
}
|
||||||
ProcessEvent::Stdout(line) => {
|
// 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
info!("{}", line);
|
info!("{}", line);
|
||||||
}
|
}
|
||||||
ProcessEvent::Stderr(line) => {
|
|
||||||
error!("{}", line);
|
|
||||||
}
|
|
||||||
ProcessEvent::Ended(Some(status)) => {
|
ProcessEvent::Ended(Some(status)) => {
|
||||||
error!("exited with status {}", status);
|
error!("exited with status {}", status);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -3,11 +3,13 @@
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
mod comp;
|
mod comp;
|
||||||
|
mod panel;
|
||||||
mod process;
|
mod process;
|
||||||
|
|
||||||
use async_signals::Signals;
|
use async_signals::Signals;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
use tokio::sync::oneshot;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::metadata::LevelFilter;
|
use tracing::metadata::LevelFilter;
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
@ -29,8 +31,15 @@ async fn main() -> Result<()> {
|
||||||
info!("Starting cosmic-session");
|
info!("Starting cosmic-session");
|
||||||
|
|
||||||
let token = CancellationToken::new();
|
let token = CancellationToken::new();
|
||||||
|
let (wayland_socket_tx, wayland_socket_rx) = oneshot::channel();
|
||||||
|
tokio::spawn(comp::run_compositor(token.child_token(), wayland_socket_tx));
|
||||||
|
let wayland_socket = wayland_socket_rx
|
||||||
|
.await
|
||||||
|
.expect("failed to get WAYLAND_SOCKET");
|
||||||
|
info!("got WAYLAND_SOCKET: {}", wayland_socket);
|
||||||
|
std::env::set_var("WAYLAND_SOCKET", wayland_socket);
|
||||||
|
|
||||||
tokio::spawn(comp::run_compositor(token.child_token()));
|
tokio::spawn(panel::run_panel(token.child_token()));
|
||||||
|
|
||||||
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
|
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
|
||||||
while let Some(signal) = signals.next().await {
|
while let Some(signal) = signals.next().await {
|
||||||
|
|
@ -38,7 +47,7 @@ async fn main() -> Result<()> {
|
||||||
libc::SIGTERM | libc::SIGINT => {
|
libc::SIGTERM | libc::SIGINT => {
|
||||||
info!("received request to terminate");
|
info!("received request to terminate");
|
||||||
token.cancel();
|
token.cancel();
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => unreachable!("received unhandled signal {}", signal),
|
_ => unreachable!("received unhandled signal {}", signal),
|
||||||
|
|
|
||||||
32
src/panel.rs
Normal file
32
src/panel.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
use crate::process::{ProcessEvent, ProcessHandler};
|
||||||
|
use tokio::sync::mpsc::unbounded_channel;
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
|
pub async fn run_panel(token: CancellationToken) {
|
||||||
|
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
||||||
|
ProcessHandler::new(tx, &token).run("cosmic-panel", vec![]);
|
||||||
|
let span = info_span!("cosmic-panel");
|
||||||
|
let _enter = span.enter();
|
||||||
|
while let Some(event) = rx.recv().await {
|
||||||
|
match event {
|
||||||
|
ProcessEvent::Started => {
|
||||||
|
info!("started");
|
||||||
|
}
|
||||||
|
ProcessEvent::Stdout(line) => {
|
||||||
|
info!("{}", line);
|
||||||
|
}
|
||||||
|
ProcessEvent::Stderr(line) => {
|
||||||
|
error!("{}", line);
|
||||||
|
}
|
||||||
|
ProcessEvent::Ended(Some(status)) => {
|
||||||
|
error!("exited with status {}", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProcessEvent::Ended(None) => {
|
||||||
|
error!("exited");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue