forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

mapped.rs1435 lines, 53.4 KiBHistoryRawDownload
1use std::cell::{Cell, Ref, RefCell};
2use std::time::Duration;
3
4use niri_config::{Color, Config, CornerRadius, GradientInterpolation, WindowRule};
5use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
6use smithay::backend::renderer::element::Kind;
7use smithay::backend::renderer::gles::GlesRenderer;
8use smithay::desktop::space::SpaceElement as _;
9use smithay::desktop::{PopupKind, PopupManager, Window};
10use smithay::output::{self, Output};
11use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
12use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
13use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
14use smithay::reexports::wayland_server::Resource as _;
15use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
16use smithay::wayland::compositor::{remove_pre_commit_hook, with_states, HookId, SurfaceData};
17use smithay::wayland::seat::WaylandFocus;
18use smithay::wayland::shell::xdg::{
19 SurfaceCachedState, ToplevelCachedState, ToplevelConfigure, ToplevelSurface,
20 XdgToplevelSurfaceData,
21};
22use wayland_backend::server::Credentials;
23
24use super::{ResolvedWindowRules, WindowRef};
25use crate::handlers::KdeDecorationsModeState;
26use crate::layout::{
27 ConfigureIntent, InteractiveResizeData, LayoutElement, LayoutElementRenderElement,
28 LayoutElementRenderSnapshot, SizingMode,
29};
30use crate::niri_render_elements;
31use crate::render_helpers::background_effect::BackgroundEffectElement;
32use crate::render_helpers::border::BorderRenderElement;
33use crate::render_helpers::offscreen::OffscreenData;
34use crate::render_helpers::renderer::NiriRenderer;
35use crate::render_helpers::snapshot::RenderSnapshot;
36use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
37use crate::render_helpers::surface::{
38 push_elements_from_surface_tree, render_snapshot_from_surface_tree,
39};
40use crate::render_helpers::xray::XrayPos;
41use crate::render_helpers::{background_effect, BakedBuffer, RenderCtx, RenderTarget};
42use crate::utils::id::IdCounter;
43use crate::utils::transaction::Transaction;
44use crate::utils::{
45 get_credentials_for_surface, send_scale_transform, update_tiled_state,
46 with_toplevel_last_uncommitted_configure, with_toplevel_role, with_toplevel_role_and_current,
47 ResizeEdge,
48};
49
50#[derive(Debug)]
51pub struct Mapped {
52 pub window: Window,
53
54 /// Unique ID of this `Mapped`.
55 id: MappedId,
56
57 /// Credentials of the process that created the Wayland connection.
58 credentials: Option<Credentials>,
59
60 /// Pre-commit hook that we have on all mapped toplevel surfaces.
61 pre_commit_hook: HookId,
62
63 /// Up-to-date rules.
64 rules: ResolvedWindowRules,
65
66 /// Whether the window rules need to be recomputed.
67 ///
68 /// This is not used in all cases; for example, app ID and title changes recompute the rules
69 /// immediately, rather than setting this flag.
70 need_to_recompute_rules: bool,
71
72 /// Whether this window needs a configure this loop cycle.
73 ///
74 /// Certain Wayland requests require a configure in response, like un/fullscreen.
75 needs_configure: bool,
76
77 /// Whether this window needs a frame callback.
78 ///
79 /// We set this after sending a configure to give invisible windows a chance to respond to
80 /// resizes immediately, without waiting for a 1 second throttled callback.
81 needs_frame_callback: bool,
82
83 /// Data of the offscreen element rendered in place of this window.
84 ///
85 /// If `None`, then the window is not offscreened.
86 offscreen_data: RefCell<Option<OffscreenData>>,
87
88 /// Whether this has an urgent indicator.
89 is_urgent: bool,
90
91 /// Whether this window has the keyboard focus.
92 is_focused: bool,
93
94 /// Whether this window is the active window in its column.
95 is_active_in_column: bool,
96
97 /// Whether this window is floating.
98 is_floating: bool,
99
100 /// Whether this window is a target of a window cast.
101 is_window_cast_target: bool,
102
103 /// Whether this window should ignore opacity set through window rules.
104 ignore_opacity_window_rule: bool,
105
106 /// Buffer to draw instead of the window when it should be blocked out.
107 block_out_buffer: RefCell<SolidColorBuffer>,
108
109 /// The blur config, passed for background effect rendering.
110 blur_config: niri_config::Blur,
111
112 /// Whether the next configure should be animated, if the configured state changed.
113 animate_next_configure: bool,
114
115 /// Serials of commits that should be animated.
116 animate_serials: Vec<Serial>,
117
118 /// Snapshot right before an animated commit, without popups.
119 animation_snapshot: Option<LayoutElementRenderSnapshot>,
120
121 /// State for the logic to request a size once (for floating windows).
122 request_size_once: Option<RequestSizeOnce>,
123
124 /// Transaction that the next configure should take part in, if any.
125 transaction_for_next_configure: Option<Transaction>,
126
127 /// Pending transactions that have not been added as blockers for this window yet.
128 pending_transactions: Vec<(Serial, Transaction)>,
129
130 /// State of an ongoing interactive resize.
131 interactive_resize: Option<InteractiveResize>,
132
133 /// Last time interactive resize was started.
134 ///
135 /// Used for double-resize-click tracking.
136 last_interactive_resize_start: Cell<Option<(Duration, ResizeEdge)>>,
137
138 /// Whether this window is in windowed (fake) fullscreen.
139 ///
140 /// In this mode, the underlying window is told that it's fullscreen, while keeping it as
141 /// a regular, non-fullscreen tile.
142 is_windowed_fullscreen: bool,
143
144 /// Whether this window is pending to go to windowed (fake) fullscreen.
145 ///
146 /// Several places in the layout code assume that is_fullscreen() can flip only on a commit.
147 /// Which is something that we do want to flip when changing is_windowed_fullscreen. Flipping
148 /// it right away would mean remembering to call layout.update_window() after any operation
149 /// that may change is_windowed_fullscreen, which is quite tricky and error-prone, especially
150 /// for deeply nested operations.
151 ///
152 /// It's also not clear what's the best way to go about it. Ideally we'd wait for configure ack
153 /// and commit before "committing" to is_windowed_fullscreen, however, since it's not real
154 /// Wayland state, we may end up with no Wayland state change to configure at all.
155 ///
156 /// For example: when the window is in real fullscreen, but its non-fullscreen size matches
157 /// its fullscreen size. Then turning on is_windowed_fullscreen will both keep the
158 /// fullscreen state, and keep the size (since it matches), resulting in no configure.
159 ///
160 /// So we work around this by emulating a configure-ack/commit cycle through
161 /// is_pending_windowed_fullscreen and uncommitted_windowed_fullscreen. We ensure we send
162 /// actual configures in all cases through needs_configure. This can result in unnecessary
163 /// configures (like in the example above), but in most cases there will be a configure
164 /// anyway to change the Fullscreen state and/or the size. What this gives us is being able
165 /// to synchronize our windowed fullscreen state to the real window updates to avoid any
166 /// flickering.
167 is_pending_windowed_fullscreen: bool,
168
169 /// Pending windowed fullscreen updates.
170 ///
171 /// These have been "sent" to the window in form of configures, but the window hadn't committed
172 /// in response yet.
173 uncommitted_windowed_fullscreen: Vec<(Serial, bool)>,
174
175 /// Whether this window is maximized.
176 ///
177 /// We have to track this ourselves in addition to the Maximized toplevel state in order to
178 /// support windowed fullscreen, since in windowed fullscreen the toplevel state is always
179 /// Fullscreen. So we need this variable to be able to report accurate sizing mode and pending
180 /// sizing mode.
181 is_maximized: bool,
182
183 /// Whether this window is pending to be maximized.
184 ///
185 /// We have to track this ourselves due to windowed fullscreen.
186 is_pending_maximized: bool,
187
188 /// Pending maximized updates.
189 ///
190 /// These have been "sent" to the window in form of configures, but the window hadn't committed
191 /// in response yet.
192 uncommitted_maximized: Vec<(Serial, bool)>,
193
194 /// Most recent monotonic time when the window had the focus.
195 focus_timestamp: Option<Duration>,
196}
197
198niri_render_elements! {
199 WindowCastRenderElements<R> => {
200 Layout = LayoutElementRenderElement<R>,
201 // Blocked-out window with rounded corners.
202 Border = BorderRenderElement,
203 }
204}
205
206static MAPPED_ID_COUNTER: IdCounter = IdCounter::new();
207
208#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
209pub struct MappedId(u64);
210
211impl MappedId {
212 pub fn next() -> MappedId {
213 MappedId(MAPPED_ID_COUNTER.next())
214 }
215
216 pub fn get(self) -> u64 {
217 self.0
218 }
219
220 /// Converts the ID to a string that can be used as an identifier in
221 /// ext_foreign_toplevel_handle_v1::identifier
222 ///
223 /// > An identifier is a string that contains up to 32 printable ASCII bytes.
224 /// > An identifier must not be an empty string.
225 ///
226 /// Since the ID is exposed to IPC, it's useful for this conversion to be stable and reversible.
227 /// That way, clients can associate a foreign toplevel handle with an IPC window ID.
228 ///
229 /// We use the decimal representation of the ID, which is up to 20 characters long for u64::MAX.
230 /// This is within the 32-character limit, and is nice because it matches up with how `niri msg`
231 /// prints the IDs to the console.
232 ///
233 /// This namespace can be extended in the future, with any non-numeric prefix to disambiguate.
234 pub fn to_protocol_identifier(self) -> String {
235 format!("{}", self.0)
236 }
237}
238
239/// Interactive resize state.
240#[derive(Debug)]
241enum InteractiveResize {
242 /// The resize is ongoing.
243 Ongoing(InteractiveResizeData),
244 /// The resize has stopped and we're waiting to send the last configure.
245 WaitingForLastConfigure(InteractiveResizeData),
246 /// We had sent the last resize configure and are waiting for the corresponding commit.
247 WaitingForLastCommit {
248 data: InteractiveResizeData,
249 serial: Serial,
250 },
251}
252
253impl InteractiveResize {
254 fn data(&self) -> InteractiveResizeData {
255 match self {
256 InteractiveResize::Ongoing(data) => *data,
257 InteractiveResize::WaitingForLastConfigure(data) => *data,
258 InteractiveResize::WaitingForLastCommit { data, .. } => *data,
259 }
260 }
261}
262
263/// Request-size-once logic state.
264#[derive(Debug, Clone, Copy)]
265enum RequestSizeOnce {
266 /// Waiting for configure to be sent with the requested size.
267 WaitingForConfigure,
268 /// Waiting for the window to commit in response to the configure.
269 WaitingForCommit(Serial),
270 /// When configuring, use the current window size.
271 UseWindowSize,
272}
273
274impl Mapped {
275 pub fn new(window: Window, rules: ResolvedWindowRules, hook: HookId, config: &Config) -> Self {
276 let surface = window.wl_surface().expect("no X11 support");
277 let credentials = get_credentials_for_surface(&surface);
278 let mut rv = Self {
279 window,
280 id: MappedId::next(),
281 credentials,
282 pre_commit_hook: hook,
283 rules,
284 need_to_recompute_rules: false,
285 needs_configure: false,
286 needs_frame_callback: false,
287 offscreen_data: RefCell::new(None),
288 is_urgent: false,
289 is_focused: false,
290 is_active_in_column: true,
291 is_floating: false,
292 is_window_cast_target: false,
293 ignore_opacity_window_rule: false,
294 block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),
295 blur_config: config.blur,
296 animate_next_configure: false,
297 animate_serials: Vec::new(),
298 animation_snapshot: None,
299 request_size_once: None,
300 transaction_for_next_configure: None,
301 pending_transactions: Vec::new(),
302 interactive_resize: None,
303 last_interactive_resize_start: Cell::new(None),
304 is_windowed_fullscreen: false,
305 is_pending_windowed_fullscreen: false,
306 uncommitted_windowed_fullscreen: Vec::new(),
307 is_maximized: false,
308 is_pending_maximized: false,
309 uncommitted_maximized: Vec::new(),
310 focus_timestamp: None,
311 };
312
313 rv.is_maximized = rv.sizing_mode().is_maximized();
314 rv.is_pending_maximized = rv.pending_sizing_mode().is_maximized();
315
316 rv
317 }
318
319 pub fn toplevel(&self) -> &ToplevelSurface {
320 self.window.toplevel().expect("no X11 support")
321 }
322
323 /// Recomputes the resolved window rules and returns whether they changed.
324 pub fn recompute_window_rules(&mut self, rules: &[WindowRule], is_at_startup: bool) -> bool {
325 self.need_to_recompute_rules = false;
326
327 let new_rules = ResolvedWindowRules::compute(rules, WindowRef::Mapped(self), is_at_startup);
328 if new_rules == self.rules {
329 return false;
330 }
331
332 // If the opacity window rule no longer makes the window semitransparent, reset the ignore
333 // flag to reduce surprises down the line.
334 if !new_rules.opacity.is_some_and(|o| o < 1.) {
335 self.ignore_opacity_window_rule = false;
336 }
337
338 self.rules = new_rules;
339 true
340 }
341
342 pub fn recompute_window_rules_if_needed(
343 &mut self,
344 rules: &[WindowRule],
345 is_at_startup: bool,
346 ) -> bool {
347 if !self.need_to_recompute_rules {
348 return false;
349 }
350
351 self.recompute_window_rules(rules, is_at_startup)
352 }
353
354 pub fn set_needs_configure(&mut self) {
355 self.needs_configure = true;
356 }
357
358 pub fn id(&self) -> MappedId {
359 self.id
360 }
361
362 pub fn credentials(&self) -> Option<&Credentials> {
363 self.credentials.as_ref()
364 }
365
366 pub fn offscreen_data(&self) -> Ref<'_, Option<OffscreenData>> {
367 self.offscreen_data.borrow()
368 }
369
370 pub fn is_focused(&self) -> bool {
371 self.is_focused
372 }
373
374 pub fn is_active_in_column(&self) -> bool {
375 self.is_active_in_column
376 }
377
378 pub fn is_floating(&self) -> bool {
379 self.is_floating
380 }
381
382 pub fn is_window_cast_target(&self) -> bool {
383 self.is_window_cast_target
384 }
385
386 pub fn toggle_ignore_opacity_window_rule(&mut self) {
387 self.ignore_opacity_window_rule = !self.ignore_opacity_window_rule;
388 }
389
390 pub fn set_is_focused(&mut self, is_focused: bool) {
391 if self.is_focused == is_focused {
392 return;
393 }
394
395 self.is_focused = is_focused;
396 self.is_urgent = false;
397 self.need_to_recompute_rules = true;
398 }
399
400 pub fn set_is_window_cast_target(&mut self, value: bool) {
401 if self.is_window_cast_target == value {
402 return;
403 }
404
405 self.is_window_cast_target = value;
406 self.need_to_recompute_rules = true;
407 }
408
409 /// Renders a snapshot of the window without popups.
410 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {
411 let _span = tracy_client::span!("Mapped::render_snapshot");
412
413 let size = self.size().to_f64();
414
415 let mut buffer = self.block_out_buffer.borrow_mut();
416 buffer.resize(size);
417 let blocked_out_contents = vec![BakedBuffer {
418 buffer: buffer.clone(),
419 location: Point::from((0., 0.)),
420 src: None,
421 dst: None,
422 }];
423
424 let buf_pos = self.window.geometry().loc.upscale(-1).to_f64();
425
426 let mut contents = vec![];
427
428 let surface = self.toplevel().wl_surface();
429 render_snapshot_from_surface_tree(renderer, surface, buf_pos, &mut contents);
430
431 RenderSnapshot {
432 contents,
433 contents_with_blocked_out_bg: None,
434 blocked_out_contents,
435 block_out_from: self.rules().block_out_from,
436 size,
437 texture: Default::default(),
438 texture_with_blocked_out_bg: Default::default(),
439 blocked_out_texture: Default::default(),
440 }
441 }
442
443 pub fn should_animate_commit(&mut self, commit_serial: Serial) -> bool {
444 let mut should_animate = false;
445 self.animate_serials.retain_mut(|serial| {
446 if commit_serial.is_no_older_than(serial) {
447 should_animate = true;
448 false
449 } else {
450 true
451 }
452 });
453 should_animate
454 }
455
456 pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) {
457 self.animation_snapshot = Some(self.render_snapshot(renderer));
458 }
459
460 pub fn take_pending_transaction(&mut self, commit_serial: Serial) -> Option<Transaction> {
461 let mut rv = None;
462
463 // Pending transactions are appended in order by serial, so we can loop from the start
464 // until we hit a serial that is too new.
465 while let Some((serial, _)) = self.pending_transactions.first() {
466 // In this loop, we will complete the transaction corresponding to the commit, as well
467 // as all transactions corresponding to previous serials. This can happen when we
468 // request resizes too quickly, and the surface only responds to the last one.
469 //
470 // Note that in this case, completing the previous transactions can result in an
471 // inconsistent visual state, if another window is waiting for this window to assume a
472 // specific size (in a previous transaction), which is now different (in this commit).
473 //
474 // However, there isn't really a good way to deal with that. We cannot cancel any
475 // transactions because we need to keep sending frame callbacks, and cancelling a
476 // transaction will make the corresponding frame callbacks get lost, and the window
477 // will hang.
478 //
479 // This is why resize throttling (implemented separately) is important: it prevents
480 // visually inconsistent states by way of never having more than one transaction in
481 // flight.
482 if commit_serial.is_no_older_than(serial) {
483 let (_, transaction) = self.pending_transactions.remove(0);
484 // Previous transaction is dropped here, signaling completion.
485 rv = Some(transaction);
486 } else {
487 break;
488 }
489 }
490
491 rv
492 }
493
494 pub fn last_interactive_resize_start(&self) -> &Cell<Option<(Duration, ResizeEdge)>> {
495 &self.last_interactive_resize_start
496 }
497
498 pub fn render_for_screen_cast<R: NiriRenderer>(
499 &self,
500 renderer: &mut R,
501 scale: Scale<f64>,
502 push: &mut dyn FnMut(WindowCastRenderElements<R>),
503 ) {
504 let bbox = self.window.bbox_with_popups().to_physical_precise_up(scale);
505
506 let has_border_shader = BorderRenderElement::has_shader(renderer);
507 let radius = self.geometry_corner_radius();
508 let window_size = self
509 .size()
510 .to_f64()
511 .to_physical_precise_round(scale)
512 .to_logical(scale);
513 let radius = radius.fit_to(window_size.w as f32, window_size.h as f32);
514 let location = self.window.geometry().loc.to_f64() - bbox.loc.to_logical(scale);
515
516 let use_border = |elem| {
517 if let LayoutElementRenderElement::SolidColor(elem) = &elem {
518 // In this branch we're rendering a blocked-out window with a solid color. We need
519 // to render it with a rounded corner shader even if clip_to_geometry is false,
520 // because in this case we're assuming that the unclipped window CSD already has
521 // corners rounded to the user-provided radius, so our blocked-out rendering should
522 // match that radius.
523 if radius != CornerRadius::default() && has_border_shader {
524 let geo = elem.geo();
525 return BorderRenderElement::new(
526 geo.size,
527 Rectangle::from_size(geo.size),
528 GradientInterpolation::default(),
529 Color::from_color32f(elem.color()),
530 Color::from_color32f(elem.color()),
531 0.,
532 Rectangle::from_size(geo.size),
533 0.,
534 radius,
535 scale.x as f32,
536 1.,
537 )
538 .with_location(geo.loc)
539 .into();
540 }
541 }
542
543 WindowCastRenderElements::from(elem)
544 };
545
546 self.render(
547 RenderCtx {
548 renderer,
549 target: RenderTarget::Screencast,
550 xray: None,
551 },
552 location,
553 scale,
554 1.,
555 XrayPos::default(),
556 &mut |elem| push(use_border(elem)),
557 );
558 }
559
560 pub fn get_focus_timestamp(&self) -> Option<Duration> {
561 self.focus_timestamp
562 }
563
564 pub fn set_focus_timestamp(&mut self, timestamp: Duration) {
565 self.focus_timestamp.replace(timestamp);
566 }
567
568 pub fn send_frame<T, F>(
569 &mut self,
570 output: &Output,
571 time: T,
572 throttle: Option<Duration>,
573 mut primary_scan_out_output: F,
574 ) where
575 T: Into<Duration>,
576 F: FnMut(&WlSurface, &SurfaceData) -> Option<Output> + Copy,
577 {
578 let needs_frame_callback = self.needs_frame_callback;
579 self.needs_frame_callback = false;
580
581 let should_send = move |surface: &WlSurface, states: &SurfaceData| {
582 // Let primary_scan_out_output() run its logic and update internal state.
583 if let Some(output) = primary_scan_out_output(surface, states) {
584 return Some(output);
585 }
586
587 // Send unconditionally to all surfaces if the window needs a surface callback.
588 needs_frame_callback.then(|| output.clone())
589 };
590 self.window.send_frame(output, time, throttle, should_send);
591 }
592
593 pub fn update_tiled_state(&self, prefer_no_csd: bool) {
594 update_tiled_state(self.toplevel(), prefer_no_csd, self.rules.tiled_state);
595 }
596
597 pub fn is_windowed_fullscreen(&self) -> bool {
598 self.is_windowed_fullscreen
599 }
600
601 pub fn set_urgent(&mut self, urgent: bool) {
602 if self.is_focused && urgent {
603 return;
604 }
605
606 let changed = self.is_urgent != urgent;
607 self.is_urgent = urgent;
608 self.need_to_recompute_rules |= changed;
609 }
610
611 pub fn is_urgent(&self) -> bool {
612 self.is_urgent
613 }
614}
615
616impl Drop for Mapped {
617 fn drop(&mut self) {
618 remove_pre_commit_hook(self.toplevel().wl_surface(), &self.pre_commit_hook);
619 }
620}
621
622impl LayoutElement for Mapped {
623 type Id = Window;
624
625 fn id(&self) -> &Self::Id {
626 &self.window
627 }
628
629 fn update_config(&mut self, blur_config: niri_config::Blur) {
630 self.blur_config = blur_config;
631 }
632
633 fn size(&self) -> Size<i32, Logical> {
634 self.window.geometry().size
635 }
636
637 fn buf_loc(&self) -> Point<i32, Logical> {
638 Point::from((0, 0)) - self.window.geometry().loc
639 }
640
641 fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool {
642 let surface_local = point + self.window.geometry().loc.to_f64();
643 self.window.is_in_input_region(&surface_local)
644 }
645
646 fn render_normal<R: NiriRenderer>(
647 &self,
648 ctx: RenderCtx<R>,
649 location: Point<f64, Logical>,
650 scale: Scale<f64>,
651 alpha: f32,
652 push: &mut dyn FnMut(LayoutElementRenderElement<R>),
653 ) {
654 if ctx.target.should_block_out(self.rules.block_out_from) {
655 let mut buffer = self.block_out_buffer.borrow_mut();
656 buffer.resize(self.window.geometry().size.to_f64());
657 let elem =
658 SolidColorRenderElement::from_buffer(&buffer, location, alpha, Kind::Unspecified);
659 push(elem.into());
660 } else {
661 let buf_pos = location - self.window.geometry().loc.to_f64();
662 let surface = self.toplevel().wl_surface();
663 let mut push = |elem: WaylandSurfaceRenderElement<R>| push(elem.into());
664 push_elements_from_surface_tree(
665 ctx.renderer,
666 surface,
667 buf_pos.to_physical_precise_round(scale),
668 scale,
669 alpha,
670 Kind::ScanoutCandidate,
671 &mut push,
672 )
673 }
674 }
675
676 fn render_popups<R: NiriRenderer>(
677 &self,
678 mut ctx: RenderCtx<R>,
679 location: Point<f64, Logical>,
680 scale: Scale<f64>,
681 alpha: f32,
682 xray_pos: XrayPos,
683 push: &mut dyn FnMut(LayoutElementRenderElement<R>),
684 ) {
685 if ctx.target.should_block_out(self.rules.block_out_from) {
686 return;
687 }
688
689 let surface = self.toplevel().wl_surface();
690 for (popup, offset) in PopupManager::popups_for_surface(surface) {
691 let popup_rules = match popup {
692 PopupKind::Xdg(_) => self.rules.popups,
693 // IME popups aren't affected by rules for regular popups.
694 PopupKind::InputMethod(_) => niri_config::ResolvedPopupsRules::default(),
695 };
696 let alpha = match popup {
697 PopupKind::Xdg(_) => alpha * popup_rules.opacity.unwrap_or(1.).clamp(0., 1.),
698 // IME popups aren't affected by the window opacity.
699 PopupKind::InputMethod(_) => 1.,
700 };
701
702 let surface = popup.wl_surface();
703 let popup_geo = popup.geometry();
704 let surface_loc = location + (offset - popup.geometry().loc).to_f64();
705
706 push_elements_from_surface_tree(
707 ctx.renderer,
708 surface,
709 surface_loc.to_physical_precise_round(scale),
710 scale,
711 alpha,
712 Kind::ScanoutCandidate,
713 &mut |elem| push(elem.into()),
714 );
715
716 let geometry = Rectangle::new(location + offset.to_f64(), popup_geo.size.to_f64());
717 let surface_off = popup_geo.loc.upscale(-1).to_f64();
718 let surface_anim_scale = Scale::from(1.);
719 let mut effect = popup_rules.background_effect;
720 // Default xray to false for pop-ups since they're always on top of something.
721 if effect.xray.is_none() {
722 effect.xray = Some(false);
723 }
724 let xray_pos = xray_pos.offset(offset.to_f64());
725 background_effect::render_for_tile(
726 ctx.as_gles(),
727 None,
728 geometry,
729 scale.x,
730 false,
731 surface,
732 surface_off,
733 surface_anim_scale,
734 self.blur_config,
735 popup_rules.geometry_corner_radius.unwrap_or_default(),
736 effect,
737 false,
738 xray_pos,
739 &mut |elem| push(elem.into()),
740 );
741 }
742 }
743
744 fn render_background_effect(
745 &self,
746 ctx: RenderCtx<GlesRenderer>,
747 geometry: Rectangle<f64, Logical>,
748 scale: f64,
749 clip_to_geometry: bool,
750 surface_anim_scale: Scale<f64>,
751 radius: CornerRadius,
752 xray_pos: XrayPos,
753 push: &mut dyn FnMut(BackgroundEffectElement),
754 ) {
755 let should_block_out = ctx.target.should_block_out(self.rules.block_out_from);
756 background_effect::render_for_tile(
757 ctx,
758 None,
759 geometry,
760 scale,
761 clip_to_geometry,
762 self.toplevel().wl_surface(),
763 self.buf_loc().to_f64(),
764 surface_anim_scale,
765 self.blur_config,
766 radius,
767 self.rules.background_effect,
768 should_block_out,
769 xray_pos,
770 push,
771 );
772 }
773
774 fn request_size(
775 &mut self,
776 size: Size<i32, Logical>,
777 mode: SizingMode,
778 animate: bool,
779 transaction: Option<Transaction>,
780 ) {
781 // Going into real fullscreen resets windowed fullscreen.
782 if mode == SizingMode::Fullscreen {
783 self.is_pending_windowed_fullscreen = false;
784
785 if self.is_windowed_fullscreen {
786 // Make sure we receive a commit to update self.is_windowed_fullscreen to false
787 // later on.
788 self.needs_configure = true;
789 }
790 }
791
792 self.is_pending_maximized = mode == SizingMode::Maximized;
793 if self.is_maximized != self.is_pending_maximized {
794 // Make sure we receive a commit to update self.is_maximized later on.
795 self.needs_configure = true;
796 }
797
798 let changed = self.toplevel().with_pending_state(|state| {
799 let changed = state.size != Some(size);
800 state.size = Some(size);
801
802 if mode.is_fullscreen() || self.is_pending_windowed_fullscreen {
803 state.states.set(xdg_toplevel::State::Fullscreen);
804 state.states.unset(xdg_toplevel::State::Maximized);
805 } else if mode.is_maximized() {
806 state.states.unset(xdg_toplevel::State::Fullscreen);
807 state.states.set(xdg_toplevel::State::Maximized);
808 } else {
809 state.states.unset(xdg_toplevel::State::Fullscreen);
810 state.states.unset(xdg_toplevel::State::Maximized);
811 }
812
813 changed
814 });
815
816 if changed && animate {
817 self.animate_next_configure = true;
818 }
819
820 self.request_size_once = None;
821
822 // Store the transaction regardless of whether the size changed. This is because with 3+
823 // windows in a column, the size may change among windows 1 and 2 and then right away among
824 // windows 2 and 3, and we want all windows 1, 2 and 3 to use the last transaction, rather
825 // than window 1 getting stuck with the previous transaction that is immediately released
826 // by 2.
827 if let Some(transaction) = transaction {
828 self.transaction_for_next_configure = Some(transaction);
829 }
830 }
831
832 fn request_size_once(&mut self, size: Size<i32, Logical>, animate: bool) {
833 // Assume that when calling this function, the window is going floating, so it can no
834 // longer participate in any transactions with other windows.
835 self.transaction_for_next_configure = None;
836
837 self.is_pending_maximized = false;
838 if self.is_maximized != self.is_pending_maximized {
839 // Make sure we receive a commit to update self.is_maximized later on.
840 self.needs_configure = true;
841 }
842
843 // If our last requested size already matches the size we want to request-once, clear the
844 // size request right away. However, we must also check if we're unfullscreening, because
845 // in that case the window itself will restore its previous size upon receiving a (0, 0)
846 // configure, whereas what we potentially want is to unfullscreen the window into its
847 // fullscreen size.
848 let already_sent = with_toplevel_last_uncommitted_configure(self.toplevel(), |configure| {
849 let ToplevelConfigure { state, serial } = configure?;
850
851 let same_size = state.size.unwrap_or_default() == size;
852 let has_fullscreen = state.states.contains(xdg_toplevel::State::Fullscreen);
853 let same_fullscreen = has_fullscreen == self.is_pending_windowed_fullscreen;
854 let has_maximized = state.states.contains(xdg_toplevel::State::Maximized);
855 let same_maximized = !has_maximized;
856 (same_size && same_fullscreen && same_maximized).then_some(*serial)
857 });
858
859 if let Some(serial) = already_sent {
860 let current_serial = with_states(self.toplevel().wl_surface(), |states| {
861 states
862 .cached_state
863 .get::<ToplevelCachedState>()
864 .current()
865 .last_acked
866 .as_ref()
867 .map(|c| c.serial)
868 });
869 if let Some(current_serial) = current_serial {
870 // God this triple negative...
871 if !current_serial.is_no_older_than(&serial) {
872 // We have already sent a request for the new size, but the surface has not
873 // committed in response yet, so we will wait for that commit.
874 self.request_size_once = Some(RequestSizeOnce::WaitingForCommit(serial));
875 } else {
876 // We have already sent a request for the new size, and the surface has
877 // committed in response, so we will start using the current size right away.
878 self.request_size_once = Some(RequestSizeOnce::UseWindowSize);
879 }
880 } else {
881 warn!("no current serial; did the surface not ack the initial configure?");
882 self.request_size_once = Some(RequestSizeOnce::UseWindowSize);
883 };
884 return;
885 }
886
887 let changed = self.toplevel().with_pending_state(|state| {
888 let changed = state.size != Some(size);
889 state.size = Some(size);
890 if !self.is_pending_windowed_fullscreen {
891 state.states.unset(xdg_toplevel::State::Fullscreen);
892 }
893 state.states.unset(xdg_toplevel::State::Maximized);
894 changed
895 });
896
897 if changed && animate {
898 self.animate_next_configure = true;
899 }
900
901 self.request_size_once = Some(RequestSizeOnce::WaitingForConfigure);
902 }
903
904 fn min_size(&self) -> Size<i32, Logical> {
905 let min_size = with_states(self.toplevel().wl_surface(), |state| {
906 let mut guard = state.cached_state.get::<SurfaceCachedState>();
907 guard.current().min_size
908 });
909
910 self.rules.apply_min_size(min_size)
911 }
912
913 fn max_size(&self) -> Size<i32, Logical> {
914 let max_size = with_states(self.toplevel().wl_surface(), |state| {
915 let mut guard = state.cached_state.get::<SurfaceCachedState>();
916 guard.current().max_size
917 });
918
919 self.rules.apply_max_size(max_size)
920 }
921
922 fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool {
923 self.toplevel().wl_surface() == wl_surface
924 }
925
926 fn set_preferred_scale_transform(&self, scale: output::Scale, transform: Transform) {
927 self.window.with_surfaces(|surface, data| {
928 send_scale_transform(surface, data, scale, transform);
929 });
930 }
931
932 fn has_ssd(&self) -> bool {
933 let toplevel = self.toplevel();
934 let mode = self
935 .toplevel()
936 .with_committed_state(|current| current.and_then(|s| s.decoration_mode));
937
938 match mode {
939 Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) => true,
940 // Check KDE decorations when XDG are not in use.
941 None => with_states(toplevel.wl_surface(), |states| {
942 states
943 .data_map
944 .get::<KdeDecorationsModeState>()
945 .map(KdeDecorationsModeState::is_server)
946 == Some(true)
947 }),
948 _ => false,
949 }
950 }
951
952 fn output_enter(&self, output: &Output) {
953 let overlap = Rectangle::from_size(Size::from((i32::MAX, i32::MAX)));
954 self.window.output_enter(output, overlap)
955 }
956
957 fn output_leave(&self, output: &Output) {
958 self.window.output_leave(output)
959 }
960
961 fn set_offscreen_data(&self, data: Option<OffscreenData>) {
962 let Some(data) = data else {
963 self.offscreen_data.replace(None);
964 return;
965 };
966
967 let mut offscreen_data = self.offscreen_data.borrow_mut();
968 match &mut *offscreen_data {
969 None => {
970 *offscreen_data = Some(data);
971 }
972 Some(existing) => {
973 // Replace the id, amend existing element states. This is necessary to handle
974 // multiple layers of offscreen (e.g. resize animation + alpha animation).
975 existing.id = data.id;
976 existing.states.states.extend(data.states.states);
977 }
978 }
979 }
980
981 fn is_urgent(&self) -> bool {
982 self.is_urgent
983 }
984
985 fn set_activated(&mut self, active: bool) {
986 let changed = self.toplevel().with_pending_state(|state| {
987 if active {
988 state.states.set(xdg_toplevel::State::Activated)
989 } else {
990 state.states.unset(xdg_toplevel::State::Activated)
991 }
992 });
993 self.need_to_recompute_rules |= changed;
994 }
995
996 fn set_active_in_column(&mut self, active: bool) {
997 let changed = self.is_active_in_column != active;
998 self.is_active_in_column = active;
999 self.need_to_recompute_rules |= changed;
1000 }
1001
1002 fn set_floating(&mut self, floating: bool) {
1003 let changed = self.is_floating != floating;
1004 self.is_floating = floating;
1005 self.need_to_recompute_rules |= changed;
1006 }
1007
1008 fn set_bounds(&self, bounds: Size<i32, Logical>) {
1009 self.toplevel().with_pending_state(|state| {
1010 state.bounds = Some(bounds);
1011 });
1012 }
1013
1014 fn configure_intent(&self) -> ConfigureIntent {
1015 let _span =
1016 trace_span!("configure_intent", surface = ?self.toplevel().wl_surface().id()).entered();
1017
1018 if self.needs_configure {
1019 trace!("the window needs_configure");
1020 return ConfigureIntent::ShouldSend;
1021 }
1022
1023 with_toplevel_role_and_current(self.toplevel(), |attributes, current_committed| {
1024 if let Some(server_pending) = &attributes.server_pending {
1025 let current_server = attributes.current_server_state();
1026 if *server_pending != current_server {
1027 // Something changed. Check if the only difference is the size, and if the
1028 // current server size matches the current committed size.
1029 let mut current_server_same_size = current_server.clone();
1030 current_server_same_size.size = server_pending.size;
1031 if current_server_same_size == *server_pending {
1032 // Only the size changed. Check if the window committed our previous size
1033 // request.
1034 let Some(current_committed) = current_committed else {
1035 error!("mapped must have had initial commit");
1036 return ConfigureIntent::ShouldSend;
1037 };
1038
1039 if current_committed.size == current_server.size {
1040 // The window had committed for our previous size change, so we can
1041 // change the size again.
1042 trace!(
1043 "current size matches server size: {:?}",
1044 current_committed.size
1045 );
1046 ConfigureIntent::CanSend
1047 } else {
1048 // The window had not committed for our previous size change yet. Since
1049 // nothing else changed, do not send the new size request yet. This
1050 // throttling is done because some clients do not batch size requests,
1051 // leading to bad behavior with very fast input devices (i.e. a 1000 Hz
1052 // mouse). This throttling also helps interactive resize transactions
1053 // preserve visual consistency.
1054 trace!("throttling resize");
1055 ConfigureIntent::Throttled
1056 }
1057 } else {
1058 // Something else changed other than the size; send it.
1059 trace!("something changed other than the size");
1060 ConfigureIntent::ShouldSend
1061 }
1062 } else {
1063 // Nothing changed since the last configure.
1064 ConfigureIntent::NotNeeded
1065 }
1066 } else {
1067 // Nothing changed since the last configure.
1068 ConfigureIntent::NotNeeded
1069 }
1070 })
1071 }
1072
1073 fn send_pending_configure(&mut self) {
1074 let toplevel = self.toplevel();
1075 let _span =
1076 trace_span!("send_pending_configure", surface = ?toplevel.wl_surface().id()).entered();
1077
1078 // If the window needs a configure, send it regardless.
1079 let has_pending_changes = self.needs_configure
1080 || with_toplevel_role(self.toplevel(), |role| {
1081 // Check for pending changes manually to account for RequestSizeOnce::UseWindowSize.
1082 if role.server_pending.is_none() {
1083 return false;
1084 }
1085
1086 let current_server_size = role.current_server_state().size;
1087 let server_pending = role.server_pending.as_mut().unwrap();
1088
1089 // With UseWindowSize, we do not consider size-only changes, because we will
1090 // request the current window size and do not expect it to actually change.
1091 if let Some(RequestSizeOnce::UseWindowSize) = self.request_size_once {
1092 server_pending.size = current_server_size;
1093 }
1094
1095 let server_pending = role.server_pending.as_ref().unwrap();
1096 *server_pending != role.current_server_state()
1097 });
1098
1099 if has_pending_changes {
1100 // If needed, replace the pending size with the current window size.
1101 if let Some(RequestSizeOnce::UseWindowSize) = self.request_size_once {
1102 let size = self.window.geometry().size;
1103 toplevel.with_pending_state(|state| {
1104 state.size = Some(size);
1105 });
1106 }
1107
1108 let serial = toplevel.send_configure();
1109 trace!(?serial, "sending configure");
1110
1111 self.needs_configure = false;
1112
1113 // Send the window a frame callback unconditionally to let it respond to size changes
1114 // and such immediately, even when it's hidden. This especially matters for cases like
1115 // tabbed columns which compute their width based on all windows in the column, even
1116 // hidden ones.
1117 self.needs_frame_callback = true;
1118
1119 if self.animate_next_configure {
1120 self.animate_serials.push(serial);
1121 }
1122
1123 if let Some(transaction) = self.transaction_for_next_configure.take() {
1124 self.pending_transactions.push((serial, transaction));
1125 }
1126
1127 self.interactive_resize = match self.interactive_resize.take() {
1128 Some(InteractiveResize::WaitingForLastConfigure(data)) => {
1129 Some(InteractiveResize::WaitingForLastCommit { data, serial })
1130 }
1131 x => x,
1132 };
1133
1134 if let Some(RequestSizeOnce::WaitingForConfigure) = self.request_size_once {
1135 self.request_size_once = Some(RequestSizeOnce::WaitingForCommit(serial));
1136 }
1137
1138 // If is_pending_windowed_fullscreen changed compared to the last value that we "sent"
1139 // to the window, store the configure serial.
1140 let last_sent_windowed_fullscreen = self
1141 .uncommitted_windowed_fullscreen
1142 .last()
1143 .map(|(_, value)| *value)
1144 .unwrap_or(self.is_windowed_fullscreen);
1145 if last_sent_windowed_fullscreen != self.is_pending_windowed_fullscreen {
1146 self.uncommitted_windowed_fullscreen
1147 .push((serial, self.is_pending_windowed_fullscreen));
1148 }
1149
1150 // If is_pending_maximized changed compared to the last value that we "sent" to the
1151 // window, store the configure serial.
1152 let last_sent_maximized = self
1153 .uncommitted_maximized
1154 .last()
1155 .map(|(_, value)| *value)
1156 .unwrap_or(self.is_maximized);
1157 if last_sent_maximized != self.is_pending_maximized {
1158 self.uncommitted_maximized
1159 .push((serial, self.is_pending_maximized));
1160 }
1161 } else {
1162 self.interactive_resize = match self.interactive_resize.take() {
1163 // We probably started and stopped resizing in the same loop cycle without anything
1164 // changing.
1165 Some(InteractiveResize::WaitingForLastConfigure { .. }) => None,
1166 x => x,
1167 };
1168 }
1169
1170 self.animate_next_configure = false;
1171 self.transaction_for_next_configure = None;
1172 }
1173
1174 fn sizing_mode(&self) -> SizingMode {
1175 if self.is_windowed_fullscreen {
1176 return if self.is_maximized {
1177 SizingMode::Maximized
1178 } else {
1179 SizingMode::Normal
1180 };
1181 }
1182
1183 self.toplevel().with_committed_state(|state| {
1184 // This must always be Some() for mapped windows. However, this function is called on
1185 // the code path when removing a just-unmapped window in the commit handler, at which
1186 // point state is already None.
1187 let Some(state) = state else {
1188 return SizingMode::Normal;
1189 };
1190
1191 if state.states.contains(xdg_toplevel::State::Fullscreen) {
1192 SizingMode::Fullscreen
1193 } else if state.states.contains(xdg_toplevel::State::Maximized) {
1194 SizingMode::Maximized
1195 } else {
1196 SizingMode::Normal
1197 }
1198 })
1199 }
1200
1201 fn pending_sizing_mode(&self) -> SizingMode {
1202 if self.is_pending_windowed_fullscreen {
1203 return if self.is_pending_maximized {
1204 SizingMode::Maximized
1205 } else {
1206 SizingMode::Normal
1207 };
1208 }
1209
1210 self.toplevel().with_pending_state(|state| {
1211 if state.states.contains(xdg_toplevel::State::Fullscreen) {
1212 SizingMode::Fullscreen
1213 } else if state.states.contains(xdg_toplevel::State::Maximized) {
1214 SizingMode::Maximized
1215 } else {
1216 SizingMode::Normal
1217 }
1218 })
1219 }
1220
1221 fn is_ignoring_opacity_window_rule(&self) -> bool {
1222 self.ignore_opacity_window_rule
1223 }
1224
1225 fn requested_size(&self) -> Option<Size<i32, Logical>> {
1226 self.toplevel().with_pending_state(|state| state.size)
1227 }
1228
1229 fn expected_size(&self) -> Option<Size<i32, Logical>> {
1230 // We can only use current size if it's not maximized or fullscreen.
1231 let current_size = (self.sizing_mode().is_normal()).then(|| self.window.geometry().size);
1232
1233 // Check if we should be using the current window size.
1234 //
1235 // This branch can be useful (give different result than the logic below) in this example
1236 // case:
1237 //
1238 // 1. We request_size_once a size change.
1239 // 2. We send a second configure requesting a state change.
1240 // 3. The window acks and commits-to the first configure but not the second, with a
1241 // different size.
1242 //
1243 // In this case self.request_size_once will already flip to UseWindowSize and this branch
1244 // will return the window's own new size, but the logic below would see an uncommitted size
1245 // change and return our size.
1246 if let Some(RequestSizeOnce::UseWindowSize) = self.request_size_once {
1247 return current_size;
1248 }
1249
1250 let pending = with_states(self.toplevel().wl_surface(), |states| {
1251 let role = states
1252 .data_map
1253 .get::<XdgToplevelSurfaceData>()
1254 .unwrap()
1255 .lock()
1256 .unwrap();
1257
1258 // If we have a server-pending size change that we haven't sent yet, use that size.
1259 let server_pending = role.server_pending.as_ref()?;
1260
1261 let current_server = role.current_server_state();
1262 if server_pending.size != current_server.size {
1263 return Some((
1264 server_pending.size.unwrap_or_default(),
1265 server_pending
1266 .states
1267 .contains(xdg_toplevel::State::Fullscreen),
1268 server_pending
1269 .states
1270 .contains(xdg_toplevel::State::Maximized),
1271 ));
1272 }
1273
1274 None
1275 })
1276 .or_else(|| {
1277 with_toplevel_last_uncommitted_configure(self.toplevel(), |configure| {
1278 // If we have a sent-but-not-committed-to size, use that.
1279 let ToplevelConfigure { state, .. } = configure?;
1280
1281 Some((
1282 state.size.unwrap_or_default(),
1283 state.states.contains(xdg_toplevel::State::Fullscreen),
1284 state.states.contains(xdg_toplevel::State::Maximized),
1285 ))
1286 })
1287 });
1288
1289 if let Some((mut size, fullscreen, maximized)) = pending {
1290 // If the pending change is maximized or fullscreen, we can't use that size.
1291 //
1292 // Pending windowed fullscreen is good (means not real fullscreen), unless it's also
1293 // pending maximized (means maximized windowed fullscreen, so maximized size, bad).
1294 if maximized
1295 || (fullscreen
1296 && (!self.is_pending_windowed_fullscreen || self.is_pending_maximized))
1297 {
1298 return None;
1299 }
1300
1301 // If some component of the pending size is zero, substitute it with the current window
1302 // size. But only if the current size is not fullscreen.
1303 if size.w == 0 {
1304 size.w = current_size?.w;
1305 }
1306 if size.h == 0 {
1307 size.h = current_size?.h;
1308 }
1309
1310 Some(size)
1311 } else {
1312 // No pending size, return the current size if it's non-fullscreen.
1313 current_size
1314 }
1315 }
1316
1317 fn is_windowed_fullscreen(&self) -> bool {
1318 self.is_windowed_fullscreen
1319 }
1320
1321 fn is_pending_windowed_fullscreen(&self) -> bool {
1322 self.is_pending_windowed_fullscreen
1323 }
1324
1325 fn request_windowed_fullscreen(&mut self, value: bool) {
1326 if self.is_pending_windowed_fullscreen == value {
1327 return;
1328 }
1329
1330 self.is_pending_windowed_fullscreen = value;
1331
1332 // Set the fullscreen state to match.
1333 //
1334 // When going from windowed to real fullscreen, we'll use request_size() which will set the
1335 // fullscreen state back.
1336 self.toplevel().with_pending_state(|state| {
1337 if value {
1338 state.states.set(xdg_toplevel::State::Fullscreen);
1339 state.states.unset(xdg_toplevel::State::Maximized);
1340 } else {
1341 state.states.unset(xdg_toplevel::State::Fullscreen);
1342
1343 if self.is_pending_maximized {
1344 state.states.set(xdg_toplevel::State::Maximized);
1345 }
1346 }
1347 });
1348
1349 // Make sure we receive a commit later to update self.is_windowed_fullscreen.
1350 self.needs_configure = true;
1351 }
1352
1353 fn is_child_of(&self, parent: &Self) -> bool {
1354 self.toplevel().parent().as_ref() == Some(parent.toplevel().wl_surface())
1355 }
1356
1357 fn refresh(&self) {
1358 self.window.refresh();
1359 }
1360
1361 fn rules(&self) -> &ResolvedWindowRules {
1362 &self.rules
1363 }
1364
1365 fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> {
1366 self.animation_snapshot.take()
1367 }
1368
1369 fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>) {
1370 self.toplevel().with_pending_state(|state| {
1371 if data.is_some() {
1372 state.states.set(xdg_toplevel::State::Resizing);
1373 } else {
1374 state.states.unset(xdg_toplevel::State::Resizing);
1375 }
1376 });
1377
1378 if let Some(data) = data {
1379 self.interactive_resize = Some(InteractiveResize::Ongoing(data));
1380 } else {
1381 self.interactive_resize = match self.interactive_resize.take() {
1382 Some(InteractiveResize::Ongoing(data)) => {
1383 Some(InteractiveResize::WaitingForLastConfigure(data))
1384 }
1385 x => x,
1386 }
1387 }
1388 }
1389
1390 fn cancel_interactive_resize(&mut self) {
1391 self.set_interactive_resize(None);
1392 self.interactive_resize = None;
1393 }
1394
1395 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
1396 Some(self.interactive_resize.as_ref()?.data())
1397 }
1398
1399 fn on_commit(&mut self, commit_serial: Serial) {
1400 if let Some(InteractiveResize::WaitingForLastCommit { serial, .. }) =
1401 &self.interactive_resize
1402 {
1403 if commit_serial.is_no_older_than(serial) {
1404 self.interactive_resize = None;
1405 }
1406 }
1407
1408 if let Some(RequestSizeOnce::WaitingForCommit(serial)) = &self.request_size_once {
1409 if commit_serial.is_no_older_than(serial) {
1410 self.request_size_once = Some(RequestSizeOnce::UseWindowSize);
1411 }
1412 }
1413
1414 // "Commit" our "acked" pending windowed fullscreen state.
1415 self.uncommitted_windowed_fullscreen
1416 .retain_mut(|(serial, value)| {
1417 if commit_serial.is_no_older_than(serial) {
1418 self.is_windowed_fullscreen = *value;
1419 false
1420 } else {
1421 true
1422 }
1423 });
1424
1425 // "Commit" our "acked" pending maximized state.
1426 self.uncommitted_maximized.retain_mut(|(serial, value)| {
1427 if commit_serial.is_no_older_than(serial) {
1428 self.is_maximized = *value;
1429 false
1430 } else {
1431 true
1432 }
1433 });
1434 }
1435}