Store offscreen element id on Mapped instead of user data

We don't need user data for this.
This commit is contained in:
Ivan Molodetskikh
2025-03-01 09:45:57 +03:00
parent 88614c08fe
commit 12817a682d
2 changed files with 15 additions and 18 deletions
+3 -11
View File
@@ -29,7 +29,7 @@ use smithay::backend::renderer::element::utils::{
select_dmabuf_feedback, Relocate, RelocateRenderElement,
};
use smithay::backend::renderer::element::{
default_primary_scanout_output_compare, Id, Kind, PrimaryScanoutOutput, RenderElementStates,
default_primary_scanout_output_compare, Kind, PrimaryScanoutOutput, RenderElementStates,
};
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::backend::renderer::sync::SyncPoint;
@@ -503,9 +503,6 @@ pub enum CenterCoords {
Both,
}
#[derive(Default)]
pub struct WindowOffscreenId(pub RefCell<Option<Id>>);
impl RedrawState {
fn queue_redraw(self) -> Self {
match self {
@@ -3796,12 +3793,7 @@ impl Niri {
for mapped in self.layout.windows_for_output(output) {
let win = &mapped.window;
let offscreen_id = win
.user_data()
.get_or_insert(WindowOffscreenId::default)
.0
.borrow();
let offscreen_id = offscreen_id.as_ref();
let offscreen_id = mapped.offscreen_element_id().clone();
win.with_surfaces(|surface, states| {
let surface_primary_scanout_output = states
@@ -3811,7 +3803,7 @@ impl Niri {
.lock()
.unwrap()
.update_from_render_element_states(
offscreen_id.cloned().unwrap_or_else(|| surface.into()),
offscreen_id.clone().unwrap_or_else(|| surface.into()),
output,
render_element_states,
|_, _, output, _| output,
+12 -7
View File
@@ -1,4 +1,4 @@
use std::cell::{Cell, RefCell};
use std::cell::{Cell, Ref, RefCell};
use std::time::Duration;
use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule};
@@ -24,7 +24,6 @@ use crate::layout::{
ConfigureIntent, InteractiveResizeData, LayoutElement, LayoutElementRenderElement,
LayoutElementRenderSnapshot,
};
use crate::niri::WindowOffscreenId;
use crate::niri_render_elements;
use crate::render_helpers::border::BorderRenderElement;
use crate::render_helpers::renderer::NiriRenderer;
@@ -71,6 +70,11 @@ pub struct Mapped {
/// resizes immediately, without waiting for a 1 second throttled callback.
needs_frame_callback: bool,
/// Id of the offscreen element rendered in place of this window.
///
/// If `None`, then the window is not offscreened.
offscreen_element_id: RefCell<Option<Id>>,
/// Whether this window has the keyboard focus.
is_focused: bool,
@@ -188,6 +192,7 @@ impl Mapped {
need_to_recompute_rules: false,
needs_configure: false,
needs_frame_callback: false,
offscreen_element_id: RefCell::new(None),
is_focused: false,
is_active_in_column: true,
is_floating: false,
@@ -252,6 +257,10 @@ impl Mapped {
self.credentials.as_ref()
}
pub fn offscreen_element_id(&self) -> Ref<Option<Id>> {
self.offscreen_element_id.borrow()
}
pub fn is_focused(&self) -> bool {
self.is_focused
}
@@ -743,11 +752,7 @@ impl LayoutElement for Mapped {
}
fn set_offscreen_element_id(&self, id: Option<Id>) {
let data = self
.window
.user_data()
.get_or_insert(WindowOffscreenId::default);
data.0.replace(id);
self.offscreen_element_id.replace(id);
}
fn set_activated(&mut self, active: bool) {