use std::sync::Arc;
use teksilo_canvas::{Point, Size};
use teksilo_core::{
HitRegions, PlatformError, PlatformTitleBarHost, ResizeEdge, TitleBarHostCallbacks,
};
use winit::window::Window;
use super::edge_to_direction;
pub struct X11Host {
window: Arc<Window>,
}
impl X11Host {
pub fn new(
window: Arc<Window>,
_callbacks: TitleBarHostCallbacks,
) -> Result<Self, PlatformError> {
if !crate::x11::capabilities().supports_custom_chrome() {
return Err(PlatformError::Unsupported);
}
Ok(Self { window })
}
}
impl PlatformTitleBarHost for X11Host {
fn reserved_leading_inset(&self) -> Size {
Size::ZERO
}
fn reserved_trailing_inset(&self) -> Size {
Size::ZERO
}
fn renders_custom_controls(&self) -> bool {
true
}
fn needs_custom_resize_handles(&self) -> bool {
true
}
fn begin_drag(&self) -> Result<(), PlatformError> {
self.window
.drag_window()
.map_err(|e| PlatformError::Os(e.to_string()))
}
fn begin_resize(&self, edge: ResizeEdge) -> Result<(), PlatformError> {
self.window
.drag_resize_window(edge_to_direction(edge))
.map_err(|e| PlatformError::Os(e.to_string()))
}
fn show_window_menu(&self, _at: Point) -> Result<(), PlatformError> {
Err(PlatformError::Unsupported)
}
fn has_window_menu(&self) -> bool {
false
}
fn update_hit_regions(&self, _regions: &HitRegions) {
}
}