oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

Added tiling to event listener loop.

Commit
66aa314e3bf4ed7926beaeba0c423f9a80fd516a
Parent
b5f09c4
Author
tonybtw <tonybtw@tonybtw.com>
Date
2025-09-24 08:05:56

Diff

diff --git a/justfile b/justfile
index b96cf29..8f1819d 100644
--- a/justfile
+++ b/justfile
@@ -1,8 +1,8 @@
-# Run oxwm inside Xephyr with some test clients
 test:
     pkill Xephyr || true
     Xephyr -screen 1280x800 :1 & sleep 1
+    DISPLAY=:1 cargo run &
+    sleep 1
     DISPLAY=:1 xterm &
     DISPLAY=:1 xclock &
-    DISPLAY=:1 cargo run
-
+    wait
diff --git a/src/main.rs b/src/main.rs
index ddb068f..789ecc7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,27 +1,57 @@
 use anyhow::Result;
 use x11rb::connection::Connection;
+use x11rb::protocol::Event;
 use x11rb::protocol::xproto::*;
 use x11rb::rust_connection::RustConnection;
 
 fn main() -> Result<()> {
-    let (conn, screen_num) = x11rb::connect(None)?;
-    let root = conn.setup().roots[screen_num].root;
+    let (connection, screen_number) = x11rb::connect(None)?;
+    let root = connection.setup().roots[screen_number].root;
+    let screen = &connection.setup().roots[screen_number];
 
-    // Ask to manage the root window (like dwm does)
-    conn.change_window_attributes(
-        root,
-        &ChangeWindowAttributesAux::new().event_mask(
-            EventMask::SUBSTRUCTURE_REDIRECT
-                | EventMask::SUBSTRUCTURE_NOTIFY
-                | EventMask::PROPERTY_CHANGE,
-        ),
-    )?.check()?; // will error if another WM is already running
+    connection
+        .change_window_attributes(
+            root,
+            &ChangeWindowAttributesAux::new().event_mask(
+                EventMask::SUBSTRUCTURE_REDIRECT
+                    | EventMask::SUBSTRUCTURE_NOTIFY
+                    | EventMask::PROPERTY_CHANGE,
+            ),
+        )?
+        .check()?;
 
-    println!("oxwm started on display {}", screen_num);
+    println!("oxwm started on display {}", screen_number);
 
+    let mut window_count = 0;
     loop {
-        let event = conn.wait_for_event()?;
+        let event = connection.wait_for_event()?;
         println!("event: {:?}", event);
+        match event {
+            Event::MapRequest(event) => {
+                connection.map_window(event.window)?;
+                let x_coordinate = if window_count == 0 {
+                    0
+                } else {
+                    (screen.width_in_pixels / 2) as i32
+                };
+                connection.configure_window(
+                    event.window,
+                    &ConfigureWindowAux::new()
+                        .x(x_coordinate)
+                        .y(0)
+                        .border_width(1)
+                        .width((screen.width_in_pixels / 2) as u32)
+                        .height(screen.height_in_pixels as u32),
+                )?;
+                window_count += 1;
+                connection.set_input_focus(
+                    InputFocus::POINTER_ROOT,
+                    event.window,
+                    x11rb::CURRENT_TIME,
+                )?;
+                connection.flush()?;
+            }
+            _ => {}
+        }
     }
 }
-