From 417939b1e54ec4f078a1788eb15f9e3e1dc10a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 23 Nov 2022 23:52:19 +0100 Subject: [PATCH] Fix X11 OpenGL issue --- src/gl/x11.rs | 20 ++++++-------------- src/x11/window.rs | 8 +++----- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/gl/x11.rs b/src/gl/x11.rs index f62d318a..0637e523 100644 --- a/src/gl/x11.rs +++ b/src/gl/x11.rs @@ -1,8 +1,6 @@ use std::ffi::{c_void, CString}; use std::os::raw::{c_int, c_ulong}; -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; - use x11::glx; use x11::xlib; @@ -80,19 +78,13 @@ impl GlContext { /// /// Use [Self::get_fb_config_and_visual] to create both of these things. pub unsafe fn create( - parent: &impl HasRawWindowHandle, config: FbConfig, + window: c_ulong, display: *mut c_void, config: FbConfig, ) -> Result { - let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() { - handle - } else { - return Err(GlError::InvalidWindowHandle); - }; - - if handle.display.is_null() { + if display.is_null() { return Err(GlError::InvalidWindowHandle); } - let display = handle.display as *mut xlib::_XDisplay; + let display = display_handle.display as *mut xlib::_XDisplay; errors::XErrorHandler::handle(display, |error_handler| { #[allow(non_snake_case)] @@ -144,13 +136,13 @@ impl GlContext { return Err(GlError::CreationFailed(CreationFailedError::ContextCreationFailed)); } - let res = glx::glXMakeCurrent(display, handle.window, context); + let res = glx::glXMakeCurrent(display, window, context); error_handler.check()?; if res == 0 { return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed)); } - glXSwapIntervalEXT(display, handle.window, config.gl_config.vsync as i32); + glXSwapIntervalEXT(display, window, config.gl_config.vsync as i32); error_handler.check()?; if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 { @@ -158,7 +150,7 @@ impl GlContext { return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed)); } - Ok(GlContext { window: handle.window, display, context }) + Ok(GlContext { window, display, context }) }) } diff --git a/src/x11/window.rs b/src/x11/window.rs index 91c3ddbb..4823e32f 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -326,13 +326,11 @@ impl Window { // compared to when raw-gl-context was a separate crate. #[cfg(feature = "opengl")] let gl_context = fb_config.map(|fb_config| { - let mut handle = XlibWindowHandle::empty(); - handle.window = window_id as c_ulong; - handle.display = xcb_connection.conn.get_raw_dpy() as *mut c_void; - let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Xlib(handle) }; + let window = window_id as c_ulong; + let display = xcb_connection.conn.get_raw_dpy() as *mut c_void; // Because of the visual negotation we had to take some extra steps to create this context - let context = unsafe { platform::GlContext::create(&handle, fb_config) } + let context = unsafe { platform::GlContext::create(window, display, fb_config) } .expect("Could not create OpenGL context"); GlContext::new(context) });