Extract utils::is_mapped()
Browse files at this commit0f30306fe52d5445bc16bd8af3e458f8d76eb45fParent: 1c6037e3 changed files +12 -26
- src/handlers/compositor.rs +4 -16
- src/handlers/layer_shell.rs +2 -10
- src/utils/mod.rs +6 -0
src/handlers/compositor.rsmodified+4 -16
| @@ -1,7 +1,7 @@ | |||
| 1 | use std::collections::hash_map::Entry; | 1 | use std::collections::hash_map::Entry; |
| 2 | 2 | ||
| 3 | use niri_ipc::PositionChange; | 3 | use niri_ipc::PositionChange; |
| 4 | -use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state}; | 4 | +use smithay::backend::renderer::utils::on_commit_buffer_handler; |
| 5 | use smithay::input::pointer::{CursorImageStatus, CursorImageSurfaceData}; | 5 | use smithay::input::pointer::{CursorImageStatus, CursorImageSurfaceData}; |
| 6 | use smithay::reexports::calloop::Interest; | 6 | use smithay::reexports::calloop::Interest; |
| 7 | use smithay::reexports::wayland_server::protocol::wl_buffer; | 7 | use smithay::reexports::wayland_server::protocol::wl_buffer; |
| @@ -22,8 +22,8 @@ use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; | |||
| 22 | use crate::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT; | 22 | use crate::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT; |
| 23 | use crate::layout::{ActivateWindow, AddWindowTarget}; | 23 | use crate::layout::{ActivateWindow, AddWindowTarget}; |
| 24 | use crate::niri::{ClientState, State}; | 24 | use crate::niri::{ClientState, State}; |
| 25 | -use crate::utils::send_scale_transform; | ||
| 26 | use crate::utils::transaction::Transaction; | 25 | use crate::utils::transaction::Transaction; |
| 26 | +use crate::utils::{is_mapped, send_scale_transform}; | ||
| 27 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; | 27 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; |
| 28 | 28 | ||
| 29 | impl CompositorHandler for State { | 29 | impl CompositorHandler for State { |
| @@ -78,14 +78,7 @@ impl CompositorHandler for State { | |||
| 78 | if surface == &root_surface { | 78 | if surface == &root_surface { |
| 79 | // This is a root surface commit. It might have mapped a previously-unmapped toplevel. | 79 | // This is a root surface commit. It might have mapped a previously-unmapped toplevel. |
| 80 | if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) { | 80 | if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) { |
| 81 | - let is_mapped = | 81 | + if is_mapped(surface) { |
| 82 | - with_renderer_surface_state(surface, |state| state.buffer().is_some()) | ||
| 83 | - .unwrap_or_else(|| { | ||
| 84 | - error!("no renderer surface state even though we use commit handler"); | ||
| 85 | - false | ||
| 86 | - }); | ||
| 87 | - | ||
| 88 | - if is_mapped { | ||
| 89 | // The toplevel got mapped. | 82 | // The toplevel got mapped. |
| 90 | let Unmapped { | 83 | let Unmapped { |
| 91 | window, | 84 | window, |
| @@ -231,12 +224,7 @@ impl CompositorHandler for State { | |||
| 231 | let id = mapped.id(); | 224 | let id = mapped.id(); |
| 232 | 225 | ||
| 233 | // This is a commit of a previously-mapped toplevel. | 226 | // This is a commit of a previously-mapped toplevel. |
| 234 | - let is_mapped = | 227 | + let is_mapped = is_mapped(surface); |
| 235 | - with_renderer_surface_state(surface, |state| state.buffer().is_some()) | ||
| 236 | - .unwrap_or_else(|| { | ||
| 237 | - error!("no renderer surface state even though we use commit handler"); | ||
| 238 | - false | ||
| 239 | - }); | ||
| 240 | 228 | ||
| 241 | // Must start the close animation before window.on_commit(). | 229 | // Must start the close animation before window.on_commit(). |
| 242 | let transaction = Transaction::new(); | 230 | let transaction = Transaction::new(); |
src/handlers/layer_shell.rsmodified+2 -10
| @@ -1,4 +1,3 @@ | |||
| 1 | -use smithay::backend::renderer::utils::with_renderer_surface_state; | ||
| 2 | use smithay::delegate_layer_shell; | 1 | use smithay::delegate_layer_shell; |
| 3 | use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; | 2 | use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; |
| 4 | use smithay::output::Output; | 3 | use smithay::output::Output; |
| @@ -13,7 +12,7 @@ use smithay::wayland::shell::xdg::PopupSurface; | |||
| 13 | 12 | ||
| 14 | use crate::layer::{MappedLayer, ResolvedLayerRules}; | 13 | use crate::layer::{MappedLayer, ResolvedLayerRules}; |
| 15 | use crate::niri::State; | 14 | use crate::niri::State; |
| 16 | -use crate::utils::send_scale_transform; | 15 | +use crate::utils::{is_mapped, send_scale_transform}; |
| 17 | 16 | ||
| 18 | impl WlrLayerShellHandler for State { | 17 | impl WlrLayerShellHandler for State { |
| 19 | fn shell_state(&mut self) -> &mut WlrLayerShellState { | 18 | fn shell_state(&mut self) -> &mut WlrLayerShellState { |
| @@ -120,14 +119,7 @@ impl State { | |||
| 120 | .unwrap(); | 119 | .unwrap(); |
| 121 | 120 | ||
| 122 | if initial_configure_sent { | 121 | if initial_configure_sent { |
| 123 | - let is_mapped = | 122 | + if is_mapped(surface) { |
| 124 | - with_renderer_surface_state(surface, |state| state.buffer().is_some()) | ||
| 125 | - .unwrap_or_else(|| { | ||
| 126 | - error!("no renderer surface state even though we use commit handler"); | ||
| 127 | - false | ||
| 128 | - }); | ||
| 129 | - | ||
| 130 | - if is_mapped { | ||
| 131 | let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface); | 123 | let was_unmapped = self.niri.unmapped_layer_surfaces.remove(surface); |
| 132 | 124 | ||
| 133 | // Resolve rules for newly mapped layer surfaces. | 125 | // Resolve rules for newly mapped layer surfaces. |
src/utils/mod.rsmodified+6 -0
| @@ -12,6 +12,7 @@ use bitflags::bitflags; | |||
| 12 | use directories::UserDirs; | 12 | use directories::UserDirs; |
| 13 | use git_version::git_version; | 13 | use git_version::git_version; |
| 14 | use niri_config::{Config, OutputName}; | 14 | use niri_config::{Config, OutputName}; |
| 15 | +use smithay::backend::renderer::utils::with_renderer_surface_state; | ||
| 15 | use smithay::input::pointer::CursorIcon; | 16 | use smithay::input::pointer::CursorIcon; |
| 16 | use smithay::output::{self, Output}; | 17 | use smithay::output::{self, Output}; |
| 17 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 18 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| @@ -181,6 +182,11 @@ pub fn ipc_transform_to_smithay(transform: niri_ipc::Transform) -> Transform { | |||
| 181 | } | 182 | } |
| 182 | } | 183 | } |
| 183 | 184 | ||
| 185 | +pub fn is_mapped(surface: &WlSurface) -> bool { | ||
| 186 | + // None if the surface hadn't committed yet. | ||
| 187 | + with_renderer_surface_state(surface, |state| state.buffer().is_some()).unwrap_or(false) | ||
| 188 | +} | ||
| 189 | + | ||
| 184 | pub fn send_scale_transform( | 190 | pub fn send_scale_transform( |
| 185 | surface: &WlSurface, | 191 | surface: &WlSurface, |
| 186 | data: &SurfaceData, | 192 | data: &SurfaceData, |