How can I get the mouse's position relative to the terminal on Linux? This is what I have so far:
use std::ptr;
use x11::xlib;
fn main() {
unsafe {
let display = xlib::XOpenDisplay(ptr::null());
if display.is_null() {
panic!("XOpenDisplay failed");
}
let mut root_return = 0;
let mut child_return = 0;
let mut root_x_return = 0;
let mut root_y_return = 0;
let mut win_x_return = 0;
let mut win_y_return = 0;
let mut mask_return = 0;
let screen = xlib::XDefaultScreen(display);
let window = xlib::XRootWindow(display, screen);
xlib::XQueryPointer(
display,
window,
&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,
);
// root_x_return and root_y_return are the same as win_x_return and win_y_return
dbg!(root_x_return, root_y_return, win_x_return, win_y_return,);
}
}
It gives me the global mouse's position on the whole screen. What do I have to do to get the output relative only to the current terminal's window? So that 0, 0 starts at the first terminal cell pixel.