Add cursor hittest window functionality (#2232)
Co-authored-by: z4122 <412213484@qq.com> Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
parent
142d55ff24
commit
bf366cb99d
14 changed files with 120 additions and 6 deletions
|
|
@ -10,7 +10,7 @@ use cocoa::{
|
|||
};
|
||||
use dispatch::Queue;
|
||||
use objc::rc::autoreleasepool;
|
||||
use objc::runtime::{BOOL, NO};
|
||||
use objc::runtime::{BOOL, NO, YES};
|
||||
|
||||
use crate::{
|
||||
dpi::LogicalSize,
|
||||
|
|
@ -93,6 +93,14 @@ pub unsafe fn set_level_async(ns_window: id, level: ffi::NSWindowLevel) {
|
|||
});
|
||||
}
|
||||
|
||||
// `setIgnoresMouseEvents_:` isn't thread-safe, and fails silently.
|
||||
pub unsafe fn set_ignore_mouse_events(ns_window: id, ignore: bool) {
|
||||
let ns_window = MainThreadSafe(ns_window);
|
||||
Queue::main().exec_async(move || {
|
||||
ns_window.setIgnoresMouseEvents_(if ignore { YES } else { NO });
|
||||
});
|
||||
}
|
||||
|
||||
// `toggleFullScreen` is thread-safe, but our additional logic to account for
|
||||
// window styles isn't.
|
||||
pub unsafe fn toggle_full_screen_async(
|
||||
|
|
|
|||
|
|
@ -678,6 +678,15 @@ impl UnownedWindow {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
|
||||
unsafe {
|
||||
util::set_ignore_mouse_events(*self.ns_window, !hittest);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn is_zoomed(&self) -> bool {
|
||||
// because `isZoomed` doesn't work if the window's borderless,
|
||||
// we make it resizable temporalily.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue