use {
reovim_driver_layout::{
LayerId, NavigateDirection, OverlayConstraints, Rect, SplitDirection, WindowId,
WindowPlacement,
},
reovim_kernel::api::v1::TabId,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CompositorError {
CannotCloseLastWindow,
NoNeighbor(NavigateDirection),
NotEnoughRoom,
CannotResizeAtEdge,
NoActiveLayer,
NoFocusedWindow,
WindowNotFound(WindowId),
LayerNotFound(LayerId),
NoTabPages,
CannotCloseLastTab,
TabNotFound(TabId),
}
impl std::fmt::Display for CompositorError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::CannotCloseLastWindow => write!(f, "cannot close last window"),
Self::NoNeighbor(dir) => write!(f, "no window {dir:?}"),
Self::NotEnoughRoom => write!(f, "not enough room to split"),
Self::CannotResizeAtEdge => write!(f, "cannot resize at edge"),
Self::NoActiveLayer => write!(f, "no active layer"),
Self::NoFocusedWindow => write!(f, "no focused window"),
Self::WindowNotFound(id) => write!(f, "window {} not found", id.as_usize()),
Self::LayerNotFound(id) => write!(f, "layer {} not found", id.as_u16()),
Self::NoTabPages => write!(f, "no tab pages"),
Self::CannotCloseLastTab => write!(f, "cannot close last tab"),
Self::TabNotFound(id) => write!(f, "tab {} not found", id.as_usize()),
}
}
}
impl std::error::Error for CompositorError {}
pub trait CompositorApi {
fn navigate(&self, direction: NavigateDirection) -> Result<WindowId, CompositorError>;
fn split(&mut self, direction: SplitDirection) -> Result<WindowId, CompositorError>;
fn close_current_window(&mut self) -> Result<WindowId, CompositorError>;
fn close_others(&mut self) -> Result<(), CompositorError>;
fn resize(&mut self, direction: NavigateDirection, delta: i16) -> Result<(), CompositorError>;
fn equalize(&mut self) -> Result<(), CompositorError>;
fn cycle(&self, forward: bool) -> Result<WindowId, CompositorError>;
fn focus(&mut self, window: WindowId) -> Result<(), CompositorError>;
fn focused_window(&self) -> Option<WindowId>;
fn compositor_window_count(&self) -> usize;
fn arrange(&self, screen: Rect) -> Vec<WindowPlacement>;
fn active_layer(&self) -> Option<LayerId>;
fn set_screen(&mut self, screen: Rect);
fn toggle_float(&mut self) -> Result<(), CompositorError>;
fn raise_float(&mut self) -> Result<(), CompositorError>;
fn lower_float(&mut self) -> Result<(), CompositorError>;
fn set_active_layer_opacity(&mut self, opacity: f32) -> Result<(), CompositorError>;
fn active_layer_opacity(&self) -> Result<f32, CompositorError>;
fn adjust_active_layer_opacity(&mut self, delta: f32) -> Result<f32, CompositorError>;
fn show_overlay(
&mut self,
constraints: OverlayConstraints,
) -> Result<WindowId, CompositorError>;
fn hide_overlay(&mut self, window: WindowId) -> Result<(), CompositorError>;
fn resize_overlay(
&mut self,
window: WindowId,
width: u16,
height: u16,
) -> Result<(), CompositorError>;
fn hide_all_overlays(&mut self) -> Result<(), CompositorError>;
fn tab_new(&mut self) -> Result<TabId, CompositorError>;
fn tab_close(&mut self) -> Result<(), CompositorError>;
fn tab_next(&mut self) -> Result<TabId, CompositorError>;
fn tab_prev(&mut self) -> Result<TabId, CompositorError>;
fn tab_goto(&mut self, index: usize) -> Result<TabId, CompositorError>;
fn tab_count(&self) -> usize;
fn active_tab_id(&self) -> Option<TabId>;
}
#[cfg(test)]
#[path = "tests/compositor.rs"]
mod tests;