tony / oxwm

Branch: 55db1a7
Switch branches/tags
master
tonybtw Added tiling to event listener loop. 66aa314 2025-09-24
57 lines · 1.8 KB Raw Blame History
1 use anyhow::Result;
2 use x11rb::connection::Connection;
3 use x11rb::protocol::Event;
4 use x11rb::protocol::xproto::*;
5 use x11rb::rust_connection::RustConnection;
6
7 fn main() -> Result<()> {
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];
11
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()?;
22
23 println!("oxwm started on display {}", screen_number);
24
25 let mut window_count = 0;
26 loop {
27 let event = connection.wait_for_event()?;
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 }
56 }
57 }