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

x11: fix exposures on child window #5408

Merged
merged 1 commit into from
May 10, 2024
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
11 changes: 11 additions & 0 deletions window/src/os/x11/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct XConnection {
pub atom_net_active_window: Atom,
pub(crate) xrm: RefCell<HashMap<String, String>>,
pub(crate) windows: RefCell<HashMap<xcb::x::Window, Arc<Mutex<XWindowInner>>>>,
pub(crate) child_to_parent_id: RefCell<HashMap<xcb::x::Window, xcb::x::Window>>,
should_terminate: RefCell<bool>,
pub(crate) visual: xcb::x::Visualtype,
pub(crate) depth: u8,
Expand Down Expand Up @@ -578,6 +579,10 @@ impl XConnection {
self.windows.borrow().get(&window_id).map(Arc::clone)
}

fn parent_id_by_child_id(&self, child_id: xcb::x::Window) -> Option<xcb::x::Window> {
self.child_to_parent_id.borrow().get(&child_id).copied()
}

fn dispatch_pending_events(&self) -> anyhow::Result<()> {
for window in self.windows.borrow().values() {
let mut inner = window.lock().unwrap();
Expand All @@ -595,6 +600,11 @@ impl XConnection {
if let Some(window) = self.window_by_id(window_id) {
let mut inner = window.lock().unwrap();
inner.dispatch_event(event)?;
} else if let Some(parent_id) = self.parent_id_by_child_id(window_id) {
if let Some(window) = self.window_by_id(parent_id) {
let mut inner = window.lock().unwrap();
inner.dispatch_event(event)?;
}
}
Ok(())
}
Expand Down Expand Up @@ -804,6 +814,7 @@ impl XConnection {
atom_xsel_data,
atom_targets,
windows: RefCell::new(HashMap::new()),
child_to_parent_id: RefCell::new(HashMap::new()),
should_terminate: RefCell::new(false),
depth,
visual,
Expand Down
12 changes: 10 additions & 2 deletions window/src/os/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ impl XWindowInner {
Event::X(xcb::x::Event::DestroyNotify(_)) => {
self.events.dispatch(WindowEvent::Destroyed);
conn.windows.borrow_mut().remove(&self.window_id);
conn.child_to_parent_id.borrow_mut().remove(&self.child_id);
}
Event::X(xcb::x::Event::SelectionClear(e)) => {
self.selection_clear(e)?;
Expand Down Expand Up @@ -1414,8 +1415,7 @@ impl XWindow {
xcb::x::Cw::BackPixel(0), // transparent background
xcb::x::Cw::BorderPixel(screen.black_pixel()),
xcb::x::Cw::EventMask(
xcb::x::EventMask::EXPOSURE
| xcb::x::EventMask::FOCUS_CHANGE
xcb::x::EventMask::FOCUS_CHANGE
| xcb::x::EventMask::KEY_PRESS
| xcb::x::EventMask::BUTTON_PRESS
| xcb::x::EventMask::BUTTON_RELEASE
Expand Down Expand Up @@ -1449,6 +1449,7 @@ impl XWindow {
xcb::x::Cw::BackPixel(0), // transparent background
xcb::x::Cw::BorderPixel(screen.black_pixel()),
xcb::x::Cw::BitGravity(xcb::x::Gravity::NorthWest),
xcb::x::Cw::EventMask(xcb::x::EventMask::EXPOSURE),
xcb::x::Cw::Colormap(color_map_id),
],
})
Expand Down Expand Up @@ -1538,6 +1539,9 @@ impl XWindow {
let window_handle = Window::X11(XWindow::from_id(window_id));

conn.windows.borrow_mut().insert(window_id, window);
conn.child_to_parent_id
.borrow_mut()
.insert(child_id, window_id);

window_handle.set_title(name);
// Before we map the window, flush to ensure that all of the other properties
Expand Down Expand Up @@ -1581,6 +1585,10 @@ impl XWindowInner {
// Drop impl, and that cannot succeed after we've
// destroyed the window at the X11 level.
self.conn().windows.borrow_mut().remove(&self.window_id);
self.conn()
.child_to_parent_id
.borrow_mut()
.remove(&self.child_id);

// Unmap the window first: calling DestroyWindow here may race
// with some requests made either by EGL or the IME, but I haven't
Expand Down
Loading