From 0e7e398df3a816b7dec1de8902af83d29a08562a Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 2 Nov 2024 10:35:25 +0300 Subject: Replace current_state() with with_toplevel_role() Avoid microallocations that happen in current_state(). --- src/handlers/mod.rs | 14 +++++++------- src/window/mapped.rs | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 5b44caf0..ed9f224c 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -74,7 +74,7 @@ use crate::protocols::gamma_control::{GammaControlHandler, GammaControlManagerSt use crate::protocols::mutter_x11_interop::MutterX11InteropHandler; use crate::protocols::output_management::{OutputManagementHandler, OutputManagementManagerState}; use crate::protocols::screencopy::{Screencopy, ScreencopyHandler, ScreencopyManagerState}; -use crate::utils::{output_size, send_scale_transform}; +use crate::utils::{output_size, send_scale_transform, with_toplevel_role}; use crate::{ delegate_foreign_toplevel, delegate_gamma_control, delegate_mutter_x11_interop, delegate_output_management, delegate_screencopy, @@ -459,12 +459,12 @@ impl ForeignToplevelHandler for State { fn set_fullscreen(&mut self, wl_surface: WlSurface, wl_output: Option) { if let Some((mapped, current_output)) = self.niri.layout.find_window_and_output(&wl_surface) { - if !mapped - .toplevel() - .current_state() - .capabilities - .contains(xdg_toplevel::WmCapabilities::Fullscreen) - { + let has_fullscreen_cap = with_toplevel_role(mapped.toplevel(), |role| { + role.current + .capabilities + .contains(xdg_toplevel::WmCapabilities::Fullscreen) + }); + if !has_fullscreen_cap { return; } diff --git a/src/window/mapped.rs b/src/window/mapped.rs index bf4aaa9b..e9f087bd 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -571,7 +571,7 @@ impl LayoutElement for Mapped { fn has_ssd(&self) -> bool { let toplevel = self.toplevel(); - let mode = toplevel.current_state().decoration_mode; + let mode = with_toplevel_role(self.toplevel(), |role| role.current.decoration_mode); match mode { Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) => true, @@ -712,10 +712,11 @@ impl LayoutElement for Mapped { } fn is_fullscreen(&self) -> bool { - self.toplevel() - .current_state() - .states - .contains(xdg_toplevel::State::Fullscreen) + with_toplevel_role(self.toplevel(), |role| { + role.current + .states + .contains(xdg_toplevel::State::Fullscreen) + }) } fn is_pending_fullscreen(&self) -> bool { -- cgit