diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index ea42009..adacdfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,15 @@ use atoms::InternedAtoms; use clients::ClientList; +use cursors::Cursors; use thiserror::Error; use xcb::{ - x::{self, ChangeWindowAttributes, Screen, Window}, + x::{self, ChangeWindowAttributes, Window}, Connection, Extension, }; mod atoms; mod clients; +mod cursors; type Result<T, E = Error> = std::result::Result<T, E>; @@ -22,6 +24,9 @@ pub enum Error { #[error("connection error: {0}")] ConnectionError(#[from] xcb::ConnError), + #[error("protocol error: {0}")] + ProtocolError(#[from] xcb::ProtocolError), + #[error("generic xcb error: {0}")] XCBError(#[from] xcb::Error), } @@ -47,6 +52,8 @@ struct WM<'a> { root: Window, clients: ClientList, + + cursors: Cursors, atoms: InternedAtoms, } @@ -60,19 +67,18 @@ impl WM<'_> { .ok_or(Error::NoSuchScreen)?; // Check no other WM is running - let cookie = conn.send_request_checked(&ChangeWindowAttributes { + conn.check_request(conn.send_request_checked(&ChangeWindowAttributes { window: screen.root(), value_list: &[ x::Cw::BackPixel(screen.white_pixel()), x::Cw::EventMask(x::EventMask::SUBSTRUCTURE_REDIRECT), ], - }); - - conn.check_request(cookie) - .map_err(|_| Error::OtherWMRunning)?; + })) + .map_err(|_| Error::OtherWMRunning)?; Ok(WM { atoms: InternedAtoms::new_with(conn)?, + cursors: Cursors::new_with(conn)?, clients: Default::default(), conn, screen_num, @@ -80,11 +86,46 @@ impl WM<'_> { }) } - fn event_loop(&mut self) -> Result<()> { - self.update_geometry()?; + fn setup_root(&self) -> Result<()> { + // TODO: set wm properties + self.conn + .check_request(self.conn.send_request_checked(&ChangeWindowAttributes { + window: self.root, + value_list: &[ + x::Cw::EventMask( + x::EventMask::SUBSTRUCTURE_REDIRECT + | x::EventMask::SUBSTRUCTURE_NOTIFY + | x::EventMask::BUTTON_PRESS + | x::EventMask::POINTER_MOTION + | x::EventMask::ENTER_WINDOW + | x::EventMask::LEAVE_WINDOW + | x::EventMask::STRUCTURE_NOTIFY + | x::EventMask::PROPERTY_CHANGE, + ), + x::Cw::Cursor(self.cursors.normal), + ], + }))?; + + // TODO: grab keys + + // TODO: reset focus Ok(()) } + + fn event_loop(&mut self) -> Result<()> { + self.update_geometry()?; + self.setup_root()?; + + loop { + match self.conn.wait_for_event()? { + e => { + dbg!(e); + // TODO: actually deal with events + } + }; + } + } } fn cleanup_process_children() { // todo: dont transform children into zombies when they terminate |