niri

niri Wayland Rust Wayland socket libwayland compositor wl_keyboard, wl_surface, xdg_shell

  • scrollable-tiling stackingcolumn
  • ****monitor workspace column
  • ** column** windowtile
  • wayland frame callback 60fps vsync

Rust smithayWayland compositor wayland-rs Rust surface tile

Wayland client → compositor buffer → compositor → → frame callback

Rust:
Rust:


# Wayland compositor 
[dependencies]
smithay = "0.3"
wayland-server = "0.31"
// Wayland compositor 
struct NiriCompositor {
 outputs: Vec<Output>,
 workspaces: HashMap<OutputId, Workspace>,
}
 
struct Workspace {
 columns: Vec<Column>,
 active_column: usize,
}
 
struct Column {
 windows: Vec<Window>,
 scroll_offset: f64,
}
 
impl Column {
 fn add_window(&mut self, window: Window) {
 self.windows.push(window);
 self.layout();
 }
 
 fn layout(&mut self) {
 let y = self.windows.iter().map(|w| w.height).sum::<f64>();
 self.scroll_offset = y;
 }
}