Compare commits
4 commits
4e6e9737f1
...
7df00dba07
Author | SHA1 | Date | |
---|---|---|---|
Alex Janka | 7df00dba07 | ||
Alex Janka | fab0f5210e | ||
Alex Janka | b3bbdea6c0 | ||
Alex Janka | 50a5602bca |
19
Cargo.toml
19
Cargo.toml
|
@ -15,12 +15,12 @@ edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["opengl"]
|
||||||
opengl = ["uuid", "x11/glx"]
|
opengl = ["uuid", "x11/glx"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
keyboard-types = { version = "0.6.1", default-features = false }
|
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]
|
[target.'cfg(target_os="linux")'.dependencies]
|
||||||
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
||||||
|
@ -29,7 +29,20 @@ xcb-util = { version = "0.3", features = ["icccm"] }
|
||||||
nix = "0.22.0"
|
nix = "0.22.0"
|
||||||
|
|
||||||
[target.'cfg(target_os="windows")'.dependencies]
|
[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 }
|
uuid = { version = "0.8", features = ["v4"], optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_os="macos")'.dependencies]
|
[target.'cfg(target_os="macos")'.dependencies]
|
||||||
|
|
|
@ -35,11 +35,7 @@ impl GlContext {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
if handle.ns_view.is_null() {
|
let parent_view = handle.ns_view.as_ptr() as id;
|
||||||
return Err(GlError::InvalidWindowHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parent_view = handle.ns_view as id;
|
|
||||||
|
|
||||||
let version = if config.version < (3, 2) && config.profile == Profile::Compatibility {
|
let version = if config.version < (3, 2) && config.profile == Profile::Compatibility {
|
||||||
NSOpenGLProfileVersionLegacy
|
NSOpenGLProfileVersionLegacy
|
||||||
|
|
|
@ -84,10 +84,6 @@ impl GlContext {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
if handle.hwnd.is_null() {
|
|
||||||
return Err(GlError::InvalidWindowHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create temporary window and context to load function pointers
|
// Create temporary window and context to load function pointers
|
||||||
|
|
||||||
let class_name_str = format!("raw-gl-context-window-{}", uuid::Uuid::new_v4().to_simple());
|
let class_name_str = format!("raw-gl-context-window-{}", uuid::Uuid::new_v4().to_simple());
|
||||||
|
@ -195,7 +191,7 @@ impl GlContext {
|
||||||
|
|
||||||
// Create actual context
|
// Create actual context
|
||||||
|
|
||||||
let hwnd = handle.hwnd as HWND;
|
let hwnd = handle.hwnd.get() as HWND;
|
||||||
|
|
||||||
let hdc = GetDC(hwnd);
|
let hdc = GetDC(hwnd);
|
||||||
|
|
||||||
|
|
|
@ -295,8 +295,6 @@ extern "C" fn view_will_move_to_window(this: &Object, _self: Sel, new_window: id
|
||||||
let tracking_areas: *mut Object = msg_send![this, trackingAreas];
|
let tracking_areas: *mut Object = msg_send![this, trackingAreas];
|
||||||
let tracking_area_count = NSArray::count(tracking_areas);
|
let tracking_area_count = NSArray::count(tracking_areas);
|
||||||
|
|
||||||
let _: () = msg_send![class!(NSEvent), setMouseCoalescingEnabled: NO];
|
|
||||||
|
|
||||||
if new_window == nil {
|
if new_window == nil {
|
||||||
if tracking_area_count != 0 {
|
if tracking_area_count != 0 {
|
||||||
let tracking_area = NSArray::objectAtIndex(tracking_areas, 0);
|
let tracking_area = NSArray::objectAtIndex(tracking_areas, 0);
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for 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()
|
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() {
|
if self.open.get() {
|
||||||
let ns_window = self.ns_window.get().unwrap_or(ptr::null_mut()) as *mut c_void;
|
Ok(RawWindowHandle::AppKit(AppKitWindowHandle::new(
|
||||||
|
std::ptr::NonNull::new(self.ns_view as *mut c_void)
|
||||||
let mut handle = AppKitWindowHandle::empty();
|
.ok_or(raw_window_handle::HandleError::Unavailable)?,
|
||||||
handle.ns_window = ns_window;
|
)))
|
||||||
handle.ns_view = self.ns_view as *mut c_void;
|
} else {
|
||||||
|
Err(raw_window_handle::HandleError::Unavailable)
|
||||||
return RawWindowHandle::AppKit(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RawWindowHandle::AppKit(AppKitWindowHandle::empty())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +136,7 @@ impl<'a> Window<'a> {
|
||||||
|
|
||||||
let window_info = WindowInfo::from_logical_size(options.size, scaling);
|
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
|
handle
|
||||||
} else {
|
} else {
|
||||||
panic!("Not a macOS window");
|
panic!("Not a macOS window");
|
||||||
|
@ -162,7 +159,7 @@ impl<'a> Window<'a> {
|
||||||
let window_handle = Self::init(window_inner, window_info, build);
|
let window_handle = Self::init(window_inner, window_info, build);
|
||||||
|
|
||||||
unsafe {
|
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];
|
let () = msg_send![pool, drain];
|
||||||
}
|
}
|
||||||
|
@ -316,10 +313,9 @@ impl<'a> Window<'a> {
|
||||||
|
|
||||||
#[cfg(feature = "opengl")]
|
#[cfg(feature = "opengl")]
|
||||||
fn create_gl_context(ns_window: Option<id>, ns_view: id, config: GlConfig) -> GlContext {
|
fn create_gl_context(ns_window: Option<id>, ns_view: id, config: GlConfig) -> GlContext {
|
||||||
let mut handle = AppKitWindowHandle::empty();
|
let handle = RawWindowHandle::AppKit(AppKitWindowHandle::new(
|
||||||
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
std::ptr::NonNull::new(ns_view as *mut c_void).expect("Could not create window handle"),
|
||||||
handle.ns_view = ns_view as *mut c_void;
|
));
|
||||||
let handle = RawWindowHandle::AppKit(handle);
|
|
||||||
|
|
||||||
unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
|
unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
|
||||||
}
|
}
|
||||||
|
@ -394,14 +390,14 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
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()
|
self.inner.raw_window_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||||
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
Ok(RawDisplayHandle::AppKit(AppKitDisplayHandle::new()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ use winapi::um::winuser::{
|
||||||
use std::cell::{Cell, Ref, RefCell, RefMut};
|
use std::cell::{Cell, Ref, RefCell, RefMut};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::{c_void, OsStr};
|
use std::ffi::{c_void, OsStr};
|
||||||
|
use std::num::NonZeroIsize;
|
||||||
use std::os::windows::ffi::OsStrExt;
|
use std::os::windows::ffi::OsStrExt;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -84,15 +85,12 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
if let Some(hwnd) = self.hwnd {
|
self.hwnd
|
||||||
let mut handle = Win32WindowHandle::empty();
|
.and_then(|hwnd| NonZeroIsize::new(hwnd as isize))
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
RawWindowHandle::Win32(handle)
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
} else {
|
|
||||||
RawWindowHandle::Win32(Win32WindowHandle::empty())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +539,7 @@ impl Window<'_> {
|
||||||
B: Send + 'static,
|
B: Send + 'static,
|
||||||
{
|
{
|
||||||
let parent = match parent.raw_window_handle() {
|
let parent = match parent.raw_window_handle() {
|
||||||
RawWindowHandle::Win32(h) => h.hwnd as HWND,
|
Ok(RawWindowHandle::Win32(h)) => h.hwnd.get() as HWND,
|
||||||
h => panic!("unsupported parent handle {:?}", h),
|
h => panic!("unsupported parent handle {:?}", h),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -638,9 +636,11 @@ impl Window<'_> {
|
||||||
|
|
||||||
#[cfg(feature = "opengl")]
|
#[cfg(feature = "opengl")]
|
||||||
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
|
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
|
||||||
let mut handle = Win32WindowHandle::empty();
|
let handle = NonZeroIsize::new(hwnd as isize)
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
let handle = RawWindowHandle::Win32(handle);
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
|
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
|
||||||
});
|
});
|
||||||
|
@ -760,17 +760,17 @@ impl Window<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for Window<'_> {
|
unsafe impl HasRawWindowHandle for Window<'_> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
let mut handle = Win32WindowHandle::empty();
|
NonZeroIsize::new(self.state.hwnd as isize)
|
||||||
handle.hwnd = self.state.hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
RawWindowHandle::Win32(handle)
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawDisplayHandle for Window<'_> {
|
unsafe impl HasRawDisplayHandle for Window<'_> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||||
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
|
Ok(RawDisplayHandle::Windows(WindowsDisplayHandle::new()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use raw_window_handle::{
|
use raw_window_handle::{
|
||||||
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
DisplayHandle, HasDisplayHandle, HasRawDisplayHandle, HasRawWindowHandle, HasWindowHandle,
|
||||||
|
RawDisplayHandle, RawWindowHandle,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::event::{Event, EventStatus};
|
use crate::event::{Event, EventStatus};
|
||||||
|
@ -39,7 +40,7 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for 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()
|
self.window_handle.raw_window_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,14 +111,16 @@ impl<'a> Window<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
impl<'a> HasWindowHandle for Window<'a> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn window_handle(
|
||||||
self.window.raw_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> {
|
impl<'a> HasDisplayHandle for Window<'a> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn display_handle(&self) -> Result<DisplayHandle<'_>, raw_window_handle::HandleError> {
|
||||||
self.window.raw_display_handle()
|
Ok(unsafe { DisplayHandle::borrow_raw(self.window.raw_display_handle()?) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,14 +46,13 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
if let Some(raw_window_handle) = self.raw_window_handle {
|
if let Some(raw_window_handle) = self.raw_window_handle {
|
||||||
if self.is_open.load(Ordering::Relaxed) {
|
if self.is_open.load(Ordering::Relaxed) {
|
||||||
return raw_window_handle;
|
return Ok(raw_window_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(raw_window_handle::HandleError::Unavailable)
|
||||||
RawWindowHandle::Xlib(XlibWindowHandle::empty())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +125,8 @@ impl<'a> Window<'a> {
|
||||||
{
|
{
|
||||||
// Convert parent into something that X understands
|
// Convert parent into something that X understands
|
||||||
let parent_id = match parent.raw_window_handle() {
|
let parent_id = match parent.raw_window_handle() {
|
||||||
RawWindowHandle::Xlib(h) => h.window as u32,
|
Ok(RawWindowHandle::Xlib(h)) => h.window as u32,
|
||||||
RawWindowHandle::Xcb(h) => h.window,
|
Ok(RawWindowHandle::Xcb(h)) => h.window.get(),
|
||||||
h => panic!("unsupported parent handle type {:?}", h),
|
h => panic!("unsupported parent handle type {:?}", h),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -341,7 +340,9 @@ impl<'a> Window<'a> {
|
||||||
// the correct dpi scaling.
|
// the correct dpi scaling.
|
||||||
handler.on_event(&mut window, Event::Window(WindowEvent::Resized(window_info)));
|
handler.on_event(&mut window, Event::Window(WindowEvent::Resized(window_info)));
|
||||||
|
|
||||||
let _ = tx.send(Ok(SendableRwh(window.raw_window_handle())));
|
if let Ok(rwh) = window.raw_window_handle() {
|
||||||
|
let _ = tx.send(Ok(SendableRwh(rwh)));
|
||||||
|
}
|
||||||
|
|
||||||
inner.run_event_loop(&mut handler);
|
inner.run_event_loop(&mut handler);
|
||||||
}
|
}
|
||||||
|
@ -700,25 +701,24 @@ impl WindowInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
let mut handle = XlibWindowHandle::empty();
|
let mut handle = XlibWindowHandle::new(self.inner.window_id.into());
|
||||||
|
|
||||||
handle.window = self.inner.window_id.into();
|
|
||||||
handle.visual_id = self.inner.visual_id.into();
|
handle.visual_id = self.inner.visual_id.into();
|
||||||
|
|
||||||
RawWindowHandle::Xlib(handle)
|
Ok(RawWindowHandle::Xlib(handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||||
let display = self.inner.xcb_connection.conn.get_raw_dpy();
|
let display = self.inner.xcb_connection.conn.get_raw_dpy();
|
||||||
let mut handle = XlibDisplayHandle::empty();
|
let handle =
|
||||||
|
XlibDisplayHandle::new(std::ptr::NonNull::new(display as *mut c_void), unsafe {
|
||||||
|
x11::xlib::XDefaultScreen(display)
|
||||||
|
});
|
||||||
|
|
||||||
handle.display = display as *mut c_void;
|
Ok(RawDisplayHandle::Xlib(handle))
|
||||||
handle.screen = unsafe { x11::xlib::XDefaultScreen(display) };
|
|
||||||
|
|
||||||
RawDisplayHandle::Xlib(handle)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue