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

glutin-winit: try to inject screen_id into RawDisplayHandle #1712

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ members = [
"glutin_wgl_sys",
"glutin_gles2_sys",
]

[patch.crates-io]
winit = { git = "https://github.com/tonarino/winit.git", branch = "x11-screen-id" }
24 changes: 20 additions & 4 deletions glutin-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use glutin::prelude::*;
#[cfg(wgl_backend)]
use raw_window_handle::HasWindowHandle;

use raw_window_handle::RawWindowHandle;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use winit::error::OsError;
use winit::window::{Window, WindowAttributes};

Expand Down Expand Up @@ -111,6 +111,23 @@ impl DisplayBuilder {
None
};

#[cfg(x11_platform)]
let mut raw_display_handle = event_loop.glutin_display_handle()?.as_raw();
#[cfg(x11_platform)]
if let Some(screen_id) = self.window_attributes.as_ref().and_then(|wa| wa.x11_screen()) {
eprintln!("Injecting screen_id {screen_id} into raw_display_handle.");
match &mut raw_display_handle {
RawDisplayHandle::Xlib(xlib) => xlib.screen = screen_id,
RawDisplayHandle::Xcb(xcb) => xcb.screen = screen_id,
other => {
eprintln!("Cannot inject screen_id to RawDisplayHandle variant {other:?}.")
},
}
}

#[cfg(not(x11_platform))]
let raw_display_handle = event_loop.glutin_display_handle()?.as_raw();

#[cfg(wgl_backend)]
let raw_window_handle = window
.as_ref()
Expand All @@ -119,7 +136,7 @@ impl DisplayBuilder {
#[cfg(not(wgl_backend))]
let raw_window_handle = None;

let gl_display = create_display(event_loop, self.preference, raw_window_handle)?;
let gl_display = create_display(raw_display_handle, self.preference, raw_window_handle)?;

// XXX the native window must be passed to config picker when WGL is used
// otherwise very limited OpenGL features will be supported.
Expand Down Expand Up @@ -149,7 +166,7 @@ impl DisplayBuilder {
}

fn create_display(
event_loop: &impl GlutinEventLoop,
handle: RawDisplayHandle,
_api_preference: ApiPreference,
_raw_window_handle: Option<RawWindowHandle>,
) -> Result<Display, Box<dyn Error>> {
Expand Down Expand Up @@ -181,7 +198,6 @@ fn create_display(
ApiPreference::FallbackEgl => DisplayApiPreference::WglThenEgl(_raw_window_handle),
};

let handle = event_loop.glutin_display_handle()?.as_raw();
unsafe { Ok(Display::new(handle, _preference)?) }
}

Expand Down
Loading