use bezel::{
gpui::{AnyElement, App, ElementId, Window, WindowDecorations, div, prelude::*},
ui::titlebar::{self, CaptionSide, DragState},
};
const NATIVE: bool = cfg!(target_os = "macos");
pub fn caption(side: CaptionSide, window: &Window, cx: &App) -> Option<AnyElement> {
has(side, window, cx).then(|| {
titlebar::controls(side, window, cx)
.flex_none()
.into_any_element()
})
}
pub fn grip(id: impl Into<ElementId>, drag: &DragState, window: &Window) -> AnyElement {
match NATIVE {
true => div().flex_1().min_w_0().into_any_element(),
false => titlebar::grip(id, drag, window)
.min_w_0()
.into_any_element(),
}
}
pub fn has(side: CaptionSide, window: &Window, cx: &App) -> bool {
if NATIVE || window.is_fullscreen() {
return false;
}
let layout = cx.button_layout();
match side {
CaptionSide::Left => layout.is_some_and(|layout| layout.left[0].is_some()),
CaptionSide::Right => layout.is_none_or(|layout| layout.right[0].is_some()),
}
}
pub fn decorations() -> Option<WindowDecorations> {
cfg!(any(target_os = "linux", target_os = "freebsd")).then_some(WindowDecorations::Client)
}