Closed AndreasOM closed 2 years ago
This works for me under X11. Sadly, I don't think there is a way to find it under Wayland or RedoxOS.
#[inline]
pub fn get_position(&self) -> (isize, isize) {
let (x, y);
let (mut nx, mut ny) = (0, 0);
// Create dummy window for child_return value
let mut dummy_window: MaybeUninit<Window> = MaybeUninit::uninit();
let mut attributes: MaybeUninit<XWindowAttributes> = MaybeUninit::uninit();
unsafe {
let root = (self.d.lib.XDefaultRootWindow)(self.d.display);
(self.d.lib.XGetWindowAttributes)(self.d.display, self.handle, attributes.as_mut_ptr());
x = attributes.assume_init().x;
y = attributes.assume_init().y;
(self.d.lib.XTranslateCoordinates)(
self.d.display,
self.handle,
root,
x,
y,
&mut nx,
&mut ny,
dummy_window.as_mut_ptr() as *mut u64,
);
}
(nx as isize, ny as isize)
}
Thanks both of you!
Yeah, as for Wayland I looked at glfw and they also don't support it https://github.com/glfw/glfw/blob/master/src/wl_window.c#L880-L887 so I think we just have to live with returning (0, 0)
on those platforms.
@AndreasOM can you bring in the changes (above) from @xkevio into the same PR?
Will be a bit busy the next few days, but should find some time on the weekend. Will be a blind add of the linux part though.
Ah, well, skipped my coffee break, and just did it.
No promises it works, but it compiles.
Thanks! I will merge it and give it a try :)
I tested this today and it works just fine under Linux/X11 :)
For a current project I wanted to store the layout of windows on the screen to reuse for the next session.
I added
get_position
to the window. It is tested on macos, and windows - with a single display connected. I created a stub for linux, which always returns 0,0. It compiles, but is untested due to lack of a system to test on.It will need some rework for multi display systems, but I don't have one to do that. I tried to keep the formatting, and style in line with the original.