From c6a963cd43cadff083bfdf4454cdef2d8ddd2070 Mon Sep 17 00:00:00 2001 From: tcmal Date: Wed, 5 Jun 2024 20:54:29 +0100 Subject: some cleanup and lints --- src/main.rs | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f99e19b..6559ad7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use atoms::InternedAtoms; -use clients::ClientList; +use clients::ClientState; use cursors::Cursors; use error::*; -use keys::KeyboardState; +use keys::KeyboardInfo; use xcb::{ x::{self, ChangeWindowAttributes, PropertyNotifyEvent, Window}, Connection, Event, Extension, @@ -16,13 +16,10 @@ mod focus; mod keys; fn main() -> Result<()> { - // todo: cli stuff - let display_name = ":1"; - cleanup_process_children(); let (conn, screen_num) = - Connection::connect_with_extensions(Some(display_name), &[], &[Extension::Xinerama])?; + Connection::connect_with_extensions(None, &[], &[Extension::Xinerama])?; let mut wm = WM::new(&conn, screen_num)?; wm.event_loop()?; @@ -30,20 +27,35 @@ fn main() -> Result<()> { Ok(()) } +/// The window manager's state struct WM<'a> { + /// The open connection to an X server conn: &'a Connection, + + /// The 'screen' number on the X server + /// Note this isn't what you think it is on multi-monitor setups screen_num: i32, + /// The root window root: Window, - clients: ClientList, + /// WM client state + clients: ClientState, + + /// Cached cursors cursors: Cursors, + + /// Cached atoms atoms: InternedAtoms, - keyboard_state: KeyboardState, + + /// Cached keyboard layout information + keyboard_state: KeyboardInfo, } impl WM<'_> { - fn new<'a>(conn: &'a Connection, screen_num: i32) -> Result> { + /// Prepare the window manager to run on the given connection and screen number. + /// This will fail if another WM is running. + fn new(conn: &'_ Connection, screen_num: i32) -> Result> { // Fetch root window let setup = conn.get_setup(); let screen = setup @@ -64,7 +76,7 @@ impl WM<'_> { Ok(WM { atoms: InternedAtoms::new_with(conn)?, cursors: Cursors::new_with(conn)?, - keyboard_state: KeyboardState::new_with(conn)?, + keyboard_state: KeyboardInfo::new_with(conn)?, clients: Default::default(), conn, screen_num, @@ -72,8 +84,9 @@ impl WM<'_> { }) } + /// Set the correct properties on the root window fn setup_root(&mut self) -> Result<()> { - // TODO: set wm properties + // TODO: Set EHWM properties on root window self.conn .check_request(self.conn.send_request_checked(&ChangeWindowAttributes { window: self.root, @@ -100,42 +113,46 @@ impl WM<'_> { } fn event_loop(&mut self) -> Result<()> { + // Perform setup self.update_geometry()?; self.setup_root()?; loop { match self.conn.wait_for_event()? { - // todo: keybinding related stuff + // See keys.rs Event::X(x::Event::KeyPress(e)) => self.handle_key_press(e)?, Event::X(x::Event::MappingNotify(e)) => self.handle_mapping_notify(e)?, - // todo: windows coming and going + // See clients.rs Event::X(x::Event::ConfigureRequest(e)) => self.handle_configure_request(e)?, Event::X(x::Event::ConfigureNotify(e)) => self.handle_configure_notify(e)?, Event::X(x::Event::DestroyNotify(e)) => self.handle_destroy_notify(e)?, Event::X(x::Event::MapRequest(e)) => self.handle_map_request(e)?, Event::X(x::Event::UnmapNotify(e)) => self.handle_unmap_notify(e)?, - // todo: focus stuff + // See focus.rs Event::X(x::Event::EnterNotify(e)) => self.handle_enter_notify(e)?, Event::X(x::Event::FocusIn(e)) => self.handle_focus_in(e)?, Event::X(x::Event::MotionNotify(e)) => self.handle_motion_notify(e)?, - // todo: other + // See below Event::X(x::Event::PropertyNotify(e)) => self.handle_property_notify(e)?, _ => {} }; } } - fn handle_property_notify(&self, e: PropertyNotifyEvent) -> Result<()> { + /// Handle a property notify event, by doing *todo* + fn handle_property_notify(&self, _e: PropertyNotifyEvent) -> Result<()> { todo!() } } +/// Cleanup this process' children and set some flags. +/// This is necessary when used with `startx` fn cleanup_process_children() { - // todo: dont transform children into zombies when they terminate - // todo: cleanup zombies + // TODO: dont transform children into zombies when they terminate + // TODO: cleanup zombies } impl<'a> std::fmt::Debug for WM<'a> { -- cgit v1.2.3