Store offscreen element id on Mapped instead of user data
Browse files at this commit12817a682d666e81e30b5a723d6419baf74cdb1cParent: 88614c02 changed files +15 -18
- src/niri.rs +3 -11
- src/window/mapped.rs +12 -7
src/niri.rsmodified+3 -11
| @@ -29,7 +29,7 @@ use smithay::backend::renderer::element::utils::{ | |||
| 29 | select_dmabuf_feedback, Relocate, RelocateRenderElement, | 29 | select_dmabuf_feedback, Relocate, RelocateRenderElement, |
| 30 | }; | 30 | }; |
| 31 | use smithay::backend::renderer::element::{ | 31 | use smithay::backend::renderer::element::{ |
| 32 | - default_primary_scanout_output_compare, Id, Kind, PrimaryScanoutOutput, RenderElementStates, | 32 | + default_primary_scanout_output_compare, Kind, PrimaryScanoutOutput, RenderElementStates, |
| 33 | }; | 33 | }; |
| 34 | use smithay::backend::renderer::gles::GlesRenderer; | 34 | use smithay::backend::renderer::gles::GlesRenderer; |
| 35 | use smithay::backend::renderer::sync::SyncPoint; | 35 | use smithay::backend::renderer::sync::SyncPoint; |
| @@ -503,9 +503,6 @@ pub enum CenterCoords { | |||
| 503 | Both, | 503 | Both, |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | -#[derive(Default)] | ||
| 507 | -pub struct WindowOffscreenId(pub RefCell<Option<Id>>); | ||
| 508 | - | ||
| 509 | impl RedrawState { | 506 | impl RedrawState { |
| 510 | fn queue_redraw(self) -> Self { | 507 | fn queue_redraw(self) -> Self { |
| 511 | match self { | 508 | match self { |
| @@ -3796,12 +3793,7 @@ impl Niri { | |||
| 3796 | 3793 | ||
| 3797 | for mapped in self.layout.windows_for_output(output) { | 3794 | for mapped in self.layout.windows_for_output(output) { |
| 3798 | let win = &mapped.window; | 3795 | let win = &mapped.window; |
| 3799 | - let offscreen_id = win | 3796 | + let offscreen_id = mapped.offscreen_element_id().clone(); |
| 3800 | - .user_data() | ||
| 3801 | - .get_or_insert(WindowOffscreenId::default) | ||
| 3802 | - .0 | ||
| 3803 | - .borrow(); | ||
| 3804 | - let offscreen_id = offscreen_id.as_ref(); | ||
| 3805 | 3797 | ||
| 3806 | win.with_surfaces(|surface, states| { | 3798 | win.with_surfaces(|surface, states| { |
| 3807 | let surface_primary_scanout_output = states | 3799 | let surface_primary_scanout_output = states |
| @@ -3811,7 +3803,7 @@ impl Niri { | |||
| 3811 | .lock() | 3803 | .lock() |
| 3812 | .unwrap() | 3804 | .unwrap() |
| 3813 | .update_from_render_element_states( | 3805 | .update_from_render_element_states( |
| 3814 | - offscreen_id.cloned().unwrap_or_else(|| surface.into()), | 3806 | + offscreen_id.clone().unwrap_or_else(|| surface.into()), |
| 3815 | output, | 3807 | output, |
| 3816 | render_element_states, | 3808 | render_element_states, |
| 3817 | |_, _, output, _| output, | 3809 | |_, _, output, _| output, |
src/window/mapped.rsmodified+12 -7
| @@ -1,4 +1,4 @@ | |||
| 1 | -use std::cell::{Cell, RefCell}; | 1 | +use std::cell::{Cell, Ref, RefCell}; |
| 2 | use std::time::Duration; | 2 | use std::time::Duration; |
| 3 | 3 | ||
| 4 | use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule}; | 4 | use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule}; |
| @@ -24,7 +24,6 @@ use crate::layout::{ | |||
| 24 | ConfigureIntent, InteractiveResizeData, LayoutElement, LayoutElementRenderElement, | 24 | ConfigureIntent, InteractiveResizeData, LayoutElement, LayoutElementRenderElement, |
| 25 | LayoutElementRenderSnapshot, | 25 | LayoutElementRenderSnapshot, |
| 26 | }; | 26 | }; |
| 27 | -use crate::niri::WindowOffscreenId; | ||
| 28 | use crate::niri_render_elements; | 27 | use crate::niri_render_elements; |
| 29 | use crate::render_helpers::border::BorderRenderElement; | 28 | use crate::render_helpers::border::BorderRenderElement; |
| 30 | use crate::render_helpers::renderer::NiriRenderer; | 29 | use crate::render_helpers::renderer::NiriRenderer; |
| @@ -71,6 +70,11 @@ pub struct Mapped { | |||
| 71 | /// resizes immediately, without waiting for a 1 second throttled callback. | 70 | /// resizes immediately, without waiting for a 1 second throttled callback. |
| 72 | needs_frame_callback: bool, | 71 | needs_frame_callback: bool, |
| 73 | 72 | ||
| 73 | + /// Id of the offscreen element rendered in place of this window. | ||
| 74 | + /// | ||
| 75 | + /// If `None`, then the window is not offscreened. | ||
| 76 | + offscreen_element_id: RefCell<Option<Id>>, | ||
| 77 | + | ||
| 74 | /// Whether this window has the keyboard focus. | 78 | /// Whether this window has the keyboard focus. |
| 75 | is_focused: bool, | 79 | is_focused: bool, |
| 76 | 80 | ||
| @@ -188,6 +192,7 @@ impl Mapped { | |||
| 188 | need_to_recompute_rules: false, | 192 | need_to_recompute_rules: false, |
| 189 | needs_configure: false, | 193 | needs_configure: false, |
| 190 | needs_frame_callback: false, | 194 | needs_frame_callback: false, |
| 195 | + offscreen_element_id: RefCell::new(None), | ||
| 191 | is_focused: false, | 196 | is_focused: false, |
| 192 | is_active_in_column: true, | 197 | is_active_in_column: true, |
| 193 | is_floating: false, | 198 | is_floating: false, |
| @@ -252,6 +257,10 @@ impl Mapped { | |||
| 252 | self.credentials.as_ref() | 257 | self.credentials.as_ref() |
| 253 | } | 258 | } |
| 254 | 259 | ||
| 260 | + pub fn offscreen_element_id(&self) -> Ref<Option<Id>> { | ||
| 261 | + self.offscreen_element_id.borrow() | ||
| 262 | + } | ||
| 263 | + | ||
| 255 | pub fn is_focused(&self) -> bool { | 264 | pub fn is_focused(&self) -> bool { |
| 256 | self.is_focused | 265 | self.is_focused |
| 257 | } | 266 | } |
| @@ -743,11 +752,7 @@ impl LayoutElement for Mapped { | |||
| 743 | } | 752 | } |
| 744 | 753 | ||
| 745 | fn set_offscreen_element_id(&self, id: Option<Id>) { | 754 | fn set_offscreen_element_id(&self, id: Option<Id>) { |
| 746 | - let data = self | 755 | + self.offscreen_element_id.replace(id); |
| 747 | - .window | ||
| 748 | - .user_data() | ||
| 749 | - .get_or_insert(WindowOffscreenId::default); | ||
| 750 | - data.0.replace(id); | ||
| 751 | } | 756 | } |
| 752 | 757 | ||
| 753 | fn set_activated(&mut self, active: bool) { | 758 | fn set_activated(&mut self, active: bool) { |