Extract utils::is_mapped()

This commit is contained in:
Ivan Molodetskikh
2025-03-13 18:34:47 +03:00
parent 1c6037e612
commit 0f30306fe5
3 changed files with 12 additions and 26 deletions
+4 -16
View File
@@ -1,7 +1,7 @@
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use niri_ipc::PositionChange; 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::input::pointer::{CursorImageStatus, CursorImageSurfaceData};
use smithay::reexports::calloop::Interest; use smithay::reexports::calloop::Interest;
use smithay::reexports::wayland_server::protocol::wl_buffer; 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::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT;
use crate::layout::{ActivateWindow, AddWindowTarget}; use crate::layout::{ActivateWindow, AddWindowTarget};
use crate::niri::{ClientState, State}; use crate::niri::{ClientState, State};
use crate::utils::send_scale_transform;
use crate::utils::transaction::Transaction; use crate::utils::transaction::Transaction;
use crate::utils::{is_mapped, send_scale_transform};
use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped};
impl CompositorHandler for State { impl CompositorHandler for State {
@@ -78,14 +78,7 @@ impl CompositorHandler for State {
if surface == &root_surface { if surface == &root_surface {
// This is a root surface commit. It might have mapped a previously-unmapped toplevel. // 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()) { if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) {
let is_mapped = if is_mapped(surface) {
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 {
// The toplevel got mapped. // The toplevel got mapped.
let Unmapped { let Unmapped {
window, window,
@@ -231,12 +224,7 @@ impl CompositorHandler for State {
let id = mapped.id(); let id = mapped.id();
// This is a commit of a previously-mapped toplevel. // This is a commit of a previously-mapped toplevel.
let is_mapped = let is_mapped = is_mapped(surface);
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
});
// Must start the close animation before window.on_commit(). // Must start the close animation before window.on_commit().
let transaction = Transaction::new(); let transaction = Transaction::new();
+2 -10
View File
@@ -1,4 +1,3 @@
use smithay::backend::renderer::utils::with_renderer_surface_state;
use smithay::delegate_layer_shell; use smithay::delegate_layer_shell;
use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType};
use smithay::output::Output; use smithay::output::Output;
@@ -13,7 +12,7 @@ use smithay::wayland::shell::xdg::PopupSurface;
use crate::layer::{MappedLayer, ResolvedLayerRules}; use crate::layer::{MappedLayer, ResolvedLayerRules};
use crate::niri::State; use crate::niri::State;
use crate::utils::send_scale_transform; use crate::utils::{is_mapped, send_scale_transform};
impl WlrLayerShellHandler for State { impl WlrLayerShellHandler for State {
fn shell_state(&mut self) -> &mut WlrLayerShellState { fn shell_state(&mut self) -> &mut WlrLayerShellState {
@@ -120,14 +119,7 @@ impl State {
.unwrap(); .unwrap();
if initial_configure_sent { if initial_configure_sent {
let is_mapped = if is_mapped(surface) {
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 {
let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface); let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface);
// Resolve rules for newly mapped layer surfaces. // Resolve rules for newly mapped layer surfaces.
+6
View File
@@ -12,6 +12,7 @@ use bitflags::bitflags;
use directories::UserDirs; use directories::UserDirs;
use git_version::git_version; use git_version::git_version;
use niri_config::{Config, OutputName}; use niri_config::{Config, OutputName};
use smithay::backend::renderer::utils::with_renderer_surface_state;
use smithay::input::pointer::CursorIcon; use smithay::input::pointer::CursorIcon;
use smithay::output::{self, Output}; use smithay::output::{self, Output};
use smithay::reexports::rustix::time::{clock_gettime, ClockId}; 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( pub fn send_scale_transform(
surface: &WlSurface, surface: &WlSurface,
data: &SurfaceData, data: &SurfaceData,