added a way to add already existing windows to wm

This commit is contained in:
Janis 2021-11-28 21:15:51 +01:00
parent df3c2e33ce
commit d3b4fcbf18
4 changed files with 34 additions and 5 deletions

View file

@ -38,7 +38,7 @@ pub trait WindowServerBackend {
fn ungrab_cursor(&self);
fn move_cursor(&self, window: Option<Self::Window>, position: Point<i32>);
fn all_windows(&self) -> Vec<Self::Window>;
fn all_windows(&self) -> Option<Vec<Self::Window>>;
fn resize_window(&self, window: Self::Window, new_size: Point<i32>) {
self.configure_window(window, Some(new_size), None, None);

View file

@ -858,8 +858,32 @@ impl WindowServerBackend for XLib {
}
}
fn all_windows(&self) -> Vec<Self::Window> {
todo!()
fn all_windows(&self) -> Option<Vec<Self::Window>> {
let mut parent = 0;
let mut root = 0;
let mut children = std::ptr::null_mut();
let mut num_children = 0;
unsafe {
xlib::XQueryTree(
self.dpy(),
self.root,
&mut root,
&mut parent,
&mut children,
&mut num_children,
) != 0
}
.then(|| {
let windows = unsafe {
std::slice::from_raw_parts(children, num_children as usize)
.to_vec()
};
unsafe { xlib::XFree(children as *mut _) };
windows
})
}
}

View file

@ -11,10 +11,8 @@ use state::WMConfig;
mod backends;
mod clients;
//mod clients2;
mod state;
mod util;
mod xlib;
pub mod error {
use thiserror::Error;

View file

@ -253,6 +253,13 @@ where
self.add_vs_switch_keybinds();
// add all already existing windows to the WM
if let Some(windows) = self.backend.all_windows() {
windows
.into_iter()
.for_each(|window| self.new_client(window));
}
self
}