use objc2::rc::Retained;
use objc2::{define_class, msg_send, MainThreadMarker, MainThreadOnly};
use objc2_app_kit::{NSBackingStoreType, NSWindow, NSWindowOcclusionState, NSWindowStyleMask};
use objc2_foundation::NSRect;
define_class!(
#[unsafe(super = NSWindow)]
#[thread_kind = MainThreadOnly]
#[name = "VsHeadlessWindow"]
pub(super) struct HeadlessWindow;
impl HeadlessWindow {
#[unsafe(method(isVisible))]
fn is_visible(&self) -> bool {
true
}
#[unsafe(method(occlusionState))]
fn occlusion_state(&self) -> NSWindowOcclusionState {
NSWindowOcclusionState::Visible
}
}
);
impl HeadlessWindow {
pub(super) fn host(
mtm: MainThreadMarker,
frame: NSRect,
style: NSWindowStyleMask,
backing: NSBackingStoreType,
) -> Retained<NSWindow> {
let this: Retained<Self> = unsafe {
msg_send![
Self::alloc(mtm),
initWithContentRect: frame,
styleMask: style,
backing: backing,
defer: false,
]
};
this.into_super()
}
}