forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBce9dd33sodiboo1 year ago2737 commits

floating.rs1412 lines, 46.8 KiBHistoryRawDownload
1use std::cmp::max;
2use std::iter::zip;
3use std::rc::Rc;
4
5use niri_config::utils::MergeWith as _;
6use niri_config::{PresetSize, RelativeTo};
7use niri_ipc::{PositionChange, SizeChange, WindowLayout};
8use smithay::backend::renderer::gles::GlesRenderer;
9use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size};
10
11use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
12use super::scrolling::ColumnWidth;
13use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
14use super::workspace::{InteractiveResize, ResolvedSize};
15use super::{
16 ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac,
17};
18use crate::animation::{Animation, Clock};
19use crate::niri_render_elements;
20use crate::render_helpers::renderer::NiriRenderer;
21use crate::render_helpers::xray::XrayPos;
22use crate::render_helpers::RenderCtx;
23use crate::utils::transaction::TransactionBlocker;
24use crate::utils::{
25 center_preferring_top_left_in_area, clamp_preferring_top_left_in_area, ensure_min_max_size,
26 ensure_min_max_size_maybe_zero, ResizeEdge,
27};
28use crate::window::ResolvedWindowRules;
29
30/// By how many logical pixels the directional move commands move floating windows.
31pub const DIRECTIONAL_MOVE_PX: f64 = 50.;
32
33/// Space for floating windows.
34#[derive(Debug)]
35pub struct FloatingSpace<W: LayoutElement> {
36 /// Tiles in top-to-bottom order.
37 tiles: Vec<Tile<W>>,
38
39 /// Extra per-tile data.
40 data: Vec<Data>,
41
42 /// Id of the active window.
43 ///
44 /// The active window is not necessarily the topmost window. Focus-follows-mouse should
45 /// activate a window, but not bring it to the top, because that's very annoying.
46 ///
47 /// This is always set to `Some()` when `tiles` isn't empty.
48 active_window_id: Option<W::Id>,
49
50 /// Ongoing interactive resize.
51 interactive_resize: Option<InteractiveResize<W>>,
52
53 /// Windows in the closing animation.
54 closing_windows: Vec<ClosingWindow>,
55
56 /// View size for this space.
57 view_size: Size<f64, Logical>,
58
59 /// Working area for this space.
60 working_area: Rectangle<f64, Logical>,
61
62 /// Scale of the output the space is on (and rounds its sizes to).
63 scale: f64,
64
65 /// Clock for driving animations.
66 clock: Clock,
67
68 /// Configurable properties of the layout.
69 options: Rc<Options>,
70}
71
72niri_render_elements! {
73 FloatingSpaceRenderElement<R> => {
74 Tile = TileRenderElement<R>,
75 ClosingWindow = ClosingWindowRenderElement,
76 }
77}
78
79/// Extra per-tile data.
80#[derive(Debug, Clone, Copy, PartialEq)]
81struct Data {
82 /// Position relative to the working area.
83 pos: Point<f64, SizeFrac>,
84
85 /// Cached position in logical coordinates.
86 ///
87 /// Not rounded to physical pixels.
88 logical_pos: Point<f64, Logical>,
89
90 /// Cached actual size of the tile.
91 size: Size<f64, Logical>,
92
93 /// Working area used for conversions.
94 working_area: Rectangle<f64, Logical>,
95}
96
97impl Data {
98 pub fn new<W: LayoutElement>(
99 working_area: Rectangle<f64, Logical>,
100 tile: &Tile<W>,
101 logical_pos: Point<f64, Logical>,
102 ) -> Self {
103 let mut rv = Self {
104 pos: Point::default(),
105 logical_pos: Point::default(),
106 size: Size::default(),
107 working_area,
108 };
109 rv.update(tile);
110 rv.set_logical_pos(logical_pos);
111 rv
112 }
113
114 pub fn scale_by_working_area(
115 area: Rectangle<f64, Logical>,
116 pos: Point<f64, SizeFrac>,
117 ) -> Point<f64, Logical> {
118 let mut logical_pos = Point::from((pos.x, pos.y));
119 logical_pos.x *= area.size.w;
120 logical_pos.y *= area.size.h;
121 logical_pos += area.loc;
122 logical_pos
123 }
124
125 pub fn logical_to_size_frac_in_working_area(
126 area: Rectangle<f64, Logical>,
127 logical_pos: Point<f64, Logical>,
128 ) -> Point<f64, SizeFrac> {
129 let pos = logical_pos - area.loc;
130 let mut pos = Point::from((pos.x, pos.y));
131 pos.x /= f64::max(area.size.w, 1.0);
132 pos.y /= f64::max(area.size.h, 1.0);
133 pos
134 }
135
136 fn recompute_logical_pos(&mut self) {
137 let mut logical_pos = Self::scale_by_working_area(self.working_area, self.pos);
138
139 // Make sure the window doesn't go too much off-screen. Numbers taken from Mutter.
140 let min_on_screen_hor = f64::clamp(self.size.w / 4., 10., 75.);
141 let min_on_screen_ver = f64::clamp(self.size.h / 4., 10., 75.);
142 let max_off_screen_hor = f64::max(0., self.size.w - min_on_screen_hor);
143 let max_off_screen_ver = f64::max(0., self.size.h - min_on_screen_ver);
144
145 logical_pos -= self.working_area.loc;
146 logical_pos.x = f64::max(logical_pos.x, -max_off_screen_hor);
147 logical_pos.y = f64::max(logical_pos.y, -max_off_screen_ver);
148 logical_pos.x = f64::min(
149 logical_pos.x,
150 self.working_area.size.w - self.size.w + max_off_screen_hor,
151 );
152 logical_pos.y = f64::min(
153 logical_pos.y,
154 self.working_area.size.h - self.size.h + max_off_screen_ver,
155 );
156 logical_pos += self.working_area.loc;
157
158 self.logical_pos = logical_pos;
159 }
160
161 pub fn update_config(&mut self, working_area: Rectangle<f64, Logical>) {
162 if self.working_area == working_area {
163 return;
164 }
165
166 self.working_area = working_area;
167 self.recompute_logical_pos();
168 }
169
170 pub fn update<W: LayoutElement>(&mut self, tile: &Tile<W>) {
171 let size = tile.tile_size();
172 if self.size == size {
173 return;
174 }
175
176 self.size = size;
177 self.recompute_logical_pos();
178 }
179
180 pub fn set_logical_pos(&mut self, logical_pos: Point<f64, Logical>) {
181 self.pos = Self::logical_to_size_frac_in_working_area(self.working_area, logical_pos);
182
183 // This will clamp the logical position to the current working area.
184 self.recompute_logical_pos();
185 }
186
187 pub fn center(&self) -> Point<f64, Logical> {
188 self.logical_pos + self.size.downscale(2.)
189 }
190
191 #[cfg(test)]
192 fn verify_invariants(&self) {
193 let mut temp = *self;
194 temp.recompute_logical_pos();
195 assert_eq!(
196 self.logical_pos, temp.logical_pos,
197 "cached logical pos must be up to date"
198 );
199 }
200}
201
202impl<W: LayoutElement> FloatingSpace<W> {
203 pub fn new(
204 view_size: Size<f64, Logical>,
205 working_area: Rectangle<f64, Logical>,
206 scale: f64,
207 clock: Clock,
208 options: Rc<Options>,
209 ) -> Self {
210 Self {
211 tiles: Vec::new(),
212 data: Vec::new(),
213 active_window_id: None,
214 interactive_resize: None,
215 closing_windows: Vec::new(),
216 view_size,
217 working_area,
218 scale,
219 clock,
220 options,
221 }
222 }
223
224 pub fn update_config(
225 &mut self,
226 view_size: Size<f64, Logical>,
227 working_area: Rectangle<f64, Logical>,
228 scale: f64,
229 options: Rc<Options>,
230 ) {
231 for (tile, data) in zip(&mut self.tiles, &mut self.data) {
232 tile.update_config(view_size, scale, options.clone());
233 data.update(tile);
234 data.update_config(working_area);
235 }
236
237 self.view_size = view_size;
238 self.working_area = working_area;
239 self.scale = scale;
240 self.options = options;
241 }
242
243 pub fn update_shaders(&mut self) {
244 for tile in &mut self.tiles {
245 tile.update_shaders();
246 }
247 }
248
249 pub fn advance_animations(&mut self) {
250 for tile in &mut self.tiles {
251 tile.advance_animations();
252 }
253
254 self.closing_windows.retain_mut(|closing| {
255 closing.advance_animations();
256 closing.are_animations_ongoing()
257 });
258 }
259
260 pub fn are_animations_ongoing(&self) -> bool {
261 self.tiles.iter().any(Tile::are_animations_ongoing) || !self.closing_windows.is_empty()
262 }
263
264 pub fn are_transitions_ongoing(&self) -> bool {
265 self.tiles.iter().any(Tile::are_transitions_ongoing) || !self.closing_windows.is_empty()
266 }
267
268 pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
269 let active = self.active_window_id.clone();
270 for (tile, offset) in self.tiles_with_offsets_mut() {
271 let id = tile.window().id();
272 let is_active = is_active && Some(id) == active.as_ref();
273
274 let mut tile_view_rect = view_rect;
275 tile_view_rect.loc -= offset + tile.render_offset();
276 tile.update_render_elements(is_active, tile_view_rect);
277 }
278 }
279
280 pub fn tiles(&self) -> impl Iterator<Item = &Tile<W>> + '_ {
281 self.tiles.iter()
282 }
283
284 pub fn tiles_mut(&mut self) -> impl Iterator<Item = &mut Tile<W>> + '_ {
285 self.tiles.iter_mut()
286 }
287
288 pub fn tiles_with_offsets(&self) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> + '_ {
289 let offsets = self.data.iter().map(|d| d.logical_pos);
290 zip(&self.tiles, offsets)
291 }
292
293 pub fn tiles_with_offsets_mut(
294 &mut self,
295 ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> + '_ {
296 let offsets = self.data.iter().map(|d| d.logical_pos);
297 zip(&mut self.tiles, offsets)
298 }
299
300 pub fn tiles_with_render_positions(
301 &self,
302 ) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> {
303 let scale = self.scale;
304 self.tiles_with_offsets().map(move |(tile, offset)| {
305 let pos = offset + tile.render_offset();
306 // Round to physical pixels.
307 let pos = pos.to_physical_precise_round(scale).to_logical(scale);
308 (tile, pos)
309 })
310 }
311
312 pub fn tiles_with_render_positions_mut(
313 &mut self,
314 round: bool,
315 ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> {
316 let scale = self.scale;
317 self.tiles_with_offsets_mut().map(move |(tile, offset)| {
318 let mut pos = offset + tile.render_offset();
319 // Round to physical pixels.
320 if round {
321 pos = pos.to_physical_precise_round(scale).to_logical(scale);
322 }
323 (tile, pos)
324 })
325 }
326
327 pub fn tiles_with_ipc_layouts(&self) -> impl Iterator<Item = (&Tile<W>, WindowLayout)> {
328 let scale = self.scale;
329 self.tiles_with_offsets().map(move |(tile, offset)| {
330 // Do not include animated render offset here to avoid IPC spam.
331 let pos = offset;
332 // Round to physical pixels.
333 let pos = pos.to_physical_precise_round(scale).to_logical(scale);
334
335 let layout = WindowLayout {
336 tile_pos_in_workspace_view: Some(pos.into()),
337 ..tile.ipc_layout_template()
338 };
339 (tile, layout)
340 })
341 }
342
343 pub fn new_window_toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> {
344 let border_config = self.options.layout.border.merged_with(&rules.border);
345 compute_toplevel_bounds(border_config, self.working_area.size)
346 }
347
348 /// Returns the geometry of the active tile relative to and clamped to the working area.
349 ///
350 /// During animations, assumes the final tile position.
351 pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> {
352 let (tile, offset) = self.tiles_with_offsets().next()?;
353
354 let tile_size = tile.tile_size();
355 let tile_rect = Rectangle::new(offset, tile_size);
356
357 self.working_area.intersection(tile_rect)
358 }
359
360 pub fn popup_target_rect(&self, id: &W::Id) -> Option<Rectangle<f64, Logical>> {
361 for (tile, pos) in self.tiles_with_offsets() {
362 if tile.window().id() == id {
363 // Position within the working area.
364 let mut target = self.working_area;
365 target.loc -= pos;
366 target.loc -= tile.window_loc();
367
368 return Some(target);
369 }
370 }
371 None
372 }
373
374 fn idx_of(&self, id: &W::Id) -> Option<usize> {
375 self.tiles.iter().position(|tile| tile.window().id() == id)
376 }
377
378 fn contains(&self, id: &W::Id) -> bool {
379 self.idx_of(id).is_some()
380 }
381
382 pub fn active_window(&self) -> Option<&W> {
383 let id = self.active_window_id.as_ref()?;
384 self.tiles
385 .iter()
386 .find(|tile| tile.window().id() == id)
387 .map(Tile::window)
388 }
389
390 pub fn active_window_mut(&mut self) -> Option<&mut W> {
391 let id = self.active_window_id.as_ref()?;
392 self.tiles
393 .iter_mut()
394 .find(|tile| tile.window().id() == id)
395 .map(Tile::window_mut)
396 }
397
398 pub fn has_window(&self, id: &W::Id) -> bool {
399 self.tiles.iter().any(|tile| tile.window().id() == id)
400 }
401
402 pub fn is_empty(&self) -> bool {
403 self.tiles.is_empty()
404 }
405
406 pub fn add_tile(&mut self, tile: Tile<W>, activate: bool) {
407 self.add_tile_at(0, tile, activate);
408 }
409
410 fn add_tile_at(&mut self, mut idx: usize, mut tile: Tile<W>, activate: bool) {
411 tile.update_config(self.view_size, self.scale, self.options.clone());
412
413 // Restore the previous floating window size, and in case the tile is fullscreen,
414 // unfullscreen it.
415 let floating_size = tile.floating_window_size;
416 let win = tile.window_mut();
417 let mut size = if !win.pending_sizing_mode().is_normal() {
418 // If the window was fullscreen or maximized without a floating size, ask for (0, 0).
419 floating_size.unwrap_or_default()
420 } else {
421 // If the window wasn't fullscreen without a floating size (e.g. it was tiled before),
422 // ask for the current size. If the current size is unknown (the window was only ever
423 // fullscreen until now), fall back to (0, 0).
424 floating_size.unwrap_or_else(|| win.expected_size().unwrap_or_default())
425 };
426
427 // Apply min/max size window rules. If requesting a concrete size, apply completely; if
428 // requesting (0, 0), apply only when min/max results in a fixed size.
429 let min_size = win.min_size();
430 let max_size = win.max_size();
431 size.w = ensure_min_max_size_maybe_zero(size.w, min_size.w, max_size.w);
432 size.h = ensure_min_max_size_maybe_zero(size.h, min_size.h, max_size.h);
433
434 win.request_size_once(size, true);
435
436 if activate || self.tiles.is_empty() {
437 self.active_window_id = Some(win.id().clone());
438 }
439
440 // Make sure the tile isn't inserted below its parent.
441 for (i, tile_above) in self.tiles.iter().enumerate().take(idx) {
442 if win.is_child_of(tile_above.window()) {
443 idx = i;
444 break;
445 }
446 }
447
448 let pos = self.stored_or_default_tile_pos(&tile).unwrap_or_else(|| {
449 center_preferring_top_left_in_area(self.working_area, tile.tile_size())
450 });
451
452 let data = Data::new(self.working_area, &tile, pos);
453 self.data.insert(idx, data);
454 self.tiles.insert(idx, tile);
455
456 self.bring_up_descendants_of(idx);
457 }
458
459 pub fn add_tile_above(&mut self, above: &W::Id, mut tile: Tile<W>, activate: bool) {
460 let idx = self.idx_of(above).unwrap();
461
462 let above_pos = self.data[idx].logical_pos;
463 let above_size = self.data[idx].size;
464 let tile_size = tile.tile_size();
465 let pos = above_pos + (above_size.to_point() - tile_size.to_point()).downscale(2.);
466 let pos = self.clamp_within_working_area(pos, tile_size);
467 tile.floating_pos = Some(self.logical_to_size_frac(pos));
468
469 self.add_tile_at(idx, tile, activate);
470 }
471
472 fn bring_up_descendants_of(&mut self, idx: usize) {
473 let tile = &self.tiles[idx];
474 let win = tile.window();
475
476 // We always maintain the correct stacking order, so walking descendants back to front
477 // should give us all of them.
478 let mut descendants: Vec<usize> = Vec::new();
479 for (i, tile_below) in self.tiles.iter().enumerate().skip(idx + 1).rev() {
480 let win_below = tile_below.window();
481 if win_below.is_child_of(win)
482 || descendants
483 .iter()
484 .any(|idx| win_below.is_child_of(self.tiles[*idx].window()))
485 {
486 descendants.push(i);
487 }
488 }
489
490 // Now, descendants is in back-to-front order, and repositioning them in the front-to-back
491 // order will preserve the subsequent indices and work out right.
492 let mut idx = idx;
493 #[allow(clippy::explicit_counter_loop)]
494 for descendant_idx in descendants.into_iter().rev() {
495 self.raise_window(descendant_idx, idx);
496 idx += 1;
497 }
498 }
499
500 pub fn remove_active_tile(&mut self) -> Option<RemovedTile<W>> {
501 let id = self.active_window_id.clone()?;
502 Some(self.remove_tile(&id))
503 }
504
505 pub fn remove_tile(&mut self, id: &W::Id) -> RemovedTile<W> {
506 let idx = self.idx_of(id).unwrap();
507 self.remove_tile_by_idx(idx)
508 }
509
510 fn remove_tile_by_idx(&mut self, idx: usize) -> RemovedTile<W> {
511 let mut tile = self.tiles.remove(idx);
512 let data = self.data.remove(idx);
513
514 if self.tiles.is_empty() {
515 self.active_window_id = None;
516 } else if Some(tile.window().id()) == self.active_window_id.as_ref() {
517 // The active tile was removed, make the topmost tile active.
518 self.active_window_id = Some(self.tiles[0].window().id().clone());
519 }
520
521 // Stop interactive resize.
522 if let Some(resize) = &self.interactive_resize {
523 if tile.window().id() == &resize.window {
524 self.interactive_resize = None;
525 }
526 }
527
528 // Store the floating size if we have one.
529 if let Some(size) = tile.window().expected_size() {
530 tile.floating_window_size = Some(size);
531 }
532 // Store the floating position.
533 tile.floating_pos = Some(data.pos);
534
535 let width = ColumnWidth::Fixed(tile.tile_expected_or_current_size().w);
536 RemovedTile {
537 tile,
538 width,
539 is_full_width: false,
540 is_floating: true,
541 }
542 }
543
544 pub fn start_close_animation_for_window(
545 &mut self,
546 renderer: &mut GlesRenderer,
547 id: &W::Id,
548 blocker: TransactionBlocker,
549 ) {
550 let (tile, tile_pos) = self
551 .tiles_with_render_positions_mut(false)
552 .find(|(tile, _)| tile.window().id() == id)
553 .unwrap();
554
555 let Some(snapshot) = tile.take_unmap_snapshot() else {
556 return;
557 };
558
559 let tile_size = tile.tile_size();
560
561 self.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
562 }
563
564 pub fn activate_window_without_raising(&mut self, id: &W::Id) -> bool {
565 if !self.contains(id) {
566 return false;
567 }
568
569 self.active_window_id = Some(id.clone());
570 true
571 }
572
573 pub fn activate_window(&mut self, id: &W::Id) -> bool {
574 let Some(idx) = self.idx_of(id) else {
575 return false;
576 };
577
578 self.raise_window(idx, 0);
579 self.active_window_id = Some(id.clone());
580 self.bring_up_descendants_of(0);
581
582 true
583 }
584
585 fn raise_window(&mut self, from_idx: usize, to_idx: usize) {
586 assert!(to_idx <= from_idx);
587
588 let tile = self.tiles.remove(from_idx);
589 let data = self.data.remove(from_idx);
590 self.tiles.insert(to_idx, tile);
591 self.data.insert(to_idx, data);
592 }
593
594 pub fn start_close_animation_for_tile(
595 &mut self,
596 renderer: &mut GlesRenderer,
597 snapshot: TileRenderSnapshot,
598 tile_size: Size<f64, Logical>,
599 tile_pos: Point<f64, Logical>,
600 blocker: TransactionBlocker,
601 ) {
602 let anim = Animation::new(
603 self.clock.clone(),
604 0.,
605 1.,
606 0.,
607 self.options.animations.window_close.anim,
608 );
609
610 let blocker = if self.options.disable_transactions {
611 TransactionBlocker::completed()
612 } else {
613 blocker
614 };
615
616 let scale = Scale::from(self.scale);
617 let res = ClosingWindow::new(
618 renderer, snapshot, scale, tile_size, tile_pos, blocker, anim,
619 );
620 match res {
621 Ok(closing) => {
622 self.closing_windows.push(closing);
623 }
624 Err(err) => {
625 warn!("error creating a closing window animation: {err:?}");
626 }
627 }
628 }
629
630 pub fn toggle_window_width(&mut self, id: Option<&W::Id>, forwards: bool) {
631 let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else {
632 return;
633 };
634 let idx = self.idx_of(&id).unwrap();
635
636 let available_size = self.working_area.size.w;
637
638 let len = self.options.layout.preset_column_widths.len();
639 let tile = &mut self.tiles[idx];
640 let preset_idx = if let Some(idx) = tile.floating_preset_width_idx {
641 (idx + if forwards { 1 } else { len - 1 }) % len
642 } else {
643 let current_window = tile.window_expected_or_current_size().w;
644 let current_tile = tile.tile_expected_or_current_size().w;
645
646 let mut it = self
647 .options
648 .layout
649 .preset_column_widths
650 .iter()
651 .map(|preset| resolve_preset_size(*preset, available_size));
652
653 if forwards {
654 it.position(|resolved| {
655 match resolved {
656 // Some allowance for fractional scaling purposes.
657 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
658 ResolvedSize::Window(resolved) => current_window + 1. < resolved,
659 }
660 })
661 .unwrap_or(0)
662 } else {
663 it.rposition(|resolved| {
664 match resolved {
665 // Some allowance for fractional scaling purposes.
666 ResolvedSize::Tile(resolved) => resolved + 1. < current_tile,
667 ResolvedSize::Window(resolved) => resolved + 1. < current_window,
668 }
669 })
670 .unwrap_or(len - 1)
671 }
672 };
673
674 let preset = self.options.layout.preset_column_widths[preset_idx];
675 self.set_window_width(Some(&id), SizeChange::from(preset), true);
676
677 self.tiles[idx].floating_preset_width_idx = Some(preset_idx);
678
679 self.interactive_resize_end(Some(&id));
680 }
681
682 pub fn start_open_animation(&mut self, id: &W::Id) -> bool {
683 let Some(idx) = self.idx_of(id) else {
684 return false;
685 };
686
687 self.tiles[idx].start_open_animation();
688 true
689 }
690
691 pub fn toggle_window_height(&mut self, id: Option<&W::Id>, forwards: bool) {
692 let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else {
693 return;
694 };
695 let idx = self.idx_of(&id).unwrap();
696
697 let available_size = self.working_area.size.h;
698
699 let len = self.options.layout.preset_window_heights.len();
700 let tile = &mut self.tiles[idx];
701 let preset_idx = if let Some(idx) = tile.floating_preset_height_idx {
702 (idx + if forwards { 1 } else { len - 1 }) % len
703 } else {
704 let current_window = tile.window_expected_or_current_size().h;
705 let current_tile = tile.tile_expected_or_current_size().h;
706
707 let mut it = self
708 .options
709 .layout
710 .preset_window_heights
711 .iter()
712 .map(|preset| resolve_preset_size(*preset, available_size));
713
714 if forwards {
715 it.position(|resolved| {
716 match resolved {
717 // Some allowance for fractional scaling purposes.
718 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
719 ResolvedSize::Window(resolved) => current_window + 1. < resolved,
720 }
721 })
722 .unwrap_or(0)
723 } else {
724 it.rposition(|resolved| {
725 match resolved {
726 // Some allowance for fractional scaling purposes.
727 ResolvedSize::Tile(resolved) => resolved + 1. < current_tile,
728 ResolvedSize::Window(resolved) => resolved + 1. < current_window,
729 }
730 })
731 .unwrap_or(len - 1)
732 }
733 };
734
735 let preset = self.options.layout.preset_window_heights[preset_idx];
736 self.set_window_height(Some(&id), SizeChange::from(preset), true);
737
738 let tile = &mut self.tiles[idx];
739 tile.floating_preset_height_idx = Some(preset_idx);
740
741 self.interactive_resize_end(Some(&id));
742 }
743
744 pub fn set_window_width(&mut self, id: Option<&W::Id>, change: SizeChange, animate: bool) {
745 let Some(id) = id.or(self.active_window_id.as_ref()) else {
746 return;
747 };
748 let idx = self.idx_of(id).unwrap();
749
750 let tile = &mut self.tiles[idx];
751 tile.floating_preset_width_idx = None;
752
753 let available_size = self.working_area.size.w;
754 let win = tile.window();
755 let current_window = win.expected_size().unwrap_or_else(|| win.size()).w;
756 let current_tile = tile.tile_expected_or_current_size().w;
757
758 const MAX_PX: f64 = 100000.;
759 const MAX_F: f64 = 10000.;
760
761 let win_width = match change {
762 SizeChange::SetFixed(win_width) => f64::from(win_width),
763 SizeChange::SetProportion(prop) => {
764 let prop = (prop / 100.).clamp(0., MAX_F);
765 let tile_width = available_size * prop;
766 tile.window_width_for_tile_width(tile_width)
767 }
768 SizeChange::AdjustFixed(delta) => f64::from(current_window.saturating_add(delta)),
769 SizeChange::AdjustProportion(delta) => {
770 let current_prop = current_tile / available_size;
771 let prop = (current_prop + delta / 100.).clamp(0., MAX_F);
772 let tile_width = available_size * prop;
773 tile.window_width_for_tile_width(tile_width)
774 }
775 };
776 let win_width = win_width.round().clamp(1., MAX_PX) as i32;
777
778 let win = tile.window_mut();
779 let min_size = win.min_size();
780 let max_size = win.max_size();
781
782 let win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
783
784 let win_height = win.expected_size().unwrap_or_default().h;
785 let win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
786
787 let win_size = Size::from((win_width, win_height));
788 win.request_size_once(win_size, animate);
789 }
790
791 pub fn set_window_height(&mut self, id: Option<&W::Id>, change: SizeChange, animate: bool) {
792 let Some(id) = id.or(self.active_window_id.as_ref()) else {
793 return;
794 };
795 let idx = self.idx_of(id).unwrap();
796
797 let tile = &mut self.tiles[idx];
798 tile.floating_preset_height_idx = None;
799
800 let available_size = self.working_area.size.h;
801 let win = tile.window();
802 let current_window = win.expected_size().unwrap_or_else(|| win.size()).h;
803 let current_tile = tile.tile_expected_or_current_size().h;
804
805 const MAX_PX: f64 = 100000.;
806 const MAX_F: f64 = 10000.;
807
808 let win_height = match change {
809 SizeChange::SetFixed(win_height) => f64::from(win_height),
810 SizeChange::SetProportion(prop) => {
811 let prop = (prop / 100.).clamp(0., MAX_F);
812 let tile_height = available_size * prop;
813 tile.window_height_for_tile_height(tile_height)
814 }
815 SizeChange::AdjustFixed(delta) => f64::from(current_window.saturating_add(delta)),
816 SizeChange::AdjustProportion(delta) => {
817 let current_prop = current_tile / available_size;
818 let prop = (current_prop + delta / 100.).clamp(0., MAX_F);
819 let tile_height = available_size * prop;
820 tile.window_height_for_tile_height(tile_height)
821 }
822 };
823 let win_height = win_height.round().clamp(1., MAX_PX) as i32;
824
825 let win = tile.window_mut();
826 let min_size = win.min_size();
827 let max_size = win.max_size();
828
829 let win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
830
831 let win_width = win.expected_size().unwrap_or_default().w;
832 let win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
833
834 let win_size = Size::from((win_width, win_height));
835 win.request_size_once(win_size, animate);
836 }
837
838 fn focus_directional(
839 &mut self,
840 distance: impl Fn(Point<f64, Logical>, Point<f64, Logical>) -> f64,
841 ) -> bool {
842 let Some(active_id) = &self.active_window_id else {
843 return false;
844 };
845 let active_idx = self.idx_of(active_id).unwrap();
846 let center = self.data[active_idx].center();
847
848 let result = zip(&self.tiles, &self.data)
849 .filter(|(tile, _)| tile.window().id() != active_id)
850 .map(|(tile, data)| (tile, distance(center, data.center())))
851 .filter(|(_, dist)| *dist > 0.)
852 .min_by(|(_, dist_a), (_, dist_b)| f64::total_cmp(dist_a, dist_b));
853 if let Some((tile, _)) = result {
854 let id = tile.window().id().clone();
855 self.activate_window(&id);
856 true
857 } else {
858 false
859 }
860 }
861
862 pub fn focus_left(&mut self) -> bool {
863 self.focus_directional(|focus, other| focus.x - other.x)
864 }
865
866 pub fn focus_right(&mut self) -> bool {
867 self.focus_directional(|focus, other| other.x - focus.x)
868 }
869
870 pub fn focus_up(&mut self) -> bool {
871 self.focus_directional(|focus, other| focus.y - other.y)
872 }
873
874 pub fn focus_down(&mut self) -> bool {
875 self.focus_directional(|focus, other| other.y - focus.y)
876 }
877
878 pub fn focus_leftmost(&mut self) {
879 let result = self
880 .tiles_with_offsets()
881 .min_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.x, &pos_b.x));
882 if let Some((tile, _)) = result {
883 let id = tile.window().id().clone();
884 self.activate_window(&id);
885 }
886 }
887
888 pub fn focus_rightmost(&mut self) {
889 let result = self
890 .tiles_with_offsets()
891 .max_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.x, &pos_b.x));
892 if let Some((tile, _)) = result {
893 let id = tile.window().id().clone();
894 self.activate_window(&id);
895 }
896 }
897
898 pub fn focus_topmost(&mut self) {
899 let result = self
900 .tiles_with_offsets()
901 .min_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.y, &pos_b.y));
902 if let Some((tile, _)) = result {
903 let id = tile.window().id().clone();
904 self.activate_window(&id);
905 }
906 }
907
908 pub fn focus_bottommost(&mut self) {
909 let result = self
910 .tiles_with_offsets()
911 .max_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.y, &pos_b.y));
912 if let Some((tile, _)) = result {
913 let id = tile.window().id().clone();
914 self.activate_window(&id);
915 }
916 }
917
918 fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) {
919 if animate {
920 self.move_and_animate(idx, new_pos);
921 } else {
922 self.data[idx].set_logical_pos(new_pos);
923 }
924
925 self.interactive_resize_end(None);
926 }
927
928 fn move_by(&mut self, amount: Point<f64, Logical>) {
929 let Some(active_id) = &self.active_window_id else {
930 return;
931 };
932 let idx = self.idx_of(active_id).unwrap();
933
934 let new_pos = self.data[idx].logical_pos + amount;
935 self.move_to(idx, new_pos, true)
936 }
937
938 pub fn move_left(&mut self) {
939 self.move_by(Point::from((-DIRECTIONAL_MOVE_PX, 0.)));
940 }
941
942 pub fn move_right(&mut self) {
943 self.move_by(Point::from((DIRECTIONAL_MOVE_PX, 0.)));
944 }
945
946 pub fn move_up(&mut self) {
947 self.move_by(Point::from((0., -DIRECTIONAL_MOVE_PX)));
948 }
949
950 pub fn move_down(&mut self) {
951 self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX)));
952 }
953
954 pub fn move_window(
955 &mut self,
956 id: Option<&W::Id>,
957 x: PositionChange,
958 y: PositionChange,
959 animate: bool,
960 ) {
961 let Some(id) = id.or(self.active_window_id.as_ref()) else {
962 return;
963 };
964 let idx = self.idx_of(id).unwrap();
965
966 let mut pos = self.data[idx].logical_pos;
967
968 let available_width = self.working_area.size.w;
969 let available_height = self.working_area.size.h;
970 let working_area_loc = self.working_area.loc;
971
972 const MAX_F: f64 = 10000.;
973
974 match x {
975 PositionChange::SetFixed(x) => pos.x = x + working_area_loc.x,
976 PositionChange::SetProportion(prop) => {
977 let prop = (prop / 100.).clamp(0., MAX_F);
978 pos.x = available_width * prop + working_area_loc.x;
979 }
980 PositionChange::AdjustFixed(x) => pos.x += x,
981 PositionChange::AdjustProportion(prop) => {
982 let current_prop = (pos.x - working_area_loc.x) / available_width.max(1.);
983 let prop = (current_prop + prop / 100.).clamp(0., MAX_F);
984 pos.x = available_width * prop + working_area_loc.x;
985 }
986 }
987 match y {
988 PositionChange::SetFixed(y) => pos.y = y + working_area_loc.y,
989 PositionChange::SetProportion(prop) => {
990 let prop = (prop / 100.).clamp(0., MAX_F);
991 pos.y = available_height * prop + working_area_loc.y;
992 }
993 PositionChange::AdjustFixed(y) => pos.y += y,
994 PositionChange::AdjustProportion(prop) => {
995 let current_prop = (pos.y - working_area_loc.y) / available_height.max(1.);
996 let prop = (current_prop + prop / 100.).clamp(0., MAX_F);
997 pos.y = available_height * prop + working_area_loc.y;
998 }
999 }
1000
1001 self.move_to(idx, pos, animate);
1002 }
1003
1004 pub fn center_window(&mut self, id: Option<&W::Id>) {
1005 let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else {
1006 return;
1007 };
1008 let idx = self.idx_of(&id).unwrap();
1009
1010 let new_pos = center_preferring_top_left_in_area(self.working_area, self.data[idx].size);
1011 self.move_to(idx, new_pos, true);
1012 }
1013
1014 pub fn descendants_added(&mut self, id: &W::Id) -> bool {
1015 let Some(idx) = self.idx_of(id) else {
1016 return false;
1017 };
1018
1019 self.bring_up_descendants_of(idx);
1020 true
1021 }
1022
1023 pub fn update_window(&mut self, id: &W::Id, serial: Option<Serial>) -> bool {
1024 let Some(tile_idx) = self.idx_of(id) else {
1025 return false;
1026 };
1027
1028 let tile = &mut self.tiles[tile_idx];
1029 let data = &mut self.data[tile_idx];
1030
1031 let resize = tile.window_mut().interactive_resize_data();
1032
1033 // Do this before calling update_window() so it can get up-to-date info.
1034 if let Some(serial) = serial {
1035 tile.window_mut().on_commit(serial);
1036 }
1037
1038 let prev_size = data.size;
1039
1040 tile.update_window();
1041 data.update(tile);
1042
1043 // When resizing by top/left edge, update the position accordingly.
1044 if let Some(resize) = resize {
1045 let mut offset = Point::from((0., 0.));
1046 if resize.edges.contains(ResizeEdge::LEFT) {
1047 offset.x += prev_size.w - data.size.w;
1048 }
1049 if resize.edges.contains(ResizeEdge::TOP) {
1050 offset.y += prev_size.h - data.size.h;
1051 }
1052 data.set_logical_pos(data.logical_pos + offset);
1053 }
1054
1055 true
1056 }
1057
1058 pub fn render<R: NiriRenderer>(
1059 &self,
1060 mut ctx: RenderCtx<R>,
1061 xray_pos: XrayPos,
1062 view_rect: Rectangle<f64, Logical>,
1063 focus_ring: bool,
1064 push: &mut dyn FnMut(FloatingSpaceRenderElement<R>),
1065 ) {
1066 let scale = Scale::from(self.scale);
1067
1068 // Draw the closing windows on top of the other windows.
1069 //
1070 // FIXME: I guess this should rather preserve the stacking order when the window is closed.
1071 for closing in self.closing_windows.iter().rev() {
1072 let elem = closing.render(ctx.as_gles(), view_rect, scale);
1073 push(elem.into());
1074 }
1075
1076 let active = self.active_window_id.clone();
1077 for (tile, tile_pos) in self.tiles_with_render_positions() {
1078 // For the active tile, draw the focus ring.
1079 let focus_ring = focus_ring && Some(tile.window().id()) == active.as_ref();
1080
1081 let xray_pos = xray_pos.offset(tile_pos);
1082 tile.render(ctx.r(), tile_pos, xray_pos, focus_ring, &mut |elem| {
1083 push(elem.into())
1084 });
1085 }
1086 }
1087
1088 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {
1089 if self.interactive_resize.is_some() {
1090 return false;
1091 }
1092
1093 let tile = self
1094 .tiles
1095 .iter_mut()
1096 .find(|tile| tile.window().id() == &window)
1097 .unwrap();
1098
1099 let original_window_size = tile.window_size();
1100
1101 let resize = InteractiveResize {
1102 window,
1103 original_window_size,
1104 data: InteractiveResizeData { edges },
1105 };
1106 self.interactive_resize = Some(resize);
1107
1108 true
1109 }
1110
1111 pub fn interactive_resize_update(
1112 &mut self,
1113 window: &W::Id,
1114 delta: Point<f64, Logical>,
1115 ) -> bool {
1116 let Some(resize) = &self.interactive_resize else {
1117 return false;
1118 };
1119
1120 if window != &resize.window {
1121 return false;
1122 }
1123
1124 let original_window_size = resize.original_window_size;
1125 let edges = resize.data.edges;
1126
1127 if edges.intersects(ResizeEdge::LEFT_RIGHT) {
1128 let mut dx = delta.x;
1129 if edges.contains(ResizeEdge::LEFT) {
1130 dx = -dx;
1131 };
1132
1133 let window_width = (original_window_size.w + dx).round() as i32;
1134 self.set_window_width(Some(window), SizeChange::SetFixed(window_width), false);
1135 }
1136
1137 if edges.intersects(ResizeEdge::TOP_BOTTOM) {
1138 let mut dy = delta.y;
1139 if edges.contains(ResizeEdge::TOP) {
1140 dy = -dy;
1141 };
1142
1143 let window_height = (original_window_size.h + dy).round() as i32;
1144 self.set_window_height(Some(window), SizeChange::SetFixed(window_height), false);
1145 }
1146
1147 true
1148 }
1149
1150 pub fn interactive_resize_end(&mut self, window: Option<&W::Id>) {
1151 let Some(resize) = &self.interactive_resize else {
1152 return;
1153 };
1154
1155 if let Some(window) = window {
1156 if window != &resize.window {
1157 return;
1158 }
1159 }
1160
1161 self.interactive_resize = None;
1162 }
1163
1164 pub fn refresh(&mut self, is_active: bool, is_focused: bool) {
1165 let active = self.active_window_id.clone();
1166 for tile in &mut self.tiles {
1167 let win = tile.window_mut();
1168
1169 win.set_active_in_column(true);
1170 win.set_floating(true);
1171
1172 let mut is_active = is_active && Some(win.id()) == active.as_ref();
1173 if self.options.deactivate_unfocused_windows {
1174 is_active &= is_focused;
1175 }
1176 win.set_activated(is_active);
1177
1178 let resize_data = self
1179 .interactive_resize
1180 .as_ref()
1181 .filter(|resize| &resize.window == win.id())
1182 .map(|resize| resize.data);
1183 win.set_interactive_resize(resize_data);
1184
1185 let border_config = self.options.layout.border.merged_with(&win.rules().border);
1186 let bounds = compute_toplevel_bounds(border_config, self.working_area.size);
1187 win.set_bounds(bounds);
1188
1189 // If transactions are disabled, also disable combined throttling, for more
1190 // intuitive behavior.
1191 let intent = if self.options.disable_resize_throttling {
1192 ConfigureIntent::CanSend
1193 } else {
1194 win.configure_intent()
1195 };
1196
1197 if matches!(
1198 intent,
1199 ConfigureIntent::CanSend | ConfigureIntent::ShouldSend
1200 ) {
1201 win.send_pending_configure();
1202 }
1203
1204 win.refresh();
1205 }
1206 }
1207
1208 pub fn clamp_within_working_area(
1209 &self,
1210 pos: Point<f64, Logical>,
1211 size: Size<f64, Logical>,
1212 ) -> Point<f64, Logical> {
1213 let mut rect = Rectangle::new(pos, size);
1214 clamp_preferring_top_left_in_area(self.working_area, &mut rect);
1215 rect.loc
1216 }
1217
1218 pub fn scale_by_working_area(&self, pos: Point<f64, SizeFrac>) -> Point<f64, Logical> {
1219 Data::scale_by_working_area(self.working_area, pos)
1220 }
1221
1222 pub fn logical_to_size_frac(&self, logical_pos: Point<f64, Logical>) -> Point<f64, SizeFrac> {
1223 Data::logical_to_size_frac_in_working_area(self.working_area, logical_pos)
1224 }
1225
1226 fn move_and_animate(&mut self, idx: usize, new_pos: Point<f64, Logical>) {
1227 // Moves up to this logical pixel distance are not animated.
1228 const ANIMATION_THRESHOLD_SQ: f64 = 10. * 10.;
1229
1230 let tile = &mut self.tiles[idx];
1231 let data = &mut self.data[idx];
1232
1233 let prev_pos = data.logical_pos;
1234 data.set_logical_pos(new_pos);
1235 let new_pos = data.logical_pos;
1236
1237 let diff = prev_pos - new_pos;
1238 if diff.x * diff.x + diff.y * diff.y > ANIMATION_THRESHOLD_SQ {
1239 tile.animate_move_from(prev_pos - new_pos);
1240 }
1241 }
1242
1243 pub fn new_window_size(
1244 &self,
1245 width: Option<PresetSize>,
1246 height: Option<PresetSize>,
1247 rules: &ResolvedWindowRules,
1248 ) -> Size<i32, Logical> {
1249 let border = self.options.layout.border.merged_with(&rules.border);
1250
1251 let resolve = |size: Option<PresetSize>, working_area_size: f64| {
1252 if let Some(size) = size {
1253 let size = match resolve_preset_size(size, working_area_size) {
1254 ResolvedSize::Tile(mut size) => {
1255 if !border.off {
1256 size -= border.width * 2.;
1257 }
1258 size
1259 }
1260 ResolvedSize::Window(size) => size,
1261 };
1262
1263 max(1, size.floor() as i32)
1264 } else {
1265 0
1266 }
1267 };
1268
1269 let width = resolve(width, self.working_area.size.w);
1270 let height = resolve(height, self.working_area.size.h);
1271
1272 Size::from((width, height))
1273 }
1274
1275 pub fn stored_or_default_tile_pos(&self, tile: &Tile<W>) -> Option<Point<f64, Logical>> {
1276 let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));
1277 pos.or_else(|| {
1278 tile.window().rules().default_floating_position.map(|pos| {
1279 let relative_to = pos.relative_to;
1280 let size = tile.tile_size();
1281 let area = self.working_area;
1282
1283 let mut pos = Point::from((pos.x.0, pos.y.0));
1284 if relative_to == RelativeTo::TopRight
1285 || relative_to == RelativeTo::BottomRight
1286 || relative_to == RelativeTo::Right
1287 {
1288 pos.x = area.size.w - size.w - pos.x;
1289 }
1290 if relative_to == RelativeTo::BottomLeft
1291 || relative_to == RelativeTo::BottomRight
1292 || relative_to == RelativeTo::Bottom
1293 {
1294 pos.y = area.size.h - size.h - pos.y;
1295 }
1296 if relative_to == RelativeTo::Top || relative_to == RelativeTo::Bottom {
1297 pos.x += area.size.w / 2.0 - size.w / 2.0
1298 }
1299 if relative_to == RelativeTo::Left || relative_to == RelativeTo::Right {
1300 pos.y += area.size.h / 2.0 - size.h / 2.0
1301 }
1302
1303 pos + self.working_area.loc
1304 })
1305 })
1306 }
1307
1308 #[cfg(test)]
1309 pub fn view_size(&self) -> Size<f64, Logical> {
1310 self.view_size
1311 }
1312
1313 pub fn working_area(&self) -> Rectangle<f64, Logical> {
1314 self.working_area
1315 }
1316
1317 #[cfg(test)]
1318 pub fn scale(&self) -> f64 {
1319 self.scale
1320 }
1321
1322 #[cfg(test)]
1323 pub fn clock(&self) -> &Clock {
1324 &self.clock
1325 }
1326
1327 #[cfg(test)]
1328 pub fn options(&self) -> &Rc<Options> {
1329 &self.options
1330 }
1331
1332 #[cfg(test)]
1333 pub fn verify_invariants(&self) {
1334 assert!(self.scale > 0.);
1335 assert!(self.scale.is_finite());
1336 assert_eq!(self.tiles.len(), self.data.len());
1337
1338 for (i, (tile, data)) in zip(&self.tiles, &self.data).enumerate() {
1339 use crate::layout::SizingMode;
1340
1341 assert!(Rc::ptr_eq(&self.options, &tile.options));
1342 assert_eq!(self.view_size, tile.view_size());
1343 assert_eq!(self.clock, tile.clock);
1344 assert_eq!(self.scale, tile.scale());
1345 tile.verify_invariants();
1346
1347 if let Some(idx) = tile.floating_preset_width_idx {
1348 assert!(idx < self.options.layout.preset_column_widths.len());
1349 }
1350 if let Some(idx) = tile.floating_preset_height_idx {
1351 assert!(idx < self.options.layout.preset_window_heights.len());
1352 }
1353
1354 assert_eq!(
1355 tile.window().pending_sizing_mode(),
1356 SizingMode::Normal,
1357 "floating windows cannot be maximized or fullscreen"
1358 );
1359
1360 data.verify_invariants();
1361
1362 let mut data2 = *data;
1363 data2.update(tile);
1364 data2.update_config(self.working_area);
1365 assert_eq!(data, &data2, "tile data must be up to date");
1366
1367 for tile_below in &self.tiles[i + 1..] {
1368 assert!(
1369 !tile_below.window().is_child_of(tile.window()),
1370 "children must be stacked above parents"
1371 );
1372 }
1373 }
1374
1375 if let Some(id) = &self.active_window_id {
1376 assert!(!self.tiles.is_empty());
1377 assert!(self.contains(id), "active window must be present in tiles");
1378 } else {
1379 assert!(self.tiles.is_empty());
1380 }
1381
1382 if let Some(resize) = &self.interactive_resize {
1383 assert!(
1384 self.contains(&resize.window),
1385 "interactive resize window must be present in tiles"
1386 );
1387 }
1388 }
1389}
1390
1391fn compute_toplevel_bounds(
1392 border_config: niri_config::Border,
1393 working_area_size: Size<f64, Logical>,
1394) -> Size<i32, Logical> {
1395 let mut border = 0.;
1396 if !border_config.off {
1397 border = border_config.width * 2.;
1398 }
1399
1400 Size::from((
1401 f64::max(working_area_size.w - border, 1.),
1402 f64::max(working_area_size.h - border, 1.),
1403 ))
1404 .to_i32_floor()
1405}
1406
1407fn resolve_preset_size(preset: PresetSize, view_size: f64) -> ResolvedSize {
1408 match preset {
1409 PresetSize::Proportion(proportion) => ResolvedSize::Tile(view_size * proportion),
1410 PresetSize::Fixed(width) => ResolvedSize::Window(f64::from(width)),
1411 }
1412}