From 1c0490f9ec6b7ab42e8133ade45f6d55d9ad3a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 23 Nov 2022 22:30:33 +0100 Subject: [PATCH] Upgrade to raw-window-handle 0.5, impl HasRawDisplayHandle for macOS --- Cargo.toml | 2 +- src/macos/window.rs | 15 ++++++++++++--- src/window.rs | 10 +++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb23f4e..a0387dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ opengl = ["uuid", "x11/glx"] [dependencies] keyboard-types = { version = "0.6.1", default-features = false } -raw-window-handle = "0.4.2" +raw-window-handle = "0.5" [target.'cfg(target_os="linux")'.dependencies] xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] } diff --git a/src/macos/window.rs b/src/macos/window.rs index 54046dd..136d9ab 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -17,7 +17,10 @@ use keyboard_types::KeyboardEvent; use objc::{msg_send, runtime::Object, sel, sel_impl}; -use raw_window_handle::{AppKitHandle, HasRawWindowHandle, RawWindowHandle}; +use raw_window_handle::{ + AppKitDisplayHandle, AppKitWindowHandle, HasRawDisplayHandle, HasRawWindowHandle, + RawDisplayHandle, RawWindowHandle, +}; use crate::{ Event, EventStatus, Size, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions, @@ -62,7 +65,13 @@ unsafe impl HasRawWindowHandle for WindowHandle { } } - RawWindowHandle::AppKit(AppKitHandle::empty()) + RawWindowHandle::AppKit(AppKitWindowHandle::empty()) + } +} + +unsafe impl HasRawDisplayHandle for WindowHandle { + fn raw_display_handle(&self) -> RawDisplayHandle { + RawDisplayHandle::AppKit(AppKitDisplayHandle::empty()) } } @@ -476,7 +485,7 @@ unsafe impl HasRawWindowHandle for Window { fn raw_window_handle(&self) -> RawWindowHandle { let ns_window = self.ns_window.unwrap_or(ptr::null_mut()) as *mut c_void; - let mut handle = AppKitHandle::empty(); + let mut handle = AppKitWindowHandle::empty(); handle.ns_window = ns_window; handle.ns_view = self.ns_view as *mut c_void; diff --git a/src/window.rs b/src/window.rs index c0ef1ac..d83f6cf 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,6 +1,8 @@ use std::marker::PhantomData; -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; +use raw_window_handle::{ + HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, +}; use crate::event::{Event, EventStatus}; use crate::window_open_options::WindowOpenOptions; @@ -48,6 +50,12 @@ unsafe impl HasRawWindowHandle for WindowHandle { } } +unsafe impl HasRawDisplayHandle for WindowHandle { + fn raw_display_handle(&self) -> RawDisplayHandle { + self.window_handle.raw_display_handle() + } +} + pub trait WindowHandler { fn on_frame(&mut self, window: &mut Window); fn on_event(&mut self, window: &mut Window, event: Event) -> EventStatus;