Skip to content

Commit d76b02d

Browse files
committed
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.
1 parent 625fde7 commit d76b02d

4 files changed

Lines changed: 28 additions & 27 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ authors = [
99
"Billy Messenger <billydm@protonmail.com>",
1010
"Anton Lazarev <https://antonok.com>",
1111
"Joakim Frostegård <joakim.frostegard@gmail.com>",
12+
"Robbert van der Helm <mail@robbertvanderhelm.nl>",
1213
]
1314
edition = "2018"
1415
license = "MIT OR Apache-2.0"
1516

1617
[dependencies]
1718
keyboard-types = { version = "0.6.1", default-features = false }
18-
raw-window-handle = "0.3.3"
19+
raw-window-handle = "0.4.2"
1920

2021
[target.'cfg(target_os="linux")'.dependencies]
2122
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }

src/macos/window.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use keyboard_types::KeyboardEvent;
1616

1717
use objc::{msg_send, runtime::Object, sel, sel_impl};
1818

19-
use raw_window_handle::{macos::MacOSHandle, HasRawWindowHandle, RawWindowHandle};
19+
use raw_window_handle::{AppKitHandle, HasRawWindowHandle, RawWindowHandle};
2020

2121
use crate::{
2222
Event, EventStatus, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions,
@@ -55,7 +55,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
5555
}
5656
}
5757

58-
RawWindowHandle::MacOS(MacOSHandle { ..MacOSHandle::empty() })
58+
RawWindowHandle::AppKit(AppKitHandle::empty())
5959
}
6060
}
6161

@@ -114,7 +114,7 @@ impl Window {
114114
{
115115
let pool = unsafe { NSAutoreleasePool::new(nil) };
116116

117-
let handle = if let RawWindowHandle::MacOS(handle) = parent.raw_window_handle() {
117+
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
118118
handle
119119
} else {
120120
panic!("Not a macOS window");
@@ -388,10 +388,10 @@ unsafe impl HasRawWindowHandle for Window {
388388
fn raw_window_handle(&self) -> RawWindowHandle {
389389
let ns_window = self.ns_window.unwrap_or(::std::ptr::null_mut()) as *mut c_void;
390390

391-
RawWindowHandle::MacOS(MacOSHandle {
392-
ns_window,
393-
ns_view: self.ns_view as *mut c_void,
394-
..MacOSHandle::empty()
395-
})
391+
let mut handle = AppKitHandle::empty();
392+
handle.ns_window = ns_window;
393+
handle.ns_view = self.ns_view as *mut c_void;
394+
395+
RawWindowHandle::AppKit(handle)
396396
}
397397
}

src/win/window.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::ptr::null_mut;
2323
use std::sync::atomic::{AtomicBool, Ordering};
2424
use std::sync::Arc;
2525

26-
use raw_window_handle::{windows::WindowsHandle, HasRawWindowHandle, RawWindowHandle};
26+
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle};
2727

2828
const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1;
2929

@@ -80,12 +80,12 @@ impl WindowHandle {
8080
unsafe impl HasRawWindowHandle for WindowHandle {
8181
fn raw_window_handle(&self) -> RawWindowHandle {
8282
if let Some(hwnd) = self.hwnd {
83-
RawWindowHandle::Windows(WindowsHandle {
84-
hwnd: hwnd as *mut std::ffi::c_void,
85-
..WindowsHandle::empty()
86-
})
83+
let mut handle = Win32Handle::empty();
84+
handle.hwnd = hwnd as *mut std::ffi::c_void;
85+
86+
RawWindowHandle::Win32(handle)
8787
} else {
88-
RawWindowHandle::Windows(WindowsHandle { ..WindowsHandle::empty() })
88+
RawWindowHandle::Win32(Win32Handle::empty())
8989
}
9090
}
9191
}
@@ -372,7 +372,7 @@ impl Window {
372372
B: Send + 'static,
373373
{
374374
let parent = match parent.raw_window_handle() {
375-
RawWindowHandle::Windows(h) => h.hwnd as HWND,
375+
RawWindowHandle::Win32(h) => h.hwnd as HWND,
376376
h => panic!("unsupported parent handle {:?}", h),
377377
};
378378

@@ -560,9 +560,9 @@ impl Window {
560560

561561
unsafe impl HasRawWindowHandle for Window {
562562
fn raw_window_handle(&self) -> RawWindowHandle {
563-
RawWindowHandle::Windows(WindowsHandle {
564-
hwnd: self.hwnd as *mut std::ffi::c_void,
565-
..WindowsHandle::empty()
566-
})
563+
let mut handle = Win32Handle::empty();
564+
handle.hwnd = self.hwnd as *mut std::ffi::c_void;
565+
566+
RawWindowHandle::Win32(handle)
567567
}
568568
}

src/x11/window.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use std::thread;
77
use std::time::*;
88

9-
use raw_window_handle::{unix::XlibHandle, HasRawWindowHandle, RawWindowHandle};
9+
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, XlibHandle};
1010

1111
use super::XcbConnection;
1212
use crate::{
@@ -49,7 +49,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
4949
}
5050
}
5151

52-
RawWindowHandle::Xlib(XlibHandle { ..raw_window_handle::unix::XlibHandle::empty() })
52+
RawWindowHandle::Xlib(XlibHandle::empty())
5353
}
5454
}
5555

@@ -595,11 +595,11 @@ impl Window {
595595

596596
unsafe impl HasRawWindowHandle for Window {
597597
fn raw_window_handle(&self) -> RawWindowHandle {
598-
RawWindowHandle::Xlib(XlibHandle {
599-
window: self.window_id as c_ulong,
600-
display: self.xcb_connection.conn.get_raw_dpy() as *mut c_void,
601-
..raw_window_handle::unix::XlibHandle::empty()
602-
})
598+
let mut handle = XlibHandle::empty();
599+
handle.window = self.window_id as c_ulong;
600+
handle.display = self.xcb_connection.conn.get_raw_dpy() as *mut c_void;
601+
602+
RawWindowHandle::Xlib(handle)
603603
}
604604
}
605605

0 commit comments

Comments
 (0)