src/window_system/
src/window_system/mod.rs
#![allow(unused)]
fn main() {
#[derive(Debug, Clone)]
pub struct WindowInfo {
pub extents: (i32, i32, i32, i32),
pub pid: u32,
pub app_name: String,
}
}
#![allow(unused)]
fn main() {
pub trait WindowSystem {
fn focused_window(&self) -> &WindowInfo;
}
}
src/window_system/x11.rs
#![allow(unused)]
fn main() {
pub struct X11 {
info: WindowInfo,
}
impl X11 {
pub fn new() -> Result<Self, Box<dyn std::error::Error>>
}
impl WindowSystem for X11 {
fn focused_window(&self) -> &WindowInfo
}
}
X11::new() sequence
RustConnection::connect(None)— open X11 display- Intern atoms:
_NET_ACTIVE_WINDOW,_NET_WM_PID,WM_CLASS get_property(_NET_ACTIVE_WINDOW, root)→ active window IDget_geometry(active_win)→ window sizetranslate_coordinates(active_win, root, 0, 0)→ absolute positionget_property(_NET_WM_PID)→ PIDget_property(WM_CLASS)→ first null-terminated string as app_name
#![allow(unused)]
fn main() {
pub fn screen_size() -> Result<(i32, i32), Box<dyn std::error::Error>>
}
Connects to X11, returns (width_in_pixels, height_in_pixels) of root window.