Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RawWindowHandleWrapper #156

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/gl/macos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::c_void;
use std::str::FromStr;

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::RawWindowHandle;

use cocoa::appkit::{
NSOpenGLContext, NSOpenGLContextParameter, NSOpenGLPFAAccelerated, NSOpenGLPFAAlphaSize,
Expand All @@ -28,10 +28,8 @@ pub struct GlContext {
}

impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::AppKit(handle) = parent {
handle
} else {
return Err(GlError::InvalidWindowHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;

// On X11 creating the context is a two step process
#[cfg(not(target_os = "linux"))]
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::RawWindowHandle;

#[cfg(target_os = "windows")]
mod win;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct GlContext {
impl GlContext {
#[cfg(not(target_os = "linux"))]
pub(crate) unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
parent: &RawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
platform::GlContext::create(parent, config)
.map(|context| GlContext { context, phantom: PhantomData })
Expand Down
8 changes: 3 additions & 5 deletions src/gl/win.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::{c_void, CString, OsStr};
use std::os::windows::ffi::OsStrExt;

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::RawWindowHandle;

use winapi::shared::minwindef::{HINSTANCE, HMODULE};
use winapi::shared::ntdef::WCHAR;
Expand Down Expand Up @@ -77,10 +77,8 @@ extern "C" {
}

impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Win32(handle) = parent.raw_window_handle() {
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Win32(handle) = parent {
handle
} else {
return Err(GlError::InvalidWindowHandle);
Expand Down
7 changes: 2 additions & 5 deletions src/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use super::keyboard::KeyboardState;
use super::view::{create_view, BASEVIEW_STATE_IVAR};

#[cfg(feature = "opengl")]
use crate::{
gl::{GlConfig, GlContext},
window::RawWindowHandleWrapper,
};
use crate::gl::{GlConfig, GlContext};

pub struct WindowHandle {
raw_window_handle: Option<RawWindowHandle>,
Expand Down Expand Up @@ -313,7 +310,7 @@ impl Window {
let mut handle = AppKitWindowHandle::empty();
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
handle.ns_view = ns_view as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::AppKit(handle) };
let handle = RawWindowHandle::AppKit(handle);

unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
}
Expand Down
4 changes: 2 additions & 2 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use super::drop_target::DropTarget;
use super::keyboard::KeyboardState;

#[cfg(feature = "opengl")]
use crate::{gl::GlContext, window::RawWindowHandleWrapper};
use crate::gl::GlContext;

unsafe fn generate_guid() -> String {
let mut guid: GUID = std::mem::zeroed();
Expand Down Expand Up @@ -655,7 +655,7 @@ impl Window<'_> {
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
let mut handle = Win32WindowHandle::empty();
handle.hwnd = hwnd as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) };
let handle = RawWindowHandle::Win32(handle);

GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
});
Expand Down
12 changes: 0 additions & 12 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub struct WindowHandle {
phantom: PhantomData<*mut ()>,
}

/// Quick wrapper to satisfy [HasRawWindowHandle], because of course a raw window handle wouldn't
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sad to see this comment go 😆

/// have a raw window handle, that would be silly.
pub(crate) struct RawWindowHandleWrapper {
pub handle: RawWindowHandle,
}

impl WindowHandle {
fn new(window_handle: platform::WindowHandle) -> Self {
Self { window_handle, phantom: PhantomData::default() }
Expand Down Expand Up @@ -126,9 +120,3 @@ unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
self.window.raw_display_handle()
}
}

unsafe impl HasRawWindowHandle for RawWindowHandleWrapper {
fn raw_window_handle(&self) -> RawWindowHandle {
self.handle
}
}
Loading