use crate::{Bounds, Error, WindowId, platform_impl::PlatformWindow};
#[derive(Clone, Debug)]
pub struct Window(pub(crate) PlatformWindow);
impl Window {
pub fn new(inner: PlatformWindow) -> Self {
Self(inner)
}
pub fn platform_window(&self) -> &PlatformWindow {
&self.0
}
pub fn into_platform_window(self) -> PlatformWindow {
self.0
}
pub fn id(&self) -> WindowId {
#[cfg(target_os = "macos")]
{
WindowId(self.0.id())
}
#[cfg(target_os = "windows")]
{
WindowId(self.0.hwnd())
}
}
pub fn title(&self) -> Result<Option<String>, Error> {
#[cfg(target_os = "macos")]
{
Ok(self.0.title())
}
#[cfg(target_os = "windows")]
{
Ok(self.0.title()?)
}
}
pub fn bounds(&self) -> Result<Bounds, Error> {
#[cfg(target_os = "macos")]
{
Ok(self.0.bounds()?)
}
#[cfg(target_os = "windows")]
{
Ok(self.0.visible_bounds()?)
}
}
pub fn owner_pid(&self) -> Result<i32, Error> {
#[cfg(target_os = "macos")]
{
Ok(self.0.owner_pid())
}
#[cfg(target_os = "windows")]
{
Ok(self.0.owner_pid()? as _)
}
}
pub fn owner_name(&self) -> Result<Option<String>, Error> {
#[cfg(target_os = "macos")]
{
Ok(self.0.owner_name())
}
#[cfg(target_os = "windows")]
{
Ok(self.0.owner_name().map(Some)?)
}
}
}