On X11, set visual_id in raw-window-handle

Fixes #2681.
This commit is contained in:
Kirill Chibisov 2023-08-06 06:07:19 +04:00 committed by GitHub
parent 793c535b01
commit 5f7955cb2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased # 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. - **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: - Removed platform-specific extensions that should be retrieved through `raw-window-handle` trait implementations instead:
- `platform::windows::HINSTANCE`. - `platform::windows::HINSTANCE`.

View file

@ -113,6 +113,7 @@ unsafe impl Sync for UnownedWindow {}
pub(crate) struct UnownedWindow { pub(crate) struct UnownedWindow {
pub(crate) xconn: Arc<XConnection>, // never changes pub(crate) xconn: Arc<XConnection>, // never changes
xwindow: xproto::Window, // never changes xwindow: xproto::Window, // never changes
visual: u32, // never changes
root: xproto::Window, // never changes root: xproto::Window, // never changes
screen_id: i32, // never changes screen_id: i32, // never changes
cursor: Mutex<CursorIcon>, cursor: Mutex<CursorIcon>,
@ -252,7 +253,7 @@ impl UnownedWindow {
} }
_ => (None, x11rb::COPY_FROM_PARENT as _, false), _ => (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 = { let window_attributes = {
use xproto::EventMask; use xproto::EventMask;
@ -319,10 +320,22 @@ impl UnownedWindow {
wid 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)] #[allow(clippy::mutex_atomic)]
let mut window = UnownedWindow { let mut window = UnownedWindow {
xconn: Arc::clone(xconn), xconn: Arc::clone(xconn),
xwindow: xwindow as xproto::Window, xwindow: xwindow as xproto::Window,
visual,
root, root,
screen_id, screen_id,
cursor: Default::default(), cursor: Default::default(),
@ -1745,6 +1758,7 @@ impl UnownedWindow {
pub fn raw_window_handle(&self) -> RawWindowHandle { pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut window_handle = XlibWindowHandle::empty(); let mut window_handle = XlibWindowHandle::empty();
window_handle.window = self.xlib_window(); window_handle.window = self.xlib_window();
window_handle.visual_id = self.visual as c_ulong;
RawWindowHandle::Xlib(window_handle) RawWindowHandle::Xlib(window_handle)
} }