forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB64a9351Ivan Molodetskikh2 years ago1319 commits

mapped.rs788 lines, 27.8 KiBHistoryRawDownload
1use std::cell::{Cell, RefCell};
2use std::cmp::{max, min};
3use std::time::Duration;
4
5use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule};
6use smithay::backend::renderer::element::surface::render_elements_from_surface_tree;
7use smithay::backend::renderer::element::{Id, Kind};
8use smithay::backend::renderer::gles::GlesRenderer;
9use smithay::desktop::space::SpaceElement as _;
10use smithay::desktop::{PopupManager, Window};
11use smithay::output::{self, Output};
12use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
13use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
14use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
15use smithay::reexports::wayland_server::Resource as _;
16use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
17use smithay::wayland::compositor::{remove_pre_commit_hook, with_states, HookId};
18use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceData};
19
20use super::{ResolvedWindowRules, WindowRef};
21use crate::handlers::KdeDecorationsModeState;
22use crate::layout::{
23 ConfigureIntent, InteractiveResizeData, LayoutElement, LayoutElementRenderElement,
24 LayoutElementRenderSnapshot,
25};
26use crate::niri::WindowOffscreenId;
27use crate::niri_render_elements;
28use crate::render_helpers::border::BorderRenderElement;
29use crate::render_helpers::renderer::NiriRenderer;
30use crate::render_helpers::snapshot::RenderSnapshot;
31use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
32use crate::render_helpers::surface::render_snapshot_from_surface_tree;
33use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};
34use crate::utils::id::IdCounter;
35use crate::utils::transaction::Transaction;
36use crate::utils::{send_scale_transform, ResizeEdge};
37
38#[derive(Debug)]
39pub struct Mapped {
40 pub window: Window,
41
42 /// Unique ID of this `Mapped`.
43 id: MappedId,
44
45 /// Pre-commit hook that we have on all mapped toplevel surfaces.
46 pre_commit_hook: HookId,
47
48 /// Up-to-date rules.
49 rules: ResolvedWindowRules,
50
51 /// Whether the window rules need to be recomputed.
52 ///
53 /// This is not used in all cases; for example, app ID and title changes recompute the rules
54 /// immediately, rather than setting this flag.
55 need_to_recompute_rules: bool,
56
57 /// Whether this window has the keyboard focus.
58 is_focused: bool,
59
60 /// Whether this window is the active window in its column.
61 is_active_in_column: bool,
62
63 /// Buffer to draw instead of the window when it should be blocked out.
64 block_out_buffer: RefCell<SolidColorBuffer>,
65
66 /// Whether the next configure should be animated, if the configured state changed.
67 animate_next_configure: bool,
68
69 /// Serials of commits that should be animated.
70 animate_serials: Vec<Serial>,
71
72 /// Snapshot right before an animated commit.
73 animation_snapshot: Option<LayoutElementRenderSnapshot>,
74
75 /// Transaction that the next configure should take part in, if any.
76 transaction_for_next_configure: Option<Transaction>,
77
78 /// Pending transactions that have not been added as blockers for this window yet.
79 pending_transactions: Vec<(Serial, Transaction)>,
80
81 /// State of an ongoing interactive resize.
82 interactive_resize: Option<InteractiveResize>,
83
84 /// Last time interactive resize was started.
85 ///
86 /// Used for double-resize-click tracking.
87 last_interactive_resize_start: Cell<Option<(Duration, ResizeEdge)>>,
88}
89
90niri_render_elements! {
91 WindowCastRenderElements<R> => {
92 Layout = LayoutElementRenderElement<R>,
93 // Blocked-out window with rounded corners.
94 Border = BorderRenderElement,
95 }
96}
97
98static MAPPED_ID_COUNTER: IdCounter = IdCounter::new();
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
101pub struct MappedId(u64);
102
103impl MappedId {
104 fn next() -> MappedId {
105 MappedId(MAPPED_ID_COUNTER.next())
106 }
107
108 pub fn get(self) -> u64 {
109 self.0
110 }
111}
112
113/// Interactive resize state.
114#[derive(Debug)]
115enum InteractiveResize {
116 /// The resize is ongoing.
117 Ongoing(InteractiveResizeData),
118 /// The resize has stopped and we're waiting to send the last configure.
119 WaitingForLastConfigure(InteractiveResizeData),
120 /// We had sent the last resize configure and are waiting for the corresponding commit.
121 WaitingForLastCommit {
122 data: InteractiveResizeData,
123 serial: Serial,
124 },
125}
126
127impl InteractiveResize {
128 fn data(&self) -> InteractiveResizeData {
129 match self {
130 InteractiveResize::Ongoing(data) => *data,
131 InteractiveResize::WaitingForLastConfigure(data) => *data,
132 InteractiveResize::WaitingForLastCommit { data, .. } => *data,
133 }
134 }
135}
136
137impl Mapped {
138 pub fn new(window: Window, rules: ResolvedWindowRules, hook: HookId) -> Self {
139 Self {
140 window,
141 id: MappedId::next(),
142 pre_commit_hook: hook,
143 rules,
144 need_to_recompute_rules: false,
145 is_focused: false,
146 is_active_in_column: false,
147 block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),
148 animate_next_configure: false,
149 animate_serials: Vec::new(),
150 animation_snapshot: None,
151 transaction_for_next_configure: None,
152 pending_transactions: Vec::new(),
153 interactive_resize: None,
154 last_interactive_resize_start: Cell::new(None),
155 }
156 }
157
158 pub fn toplevel(&self) -> &ToplevelSurface {
159 self.window.toplevel().expect("no X11 support")
160 }
161
162 /// Recomputes the resolved window rules and returns whether they changed.
163 pub fn recompute_window_rules(&mut self, rules: &[WindowRule], is_at_startup: bool) -> bool {
164 self.need_to_recompute_rules = false;
165
166 let new_rules = ResolvedWindowRules::compute(rules, WindowRef::Mapped(self), is_at_startup);
167 if new_rules == self.rules {
168 return false;
169 }
170
171 self.rules = new_rules;
172 true
173 }
174
175 pub fn recompute_window_rules_if_needed(
176 &mut self,
177 rules: &[WindowRule],
178 is_at_startup: bool,
179 ) -> bool {
180 if !self.need_to_recompute_rules {
181 return false;
182 }
183
184 self.recompute_window_rules(rules, is_at_startup)
185 }
186
187 pub fn id(&self) -> MappedId {
188 self.id
189 }
190
191 pub fn is_focused(&self) -> bool {
192 self.is_focused
193 }
194
195 pub fn is_active_in_column(&self) -> bool {
196 self.is_active_in_column
197 }
198
199 pub fn set_is_focused(&mut self, is_focused: bool) {
200 if self.is_focused == is_focused {
201 return;
202 }
203
204 self.is_focused = is_focused;
205 self.need_to_recompute_rules = true;
206 }
207
208 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {
209 let _span = tracy_client::span!("Mapped::render_snapshot");
210
211 let size = self.size().to_f64();
212
213 let mut buffer = self.block_out_buffer.borrow_mut();
214 buffer.resize(size);
215 let blocked_out_contents = vec![BakedBuffer {
216 buffer: buffer.clone(),
217 location: Point::from((0., 0.)),
218 src: None,
219 dst: None,
220 }];
221
222 let buf_pos = self.window.geometry().loc.upscale(-1).to_f64();
223
224 let mut contents = vec![];
225
226 let surface = self.toplevel().wl_surface();
227 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {
228 let offset = self.window.geometry().loc + popup_offset - popup.geometry().loc;
229
230 render_snapshot_from_surface_tree(
231 renderer,
232 popup.wl_surface(),
233 buf_pos + offset.to_f64(),
234 &mut contents,
235 );
236 }
237
238 render_snapshot_from_surface_tree(renderer, surface, buf_pos, &mut contents);
239
240 RenderSnapshot {
241 contents,
242 blocked_out_contents,
243 block_out_from: self.rules().block_out_from,
244 size,
245 texture: Default::default(),
246 blocked_out_texture: Default::default(),
247 }
248 }
249
250 pub fn should_animate_commit(&mut self, commit_serial: Serial) -> bool {
251 let mut should_animate = false;
252 self.animate_serials.retain_mut(|serial| {
253 if commit_serial.is_no_older_than(serial) {
254 should_animate = true;
255 false
256 } else {
257 true
258 }
259 });
260 should_animate
261 }
262
263 pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) {
264 self.animation_snapshot = Some(self.render_snapshot(renderer));
265 }
266
267 pub fn take_pending_transaction(&mut self, commit_serial: Serial) -> Option<Transaction> {
268 let mut rv = None;
269
270 // Pending transactions are appended in order by serial, so we can loop from the start
271 // until we hit a serial that is too new.
272 while let Some((serial, _)) = self.pending_transactions.first() {
273 // In this loop, we will complete the transaction corresponding to the commit, as well
274 // as all transactions corresponding to previous serials. This can happen when we
275 // request resizes too quickly, and the surface only responds to the last one.
276 //
277 // Note that in this case, completing the previous transactions can result in an
278 // inconsistent visual state, if another window is waiting for this window to assume a
279 // specific size (in a previous transaction), which is now different (in this commit).
280 //
281 // However, there isn't really a good way to deal with that. We cannot cancel any
282 // transactions because we need to keep sending frame callbacks, and cancelling a
283 // transaction will make the corresponding frame callbacks get lost, and the window
284 // will hang.
285 //
286 // This is why resize throttling (implemented separately) is important: it prevents
287 // visually inconsistent states by way of never having more than one transaction in
288 // flight.
289 if commit_serial.is_no_older_than(serial) {
290 let (_, transaction) = self.pending_transactions.remove(0);
291 // Previous transaction is dropped here, signaling completion.
292 rv = Some(transaction);
293 } else {
294 break;
295 }
296 }
297
298 rv
299 }
300
301 pub fn last_interactive_resize_start(&self) -> &Cell<Option<(Duration, ResizeEdge)>> {
302 &self.last_interactive_resize_start
303 }
304
305 pub fn render_for_screen_cast<R: NiriRenderer>(
306 &self,
307 renderer: &mut R,
308 scale: Scale<f64>,
309 ) -> impl DoubleEndedIterator<Item = WindowCastRenderElements<R>> {
310 let bbox = self.window.bbox_with_popups().to_physical_precise_up(scale);
311
312 let has_border_shader = BorderRenderElement::has_shader(renderer);
313 let rules = self.rules();
314 let radius = rules.geometry_corner_radius.unwrap_or_default();
315 let window_size = self
316 .size()
317 .to_f64()
318 .to_physical_precise_round(scale)
319 .to_logical(scale);
320 let radius = radius.fit_to(window_size.w as f32, window_size.h as f32);
321
322 let location = self.window.geometry().loc.to_f64() - bbox.loc.to_logical(scale);
323 let elements = self.render(renderer, location, scale, 1., RenderTarget::Screencast);
324
325 elements.into_iter().map(move |elem| {
326 if let LayoutElementRenderElement::SolidColor(elem) = &elem {
327 // In this branch we're rendering a blocked-out window with a solid color. We need
328 // to render it with a rounded corner shader even if clip_to_geometry is false,
329 // because in this case we're assuming that the unclipped window CSD already has
330 // corners rounded to the user-provided radius, so our blocked-out rendering should
331 // match that radius.
332 if radius != CornerRadius::default() && has_border_shader {
333 let geo = elem.geo();
334 return BorderRenderElement::new(
335 geo.size,
336 Rectangle::from_loc_and_size((0., 0.), geo.size),
337 GradientInterpolation::default(),
338 Color::from_color32f(elem.color()),
339 Color::from_color32f(elem.color()),
340 0.,
341 Rectangle::from_loc_and_size((0., 0.), geo.size),
342 0.,
343 radius,
344 scale.x as f32,
345 )
346 .with_location(geo.loc)
347 .into();
348 }
349 }
350
351 WindowCastRenderElements::from(elem)
352 })
353 }
354}
355
356impl Drop for Mapped {
357 fn drop(&mut self) {
358 remove_pre_commit_hook(self.toplevel().wl_surface(), self.pre_commit_hook);
359 }
360}
361
362impl LayoutElement for Mapped {
363 type Id = Window;
364
365 fn id(&self) -> &Self::Id {
366 &self.window
367 }
368
369 fn size(&self) -> Size<i32, Logical> {
370 self.window.geometry().size
371 }
372
373 fn buf_loc(&self) -> Point<i32, Logical> {
374 Point::from((0, 0)) - self.window.geometry().loc
375 }
376
377 fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool {
378 let surface_local = point + self.window.geometry().loc.to_f64();
379 self.window.is_in_input_region(&surface_local)
380 }
381
382 fn render<R: NiriRenderer>(
383 &self,
384 renderer: &mut R,
385 location: Point<f64, Logical>,
386 scale: Scale<f64>,
387 alpha: f32,
388 target: RenderTarget,
389 ) -> SplitElements<LayoutElementRenderElement<R>> {
390 let mut rv = SplitElements::default();
391
392 if target.should_block_out(self.rules.block_out_from) {
393 let mut buffer = self.block_out_buffer.borrow_mut();
394 buffer.resize(self.window.geometry().size.to_f64());
395 let elem =
396 SolidColorRenderElement::from_buffer(&buffer, location, alpha, Kind::Unspecified);
397 rv.normal.push(elem.into());
398 } else {
399 let buf_pos = location - self.window.geometry().loc.to_f64();
400
401 let surface = self.toplevel().wl_surface();
402 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {
403 let offset = self.window.geometry().loc + popup_offset - popup.geometry().loc;
404
405 rv.popups.extend(render_elements_from_surface_tree(
406 renderer,
407 popup.wl_surface(),
408 (buf_pos + offset.to_f64()).to_physical_precise_round(scale),
409 scale,
410 alpha,
411 Kind::Unspecified,
412 ));
413 }
414
415 rv.normal = render_elements_from_surface_tree(
416 renderer,
417 surface,
418 buf_pos.to_physical_precise_round(scale),
419 scale,
420 alpha,
421 Kind::Unspecified,
422 );
423 }
424
425 rv
426 }
427
428 fn render_normal<R: NiriRenderer>(
429 &self,
430 renderer: &mut R,
431 location: Point<f64, Logical>,
432 scale: Scale<f64>,
433 alpha: f32,
434 target: RenderTarget,
435 ) -> Vec<LayoutElementRenderElement<R>> {
436 if target.should_block_out(self.rules.block_out_from) {
437 let mut buffer = self.block_out_buffer.borrow_mut();
438 buffer.resize(self.window.geometry().size.to_f64());
439 let elem =
440 SolidColorRenderElement::from_buffer(&buffer, location, alpha, Kind::Unspecified);
441 vec![elem.into()]
442 } else {
443 let buf_pos = location - self.window.geometry().loc.to_f64();
444 let surface = self.toplevel().wl_surface();
445 render_elements_from_surface_tree(
446 renderer,
447 surface,
448 buf_pos.to_physical_precise_round(scale),
449 scale,
450 alpha,
451 Kind::Unspecified,
452 )
453 }
454 }
455
456 fn render_popups<R: NiriRenderer>(
457 &self,
458 renderer: &mut R,
459 location: Point<f64, Logical>,
460 scale: Scale<f64>,
461 alpha: f32,
462 target: RenderTarget,
463 ) -> Vec<LayoutElementRenderElement<R>> {
464 if target.should_block_out(self.rules.block_out_from) {
465 vec![]
466 } else {
467 let mut rv = vec![];
468
469 let buf_pos = location - self.window.geometry().loc.to_f64();
470 let surface = self.toplevel().wl_surface();
471 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {
472 let offset = self.window.geometry().loc + popup_offset - popup.geometry().loc;
473
474 rv.extend(render_elements_from_surface_tree(
475 renderer,
476 popup.wl_surface(),
477 (buf_pos + offset.to_f64()).to_physical_precise_round(scale),
478 scale,
479 alpha,
480 Kind::Unspecified,
481 ));
482 }
483
484 rv
485 }
486 }
487
488 fn request_size(
489 &mut self,
490 size: Size<i32, Logical>,
491 animate: bool,
492 transaction: Option<Transaction>,
493 ) {
494 let changed = self.toplevel().with_pending_state(|state| {
495 let changed = state.size != Some(size);
496 state.size = Some(size);
497 state.states.unset(xdg_toplevel::State::Fullscreen);
498 changed
499 });
500
501 if changed && animate {
502 self.animate_next_configure = true;
503 }
504
505 // Store the transaction regardless of whether the size changed. This is because with 3+
506 // windows in a column, the size may change among windows 1 and 2 and then right away among
507 // windows 2 and 3, and we want all windows 1, 2 and 3 to use the last transaction, rather
508 // than window 1 getting stuck with the previous transaction that is immediately released
509 // by 2.
510 if let Some(transaction) = transaction {
511 self.transaction_for_next_configure = Some(transaction);
512 }
513 }
514
515 fn request_fullscreen(&self, size: Size<i32, Logical>) {
516 self.toplevel().with_pending_state(|state| {
517 state.size = Some(size);
518 state.states.set(xdg_toplevel::State::Fullscreen);
519 });
520 }
521
522 fn min_size(&self) -> Size<i32, Logical> {
523 let mut size = with_states(self.toplevel().wl_surface(), |state| {
524 let mut guard = state.cached_state.get::<SurfaceCachedState>();
525 guard.current().min_size
526 });
527
528 if let Some(x) = self.rules.min_width {
529 size.w = max(size.w, i32::from(x));
530 }
531 if let Some(x) = self.rules.min_height {
532 size.h = max(size.h, i32::from(x));
533 }
534
535 size
536 }
537
538 fn max_size(&self) -> Size<i32, Logical> {
539 let mut size = with_states(self.toplevel().wl_surface(), |state| {
540 let mut guard = state.cached_state.get::<SurfaceCachedState>();
541 guard.current().max_size
542 });
543
544 if let Some(x) = self.rules.max_width {
545 if size.w == 0 {
546 size.w = i32::from(x);
547 } else if x > 0 {
548 size.w = min(size.w, i32::from(x));
549 }
550 }
551 if let Some(x) = self.rules.max_height {
552 if size.h == 0 {
553 size.h = i32::from(x);
554 } else if x > 0 {
555 size.h = min(size.h, i32::from(x));
556 }
557 }
558
559 size
560 }
561
562 fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool {
563 self.toplevel().wl_surface() == wl_surface
564 }
565
566 fn set_preferred_scale_transform(&self, scale: output::Scale, transform: Transform) {
567 self.window.with_surfaces(|surface, data| {
568 send_scale_transform(surface, data, scale, transform);
569 });
570 }
571
572 fn has_ssd(&self) -> bool {
573 let toplevel = self.toplevel();
574 let mode = toplevel.current_state().decoration_mode;
575
576 match mode {
577 Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) => true,
578 // Check KDE decorations when XDG are not in use.
579 None => with_states(toplevel.wl_surface(), |states| {
580 states
581 .data_map
582 .get::<KdeDecorationsModeState>()
583 .map(KdeDecorationsModeState::is_server)
584 == Some(true)
585 }),
586 _ => false,
587 }
588 }
589
590 fn output_enter(&self, output: &Output) {
591 let overlap = Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX));
592 self.window.output_enter(output, overlap)
593 }
594
595 fn output_leave(&self, output: &Output) {
596 self.window.output_leave(output)
597 }
598
599 fn set_offscreen_element_id(&self, id: Option<Id>) {
600 let data = self
601 .window
602 .user_data()
603 .get_or_insert(WindowOffscreenId::default);
604 data.0.replace(id);
605 }
606
607 fn set_activated(&mut self, active: bool) {
608 let changed = self.toplevel().with_pending_state(|state| {
609 if active {
610 state.states.set(xdg_toplevel::State::Activated)
611 } else {
612 state.states.unset(xdg_toplevel::State::Activated)
613 }
614 });
615 self.need_to_recompute_rules |= changed;
616 }
617
618 fn set_active_in_column(&mut self, active: bool) {
619 let changed = self.is_active_in_column != active;
620 self.is_active_in_column = active;
621 self.need_to_recompute_rules |= changed;
622 }
623
624 fn set_bounds(&self, bounds: Size<i32, Logical>) {
625 self.toplevel().with_pending_state(|state| {
626 state.bounds = Some(bounds);
627 });
628 }
629
630 fn configure_intent(&self) -> ConfigureIntent {
631 let _span =
632 trace_span!("configure_intent", surface = ?self.toplevel().wl_surface().id()).entered();
633
634 with_states(self.toplevel().wl_surface(), |states| {
635 let attributes = states
636 .data_map
637 .get::<XdgToplevelSurfaceData>()
638 .unwrap()
639 .lock()
640 .unwrap();
641
642 if let Some(server_pending) = &attributes.server_pending {
643 let current_server = attributes.current_server_state();
644 if server_pending != current_server {
645 // Something changed. Check if the only difference is the size, and if the
646 // current server size matches the current committed size.
647 let mut current_server_same_size = current_server.clone();
648 current_server_same_size.size = server_pending.size;
649 if current_server_same_size == *server_pending {
650 // Only the size changed. Check if the window committed our previous size
651 // request.
652 if attributes.current.size == current_server.size {
653 // The window had committed for our previous size change, so we can
654 // change the size again.
655 trace!(
656 "current size matches server size: {:?}",
657 attributes.current.size
658 );
659 ConfigureIntent::CanSend
660 } else {
661 // The window had not committed for our previous size change yet. Since
662 // nothing else changed, do not send the new size request yet. This
663 // throttling is done because some clients do not batch size requests,
664 // leading to bad behavior with very fast input devices (i.e. a 1000 Hz
665 // mouse). This throttling also helps interactive resize transactions
666 // preserve visual consistency.
667 trace!("throttling resize");
668 ConfigureIntent::Throttled
669 }
670 } else {
671 // Something else changed other than the size; send it.
672 trace!("something changed other than the size");
673 ConfigureIntent::ShouldSend
674 }
675 } else {
676 // Nothing changed since the last configure.
677 ConfigureIntent::NotNeeded
678 }
679 } else {
680 // Nothing changed since the last configure.
681 ConfigureIntent::NotNeeded
682 }
683 })
684 }
685
686 fn send_pending_configure(&mut self) {
687 let _span =
688 trace_span!("send_pending_configure", surface = ?self.toplevel().wl_surface().id())
689 .entered();
690
691 if let Some(serial) = self.toplevel().send_pending_configure() {
692 trace!(?serial, "sending configure");
693
694 if self.animate_next_configure {
695 self.animate_serials.push(serial);
696 }
697
698 if let Some(transaction) = self.transaction_for_next_configure.take() {
699 self.pending_transactions.push((serial, transaction));
700 }
701
702 self.interactive_resize = match self.interactive_resize.take() {
703 Some(InteractiveResize::WaitingForLastConfigure(data)) => {
704 Some(InteractiveResize::WaitingForLastCommit { data, serial })
705 }
706 x => x,
707 }
708 } else {
709 self.interactive_resize = match self.interactive_resize.take() {
710 // We probably started and stopped resizing in the same loop cycle without anything
711 // changing.
712 Some(InteractiveResize::WaitingForLastConfigure { .. }) => None,
713 x => x,
714 }
715 }
716
717 self.animate_next_configure = false;
718 self.transaction_for_next_configure = None;
719 }
720
721 fn is_fullscreen(&self) -> bool {
722 self.toplevel()
723 .current_state()
724 .states
725 .contains(xdg_toplevel::State::Fullscreen)
726 }
727
728 fn is_pending_fullscreen(&self) -> bool {
729 self.toplevel()
730 .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))
731 }
732
733 fn refresh(&self) {
734 self.window.refresh();
735 }
736
737 fn rules(&self) -> &ResolvedWindowRules {
738 &self.rules
739 }
740
741 fn animation_snapshot(&self) -> Option<&LayoutElementRenderSnapshot> {
742 self.animation_snapshot.as_ref()
743 }
744
745 fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> {
746 self.animation_snapshot.take()
747 }
748
749 fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>) {
750 self.toplevel().with_pending_state(|state| {
751 if data.is_some() {
752 state.states.set(xdg_toplevel::State::Resizing);
753 } else {
754 state.states.unset(xdg_toplevel::State::Resizing);
755 }
756 });
757
758 if let Some(data) = data {
759 self.interactive_resize = Some(InteractiveResize::Ongoing(data));
760 } else {
761 self.interactive_resize = match self.interactive_resize.take() {
762 Some(InteractiveResize::Ongoing(data)) => {
763 Some(InteractiveResize::WaitingForLastConfigure(data))
764 }
765 x => x,
766 }
767 }
768 }
769
770 fn cancel_interactive_resize(&mut self) {
771 self.set_interactive_resize(None);
772 self.interactive_resize = None;
773 }
774
775 fn update_interactive_resize(&mut self, commit_serial: Serial) {
776 if let Some(InteractiveResize::WaitingForLastCommit { serial, .. }) =
777 &self.interactive_resize
778 {
779 if commit_serial.is_no_older_than(serial) {
780 self.interactive_resize = None;
781 }
782 }
783 }
784
785 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
786 Some(self.interactive_resize.as_ref()?.data())
787 }
788}