keybinds...
Browse files
+47 −16 readme.org
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | #+AUTHOR: Tony |
| 2 | 2 | #+STARTUP: overview |
| 3 | 3 | |
| 4 | -* OxWM β Oxidize Window Manager | |
| 4 | +* OXWM β DWM but Better (and oxidized) | |
| 5 | 5 | A dynamic window manager written in /Rustπ¦/, inspired by dwm but designed to evolve |
| 6 | 6 | on its own. Configuration is done in Rust source code, keeping with the suckless |
| 7 | 7 | philosophy of *"edit + recompile."* |
| @@ -24,7 +24,7 @@ nix develop | ||
| 24 | 24 | cargo build |
| 25 | 25 | #+end_src |
| 26 | 26 | |
| 27 | -* π§ͺ Running Tests with just | |
| 27 | +* Testing Xephyr with Justfile | |
| 28 | 28 | The =justfile= includes a =test= recipe that starts Xephyr on =:1=, launches |
| 29 | 29 | test clients (xterm, xclock), and runs oxwm in the foreground. |
| 30 | 30 | |
| @@ -36,24 +36,55 @@ just test | ||
| 36 | 36 | This should open a new Xephyr window. oxwm will attach to it and log X11 |
| 37 | 37 | events in your host terminal. Clients like xterm/xclock will appear inside Xephyr. |
| 38 | 38 | |
| 39 | -* πΊ Roadmap (High Level) | |
| 40 | -| Step | Task | Status | | |
| 41 | -|------+---------------------------------------------------------------------------------------+--------| | |
| 42 | -| 1 | Connect to X, claim =SubstructureRedirect=, print events | DONE | | |
| 43 | -| 2 | Handle =MapRequest= and =ConfigureRequest= so clients can map and appear in Xephyr | β³ | | |
| 44 | -| 3 | Implement client tracking and a trivial tiling layout | β | | |
| 45 | -| 4 | Add keybindings (Mod+j/k, Mod+Enter, etc.) | β | | |
| 46 | -| 5 | Per-tag state, multiple layouts, borders, focus handling | β | | |
| 47 | -| 6 | ICCCM/EWMH basics (WM_DELETE_WINDOW, fullscreen, etc) | β | | |
| 48 | -| 7 | Split into =oxwm-core= library and =oxwm-user= config crate | β | | |
| 49 | -| 8 | Polish developer workflow (Nix flake, just, docs) | β | | |
| 50 | - | |
| 51 | -* π Status | |
| 39 | +* OXWM Todo List: | |
| 40 | +** Reorganization Tasks | |
| 41 | +- [ ] Move keyboard module to folder structure: | |
| 42 | + - [ ] Create =src/keyboard/mod.rs= with re-exports | |
| 43 | + - [ ] Move constants to =src/keyboard/keycodes.rs= | |
| 44 | + - [ ] Move key handlers to =src/keyboard/handlers.rs= | |
| 45 | + - [ ] Update imports in main.rs and window_manager.rs | |
| 46 | +- [ ] Create =src/config.rs= in root directory for future configuration system | |
| 47 | + | |
| 48 | +** Core Window Management | |
| 49 | +- [ ] Fix layout after program is closed (handle UnmapNotify events) | |
| 50 | + - [ ] Add UnmapNotify to event handling | |
| 51 | + - [ ] Remove closed windows from windows vector | |
| 52 | + - [ ] Re-apply layout after window removal | |
| 53 | +- [ ] Add keybind to swap focus between windows | |
| 54 | + - [ ] Track focused window in WindowManager struct | |
| 55 | + - [ ] Implement focus cycling logic | |
| 56 | + - [ ] Add visual focus indication (borders/colors) | |
| 57 | + | |
| 58 | +** Key System Improvements | |
| 59 | +- [ ] Connect config.rs to keyboard system for dynamic keybind generation | |
| 60 | +- [ ] Add more dwm-like keybinds: | |
| 61 | + - [ ] Window focus switching (Alt+J/K) | |
| 62 | + - [ ] Master area resizing | |
| 63 | + - [ ] Layout switching | |
| 64 | + - [ ] Workspace/tag management | |
| 65 | +- [ ] Better error handling for failed key grabs | |
| 66 | + | |
| 67 | +** Layout System | |
| 68 | +- [ ] Add more layout types (monocle, floating) | |
| 69 | +- [ ] Handle window resize requests properly | |
| 70 | +- [ ] Add configurable gaps between windows | |
| 71 | +- [ ] Implement layout switching keybinds | |
| 72 | + | |
| 73 | +** Polish & Features | |
| 74 | +- [ ] Clean window destruction/cleanup | |
| 75 | +- [ ] Handle edge cases (empty window list, invalid windows) | |
| 76 | +- [ ] Add status bar integration | |
| 77 | +- [ ] Better error messages and logging | |
| 78 | + | |
| 79 | +** Priority | |
| 80 | +Reorganization and UnmapNotify handling should be immediate priorities. | |
| 81 | + | |
| 82 | +* Status | |
| 52 | 83 | - Rust + x11rb skeleton running |
| 53 | 84 | - Nix flake devShell available |
| 54 | 85 | - =just test= launches Xephyr, clients, and oxwm |
| 55 | 86 | |
| 56 | -* π License | |
| 87 | +* License | |
| 57 | 88 | [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL]] |
| 58 | 89 | |
| 59 | 90 |
+28 −0 src/keyboard.rs new file mode 100644
| @@ -0,0 +1,28 @@ | ||
| 1 | +// wip | |
| 2 | +pub const RETURN: u8 = 36; | |
| 3 | +pub const Q: u8 = 24; | |
| 4 | +pub const ESCAPE: u8 = 9; | |
| 5 | +pub const SPACE: u8 = 65; | |
| 6 | +pub const TAB: u8 = 23; | |
| 7 | +pub const BACKSPACE: u8 = 22; | |
| 8 | +pub const DELETE: u8 = 119; | |
| 9 | + | |
| 10 | +// Function keys | |
| 11 | +pub const F1: u8 = 67; | |
| 12 | +pub const F2: u8 = 68; | |
| 13 | +pub const F3: u8 = 69; | |
| 14 | +pub const F4: u8 = 70; | |
| 15 | + | |
| 16 | +// Letters (assuming QWERTY) | |
| 17 | +pub const A: u8 = 38; | |
| 18 | +pub const S: u8 = 39; | |
| 19 | +pub const D: u8 = 40; | |
| 20 | +pub const F: u8 = 41; | |
| 21 | +pub const J: u8 = 44; | |
| 22 | +pub const K: u8 = 45; | |
| 23 | +pub const L: u8 = 46; | |
| 24 | + | |
| 25 | +// Numbers | |
| 26 | +pub const KEY_1: u8 = 10; | |
| 27 | +pub const KEY_2: u8 = 11; | |
| 28 | +pub const KEY_3: u8 = 12; |
+55 −0 src/keys.rs new file mode 100644
| @@ -0,0 +1,55 @@ | ||
| 1 | +use crate::keyboard; | |
| 2 | +use anyhow::Result; | |
| 3 | +use x11rb::connection::Connection; | |
| 4 | +use x11rb::protocol::xproto::*; | |
| 5 | + | |
| 6 | +pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()> { | |
| 7 | + connection.grab_key( | |
| 8 | + false, | |
| 9 | + root, | |
| 10 | + ModMask::M4.into(), | |
| 11 | + keyboard::RETURN, | |
| 12 | + GrabMode::ASYNC, | |
| 13 | + GrabMode::ASYNC, | |
| 14 | + )?; | |
| 15 | + connection.grab_key( | |
| 16 | + false, | |
| 17 | + root, | |
| 18 | + (ModMask::M1 | ModMask::SHIFT).into(), | |
| 19 | + keyboard::Q, | |
| 20 | + GrabMode::ASYNC, | |
| 21 | + GrabMode::ASYNC, | |
| 22 | + )?; | |
| 23 | + | |
| 24 | + connection.grab_key( | |
| 25 | + false, | |
| 26 | + root, | |
| 27 | + ModMask::M4.into(), | |
| 28 | + keyboard::Q, | |
| 29 | + GrabMode::ASYNC, | |
| 30 | + GrabMode::ASYNC, | |
| 31 | + )?; | |
| 32 | + | |
| 33 | + Ok(()) | |
| 34 | +} | |
| 35 | + | |
| 36 | +pub fn handle_key_press(connection: &impl Connection, event: KeyPressEvent) -> Result<()> { | |
| 37 | + println!("KeyPress: detail={}, state={:?}", event.detail, event.state); | |
| 38 | + | |
| 39 | + match (event.detail, event.state) { | |
| 40 | + (keyboard::RETURN, state) if state.contains(KeyButMask::MOD1) => { | |
| 41 | + println!("Spawning terminal"); | |
| 42 | + std::process::Command::new("xterm").spawn()?; | |
| 43 | + } | |
| 44 | + (keyboard::Q, state) if state.contains(KeyButMask::MOD1 | KeyButMask::SHIFT) => { | |
| 45 | + println!("Closing focused window"); | |
| 46 | + let focus_reply = connection.get_input_focus()?.reply()?; | |
| 47 | + if focus_reply.focus != x11rb::NONE && focus_reply.focus != event.root { | |
| 48 | + connection.kill_client(focus_reply.focus)?; | |
| 49 | + connection.flush()?; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + _ => {} | |
| 53 | + } | |
| 54 | + Ok(()) | |
| 55 | +} |
+2 −0 src/main.rs
| @@ -1,4 +1,6 @@ | ||
| 1 | 1 | use anyhow::Result; |
| 2 | +mod keyboard; | |
| 3 | +mod keys; | |
| 2 | 4 | mod layout; |
| 3 | 5 | mod window_manager; |
| 4 | 6 |
+11 −1 src/window_manager.rs
| @@ -1,3 +1,4 @@ | ||
| 1 | +use crate::keys; | |
| 1 | 2 | use crate::layout::Layout; |
| 2 | 3 | use crate::layout::tiling::TilingLayout; |
| 3 | 4 | |
| @@ -11,6 +12,7 @@ use x11rb::rust_connection::RustConnection; | ||
| 11 | 12 | pub struct WindowManager { |
| 12 | 13 | connection: RustConnection, |
| 13 | 14 | screen_number: usize, |
| 15 | + root: Window, | |
| 14 | 16 | screen: Screen, |
| 15 | 17 | windows: Vec<Window>, |
| 16 | 18 | layout: Box<dyn Layout>, |
| @@ -28,7 +30,8 @@ impl WindowManager { | ||
| 28 | 30 | &ChangeWindowAttributesAux::new().event_mask( |
| 29 | 31 | EventMask::SUBSTRUCTURE_REDIRECT |
| 30 | 32 | | EventMask::SUBSTRUCTURE_NOTIFY |
| 31 | - | EventMask::PROPERTY_CHANGE, | |
| 33 | + | EventMask::PROPERTY_CHANGE | |
| 34 | + | EventMask::KEY_PRESS, | |
| 32 | 35 | ), |
| 33 | 36 | )? |
| 34 | 37 | .check()?; |
| @@ -36,6 +39,7 @@ impl WindowManager { | ||
| 36 | 39 | return Ok(Self { |
| 37 | 40 | connection, |
| 38 | 41 | screen_number, |
| 42 | + root, | |
| 39 | 43 | screen, |
| 40 | 44 | windows: Vec::new(), |
| 41 | 45 | layout: Box::new(TilingLayout), |
| @@ -45,6 +49,8 @@ impl WindowManager { | ||
| 45 | 49 | pub fn run(&mut self) -> Result<()> { |
| 46 | 50 | println!("oxwm started on display {}", self.screen_number); |
| 47 | 51 | |
| 52 | + keys::setup_keybinds(&self.connection, self.root)?; | |
| 53 | + | |
| 48 | 54 | loop { |
| 49 | 55 | let event = self.connection.wait_for_event()?; |
| 50 | 56 | println!("event: {:?}", event); |
| @@ -65,6 +71,10 @@ impl WindowManager { | ||
| 65 | 71 | )?; |
| 66 | 72 | self.connection.flush()?; |
| 67 | 73 | } |
| 74 | + Event::KeyPress(event) => { | |
| 75 | + println!("KeyPress event received!"); | |
| 76 | + keys::handle_key_press(&self.connection, event)?; | |
| 77 | + } | |
| 68 | 78 | _ => {} |
| 69 | 79 | } |
| 70 | 80 | return Ok(()); |