use std::path::{Path, PathBuf};
use async_trait::async_trait;
use crate::error::Result;
#[async_trait]
pub trait CompositorRuntime: Send + Sync {
async fn start(&mut self, resolution: Option<&str>) -> Result<()>;
async fn stop(&mut self) -> Result<()>;
fn id(&self) -> &str;
fn wayland_display(&self) -> &str;
fn runtime_dir(&self) -> &Path;
}
#[async_trait]
pub trait InputBackend: Send + Sync {
async fn press_keysym(&self, keysym: u32) -> Result<()>;
async fn key_down(&self, keysym: u32) -> Result<()>;
async fn key_up(&self, keysym: u32) -> Result<()>;
async fn pointer_motion_relative(&self, dx: f64, dy: f64) -> Result<()>;
async fn pointer_button(&self, button: u32) -> Result<()>;
}
pub struct PipeWireStream {
pub node_id: u32,
pub token: Box<dyn std::any::Any + Send + Sync>,
}
#[async_trait]
pub trait CaptureBackend: Send + Sync {
async fn start_stream(&self) -> Result<PipeWireStream>;
async fn stop_stream(&self, stream: PipeWireStream) -> Result<()>;
fn pipewire_socket(&self) -> PathBuf;
async fn grab_screenshot(&self, stream: &PipeWireStream) -> Result<Vec<u8>> {
crate::capture::grab_png(stream.node_id, &self.pipewire_socket()).await
}
async fn start_recording(
&self,
stream: &PipeWireStream,
output_path: &Path,
bitrate: u32,
) -> Result<crate::capture::VideoRecorder> {
crate::capture::VideoRecorder::start(
stream.node_id,
&self.pipewire_socket(),
output_path,
bitrate,
)
.await
}
async fn stop_recording(&self, recorder: crate::capture::VideoRecorder) -> Result<()> {
recorder.stop().await
}
}