diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-03-13 18:34:47 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-03-13 18:56:35 +0300 |
| commit | 0f30306fe52d5445bc16bd8af3e458f8d76eb45f (patch) | |
| tree | 03bb92e7f8480a6f4c995a7f7251cc57b37e719e | |
| parent | 1c6037e6125870205a878f5267ffb02d3b02db64 (diff) | |
| download | niri-0f30306fe52d5445bc16bd8af3e458f8d76eb45f.tar.gz niri-0f30306fe52d5445bc16bd8af3e458f8d76eb45f.tar.bz2 niri-0f30306fe52d5445bc16bd8af3e458f8d76eb45f.zip | |
Extract utils::is_mapped()
| -rw-r--r-- | src/handlers/compositor.rs | 20 | ||||
| -rw-r--r-- | src/handlers/layer_shell.rs | 12 | ||||
| -rw-r--r-- | src/utils/mod.rs | 6 |
3 files changed, 12 insertions, 26 deletions
diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 012f6af3..527f88b7 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -1,7 +1,7 @@ use std::collections::hash_map::Entry; use niri_ipc::PositionChange; -use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state}; +use smithay::backend::renderer::utils::on_commit_buffer_handler; use smithay::input::pointer::{CursorImageStatus, CursorImageSurfaceData}; use smithay::reexports::calloop::Interest; use smithay::reexports::wayland_server::protocol::wl_buffer; @@ -22,8 +22,8 @@ use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; use crate::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT; use crate::layout::{ActivateWindow, AddWindowTarget}; use crate::niri::{ClientState, State}; -use crate::utils::send_scale_transform; use crate::utils::transaction::Transaction; +use crate::utils::{is_mapped, send_scale_transform}; use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; impl CompositorHandler for State { @@ -78,14 +78,7 @@ impl CompositorHandler for State { if surface == &root_surface { // This is a root surface commit. It might have mapped a previously-unmapped toplevel. if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) { - let is_mapped = - with_renderer_surface_state(surface, |state| state.buffer().is_some()) - .unwrap_or_else(|| { - error!("no renderer surface state even though we use commit handler"); - false - }); - - if is_mapped { + if is_mapped(surface) { // The toplevel got mapped. let Unmapped { window, @@ -231,12 +224,7 @@ impl CompositorHandler for State { let id = mapped.id(); // This is a commit of a previously-mapped toplevel. - let is_mapped = - with_renderer_surface_state(surface, |state| state.buffer().is_some()) - .unwrap_or_else(|| { - error!("no renderer surface state even though we use commit handler"); - false - }); + let is_mapped = is_mapped(surface); // Must start the close animation before window.on_commit(). let transaction = Transaction::new(); diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index 73a61e6e..04366ab3 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -1,4 +1,3 @@ -use smithay::backend::renderer::utils::with_renderer_surface_state; use smithay::delegate_layer_shell; use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; use smithay::output::Output; @@ -13,7 +12,7 @@ use smithay::wayland::shell::xdg::PopupSurface; use crate::layer::{MappedLayer, ResolvedLayerRules}; use crate::niri::State; -use crate::utils::send_scale_transform; +use crate::utils::{is_mapped, send_scale_transform}; impl WlrLayerShellHandler for State { fn shell_state(&mut self) -> &mut WlrLayerShellState { @@ -120,14 +119,7 @@ impl State { .unwrap(); if initial_configure_sent { - let is_mapped = - with_renderer_surface_state(surface, |state| state.buffer().is_some()) - .unwrap_or_else(|| { - error!("no renderer surface state even though we use commit handler"); - false - }); - - if is_mapped { + if is_mapped(surface) { let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface); // Resolve rules for newly mapped layer surfaces. diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2f16e855..c1e57b7b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,6 +12,7 @@ use bitflags::bitflags; use directories::UserDirs; use git_version::git_version; use niri_config::{Config, OutputName}; +use smithay::backend::renderer::utils::with_renderer_surface_state; use smithay::input::pointer::CursorIcon; use smithay::output::{self, Output}; use smithay::reexports::rustix::time::{clock_gettime, ClockId}; @@ -181,6 +182,11 @@ pub fn ipc_transform_to_smithay(transform: niri_ipc::Transform) -> Transform { } } +pub fn is_mapped(surface: &WlSurface) -> bool { + // None if the surface hadn't committed yet. + with_renderer_surface_state(surface, |state| state.buffer().is_some()).unwrap_or(false) +} + pub fn send_scale_transform( surface: &WlSurface, data: &SurfaceData, |
