Use the correct position for Xwayland surfaces

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2021-01-04 10:07:35 +01:00 committed by Victor Berger
parent 3504182a5e
commit ff09b8e116
1 changed files with 22 additions and 7 deletions

View File

@ -90,7 +90,7 @@ struct X11State {
conn: Rc<RustConnection>, conn: Rc<RustConnection>,
atoms: Atoms, atoms: Atoms,
log: slog::Logger, log: slog::Logger,
unpaired_surfaces: HashMap<u32, Window>, unpaired_surfaces: HashMap<u32, (Window, (i32, i32))>,
token: CompositorToken<Roles>, token: CompositorToken<Roles>,
window_map: Rc<RefCell<MyWindowMap>>, window_map: Rc<RefCell<MyWindowMap>>,
} }
@ -193,6 +193,21 @@ impl X11State {
// wayland socket). Thus, we could receive these two in any order. Hence, it // wayland socket). Thus, we could receive these two in any order. Hence, it
// can happen that we get None below when X11 was faster than Wayland. // can happen that we get None below when X11 was faster than Wayland.
let location = {
match self.conn.get_geometry(msg.window)?.reply() {
Ok(geo) => (geo.x.into(), geo.y.into()),
Err(err) => {
error!(
self.log,
"Failed to get geometry for {:x}, perhaps the window was already destroyed?",
msg.window;
"err" => format!("{:?}", err),
);
(0, 0)
}
}
};
let id = msg.data.as_data32()[0]; let id = msg.data.as_data32()[0];
let surface = client.get_resource::<WlSurface>(id); let surface = client.get_resource::<WlSurface>(id);
info!( info!(
@ -201,9 +216,9 @@ impl X11State {
); );
match surface { match surface {
None => { None => {
self.unpaired_surfaces.insert(id, msg.window); self.unpaired_surfaces.insert(id, (msg.window, location));
} }
Some(surface) => self.new_window(msg.window, surface), Some(surface) => self.new_window(msg.window, surface, location),
} }
} }
} }
@ -212,7 +227,7 @@ impl X11State {
Ok(()) Ok(())
} }
fn new_window(&mut self, window: Window, surface: WlSurface) { fn new_window(&mut self, window: Window, surface: WlSurface, location: (i32, i32)) {
debug!(self.log, "Matched X11 surface {:x?} to {:x?}", window, surface); debug!(self.log, "Matched X11 surface {:x?} to {:x?}", window, surface);
if self.token.give_role_with(&surface, X11SurfaceRole).is_err() { if self.token.give_role_with(&surface, X11SurfaceRole).is_err() {
@ -224,7 +239,7 @@ impl X11State {
let x11surface = X11Surface { surface }; let x11surface = X11Surface { surface };
self.window_map self.window_map
.borrow_mut() .borrow_mut()
.insert(Kind::X11(x11surface), (0, 0)); .insert(Kind::X11(x11surface), location);
} }
} }
@ -236,8 +251,8 @@ pub fn commit_hook(surface: &WlSurface) {
let mut inner = x11.borrow_mut(); let mut inner = x11.borrow_mut();
// Is the surface among the unpaired surfaces (see comment next to WL_SURFACE_ID // Is the surface among the unpaired surfaces (see comment next to WL_SURFACE_ID
// handling above) // handling above)
if let Some(window) = inner.unpaired_surfaces.remove(&surface.as_ref().id()) { if let Some((window, location)) = inner.unpaired_surfaces.remove(&surface.as_ref().id()) {
inner.new_window(window, surface.clone()); inner.new_window(window, surface.clone(), location);
} }
} }
} }