aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/handlers/compositor.rs20
-rw-r--r--src/handlers/layer_shell.rs12
-rw-r--r--src/utils/mod.rs6
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,