Skip to content

Commit

Permalink
implement get_position for x11 and wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
alfa07 committed Feb 1, 2023
1 parent 899967f commit b4d29a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 9 additions & 0 deletions window/src/os/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,15 @@ impl WindowOps for WaylandWindow {
Ok(())
});
}

fn get_window_position(&self) -> Future<ScreenPoint> {
WaylandConnection::with_window_inner(self.0, move |_inner| {
// Wayland does not support getting window position. Potential workarounds:
// 1. Use window manager like GTK
// 2. Create window covering the all screens and use subsurfaces
Ok(ScreenPoint::new(0, 0))
})
}
}

pub(crate) fn read_pipe_with_timeout(mut file: FileDescriptor) -> anyhow::Result<String> {
Expand Down
11 changes: 7 additions & 4 deletions window/src/os/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,16 +1397,15 @@ impl XWindowInner {
});
}

fn get_window_position(&mut self) -> ScreenPoint {
let conn = self.conn();
/// Get position of the top left corner of client region of the window.
fn get_window_position(&mut self) -> anyhow::Result<ScreenPoint> {
let geom = self
.conn()
.send_and_wait_request(&xcb::x::GetGeometry {
drawable: xcb::x::Drawable::Window(self.window_id),
})
.context("querying geometry")?;
log::trace!("window position is x={} y={}", geom.x(), geom.y(),);
ScreenPoint::new(geom.x(), geom.y())
Ok(ScreenPoint::new(geom.x().into(), geom.y().into()))
}

/// Change the title for the window manager
Expand Down Expand Up @@ -1686,6 +1685,10 @@ impl WindowOps for XWindow {
});
}

fn get_window_position(&self) -> Future<ScreenPoint> {
XConnection::with_window_inner(self.0, move |inner| inner.get_window_position())
}

fn set_window_position(&self, coords: ScreenPoint) {
XConnection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords);
Expand Down
4 changes: 2 additions & 2 deletions window/src/os/x_and_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ impl WindowOps for Window {
}
}

fn get_window_position(&self) -> ScreenPoint {
fn get_window_position(&self) -> Future<ScreenPoint> {
match self {
Self::X11(x) => x.get_window_position(),
#[cfg(feature = "wayland")]
Self::Wayland(w) => ScreenPoint(0, 0),
Self::Wayland(w) => w.get_window_position(),
}
}

Expand Down

0 comments on commit b4d29a9

Please sign in to comment.