use std::cmp::max;
use std::iter::zip;
use std::rc::Rc;
use niri_config::{PresetSize, RelativeTo};
use niri_ipc::{PositionChange, SizeChange};
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size};
use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
use super::scrolling::ColumnWidth;
use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
use super::workspace::{InteractiveResize, ResolvedSize};
use super::{
ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac,
};
use crate::animation::{Animation, Clock};
use crate::niri_render_elements;
use crate::render_helpers::renderer::NiriRenderer;
use crate::render_helpers::RenderTarget;
use crate::utils::transaction::TransactionBlocker;
use crate::utils::{
center_preferring_top_left_in_area, clamp_preferring_top_left_in_area, ensure_min_max_size,
ensure_min_max_size_maybe_zero, ResizeEdge,
};
use crate::window::ResolvedWindowRules;
/// By how many logical pixels the directional move commands move floating windows.
pub const DIRECTIONAL_MOVE_PX: f64 = 50.;
/// Space for floating windows.
#[derive(Debug)]
pub struct FloatingSpace<W: LayoutElement> {
/// Tiles in top-to-bottom order.
tiles: Vec<Tile<W>>,
/// Extra per-tile data.
data: Vec<Data>,
/// Id of the active window.
///
/// The active window is not necessarily the topmost window. Focus-follows-mouse should
/// activate a window, but not bring it to the top, because that's very annoying.
///
/// This is always set to `Some()` when `tiles` isn't empty.
active_window_id: Option<W::Id>,
/// Ongoing interactive resize.
interactive_resize: Option<InteractiveResize<W>>,
/// Windows in the closing animation.
closing_windows: Vec<ClosingWindow>,
/// View size for this space.
view_size: Size<f64, Logical>,
/// Working area for this space.
working_area: Rectangle<f64, Logical>,
/// Scale of the output the space is on (and rounds its sizes to).
scale: f64,
/// Clock for driving animations.
clock: Clock,
/// Configurable properties of the layout.
options: Rc<Options>,