Skip to content

Commit

Permalink
Partially fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Oct 3, 2023
1 parent 29da06e commit 9e15334
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 23 deletions.
2 changes: 0 additions & 2 deletions examples/util/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//! The `softbuffer` crate is used, largely because of its ease of use. `glutin` or `wgpu` could
//! also be used to fill the window buffer, but they are more complicated to use.

// TODO: Once softbuffer uses rwh_06, use that instead.

use winit::window::Window;

#[cfg(all(feature = "rwh_05", not(any(target_os = "android", target_os = "ios"))))]
Expand Down
5 changes: 2 additions & 3 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,9 @@ impl Inner {

#[cfg(feature = "rwh_06")]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
let mut window_handle = rwh_06::UiKitWindowHandle::new(unsafe {
// SAFETY: ns_view will never be null
let mut window_handle = rwh_06::UiKitWindowHandle::new({
let ui_view = Id::as_ptr(&self.view) as _;
std::ptr::NonNull::new_unchecked(ui_view)
std::ptr::NonNull::new(ui_view).expect("Id<T> should never be null")
});
window_handle.ui_view_controller =
std::ptr::NonNull::new(Id::as_ptr(&self.view_controller) as _);
Expand Down
5 changes: 2 additions & 3 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,9 @@ impl<T> EventLoopWindowTarget<T> {
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
use sctk::reexports::client::Proxy;

Ok(rwh_06::WaylandDisplayHandle::new(unsafe {
// SAFETY: The display handle will never be null.
Ok(rwh_06::WaylandDisplayHandle::new({
let ptr = self.connection.display().id().as_ptr();
std::ptr::NonNull::new_unchecked(ptr as *mut _)
std::ptr::NonNull::new(ptr as *mut _).expect("wl_display should never be null")
})
.into())
}
Expand Down
10 changes: 4 additions & 6 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,9 @@ impl Window {
#[cfg(feature = "rwh_06")]
#[inline]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
Ok(rwh_06::WaylandWindowHandle::new(unsafe {
// SAFETY: Surface pointer will never be null.
Ok(rwh_06::WaylandWindowHandle::new({
let ptr = self.window.wl_surface().id().as_ptr();
std::ptr::NonNull::new_unchecked(ptr as *mut _)
std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null")
})
.into())
}
Expand All @@ -681,10 +680,9 @@ impl Window {
pub fn raw_display_handle_rwh_06(
&self,
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::WaylandDisplayHandle::new(unsafe {
// SAFETY: Display pointer will never be null.
Ok(rwh_06::WaylandDisplayHandle::new({
let ptr = self.display.id().as_ptr();
std::ptr::NonNull::new_unchecked(ptr as *mut _)
std::ptr::NonNull::new(ptr as *mut _).expect("wl_proxy should never be null")
})
.into())
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl<T> EventLoopWindowTarget<T> {
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
let display_handle = rwh_06::XlibDisplayHandle::new(
// SAFETY: display will never be null
Some(unsafe { std::ptr::NonNull::new_unchecked(self.xconn.display as *mut _) }),
Some(std::ptr::NonNull::new(self.xconn.display as *mut _).expect("X11 display should never be null")),
self.xconn.default_screen_index() as c_int,
);
Ok(display_handle.into())
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,8 +1839,7 @@ impl UnownedWindow {
&self,
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::XlibDisplayHandle::new(
// SAFETY: The Xlib display pointer will never be null
Some(unsafe { std::ptr::NonNull::new_unchecked(self.xlib_display()) }),
Some(std::ptr::NonNull::new(self.xlib_display()).expect("display pointer should never be null")),
self.screen_id,
)
.into())
Expand Down
5 changes: 2 additions & 3 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,9 @@ impl WinitWindow {
#[cfg(feature = "rwh_06")]
#[inline]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
let window_handle = rwh_06::AppKitWindowHandle::new(unsafe {
// SAFETY: ns_view is never null.
let window_handle = rwh_06::AppKitWindowHandle::new({
let ptr = Id::as_ptr(&self.contentView()) as *mut _;
std::ptr::NonNull::new_unchecked(ptr)
std::ptr::NonNull::new(ptr).expect("Id<T> should never be null")
});
Ok(rwh_06::RawWindowHandle::AppKit(window_handle))
}
Expand Down
5 changes: 2 additions & 3 deletions src/platform_impl/orbital/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,9 @@ impl Window {
#[cfg(feature = "rwh_06")]
#[inline]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
let handle = rwh_06::OrbitalWindowHandle::new(unsafe {
// SAFETY: not zero.
let handle = rwh_06::OrbitalWindowHandle::new({
let window = self.window_socket.fd as *mut _;
std::ptr::NonNull::new_unchecked(window)
std::ptr::NonNull::new(window).expect("orbital fd shoul never be null")
});
Ok(rwh_06::RawWindowHandle::Orbital(handle))
}
Expand Down

0 comments on commit 9e15334

Please sign in to comment.