raw-window-handle 0.6.0 (windows only!!!!)
This commit is contained in:
parent
50a5602bca
commit
b3bbdea6c0
19
Cargo.toml
19
Cargo.toml
|
@ -15,12 +15,12 @@ edition = "2018"
|
|||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["opengl"]
|
||||
opengl = ["uuid", "x11/glx"]
|
||||
|
||||
[dependencies]
|
||||
keyboard-types = { version = "0.6.1", default-features = false }
|
||||
raw-window-handle = "0.5"
|
||||
raw-window-handle = "0.6"
|
||||
|
||||
[target.'cfg(target_os="linux")'.dependencies]
|
||||
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
||||
|
@ -29,7 +29,20 @@ xcb-util = { version = "0.3", features = ["icccm"] }
|
|||
nix = "0.22.0"
|
||||
|
||||
[target.'cfg(target_os="windows")'.dependencies]
|
||||
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi", "wingdi", "errhandlingapi", "ole2", "oleidl", "shellapi", "winerror"] }
|
||||
winapi = { version = "0.3.8", features = [
|
||||
"libloaderapi",
|
||||
"winuser",
|
||||
"windef",
|
||||
"minwindef",
|
||||
"guiddef",
|
||||
"combaseapi",
|
||||
"wingdi",
|
||||
"errhandlingapi",
|
||||
"ole2",
|
||||
"oleidl",
|
||||
"shellapi",
|
||||
"winerror",
|
||||
] }
|
||||
uuid = { version = "0.8", features = ["v4"], optional = true }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
|
|
|
@ -35,11 +35,7 @@ impl GlContext {
|
|||
return Err(GlError::InvalidWindowHandle);
|
||||
};
|
||||
|
||||
if handle.ns_view.is_null() {
|
||||
return Err(GlError::InvalidWindowHandle);
|
||||
}
|
||||
|
||||
let parent_view = handle.ns_view as id;
|
||||
let parent_view = handle.ns_view.as_ptr() as id;
|
||||
|
||||
let version = if config.version < (3, 2) && config.profile == Profile::Compatibility {
|
||||
NSOpenGLProfileVersionLegacy
|
||||
|
|
|
@ -47,7 +47,7 @@ impl WindowHandle {
|
|||
}
|
||||
|
||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||
self.state.window_inner.raw_window_handle()
|
||||
}
|
||||
}
|
||||
|
@ -103,18 +103,15 @@ impl WindowInner {
|
|||
}
|
||||
}
|
||||
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||
if self.open.get() {
|
||||
let ns_window = self.ns_window.get().unwrap_or(ptr::null_mut()) as *mut c_void;
|
||||
|
||||
let mut handle = AppKitWindowHandle::empty();
|
||||
handle.ns_window = ns_window;
|
||||
handle.ns_view = self.ns_view as *mut c_void;
|
||||
|
||||
return RawWindowHandle::AppKit(handle);
|
||||
Ok(RawWindowHandle::AppKit(AppKitWindowHandle::new(
|
||||
std::ptr::NonNull::new(self.ns_view as *mut c_void)
|
||||
.ok_or(raw_window_handle::HandleError::Unavailable)?,
|
||||
)))
|
||||
} else {
|
||||
Err(raw_window_handle::HandleError::Unavailable)
|
||||
}
|
||||
|
||||
RawWindowHandle::AppKit(AppKitWindowHandle::empty())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +136,7 @@ impl<'a> Window<'a> {
|
|||
|
||||
let window_info = WindowInfo::from_logical_size(options.size, scaling);
|
||||
|
||||
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
|
||||
let handle = if let Ok(RawWindowHandle::AppKit(handle)) = parent.raw_window_handle() {
|
||||
handle
|
||||
} else {
|
||||
panic!("Not a macOS window");
|
||||
|
@ -162,7 +159,7 @@ impl<'a> Window<'a> {
|
|||
let window_handle = Self::init(window_inner, window_info, build);
|
||||
|
||||
unsafe {
|
||||
let _: id = msg_send![handle.ns_view as *mut Object, addSubview: ns_view];
|
||||
let _: id = msg_send![handle.ns_view.as_ptr() as *mut Object, addSubview: ns_view];
|
||||
|
||||
let () = msg_send![pool, drain];
|
||||
}
|
||||
|
@ -316,10 +313,9 @@ impl<'a> Window<'a> {
|
|||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn create_gl_context(ns_window: Option<id>, ns_view: id, config: GlConfig) -> GlContext {
|
||||
let mut handle = AppKitWindowHandle::empty();
|
||||
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
||||
handle.ns_view = ns_view as *mut c_void;
|
||||
let handle = RawWindowHandle::AppKit(handle);
|
||||
let handle = RawWindowHandle::AppKit(AppKitWindowHandle::new(
|
||||
std::ptr::NonNull::new(ns_view as *mut c_void).expect("Could not create window handle"),
|
||||
));
|
||||
|
||||
unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
|
||||
}
|
||||
|
@ -394,14 +390,14 @@ impl WindowState {
|
|||
}
|
||||
|
||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||
self.inner.raw_window_handle()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
||||
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||
Ok(RawDisplayHandle::AppKit(AppKitDisplayHandle::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use raw_window_handle::{
|
||||
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||
DisplayHandle, HasDisplayHandle, HasRawDisplayHandle, HasRawWindowHandle, HasWindowHandle,
|
||||
RawDisplayHandle, RawWindowHandle,
|
||||
};
|
||||
|
||||
use crate::event::{Event, EventStatus};
|
||||
|
@ -39,7 +40,7 @@ impl WindowHandle {
|
|||
}
|
||||
|
||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||
self.window_handle.raw_window_handle()
|
||||
}
|
||||
}
|
||||
|
@ -110,14 +111,16 @@ impl<'a> Window<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
self.window.raw_window_handle()
|
||||
impl<'a> HasWindowHandle for Window<'a> {
|
||||
fn window_handle(
|
||||
&self,
|
||||
) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
|
||||
Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(self.window.raw_window_handle()?) })
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||
self.window.raw_display_handle()
|
||||
impl<'a> HasDisplayHandle for Window<'a> {
|
||||
fn display_handle(&self) -> Result<DisplayHandle<'_>, raw_window_handle::HandleError> {
|
||||
Ok(unsafe { DisplayHandle::borrow_raw(self.window.raw_display_handle()?) })
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue