// Copyright (C) 2026 alto555
// SPDX-License-Identifier: GPL-2.0-only

use wave_x11::{Kind, Window};

fn main() -> std::io::Result<()> {
    let (w, h) = (640usize, 400usize);
    let mut win = Window::open("waveview smoke", w as u16, h as u16)?;
    let mut buf = vec![0u8; w * h * 3];
    for y in 0..h {
        for x in 0..w {
            let i = (y * w + x) * 3;
            buf[i] = (x * 255 / w) as u8;
            buf[i + 1] = (y * 255 / h) as u8;
            buf[i + 2] = 0x80;
        }
    }
    // a white cross so geometry errors are obvious
    for x in 0..w { let i=((h/2)*w+x)*3; buf[i]=255; buf[i+1]=255; buf[i+2]=255; }
    for y in 0..h { let i=(y*w+w/2)*3; buf[i]=255; buf[i+1]=255; buf[i+2]=255; }
    println!("window id = 0x{:x}", win.id());
    win.present(&buf, w, h)?;
    let t0 = std::time::Instant::now();
    while t0.elapsed().as_secs() < 12 {
        for e in win.next_events()? {
            match e.kind {
                Kind::Expose | Kind::Resize(_, _) => win.present(&buf, w, h)?,
                Kind::Close => return Ok(()),
                Kind::Key(k, _, _) => println!("key keysym=0x{:x}", k),
                Kind::ButtonPress(b, x, y, _) => println!("button {} at {},{}", b, x, y),
                _ => {}
            }
        }
    }
    Ok(())
}
