1
0
Fork 0

Upgrade to raw-window-handle 0.4.x

The main change is that all of these types are simplified, there are
more different OS-specific window handle types, and they are no longer
gated behind the respective targets which makes the library a bit easier
to use for applications.
This commit is contained in:
Robbert van der Helm 2022-02-07 17:13:51 +01:00
parent 625fde7957
commit d76b02df44
4 changed files with 28 additions and 27 deletions

View file

@ -9,13 +9,14 @@ authors = [
"Billy Messenger <billydm@protonmail.com>",
"Anton Lazarev <https://antonok.com>",
"Joakim Frostegård <joakim.frostegard@gmail.com>",
"Robbert van der Helm <mail@robbertvanderhelm.nl>",
]
edition = "2018"
license = "MIT OR Apache-2.0"
[dependencies]
keyboard-types = { version = "0.6.1", default-features = false }
raw-window-handle = "0.3.3"
raw-window-handle = "0.4.2"
[target.'cfg(target_os="linux")'.dependencies]
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }

View file

@ -16,7 +16,7 @@ use keyboard_types::KeyboardEvent;
use objc::{msg_send, runtime::Object, sel, sel_impl};
use raw_window_handle::{macos::MacOSHandle, HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{AppKitHandle, HasRawWindowHandle, RawWindowHandle};
use crate::{
Event, EventStatus, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions,
@ -55,7 +55,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
}
}
RawWindowHandle::MacOS(MacOSHandle { ..MacOSHandle::empty() })
RawWindowHandle::AppKit(AppKitHandle::empty())
}
}
@ -114,7 +114,7 @@ impl Window {
{
let pool = unsafe { NSAutoreleasePool::new(nil) };
let handle = if let RawWindowHandle::MacOS(handle) = parent.raw_window_handle() {
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
handle
} else {
panic!("Not a macOS window");
@ -388,10 +388,10 @@ unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
let ns_window = self.ns_window.unwrap_or(::std::ptr::null_mut()) as *mut c_void;
RawWindowHandle::MacOS(MacOSHandle {
ns_window,
ns_view: self.ns_view as *mut c_void,
..MacOSHandle::empty()
})
let mut handle = AppKitHandle::empty();
handle.ns_window = ns_window;
handle.ns_view = self.ns_view as *mut c_void;
RawWindowHandle::AppKit(handle)
}
}

View file

@ -23,7 +23,7 @@ use std::ptr::null_mut;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use raw_window_handle::{windows::WindowsHandle, HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle};
const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1;
@ -80,12 +80,12 @@ impl WindowHandle {
unsafe impl HasRawWindowHandle for WindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
if let Some(hwnd) = self.hwnd {
RawWindowHandle::Windows(WindowsHandle {
hwnd: hwnd as *mut std::ffi::c_void,
..WindowsHandle::empty()
})
let mut handle = Win32Handle::empty();
handle.hwnd = hwnd as *mut std::ffi::c_void;
RawWindowHandle::Win32(handle)
} else {
RawWindowHandle::Windows(WindowsHandle { ..WindowsHandle::empty() })
RawWindowHandle::Win32(Win32Handle::empty())
}
}
}
@ -372,7 +372,7 @@ impl Window {
B: Send + 'static,
{
let parent = match parent.raw_window_handle() {
RawWindowHandle::Windows(h) => h.hwnd as HWND,
RawWindowHandle::Win32(h) => h.hwnd as HWND,
h => panic!("unsupported parent handle {:?}", h),
};
@ -560,9 +560,9 @@ impl Window {
unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
RawWindowHandle::Windows(WindowsHandle {
hwnd: self.hwnd as *mut std::ffi::c_void,
..WindowsHandle::empty()
})
let mut handle = Win32Handle::empty();
handle.hwnd = self.hwnd as *mut std::ffi::c_void;
RawWindowHandle::Win32(handle)
}
}

View file

@ -6,7 +6,7 @@ use std::sync::Arc;
use std::thread;
use std::time::*;
use raw_window_handle::{unix::XlibHandle, HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, XlibHandle};
use super::XcbConnection;
use crate::{
@ -49,7 +49,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
}
}
RawWindowHandle::Xlib(XlibHandle { ..raw_window_handle::unix::XlibHandle::empty() })
RawWindowHandle::Xlib(XlibHandle::empty())
}
}
@ -595,11 +595,11 @@ impl Window {
unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
RawWindowHandle::Xlib(XlibHandle {
window: self.window_id as c_ulong,
display: self.xcb_connection.conn.get_raw_dpy() as *mut c_void,
..raw_window_handle::unix::XlibHandle::empty()
})
let mut handle = XlibHandle::empty();
handle.window = self.window_id as c_ulong;
handle.display = self.xcb_connection.conn.get_raw_dpy() as *mut c_void;
RawWindowHandle::Xlib(handle)
}
}