-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa98b29
commit e81dcb0
Showing
6 changed files
with
60 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
use objc::runtime::Object; | ||
use objc::{msg_send, sel, sel_impl}; | ||
use objc2::msg_send; | ||
use objc2::runtime::NSObject; | ||
use raw_window_handle::{HasWindowHandle, RawWindowHandle}; | ||
|
||
pub fn with_window<T>(win: impl HasWindowHandle, f: impl FnOnce(*mut Object) -> T) -> T { | ||
// Get NSView. | ||
/// The returned `NSWindow` will be valid while `win` still alive. | ||
pub fn get_window(win: impl HasWindowHandle) -> *mut NSObject { | ||
let win = get_view(win); | ||
|
||
unsafe { msg_send![win, window] } | ||
} | ||
|
||
/// The returned `NSView` will be valid while `win` still alive. | ||
pub fn get_view(win: impl HasWindowHandle) -> *mut NSObject { | ||
let win = win.window_handle().unwrap(); | ||
let win = match win.as_ref() { | ||
RawWindowHandle::AppKit(v) => v.ns_view.as_ptr().cast::<Object>(), | ||
_ => unreachable!(), | ||
}; | ||
|
||
// Get NSWindow. | ||
f(unsafe { msg_send![win, window] }) | ||
match win.as_ref() { | ||
RawWindowHandle::AppKit(v) => v.ns_view.as_ptr().cast(), | ||
_ => unreachable!(), | ||
} | ||
} |