forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBdde9214Ivan Molodetskikh1 year ago1835 commits

workspace.rs1721 lines, 54.6 KiBHistoryRawDownload
1use std::cmp::max;
2use std::rc::Rc;
3use std::time::Duration;
4
5use niri_config::{CenterFocusedColumn, OutputName, PresetSize, Workspace as WorkspaceConfig};
6use niri_ipc::{ColumnDisplay, PositionChange, SizeChange};
7use smithay::backend::renderer::gles::GlesRenderer;
8use smithay::desktop::{layer_map_for_output, Window};
9use smithay::output::Output;
10use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
11use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
12use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
13use smithay::wayland::compositor::with_states;
14use smithay::wayland::shell::xdg::SurfaceCachedState;
15
16use super::floating::{FloatingSpace, FloatingSpaceRenderElement};
17use super::scrolling::{
18 Column, ColumnWidth, InsertHint, InsertPosition, ScrollDirection, ScrollingSpace,
19 ScrollingSpaceRenderElement,
20};
21use super::tile::{Tile, TileRenderSnapshot};
22use super::{
23 ActivateWindow, HitType, InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac,
24};
25use crate::animation::Clock;
26use crate::niri_render_elements;
27use crate::render_helpers::renderer::NiriRenderer;
28use crate::render_helpers::RenderTarget;
29use crate::utils::id::IdCounter;
30use crate::utils::transaction::{Transaction, TransactionBlocker};
31use crate::utils::{
32 ensure_min_max_size, ensure_min_max_size_maybe_zero, output_size, send_scale_transform,
33 ResizeEdge,
34};
35use crate::window::ResolvedWindowRules;
36
37#[derive(Debug)]
38pub struct Workspace<W: LayoutElement> {
39 /// The scrollable-tiling layout.
40 scrolling: ScrollingSpace<W>,
41
42 /// The floating layout.
43 floating: FloatingSpace<W>,
44
45 /// Whether the floating layout is active instead of the scrolling layout.
46 floating_is_active: FloatingActive,
47
48 /// The original output of this workspace.
49 ///
50 /// Most of the time this will be the workspace's current output, however, after an output
51 /// disconnection, it may remain pointing to the disconnected output.
52 pub(super) original_output: OutputId,
53
54 /// Current output of this workspace.
55 output: Option<Output>,
56
57 /// Latest known output scale for this workspace.
58 ///
59 /// This should be set from the current workspace output, or, if all outputs have been
60 /// disconnected, preserved until a new output is connected.
61 scale: smithay::output::Scale,
62
63 /// Latest known output transform for this workspace.
64 ///
65 /// This should be set from the current workspace output, or, if all outputs have been
66 /// disconnected, preserved until a new output is connected.
67 transform: Transform,
68
69 /// Latest known view size for this workspace.
70 ///
71 /// This should be computed from the current workspace output size, or, if all outputs have
72 /// been disconnected, preserved until a new output is connected.
73 view_size: Size<f64, Logical>,
74
75 /// Latest known working area for this workspace.
76 ///
77 /// Not rounded to physical pixels.
78 ///
79 /// This is similar to view size, but takes into account things like layer shell exclusive
80 /// zones.
81 working_area: Rectangle<f64, Logical>,
82
83 /// Clock for driving animations.
84 pub(super) clock: Clock,
85
86 /// Configurable properties of the layout as received from the parent monitor.
87 pub(super) base_options: Rc<Options>,
88
89 /// Configurable properties of the layout with logical sizes adjusted for the current `scale`.
90 pub(super) options: Rc<Options>,
91
92 /// Optional name of this workspace.
93 pub(super) name: Option<String>,
94
95 /// Unique ID of this workspace.
96 id: WorkspaceId,
97}
98
99#[derive(Debug, Clone)]
100pub struct OutputId(String);
101
102impl OutputId {
103 pub fn matches(&self, output: &Output) -> bool {
104 let output_name = output.user_data().get::<OutputName>().unwrap();
105 output_name.matches(&self.0)
106 }
107}
108
109static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new();
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
112pub struct WorkspaceId(u64);
113
114impl WorkspaceId {
115 fn next() -> WorkspaceId {
116 WorkspaceId(WORKSPACE_ID_COUNTER.next())
117 }
118
119 pub fn get(self) -> u64 {
120 self.0
121 }
122
123 pub fn specific(id: u64) -> Self {
124 Self(id)
125 }
126}
127
128niri_render_elements! {
129 WorkspaceRenderElement<R> => {
130 Scrolling = ScrollingSpaceRenderElement<R>,
131 Floating = FloatingSpaceRenderElement<R>,
132 }
133}
134
135#[derive(Debug)]
136pub(super) struct InteractiveResize<W: LayoutElement> {
137 pub window: W::Id,
138 pub original_window_size: Size<f64, Logical>,
139 pub data: InteractiveResizeData,
140}
141
142/// Resolved width or height in logical pixels.
143#[derive(Debug, Clone, Copy)]
144pub enum ResolvedSize {
145 /// Size of the tile including borders.
146 Tile(f64),
147 /// Size of the window excluding borders.
148 Window(f64),
149}
150
151/// Whether the floating space is active.
152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
153enum FloatingActive {
154 /// The scrolling space is active.
155 No,
156 /// The scrolling space is active, but the floating space should render on top, even if the
157 /// active scrolling window is fullscreen.
158 ///
159 /// This is necessary for focus-follows-mouse that activates but doesn't raise the window to
160 /// avoid being annoying.
161 NoButRaised,
162 /// The floating space is active.
163 Yes,
164}
165
166/// Where to put a newly added window.
167#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
168pub enum WorkspaceAddWindowTarget<'a, W: LayoutElement> {
169 /// No particular preference.
170 #[default]
171 Auto,
172 /// As a new column at this index.
173 NewColumnAt(usize),
174 /// Next to this existing window.
175 NextTo(&'a W::Id),
176}
177
178impl OutputId {
179 pub fn new(output: &Output) -> Self {
180 let output_name = output.user_data().get::<OutputName>().unwrap();
181 Self(output_name.format_make_model_serial_or_connector())
182 }
183}
184
185impl FloatingActive {
186 fn get(self) -> bool {
187 self == Self::Yes
188 }
189}
190
191impl<W: LayoutElement> Workspace<W> {
192 pub fn new(output: Output, clock: Clock, options: Rc<Options>) -> Self {
193 Self::new_with_config(output, None, clock, options)
194 }
195
196 pub fn new_with_config(
197 output: Output,
198 config: Option<WorkspaceConfig>,
199 clock: Clock,
200 base_options: Rc<Options>,
201 ) -> Self {
202 let original_output = config
203 .as_ref()
204 .and_then(|c| c.open_on_output.clone())
205 .map(OutputId)
206 .unwrap_or(OutputId::new(&output));
207
208 let scale = output.current_scale();
209 let options =
210 Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale()));
211
212 let view_size = output_size(&output);
213 let working_area = compute_working_area(&output);
214
215 let scrolling = ScrollingSpace::new(
216 view_size,
217 working_area,
218 scale.fractional_scale(),
219 clock.clone(),
220 options.clone(),
221 );
222
223 let floating = FloatingSpace::new(
224 view_size,
225 working_area,
226 scale.fractional_scale(),
227 clock.clone(),
228 options.clone(),
229 );
230
231 Self {
232 scrolling,
233 floating,
234 floating_is_active: FloatingActive::No,
235 original_output,
236 scale,
237 transform: output.current_transform(),
238 view_size,
239 working_area,
240 output: Some(output),
241 clock,
242 base_options,
243 options,
244 name: config.map(|c| c.name.0),
245 id: WorkspaceId::next(),
246 }
247 }
248
249 pub fn new_with_config_no_outputs(
250 config: Option<WorkspaceConfig>,
251 clock: Clock,
252 base_options: Rc<Options>,
253 ) -> Self {
254 let original_output = OutputId(
255 config
256 .as_ref()
257 .and_then(|c| c.open_on_output.clone())
258 .unwrap_or_default(),
259 );
260
261 let scale = smithay::output::Scale::Integer(1);
262 let options =
263 Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale()));
264
265 let view_size = Size::from((1280., 720.));
266 let working_area = Rectangle::from_size(Size::from((1280., 720.)));
267
268 let scrolling = ScrollingSpace::new(
269 view_size,
270 working_area,
271 scale.fractional_scale(),
272 clock.clone(),
273 options.clone(),
274 );
275
276 let floating = FloatingSpace::new(
277 view_size,
278 working_area,
279 scale.fractional_scale(),
280 clock.clone(),
281 options.clone(),
282 );
283
284 Self {
285 scrolling,
286 floating,
287 floating_is_active: FloatingActive::No,
288 output: None,
289 scale,
290 transform: Transform::Normal,
291 original_output,
292 view_size,
293 working_area,
294 clock,
295 base_options,
296 options,
297 name: config.map(|c| c.name.0),
298 id: WorkspaceId::next(),
299 }
300 }
301
302 pub fn new_no_outputs(clock: Clock, options: Rc<Options>) -> Self {
303 Self::new_with_config_no_outputs(None, clock, options)
304 }
305
306 pub fn id(&self) -> WorkspaceId {
307 self.id
308 }
309
310 pub fn name(&self) -> Option<&String> {
311 self.name.as_ref()
312 }
313
314 pub fn unname(&mut self) {
315 self.name = None;
316 }
317
318 pub fn has_windows_or_name(&self) -> bool {
319 self.has_windows() || self.name.is_some()
320 }
321
322 pub fn scale(&self) -> smithay::output::Scale {
323 self.scale
324 }
325
326 pub fn advance_animations(&mut self) {
327 self.scrolling.advance_animations();
328 self.floating.advance_animations();
329 }
330
331 pub fn are_animations_ongoing(&self) -> bool {
332 self.scrolling.are_animations_ongoing() || self.floating.are_animations_ongoing()
333 }
334
335 pub fn are_transitions_ongoing(&self) -> bool {
336 self.scrolling.are_transitions_ongoing() || self.floating.are_animations_ongoing()
337 }
338
339 pub fn update_render_elements(&mut self, is_active: bool) {
340 self.scrolling
341 .update_render_elements(is_active && !self.floating_is_active.get());
342
343 let view_rect = Rectangle::from_size(self.view_size);
344 self.floating
345 .update_render_elements(is_active && self.floating_is_active.get(), view_rect);
346 }
347
348 pub fn update_config(&mut self, base_options: Rc<Options>) {
349 let scale = self.scale.fractional_scale();
350 let options = Rc::new(Options::clone(&base_options).adjusted_for_scale(scale));
351
352 self.scrolling.update_config(
353 self.view_size,
354 self.working_area,
355 self.scale.fractional_scale(),
356 options.clone(),
357 );
358
359 self.floating.update_config(
360 self.view_size,
361 self.working_area,
362 self.scale.fractional_scale(),
363 options.clone(),
364 );
365
366 self.base_options = base_options;
367 self.options = options;
368 }
369
370 pub fn update_shaders(&mut self) {
371 self.scrolling.update_shaders();
372 self.floating.update_shaders();
373 }
374
375 pub fn windows(&self) -> impl Iterator<Item = &W> + '_ {
376 self.tiles().map(Tile::window)
377 }
378
379 pub fn windows_mut(&mut self) -> impl Iterator<Item = &mut W> + '_ {
380 self.tiles_mut().map(Tile::window_mut)
381 }
382
383 pub fn tiles(&self) -> impl Iterator<Item = &Tile<W>> + '_ {
384 let scrolling = self.scrolling.tiles();
385 let floating = self.floating.tiles();
386 scrolling.chain(floating)
387 }
388
389 pub fn tiles_mut(&mut self) -> impl Iterator<Item = &mut Tile<W>> + '_ {
390 let scrolling = self.scrolling.tiles_mut();
391 let floating = self.floating.tiles_mut();
392 scrolling.chain(floating)
393 }
394
395 pub fn is_floating(&self, id: &W::Id) -> bool {
396 self.floating.has_window(id)
397 }
398
399 pub fn current_output(&self) -> Option<&Output> {
400 self.output.as_ref()
401 }
402
403 pub fn active_window(&self) -> Option<&W> {
404 if self.floating_is_active.get() {
405 self.floating.active_window()
406 } else {
407 self.scrolling.active_window()
408 }
409 }
410
411 pub fn active_window_mut(&mut self) -> Option<&mut W> {
412 if self.floating_is_active.get() {
413 self.floating.active_window_mut()
414 } else {
415 self.scrolling.active_window_mut()
416 }
417 }
418
419 pub fn is_active_fullscreen(&self) -> bool {
420 self.scrolling.is_active_fullscreen()
421 }
422
423 pub fn set_output(&mut self, output: Option<Output>) {
424 if self.output == output {
425 return;
426 }
427
428 if let Some(output) = self.output.take() {
429 for win in self.windows() {
430 win.output_leave(&output);
431 }
432 }
433
434 self.output = output;
435
436 if let Some(output) = &self.output {
437 // Normalize original output: possibly replace connector with make/model/serial.
438 if self.original_output.matches(output) {
439 self.original_output = OutputId::new(output);
440 }
441
442 self.update_output_size();
443
444 for win in self.windows() {
445 self.enter_output_for_window(win);
446 }
447 }
448 }
449
450 fn enter_output_for_window(&self, window: &W) {
451 if let Some(output) = &self.output {
452 window.set_preferred_scale_transform(self.scale, self.transform);
453 window.output_enter(output);
454 }
455 }
456
457 pub fn update_output_size(&mut self) {
458 let output = self.output.as_ref().unwrap();
459 let scale = output.current_scale();
460 let transform = output.current_transform();
461 let view_size = output_size(output);
462 let working_area = compute_working_area(output);
463 self.set_view_size(scale, transform, view_size, working_area);
464 }
465
466 fn set_view_size(
467 &mut self,
468 scale: smithay::output::Scale,
469 transform: Transform,
470 size: Size<f64, Logical>,
471 working_area: Rectangle<f64, Logical>,
472 ) {
473 let scale_transform_changed = self.transform != transform
474 || self.scale.integer_scale() != scale.integer_scale()
475 || self.scale.fractional_scale() != scale.fractional_scale();
476 if !scale_transform_changed && self.view_size == size && self.working_area == working_area {
477 return;
478 }
479
480 let fractional_scale_changed = self.scale.fractional_scale() != scale.fractional_scale();
481
482 self.scale = scale;
483 self.transform = transform;
484 self.view_size = size;
485 self.working_area = working_area;
486
487 if fractional_scale_changed {
488 // Options need to be recomputed for the new scale.
489 self.update_config(self.base_options.clone());
490 } else {
491 // Pass our existing options as is.
492 self.scrolling.update_config(
493 size,
494 working_area,
495 scale.fractional_scale(),
496 self.options.clone(),
497 );
498 self.floating.update_config(
499 size,
500 working_area,
501 scale.fractional_scale(),
502 self.options.clone(),
503 );
504 }
505
506 if scale_transform_changed {
507 for window in self.windows() {
508 window.set_preferred_scale_transform(self.scale, self.transform);
509 }
510 }
511 }
512
513 pub fn view_size(&self) -> Size<f64, Logical> {
514 self.view_size
515 }
516
517 pub fn make_tile(&self, window: W) -> Tile<W> {
518 Tile::new(
519 window,
520 self.view_size,
521 self.scale.fractional_scale(),
522 self.clock.clone(),
523 self.options.clone(),
524 )
525 }
526
527 pub fn add_tile(
528 &mut self,
529 mut tile: Tile<W>,
530 target: WorkspaceAddWindowTarget<W>,
531 activate: ActivateWindow,
532 width: ColumnWidth,
533 is_full_width: bool,
534 is_floating: bool,
535 ) {
536 self.enter_output_for_window(tile.window());
537 tile.unfullscreen_to_floating = is_floating;
538
539 match target {
540 WorkspaceAddWindowTarget::Auto => {
541 // Don't steal focus from an active fullscreen window.
542 let activate = activate.map_smart(|| !self.is_active_fullscreen());
543
544 // If the tile is pending fullscreen, open it in the scrolling layout where it can
545 // go fullscreen.
546 if is_floating && !tile.window().is_pending_fullscreen() {
547 self.floating.add_tile(tile, activate);
548
549 if activate || self.scrolling.is_empty() {
550 self.floating_is_active = FloatingActive::Yes;
551 }
552 } else {
553 self.scrolling
554 .add_tile(None, tile, activate, width, is_full_width, None);
555
556 if activate {
557 self.floating_is_active = FloatingActive::No;
558 }
559 }
560 }
561 WorkspaceAddWindowTarget::NewColumnAt(col_idx) => {
562 let activate = activate.map_smart(|| false);
563 self.scrolling
564 .add_tile(Some(col_idx), tile, activate, width, is_full_width, None);
565
566 if activate {
567 self.floating_is_active = FloatingActive::No;
568 }
569 }
570 WorkspaceAddWindowTarget::NextTo(next_to) => {
571 let activate = activate.map_smart(|| self.active_window().unwrap().id() == next_to);
572
573 let floating_has_window = self.floating.has_window(next_to);
574
575 if is_floating && !tile.window().is_pending_fullscreen() {
576 if floating_has_window {
577 self.floating.add_tile_above(next_to, tile, activate);
578 } else {
579 // FIXME: use static pos
580 let (next_to_tile, render_pos, _visible) = self
581 .scrolling
582 .tiles_with_render_positions()
583 .find(|(tile, _, _)| tile.window().id() == next_to)
584 .unwrap();
585
586 // Position the new tile in the center above the next_to tile. Think a
587 // dialog opening on top of a window.
588 let tile_size = tile.tile_size();
589 let pos = render_pos
590 + (next_to_tile.tile_size().to_point() - tile_size.to_point())
591 .downscale(2.);
592 let pos = self.floating.clamp_within_working_area(pos, tile_size);
593 let pos = self.floating.logical_to_size_frac(pos);
594 tile.floating_pos = Some(pos);
595
596 self.floating.add_tile(tile, activate);
597 }
598
599 if activate || self.scrolling.is_empty() {
600 self.floating_is_active = FloatingActive::Yes;
601 }
602 } else if floating_has_window {
603 self.scrolling
604 .add_tile(None, tile, activate, width, is_full_width, None);
605
606 if activate {
607 self.floating_is_active = FloatingActive::No;
608 }
609 } else {
610 self.scrolling
611 .add_tile_right_of(next_to, tile, activate, width, is_full_width);
612
613 if activate {
614 self.floating_is_active = FloatingActive::No;
615 }
616 }
617 }
618 }
619 }
620
621 pub fn add_tile_to_column(
622 &mut self,
623 col_idx: usize,
624 tile_idx: Option<usize>,
625 tile: Tile<W>,
626 activate: bool,
627 ) {
628 self.enter_output_for_window(tile.window());
629 self.scrolling
630 .add_tile_to_column(col_idx, tile_idx, tile, activate);
631
632 if activate {
633 self.floating_is_active = FloatingActive::No;
634 }
635 }
636
637 pub fn add_column(&mut self, column: Column<W>, activate: bool) {
638 for (tile, _) in column.tiles() {
639 self.enter_output_for_window(tile.window());
640 }
641
642 self.scrolling.add_column(None, column, activate, None);
643
644 if activate {
645 self.floating_is_active = FloatingActive::No;
646 }
647 }
648
649 fn update_focus_floating_tiling_after_removing(&mut self, removed_from_floating: bool) {
650 if removed_from_floating {
651 if self.floating.is_empty() {
652 self.floating_is_active = FloatingActive::No;
653 }
654 } else {
655 // Scrolling should remain focused if both are empty.
656 if self.scrolling.is_empty() && !self.floating.is_empty() {
657 self.floating_is_active = FloatingActive::Yes;
658 }
659 }
660 }
661
662 pub fn remove_tile(&mut self, id: &W::Id, transaction: Transaction) -> RemovedTile<W> {
663 let mut from_floating = false;
664 let removed = if self.floating.has_window(id) {
665 from_floating = true;
666 self.floating.remove_tile(id)
667 } else {
668 self.scrolling.remove_tile(id, transaction)
669 };
670
671 if let Some(output) = &self.output {
672 removed.tile.window().output_leave(output);
673 }
674
675 self.update_focus_floating_tiling_after_removing(from_floating);
676
677 removed
678 }
679
680 pub fn remove_active_tile(&mut self, transaction: Transaction) -> Option<RemovedTile<W>> {
681 let from_floating = self.floating_is_active.get();
682 let removed = if from_floating {
683 self.floating.remove_active_tile()?
684 } else {
685 self.scrolling.remove_active_tile(transaction)?
686 };
687
688 if let Some(output) = &self.output {
689 removed.tile.window().output_leave(output);
690 }
691
692 self.update_focus_floating_tiling_after_removing(from_floating);
693
694 Some(removed)
695 }
696
697 pub fn remove_active_column(&mut self) -> Option<Column<W>> {
698 let from_floating = self.floating_is_active.get();
699 if from_floating {
700 return None;
701 }
702
703 let column = self.scrolling.remove_active_column()?;
704
705 if let Some(output) = &self.output {
706 for (tile, _) in column.tiles() {
707 tile.window().output_leave(output);
708 }
709 }
710
711 self.update_focus_floating_tiling_after_removing(from_floating);
712
713 Some(column)
714 }
715
716 pub fn resolve_default_width(
717 &self,
718 default_width: Option<Option<PresetSize>>,
719 is_floating: bool,
720 ) -> Option<PresetSize> {
721 match default_width {
722 Some(Some(width)) => Some(width),
723 Some(None) => None,
724 None if is_floating => None,
725 None => self.options.default_column_width,
726 }
727 }
728
729 pub fn resolve_default_height(
730 &self,
731 default_height: Option<Option<PresetSize>>,
732 is_floating: bool,
733 ) -> Option<PresetSize> {
734 match default_height {
735 Some(Some(height)) => Some(height),
736 Some(None) => None,
737 None if is_floating => None,
738 // We don't have a global default at the moment.
739 None => None,
740 }
741 }
742
743 pub fn new_window_size(
744 &self,
745 width: Option<PresetSize>,
746 height: Option<PresetSize>,
747 is_floating: bool,
748 rules: &ResolvedWindowRules,
749 (min_size, max_size): (Size<i32, Logical>, Size<i32, Logical>),
750 ) -> Size<i32, Logical> {
751 let mut size = if is_floating {
752 self.floating.new_window_size(width, height, rules)
753 } else {
754 self.scrolling.new_window_size(width, height, rules)
755 };
756
757 // If the window has a fixed size, or we're picking some fixed size, apply min and max
758 // size. This is to ensure that a fixed-size window rule works on open, while still
759 // allowing the window freedom to pick its default size otherwise.
760 let (min_size, max_size) = rules.apply_min_max_size(min_size, max_size);
761 size.w = ensure_min_max_size_maybe_zero(size.w, min_size.w, max_size.w);
762 // For scrolling (where height is > 0) only ensure fixed height, since at runtime scrolling
763 // will only honor fixed height currently.
764 if min_size.h == max_size.h {
765 size.h = ensure_min_max_size(size.h, min_size.h, max_size.h);
766 } else if size.h > 0 {
767 // Also always honor min height, scrolling always does.
768 size.h = max(size.h, min_size.h);
769 }
770
771 size
772 }
773
774 pub fn configure_new_window(
775 &self,
776 window: &Window,
777 width: Option<PresetSize>,
778 height: Option<PresetSize>,
779 is_floating: bool,
780 rules: &ResolvedWindowRules,
781 ) {
782 window.with_surfaces(|surface, data| {
783 send_scale_transform(surface, data, self.scale, self.transform);
784 });
785
786 let toplevel = window.toplevel().expect("no x11 support");
787 let (min_size, max_size) = with_states(toplevel.wl_surface(), |state| {
788 let mut guard = state.cached_state.get::<SurfaceCachedState>();
789 let current = guard.current();
790 (current.min_size, current.max_size)
791 });
792 toplevel.with_pending_state(|state| {
793 if state.states.contains(xdg_toplevel::State::Fullscreen) {
794 state.size = Some(self.view_size.to_i32_round());
795 } else {
796 let size =
797 self.new_window_size(width, height, is_floating, rules, (min_size, max_size));
798 state.size = Some(size);
799 }
800
801 if is_floating {
802 state.bounds = Some(self.floating.new_window_toplevel_bounds(rules));
803 } else {
804 state.bounds = Some(self.scrolling.new_window_toplevel_bounds(rules));
805 }
806 });
807 }
808
809 pub fn focus_left(&mut self) -> bool {
810 if self.floating_is_active.get() {
811 self.floating.focus_left()
812 } else {
813 self.scrolling.focus_left()
814 }
815 }
816
817 pub fn focus_right(&mut self) -> bool {
818 if self.floating_is_active.get() {
819 self.floating.focus_right()
820 } else {
821 self.scrolling.focus_right()
822 }
823 }
824
825 pub fn focus_column_first(&mut self) {
826 if self.floating_is_active.get() {
827 self.floating.focus_leftmost();
828 } else {
829 self.scrolling.focus_column_first();
830 }
831 }
832
833 pub fn focus_column_last(&mut self) {
834 if self.floating_is_active.get() {
835 self.floating.focus_rightmost();
836 } else {
837 self.scrolling.focus_column_last();
838 }
839 }
840
841 pub fn focus_column_right_or_first(&mut self) {
842 if !self.focus_right() {
843 self.focus_column_first();
844 }
845 }
846
847 pub fn focus_column_left_or_last(&mut self) {
848 if !self.focus_left() {
849 self.focus_column_last();
850 }
851 }
852
853 pub fn focus_window_in_column(&mut self, index: u8) {
854 if self.floating_is_active.get() {
855 return;
856 }
857 self.scrolling.focus_window_in_column(index);
858 }
859
860 pub fn focus_down(&mut self) -> bool {
861 if self.floating_is_active.get() {
862 self.floating.focus_down()
863 } else {
864 self.scrolling.focus_down()
865 }
866 }
867
868 pub fn focus_up(&mut self) -> bool {
869 if self.floating_is_active.get() {
870 self.floating.focus_up()
871 } else {
872 self.scrolling.focus_up()
873 }
874 }
875
876 pub fn focus_down_or_left(&mut self) {
877 if self.floating_is_active.get() {
878 self.floating.focus_down();
879 } else {
880 self.scrolling.focus_down_or_left();
881 }
882 }
883
884 pub fn focus_down_or_right(&mut self) {
885 if self.floating_is_active.get() {
886 self.floating.focus_down();
887 } else {
888 self.scrolling.focus_down_or_right();
889 }
890 }
891
892 pub fn focus_up_or_left(&mut self) {
893 if self.floating_is_active.get() {
894 self.floating.focus_up();
895 } else {
896 self.scrolling.focus_up_or_left();
897 }
898 }
899
900 pub fn focus_up_or_right(&mut self) {
901 if self.floating_is_active.get() {
902 self.floating.focus_up();
903 } else {
904 self.scrolling.focus_up_or_right();
905 }
906 }
907
908 pub fn focus_window_top(&mut self) {
909 if self.floating_is_active.get() {
910 self.floating.focus_topmost();
911 } else {
912 self.scrolling.focus_top();
913 }
914 }
915
916 pub fn focus_window_bottom(&mut self) {
917 if self.floating_is_active.get() {
918 self.floating.focus_bottommost();
919 } else {
920 self.scrolling.focus_bottom();
921 }
922 }
923
924 pub fn focus_window_down_or_top(&mut self) {
925 if !self.focus_down() {
926 self.focus_window_top();
927 }
928 }
929
930 pub fn focus_window_up_or_bottom(&mut self) {
931 if !self.focus_up() {
932 self.focus_window_bottom();
933 }
934 }
935
936 pub fn move_left(&mut self) -> bool {
937 if self.floating_is_active.get() {
938 self.floating.move_left();
939 true
940 } else {
941 self.scrolling.move_left()
942 }
943 }
944
945 pub fn move_right(&mut self) -> bool {
946 if self.floating_is_active.get() {
947 self.floating.move_right();
948 true
949 } else {
950 self.scrolling.move_right()
951 }
952 }
953
954 pub fn move_column_to_first(&mut self) {
955 if self.floating_is_active.get() {
956 return;
957 }
958 self.scrolling.move_column_to_first();
959 }
960
961 pub fn move_column_to_last(&mut self) {
962 if self.floating_is_active.get() {
963 return;
964 }
965 self.scrolling.move_column_to_last();
966 }
967
968 pub fn move_down(&mut self) -> bool {
969 if self.floating_is_active.get() {
970 self.floating.move_down();
971 true
972 } else {
973 self.scrolling.move_down()
974 }
975 }
976
977 pub fn move_up(&mut self) -> bool {
978 if self.floating_is_active.get() {
979 self.floating.move_up();
980 true
981 } else {
982 self.scrolling.move_up()
983 }
984 }
985
986 pub fn consume_or_expel_window_left(&mut self, window: Option<&W::Id>) {
987 if window.map_or(self.floating_is_active.get(), |id| {
988 self.floating.has_window(id)
989 }) {
990 return;
991 }
992 self.scrolling.consume_or_expel_window_left(window);
993 }
994
995 pub fn consume_or_expel_window_right(&mut self, window: Option<&W::Id>) {
996 if window.map_or(self.floating_is_active.get(), |id| {
997 self.floating.has_window(id)
998 }) {
999 return;
1000 }
1001 self.scrolling.consume_or_expel_window_right(window);
1002 }
1003
1004 pub fn consume_into_column(&mut self) {
1005 if self.floating_is_active.get() {
1006 return;
1007 }
1008 self.scrolling.consume_into_column();
1009 }
1010
1011 pub fn expel_from_column(&mut self) {
1012 if self.floating_is_active.get() {
1013 return;
1014 }
1015 self.scrolling.expel_from_column();
1016 }
1017
1018 pub fn swap_window_in_direction(&mut self, direction: ScrollDirection) {
1019 if self.floating_is_active.get() {
1020 return;
1021 }
1022 self.scrolling.swap_window_in_direction(direction);
1023 }
1024
1025 pub fn toggle_column_tabbed_display(&mut self) {
1026 if self.floating_is_active.get() {
1027 return;
1028 }
1029 self.scrolling.toggle_column_tabbed_display();
1030 }
1031
1032 pub fn set_column_display(&mut self, display: ColumnDisplay) {
1033 if self.floating_is_active.get() {
1034 return;
1035 }
1036 self.scrolling.set_column_display(display);
1037 }
1038
1039 pub fn center_column(&mut self) {
1040 if self.floating_is_active.get() {
1041 self.floating.center_window(None);
1042 } else {
1043 self.scrolling.center_column();
1044 }
1045 }
1046
1047 pub fn center_window(&mut self, id: Option<&W::Id>) {
1048 if id.map_or(self.floating_is_active.get(), |id| {
1049 self.floating.has_window(id)
1050 }) {
1051 self.floating.center_window(id);
1052 } else {
1053 self.scrolling.center_window(id);
1054 }
1055 }
1056
1057 pub fn toggle_width(&mut self) {
1058 if self.floating_is_active.get() {
1059 self.floating.toggle_window_width(None);
1060 } else {
1061 self.scrolling.toggle_width();
1062 }
1063 }
1064
1065 pub fn toggle_full_width(&mut self) {
1066 if self.floating_is_active.get() {
1067 // Leave this unimplemented for now. For good UX, this probably needs moving the tile
1068 // to be against the left edge of the working area while it is full-width.
1069 return;
1070 }
1071 self.scrolling.toggle_full_width();
1072 }
1073
1074 pub fn set_column_width(&mut self, change: SizeChange) {
1075 if self.floating_is_active.get() {
1076 self.floating.set_window_width(None, change, true);
1077 } else {
1078 self.scrolling.set_window_width(None, change);
1079 }
1080 }
1081
1082 pub fn set_window_width(&mut self, window: Option<&W::Id>, change: SizeChange) {
1083 if window.map_or(self.floating_is_active.get(), |id| {
1084 self.floating.has_window(id)
1085 }) {
1086 self.floating.set_window_width(window, change, true);
1087 } else {
1088 self.scrolling.set_window_width(window, change);
1089 }
1090 }
1091
1092 pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {
1093 if window.map_or(self.floating_is_active.get(), |id| {
1094 self.floating.has_window(id)
1095 }) {
1096 self.floating.set_window_height(window, change, true);
1097 } else {
1098 self.scrolling.set_window_height(window, change);
1099 }
1100 }
1101
1102 pub fn reset_window_height(&mut self, window: Option<&W::Id>) {
1103 if window.map_or(self.floating_is_active.get(), |id| {
1104 self.floating.has_window(id)
1105 }) {
1106 return;
1107 }
1108 self.scrolling.reset_window_height(window);
1109 }
1110
1111 pub fn toggle_window_width(&mut self, window: Option<&W::Id>) {
1112 if window.map_or(self.floating_is_active.get(), |id| {
1113 self.floating.has_window(id)
1114 }) {
1115 self.floating.toggle_window_width(window);
1116 } else {
1117 self.scrolling.toggle_window_width(window);
1118 }
1119 }
1120
1121 pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {
1122 if window.map_or(self.floating_is_active.get(), |id| {
1123 self.floating.has_window(id)
1124 }) {
1125 self.floating.toggle_window_height(window);
1126 } else {
1127 self.scrolling.toggle_window_height(window);
1128 }
1129 }
1130
1131 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {
1132 let mut unfullscreen_to_floating = false;
1133 if self.floating.has_window(window) {
1134 if is_fullscreen {
1135 unfullscreen_to_floating = true;
1136 self.toggle_window_floating(Some(window));
1137 } else {
1138 // Floating windows are never fullscreen, so this is an unfullscreen request for an
1139 // already unfullscreen window.
1140 return;
1141 }
1142 } else if !is_fullscreen {
1143 // The window is in the scrolling layout and we're requesting an unfullscreen. If it is
1144 // indeed fullscreen (i.e. this isn't a duplicate unfullscreen request), then we may
1145 // need to unfullscreen into floating.
1146 let tile = self
1147 .scrolling
1148 .tiles()
1149 .find(|tile| tile.window().id() == window)
1150 .unwrap();
1151 if tile.window().is_pending_fullscreen() && tile.unfullscreen_to_floating {
1152 // Unfullscreen and float in one call so it has a chance to notice and request a
1153 // (0, 0) size, rather than the scrolling column size.
1154 self.toggle_window_floating(Some(window));
1155 return;
1156 }
1157 }
1158
1159 let changed = self.scrolling.set_fullscreen(window, is_fullscreen);
1160
1161 // When going to fullscreen, remember if we should unfullscreen to floating.
1162 if changed && is_fullscreen {
1163 let tile = self
1164 .scrolling
1165 .tiles_mut()
1166 .find(|tile| tile.window().id() == window)
1167 .unwrap();
1168
1169 tile.unfullscreen_to_floating = unfullscreen_to_floating;
1170 }
1171 }
1172
1173 pub fn toggle_fullscreen(&mut self, window: &W::Id) {
1174 let tile = self
1175 .tiles()
1176 .find(|tile| tile.window().id() == window)
1177 .unwrap();
1178 let current = tile.window().is_pending_fullscreen();
1179 self.set_fullscreen(window, !current);
1180 }
1181
1182 pub fn toggle_window_floating(&mut self, id: Option<&W::Id>) {
1183 let active_id = self.active_window().map(|win| win.id().clone());
1184 let target_is_active = id.map_or(true, |id| Some(id) == active_id.as_ref());
1185 let Some(id) = id.cloned().or(active_id) else {
1186 return;
1187 };
1188
1189 let (_, render_pos, _) = self
1190 .tiles_with_render_positions()
1191 .find(|(tile, _, _)| *tile.window().id() == id)
1192 .unwrap();
1193
1194 if self.floating.has_window(&id) {
1195 let removed = self.floating.remove_tile(&id);
1196 // FIXME: compute closest pos?
1197 self.scrolling.add_tile(
1198 None,
1199 removed.tile,
1200 target_is_active,
1201 removed.width,
1202 removed.is_full_width,
1203 None,
1204 );
1205 if target_is_active {
1206 self.floating_is_active = FloatingActive::No;
1207 }
1208 } else {
1209 let mut removed = self.scrolling.remove_tile(&id, Transaction::new());
1210 removed.tile.stop_move_animations();
1211
1212 // Come up with a default floating position close to the tile position.
1213 let stored_or_default = self.floating.stored_or_default_tile_pos(&removed.tile);
1214 if stored_or_default.is_none() {
1215 let offset = if self.options.center_focused_column == CenterFocusedColumn::Always {
1216 Point::from((0., 0.))
1217 } else {
1218 Point::from((50., 50.))
1219 };
1220 let pos = render_pos + offset;
1221 let size = removed.tile.tile_size();
1222 let pos = self.floating.clamp_within_working_area(pos, size);
1223 let pos = self.floating.logical_to_size_frac(pos);
1224 removed.tile.floating_pos = Some(pos);
1225 }
1226
1227 self.floating.add_tile(removed.tile, target_is_active);
1228 if target_is_active {
1229 self.floating_is_active = FloatingActive::Yes;
1230 }
1231 }
1232
1233 let (tile, new_render_pos) = self
1234 .tiles_with_render_positions_mut(false)
1235 .find(|(tile, _)| *tile.window().id() == id)
1236 .unwrap();
1237
1238 tile.animate_move_from(render_pos - new_render_pos);
1239 }
1240
1241 pub fn set_window_floating(&mut self, id: Option<&W::Id>, floating: bool) {
1242 if id.map_or(self.floating_is_active.get(), |id| {
1243 self.floating.has_window(id)
1244 }) == floating
1245 {
1246 return;
1247 }
1248
1249 self.toggle_window_floating(id);
1250 }
1251
1252 pub fn focus_floating(&mut self) {
1253 if !self.floating_is_active.get() {
1254 self.switch_focus_floating_tiling();
1255 }
1256 }
1257
1258 pub fn focus_tiling(&mut self) {
1259 if self.floating_is_active.get() {
1260 self.switch_focus_floating_tiling();
1261 }
1262 }
1263
1264 pub fn switch_focus_floating_tiling(&mut self) {
1265 if self.floating.is_empty() {
1266 // If floating is empty, keep focus on scrolling.
1267 return;
1268 } else if self.scrolling.is_empty() {
1269 // If floating isn't empty but scrolling is, keep focus on floating.
1270 return;
1271 }
1272
1273 self.floating_is_active = if self.floating_is_active.get() {
1274 FloatingActive::No
1275 } else {
1276 FloatingActive::Yes
1277 };
1278 }
1279
1280 pub fn move_floating_window(
1281 &mut self,
1282 id: Option<&W::Id>,
1283 x: PositionChange,
1284 y: PositionChange,
1285 animate: bool,
1286 ) {
1287 if id.map_or(self.floating_is_active.get(), |id| {
1288 self.floating.has_window(id)
1289 }) {
1290 self.floating.move_window(id, x, y, animate);
1291 } else {
1292 // If the target tile isn't floating, set its stored floating position.
1293 let tile = if let Some(id) = id {
1294 self.scrolling
1295 .tiles_mut()
1296 .find(|tile| tile.window().id() == id)
1297 .unwrap()
1298 } else if let Some(tile) = self.scrolling.active_tile_mut() {
1299 tile
1300 } else {
1301 return;
1302 };
1303
1304 let working_area_loc = self.floating.working_area().loc;
1305 let pos = self.floating.stored_or_default_tile_pos(tile);
1306
1307 // If there's no stored floating position, we can only set both components at once, not
1308 // adjust.
1309 let pos = pos.or_else(|| {
1310 (matches!(x, PositionChange::SetFixed(_))
1311 && matches!(y, PositionChange::SetFixed(_)))
1312 .then_some(Point::default())
1313 });
1314
1315 let Some(mut pos) = pos else {
1316 return;
1317 };
1318
1319 match x {
1320 PositionChange::SetFixed(x) => pos.x = x + working_area_loc.x,
1321 PositionChange::AdjustFixed(x) => pos.x += x,
1322 }
1323 match y {
1324 PositionChange::SetFixed(y) => pos.y = y + working_area_loc.y,
1325 PositionChange::AdjustFixed(y) => pos.y += y,
1326 }
1327
1328 let pos = self.floating.logical_to_size_frac(pos);
1329 tile.floating_pos = Some(pos);
1330 }
1331 }
1332
1333 pub fn has_windows(&self) -> bool {
1334 self.windows().next().is_some()
1335 }
1336
1337 pub fn has_window(&self, window: &W::Id) -> bool {
1338 self.windows().any(|win| win.id() == window)
1339 }
1340
1341 pub fn find_wl_surface(&self, wl_surface: &WlSurface) -> Option<&W> {
1342 self.windows().find(|win| win.is_wl_surface(wl_surface))
1343 }
1344
1345 pub fn find_wl_surface_mut(&mut self, wl_surface: &WlSurface) -> Option<&mut W> {
1346 self.windows_mut().find(|win| win.is_wl_surface(wl_surface))
1347 }
1348
1349 pub fn tiles_with_render_positions(
1350 &self,
1351 ) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>, bool)> {
1352 let scrolling = self.scrolling.tiles_with_render_positions();
1353
1354 let floating = self.floating.tiles_with_render_positions();
1355 let visible = self.is_floating_visible();
1356 let floating = floating.map(move |(tile, pos)| (tile, pos, visible));
1357
1358 floating.chain(scrolling)
1359 }
1360
1361 pub fn tiles_with_render_positions_mut(
1362 &mut self,
1363 round: bool,
1364 ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> {
1365 let scrolling = self.scrolling.tiles_with_render_positions_mut(round);
1366 let floating = self.floating.tiles_with_render_positions_mut(round);
1367 floating.chain(scrolling)
1368 }
1369
1370 pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> {
1371 if self.floating_is_active.get() {
1372 self.floating.active_tile_visual_rectangle()
1373 } else {
1374 self.scrolling.active_tile_visual_rectangle()
1375 }
1376 }
1377
1378 pub fn popup_target_rect(&self, window: &W::Id) -> Option<Rectangle<f64, Logical>> {
1379 if self.floating.has_window(window) {
1380 self.floating.popup_target_rect(window)
1381 } else {
1382 self.scrolling.popup_target_rect(window)
1383 }
1384 }
1385
1386 pub fn render_elements<R: NiriRenderer>(
1387 &self,
1388 renderer: &mut R,
1389 target: RenderTarget,
1390 focus_ring: bool,
1391 ) -> impl Iterator<Item = WorkspaceRenderElement<R>> {
1392 let scale = Scale::from(self.scale.fractional_scale());
1393 let scrolling_focus_ring = focus_ring && !self.floating_is_active();
1394 let scrolling =
1395 self.scrolling
1396 .render_elements(renderer, scale, target, scrolling_focus_ring);
1397 let scrolling = scrolling.into_iter().map(WorkspaceRenderElement::from);
1398
1399 let floating_focus_ring = focus_ring && self.floating_is_active();
1400 let floating = self.is_floating_visible().then(|| {
1401 let view_rect = Rectangle::from_size(self.view_size);
1402 let floating = self.floating.render_elements(
1403 renderer,
1404 view_rect,
1405 scale,
1406 target,
1407 floating_focus_ring,
1408 );
1409 floating.into_iter().map(WorkspaceRenderElement::from)
1410 });
1411
1412 floating.into_iter().flatten().chain(scrolling)
1413 }
1414
1415 pub fn render_above_top_layer(&self) -> bool {
1416 self.scrolling.render_above_top_layer()
1417 }
1418
1419 pub fn is_floating_visible(&self) -> bool {
1420 // If the focus is on a fullscreen scrolling window, hide the floating windows.
1421 matches!(
1422 self.floating_is_active,
1423 FloatingActive::Yes | FloatingActive::NoButRaised
1424 ) || !self.render_above_top_layer()
1425 }
1426
1427 pub fn store_unmap_snapshot_if_empty(&mut self, renderer: &mut GlesRenderer, window: &W::Id) {
1428 let output_scale = Scale::from(self.scale.fractional_scale());
1429 let view_size = self.view_size();
1430 for (tile, tile_pos) in self.tiles_with_render_positions_mut(false) {
1431 if tile.window().id() == window {
1432 let view_pos = Point::from((-tile_pos.x, -tile_pos.y));
1433 let view_rect = Rectangle::new(view_pos, view_size);
1434 tile.update_render_elements(false, view_rect);
1435 tile.store_unmap_snapshot_if_empty(renderer, output_scale);
1436 return;
1437 }
1438 }
1439 }
1440
1441 pub fn clear_unmap_snapshot(&mut self, window: &W::Id) {
1442 for tile in self.tiles_mut() {
1443 if tile.window().id() == window {
1444 let _ = tile.take_unmap_snapshot();
1445 return;
1446 }
1447 }
1448 }
1449
1450 pub fn start_close_animation_for_window(
1451 &mut self,
1452 renderer: &mut GlesRenderer,
1453 window: &W::Id,
1454 blocker: TransactionBlocker,
1455 ) {
1456 if self.floating.has_window(window) {
1457 self.floating
1458 .start_close_animation_for_window(renderer, window, blocker);
1459 } else {
1460 self.scrolling
1461 .start_close_animation_for_window(renderer, window, blocker);
1462 }
1463 }
1464
1465 pub fn start_close_animation_for_tile(
1466 &mut self,
1467 renderer: &mut GlesRenderer,
1468 snapshot: TileRenderSnapshot,
1469 tile_size: Size<f64, Logical>,
1470 tile_pos: Point<f64, Logical>,
1471 blocker: TransactionBlocker,
1472 ) {
1473 self.floating
1474 .start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
1475 }
1476
1477 pub fn start_open_animation(&mut self, id: &W::Id) -> bool {
1478 self.scrolling.start_open_animation(id) || self.floating.start_open_animation(id)
1479 }
1480
1481 pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> {
1482 // This logic is consistent with tiles_with_render_positions().
1483 if self.is_floating_visible() {
1484 if let Some(rv) = self
1485 .floating
1486 .tiles_with_render_positions()
1487 .find_map(|(tile, tile_pos)| HitType::hit_tile(tile, tile_pos, pos))
1488 {
1489 return Some(rv);
1490 }
1491 }
1492
1493 self.scrolling.window_under(pos)
1494 }
1495
1496 pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> {
1497 self.tiles_with_render_positions()
1498 .find_map(|(tile, tile_pos, visible)| {
1499 // This logic should be consistent with window_under() in when it returns Some vs.
1500 // None.
1501 if !visible {
1502 return None;
1503 }
1504
1505 let pos_within_tile = pos - tile_pos;
1506
1507 if tile.hit(pos_within_tile).is_some() {
1508 let size = tile.tile_size().to_f64();
1509
1510 let mut edges = ResizeEdge::empty();
1511 if pos_within_tile.x < size.w / 3. {
1512 edges |= ResizeEdge::LEFT;
1513 } else if 2. * size.w / 3. < pos_within_tile.x {
1514 edges |= ResizeEdge::RIGHT;
1515 }
1516 if pos_within_tile.y < size.h / 3. {
1517 edges |= ResizeEdge::TOP;
1518 } else if 2. * size.h / 3. < pos_within_tile.y {
1519 edges |= ResizeEdge::BOTTOM;
1520 }
1521 return Some(edges);
1522 }
1523
1524 None
1525 })
1526 }
1527
1528 pub fn descendants_added(&mut self, id: &W::Id) -> bool {
1529 self.floating.descendants_added(id)
1530 }
1531
1532 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {
1533 if !self.floating.update_window(window, serial) {
1534 self.scrolling.update_window(window, serial);
1535 }
1536 }
1537
1538 pub fn refresh(&mut self, is_active: bool) {
1539 self.scrolling
1540 .refresh(is_active && !self.floating_is_active.get());
1541 self.floating
1542 .refresh(is_active && self.floating_is_active.get());
1543 }
1544
1545 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
1546 if self.floating.has_window(window) {
1547 return 0.;
1548 }
1549
1550 self.scrolling.scroll_amount_to_activate(window)
1551 }
1552
1553 pub fn activate_window(&mut self, window: &W::Id) -> bool {
1554 if self.floating.activate_window(window) {
1555 self.floating_is_active = FloatingActive::Yes;
1556 true
1557 } else if self.scrolling.activate_window(window) {
1558 self.floating_is_active = FloatingActive::No;
1559 true
1560 } else {
1561 false
1562 }
1563 }
1564
1565 pub fn activate_window_without_raising(&mut self, window: &W::Id) -> bool {
1566 if self.floating.activate_window_without_raising(window) {
1567 self.floating_is_active = FloatingActive::Yes;
1568 true
1569 } else if self.scrolling.activate_window(window) {
1570 self.floating_is_active = match self.floating_is_active {
1571 FloatingActive::No => FloatingActive::No,
1572 FloatingActive::NoButRaised => FloatingActive::NoButRaised,
1573 FloatingActive::Yes => FloatingActive::NoButRaised,
1574 };
1575 true
1576 } else {
1577 false
1578 }
1579 }
1580
1581 pub fn set_insert_hint(&mut self, insert_hint: InsertHint) {
1582 self.scrolling.set_insert_hint(insert_hint);
1583 }
1584
1585 pub fn clear_insert_hint(&mut self) {
1586 self.scrolling.clear_insert_hint();
1587 }
1588
1589 pub fn get_insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition {
1590 self.scrolling.get_insert_position(pos)
1591 }
1592
1593 pub fn view_offset_gesture_begin(&mut self, is_touchpad: bool) {
1594 self.scrolling.view_offset_gesture_begin(is_touchpad);
1595 }
1596
1597 pub fn view_offset_gesture_update(
1598 &mut self,
1599 delta_x: f64,
1600 timestamp: Duration,
1601 is_touchpad: bool,
1602 ) -> Option<bool> {
1603 self.scrolling
1604 .view_offset_gesture_update(delta_x, timestamp, is_touchpad)
1605 }
1606
1607 pub fn view_offset_gesture_end(&mut self, cancelled: bool, is_touchpad: Option<bool>) -> bool {
1608 self.scrolling
1609 .view_offset_gesture_end(cancelled, is_touchpad)
1610 }
1611
1612 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {
1613 if self.floating.has_window(&window) {
1614 self.floating.interactive_resize_begin(window, edges)
1615 } else {
1616 self.scrolling.interactive_resize_begin(window, edges)
1617 }
1618 }
1619
1620 pub fn interactive_resize_update(
1621 &mut self,
1622 window: &W::Id,
1623 delta: Point<f64, Logical>,
1624 ) -> bool {
1625 if self.floating.has_window(window) {
1626 self.floating.interactive_resize_update(window, delta)
1627 } else {
1628 self.scrolling.interactive_resize_update(window, delta)
1629 }
1630 }
1631
1632 pub fn interactive_resize_end(&mut self, window: Option<&W::Id>) {
1633 if let Some(window) = window {
1634 if self.floating.has_window(window) {
1635 self.floating.interactive_resize_end(Some(window));
1636 } else {
1637 self.scrolling.interactive_resize_end(Some(window));
1638 }
1639 } else {
1640 self.floating.interactive_resize_end(None);
1641 self.scrolling.interactive_resize_end(None);
1642 }
1643 }
1644
1645 pub fn floating_is_active(&self) -> bool {
1646 self.floating_is_active.get()
1647 }
1648
1649 pub fn floating_logical_to_size_frac(
1650 &self,
1651 logical_pos: Point<f64, Logical>,
1652 ) -> Point<f64, SizeFrac> {
1653 self.floating.logical_to_size_frac(logical_pos)
1654 }
1655
1656 #[cfg(test)]
1657 pub fn scrolling(&self) -> &ScrollingSpace<W> {
1658 &self.scrolling
1659 }
1660
1661 #[cfg(test)]
1662 pub fn floating(&self) -> &FloatingSpace<W> {
1663 &self.floating
1664 }
1665
1666 #[cfg(test)]
1667 pub fn verify_invariants(&self, move_win_id: Option<&W::Id>) {
1668 use approx::assert_abs_diff_eq;
1669
1670 let scale = self.scale.fractional_scale();
1671 assert!(self.view_size.w > 0.);
1672 assert!(self.view_size.h > 0.);
1673 assert!(scale > 0.);
1674 assert!(scale.is_finite());
1675
1676 assert_eq!(self.view_size, self.scrolling.view_size());
1677 assert_eq!(&self.clock, self.scrolling.clock());
1678 assert!(Rc::ptr_eq(&self.options, self.scrolling.options()));
1679 self.scrolling.verify_invariants(self.working_area);
1680
1681 assert_eq!(self.view_size, self.floating.view_size());
1682 assert_eq!(self.working_area, self.floating.working_area());
1683 assert_eq!(&self.clock, self.floating.clock());
1684 assert!(Rc::ptr_eq(&self.options, self.floating.options()));
1685 self.floating.verify_invariants();
1686
1687 if self.floating.is_empty() {
1688 assert!(
1689 !self.floating_is_active.get(),
1690 "when floating is empty it must never be active"
1691 );
1692 } else if self.scrolling.is_empty() {
1693 assert!(
1694 self.floating_is_active.get(),
1695 "when scrolling is empty but floating isn't, floating should be active"
1696 );
1697 }
1698
1699 for (tile, tile_pos, visible) in self.tiles_with_render_positions() {
1700 if Some(tile.window().id()) != move_win_id {
1701 assert_eq!(tile.interactive_move_offset, Point::from((0., 0.)));
1702 }
1703
1704 let rounded_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);
1705
1706 // Tile positions must be rounded to physical pixels.
1707 assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);
1708 assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);
1709
1710 if let Some(anim) = &tile.alpha_animation {
1711 if visible {
1712 assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1");
1713 }
1714 }
1715 }
1716 }
1717}
1718
1719fn compute_working_area(output: &Output) -> Rectangle<f64, Logical> {
1720 layer_map_for_output(output).non_exclusive_zone().to_f64()
1721}