Add 'WindowEvent::Occluded(bool)'
This commits and an event to track window occlusion state, which could help optimize rendering downstream.
This commit is contained in:
parent
4b10993970
commit
e289f30e5d
4 changed files with 39 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use cocoa::{
|
||||
appkit::{self, NSApplicationPresentationOptions, NSView, NSWindow},
|
||||
appkit::{self, NSApplicationPresentationOptions, NSView, NSWindow, NSWindowOcclusionState},
|
||||
base::{id, nil},
|
||||
foundation::NSUInteger,
|
||||
};
|
||||
|
|
@ -220,6 +220,10 @@ static WINDOW_DELEGATE_CLASS: Lazy<WindowDelegateClass> = Lazy::new(|| unsafe {
|
|||
sel!(windowDidFailToEnterFullScreen:),
|
||||
window_did_fail_to_enter_fullscreen as extern "C" fn(&Object, Sel, id),
|
||||
);
|
||||
decl.add_method(
|
||||
sel!(windowDidChangeOcclusionState:),
|
||||
window_did_change_occlusion_state as extern "C" fn(&Object, Sel, id),
|
||||
);
|
||||
|
||||
decl.add_ivar::<*mut c_void>("winitState");
|
||||
WindowDelegateClass(decl.register())
|
||||
|
|
@ -554,3 +558,18 @@ extern "C" fn window_did_fail_to_enter_fullscreen(this: &Object, _: Sel, _: id)
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Invoked when the occlusion state of the window changes
|
||||
extern "C" fn window_did_change_occlusion_state(this: &Object, _: Sel, _: id) {
|
||||
trace_scope!("windowDidChangeOcclusionState:");
|
||||
unsafe {
|
||||
with_state(this, |state| {
|
||||
state.emit_event(WindowEvent::Occluded(
|
||||
!state
|
||||
.ns_window
|
||||
.occlusionState()
|
||||
.contains(NSWindowOcclusionState::NSWindowOcclusionStateVisible),
|
||||
))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue