diff --git a/CHANGELOG.md b/CHANGELOG.md index ae43fda9..d9cd90f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On X11, set `visual_id` in returned `raw-window-handle`. - **Breaking:** on Wayland, dispatching user created wayland queue won't wake up the loop unless winit has event to send back. - Removed platform-specific extensions that should be retrieved through `raw-window-handle` trait implementations instead: - `platform::windows::HINSTANCE`. diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index d44fa4fa..d9082a97 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -113,6 +113,7 @@ unsafe impl Sync for UnownedWindow {} pub(crate) struct UnownedWindow { pub(crate) xconn: Arc, // never changes xwindow: xproto::Window, // never changes + visual: u32, // never changes root: xproto::Window, // never changes screen_id: i32, // never changes cursor: Mutex, @@ -252,7 +253,7 @@ impl UnownedWindow { } _ => (None, x11rb::COPY_FROM_PARENT as _, false), }; - let visual = visualtype.map_or(x11rb::COPY_FROM_PARENT, |v| v.visual_id); + let mut visual = visualtype.map_or(x11rb::COPY_FROM_PARENT, |v| v.visual_id); let window_attributes = { use xproto::EventMask; @@ -319,10 +320,22 @@ impl UnownedWindow { wid }; + // The COPY_FROM_PARENT is a special value for the visual used to copy + // the visual from the parent window, thus we have to query the visual + // we've got when we built the window above. + if visual == x11rb::COPY_FROM_PARENT { + visual = leap!(leap!(xconn + .xcb_connection() + .get_window_attributes(xwindow as xproto::Window)) + .reply()) + .visual; + } + #[allow(clippy::mutex_atomic)] let mut window = UnownedWindow { xconn: Arc::clone(xconn), xwindow: xwindow as xproto::Window, + visual, root, screen_id, cursor: Default::default(), @@ -1745,6 +1758,7 @@ impl UnownedWindow { pub fn raw_window_handle(&self) -> RawWindowHandle { let mut window_handle = XlibWindowHandle::empty(); window_handle.window = self.xlib_window(); + window_handle.visual_id = self.visual as c_ulong; RawWindowHandle::Xlib(window_handle) }