Skip to content

Commit

Permalink
Update winit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm authored and mrobinson committed Jan 15, 2024
1 parent 8ab0d46 commit fb92ab5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions surfman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ libc = "0.2"
log = "0.4"
sparkle = { version = "0.1", optional = true }
osmesa-sys = { version = "0.1", optional = true }
winit = { version = "0.28.1", optional = true }
raw-window-handle = { version = "0.5", optional = true }
winit = { version = "0.29.3", optional = true }
raw-window-handle = { version = "0.6", optional = true }

[dev-dependencies]
clap = "2"
Expand Down
12 changes: 8 additions & 4 deletions surfman/src/platform/macos/cgl/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ impl Connection {
use raw_window_handle::RawWindowHandle::AppKit;

match raw_handle {
AppKit(handle) => Ok(NativeWidget {
view: NSView(unsafe { msg_send![handle.ns_view as id, retain] }),
opaque: unsafe { msg_send![handle.ns_window as id, isOpaque] },
}),
AppKit(handle) => {
let view = NSView(unsafe { msg_send![handle.ns_view.as_ptr() as id, retain] });
let window: id = unsafe { msg_send![view.0, window] };
Ok(NativeWidget {
view: view,
opaque: unsafe { msg_send![window, isOpaque] },
})
}
_ => Err(Error::IncompatibleNativeWidget),
}
}
Expand Down
45 changes: 29 additions & 16 deletions surfman/src/platform/macos/system/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use euclid::default::Size2D;
use std::os::raw::c_void;
use std::str::FromStr;

#[cfg(feature = "sm-winit")]
use winit::platform::macos::WindowExtMacOS;
#[cfg(feature = "sm-winit")]
use winit::window::Window;
#[cfg(feature = "sm-winit")]
use raw_window_handle::HasWindowHandle;

/// A no-op connection.
///
Expand Down Expand Up @@ -145,16 +145,25 @@ impl Connection {
&self,
window: &Window,
) -> Result<NativeWidget, Error> {
let ns_view = window.ns_view() as id;
let ns_window = window.ns_window() as id;
if ns_view.is_null() {
return Err(Error::IncompatibleNativeWidget);
}
unsafe {
Ok(NativeWidget {
view: NSView(msg_send![ns_view, retain]),
opaque: msg_send![ns_window as id, isOpaque],
})
use raw_window_handle::RawWindowHandle::AppKit;

let handle = window.window_handle().map_err(|_| Error::IncompatibleNativeWidget)?;
let raw_handle = handle.as_raw();
match raw_handle {
AppKit(handle) => {
let ns_view = handle.ns_view.as_ptr() as id;
if ns_view.is_null() {
return Err(Error::IncompatibleNativeWidget);
}
let ns_window: id = unsafe { msg_send![ns_view, window] };
unsafe {
Ok(NativeWidget {
view: NSView(msg_send![ns_view, retain]),
opaque: msg_send![ns_window, isOpaque],
})
}
}
_ => Err(Error::IncompatibleNativeWidget),
}
}

Expand All @@ -180,10 +189,14 @@ impl Connection {
use raw_window_handle::RawWindowHandle::AppKit;

match raw_handle {
AppKit(handle) => Ok(NativeWidget {
view: NSView(unsafe { msg_send![handle.ns_view as id, retain] }),
opaque: unsafe { msg_send![handle.ns_window as id, isOpaque] },
}),
AppKit(handle) => {
let view = NSView(unsafe { msg_send![handle.ns_view.as_ptr() as id, retain] });
let window: id = unsafe { msg_send![view.0, window] };
Ok(NativeWidget {
view: view,
opaque: unsafe { msg_send![window, isOpaque] },
})
}
_ => Err(Error::IncompatibleNativeWidget),
}
}
Expand Down
2 changes: 1 addition & 1 deletion surfman/src/platform/macos/system/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl Drop for ViewInfo {
self.display_link.stop();

// Drop the reference that the callback was holding onto.
mem::transmute_copy::<Arc<VblankCond>, Arc<VblankCond>>(&self.next_vblank);
let _ = mem::transmute_copy::<Arc<VblankCond>, Arc<VblankCond>>(&self.next_vblank);
}
}
}
Expand Down

0 comments on commit fb92ab5

Please sign in to comment.