use super::Layer;
use smithay_client_toolkit::{
    reexports::client::{
        Connection,
        QueueHandle
    },
    shell::wlr_layer::{
        KeyboardInteractivity,
        LayerShellHandler,
        LayerSurface,
        LayerSurfaceConfigure
    }
};

impl LayerShellHandler for Layer {
    fn closed(
        &mut self,
        _conn: &Connection,
        _qh: &QueueHandle<Self>,
        _layer: &LayerSurface,
    ) {
        self.exit = true;
    }

    fn configure(
        &mut self,
        _conn: &Connection,
        _qh: &QueueHandle<Self>,
        layer: &LayerSurface,
        configure: LayerSurfaceConfigure,
        _serial: u32,
    ) {
        let (w, h) = configure.new_size;

        tracing::info!("configuring new size: {:?}", (w, h));

        self.width = w;
        self.height = h;

        layer.set_keyboard_interactivity(KeyboardInteractivity::None);

        if !self.configured_surface {
            self.configured_surface = true;

            self.paint();
        }
    }
}
