tony / oxwm

Added tiling to event listener loop. Browse files
tonybtw committed 2025-09-24 parent b5f09c4 commit 66aa314e3bf4ed7926beaeba0c423f9a80fd516a
Showing 2 changed files with 47 additions and 17 deletions. UnifiedSplit
+3 −3 justfile
@@ -1,8 +1,8 @@
1 -# Run oxwm inside Xephyr with some test clients
2 1 test:
3 2 pkill Xephyr || true
4 3 Xephyr -screen 1280x800 :1 & sleep 1
4 + DISPLAY=:1 cargo run &
5 + sleep 1
5 6 DISPLAY=:1 xterm &
6 7 DISPLAY=:1 xclock &
7 - DISPLAY=:1 cargo run
8 -
8 + wait
+44 −14 src/main.rs
@@ -1,27 +1,57 @@
1 1 use anyhow::Result;
2 2 use x11rb::connection::Connection;
3 +use x11rb::protocol::Event;
3 4 use x11rb::protocol::xproto::*;
4 5 use x11rb::rust_connection::RustConnection;
5 6
6 7 fn main() -> Result<()> {
7 - let (conn, screen_num) = x11rb::connect(None)?;
8 - let root = conn.setup().roots[screen_num].root;
8 + let (connection, screen_number) = x11rb::connect(None)?;
9 + let root = connection.setup().roots[screen_number].root;
10 + let screen = &connection.setup().roots[screen_number];
9 11
10 - // Ask to manage the root window (like dwm does)
11 - conn.change_window_attributes(
12 - root,
13 - &ChangeWindowAttributesAux::new().event_mask(
14 - EventMask::SUBSTRUCTURE_REDIRECT
15 - | EventMask::SUBSTRUCTURE_NOTIFY
16 - | EventMask::PROPERTY_CHANGE,
17 - ),
18 - )?.check()?; // will error if another WM is already running
12 + connection
13 + .change_window_attributes(
14 + root,
15 + &ChangeWindowAttributesAux::new().event_mask(
16 + EventMask::SUBSTRUCTURE_REDIRECT
17 + | EventMask::SUBSTRUCTURE_NOTIFY
18 + | EventMask::PROPERTY_CHANGE,
19 + ),
20 + )?
21 + .check()?;
19 22
20 - println!("oxwm started on display {}", screen_num);
23 + println!("oxwm started on display {}", screen_number);
21 24
25 + let mut window_count = 0;
22 26 loop {
23 - let event = conn.wait_for_event()?;
27 + let event = connection.wait_for_event()?;
24 28 println!("event: {:?}", event);
29 + match event {
30 + Event::MapRequest(event) => {
31 + connection.map_window(event.window)?;
32 + let x_coordinate = if window_count == 0 {
33 + 0
34 + } else {
35 + (screen.width_in_pixels / 2) as i32
36 + };
37 + connection.configure_window(
38 + event.window,
39 + &ConfigureWindowAux::new()
40 + .x(x_coordinate)
41 + .y(0)
42 + .border_width(1)
43 + .width((screen.width_in_pixels / 2) as u32)
44 + .height(screen.height_in_pixels as u32),
45 + )?;
46 + window_count += 1;
47 + connection.set_input_focus(
48 + InputFocus::POINTER_ROOT,
49 + event.window,
50 + x11rb::CURRENT_TIME,
51 + )?;
52 + connection.flush()?;
53 + }
54 + _ => {}
55 + }
25 56 }
26 57 }
27 -