#[cfg(any(target_os = "linux", target_os = "freebsd"))]
use crate::mouse_position::Mouse;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
impl Mouse {
pub fn get_mouse_position() -> Mouse {
use x11_dl::xlib;
let xlib = xlib::Xlib::open().unwrap();
let display = unsafe { (xlib.XOpenDisplay)(std::ptr::null()) };
let screen = unsafe { (xlib.XDefaultScreen)(display) };
let root = unsafe { (xlib.XRootWindow)(display, screen) };
let mut root_return: xlib::Window = 0;
let mut child_return: xlib::Window = 0;
let mut root_x_return: i32 = -1;
let mut root_y_return: i32 = -1;
let mut win_x_return: i32 = 0;
let mut win_y_return: i32 = 0;
let mut mask_return: u32 = 0;
unsafe {
(xlib.XQueryPointer)(
display,
root,
&mut root_return,
&mut child_return,
&mut root_x_return,
&mut root_y_return,
&mut win_x_return,
&mut win_y_return,
&mut mask_return,
);
}
unsafe {
(xlib.XCloseDisplay)(display);
}
if root_x_return == -1 || root_y_return == -1 {
return Mouse::Error;
}
Mouse::Position {
x: root_x_return,
y: root_y_return,
}
}
}