Refactor column and tile offsets, fix a few issues

This commit is contained in:
Ivan Molodetskikh
2024-05-14 15:00:11 +04:00
parent b14405904a
commit 5f40221051
4 changed files with 462 additions and 370 deletions
+1 -3
View File
@@ -759,7 +759,7 @@ impl State {
// height. // height.
let mut target = let mut target =
Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h));
target.loc.y -= self.niri.layout.window_y(window).unwrap(); target.loc -= self.niri.layout.window_loc(window).unwrap();
target.loc -= get_popup_toplevel_coords(popup); target.loc -= get_popup_toplevel_coords(popup);
self.position_popup_within_rect(popup, target); self.position_popup_within_rect(popup, target);
@@ -953,8 +953,6 @@ pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId
state.backend.with_primary_renderer(|renderer| { state.backend.with_primary_renderer(|renderer| {
mapped.store_animation_snapshot(renderer); mapped.store_animation_snapshot(renderer);
}); });
state.niri.layout.prepare_for_resize_animation(&window);
} }
// The toplevel remains mapped; clear any stored unmap snapshot. // The toplevel remains mapped; clear any stored unmap snapshot.
+3 -28
View File
@@ -745,14 +745,14 @@ impl<W: LayoutElement> Layout<W> {
None None
} }
pub fn window_y(&self, window: &W::Id) -> Option<i32> { pub fn window_loc(&self, window: &W::Id) -> Option<Point<i32, Logical>> {
match &self.monitor_set { match &self.monitor_set {
MonitorSet::Normal { monitors, .. } => { MonitorSet::Normal { monitors, .. } => {
for mon in monitors { for mon in monitors {
for ws in &mon.workspaces { for ws in &mon.workspaces {
for col in &ws.columns { for col in &ws.columns {
if let Some(idx) = col.position(window) { if let Some(idx) = col.position(window) {
return Some(col.window_y(idx)); return Some(col.window_loc(idx));
} }
} }
} }
@@ -762,7 +762,7 @@ impl<W: LayoutElement> Layout<W> {
for ws in workspaces { for ws in workspaces {
for col in &ws.columns { for col in &ws.columns {
if let Some(idx) = col.position(window) { if let Some(idx) = col.position(window) {
return Some(col.window_y(idx)); return Some(col.window_loc(idx));
} }
} }
} }
@@ -1995,31 +1995,6 @@ impl<W: LayoutElement> Layout<W> {
} }
} }
pub fn prepare_for_resize_animation(&mut self, window: &W::Id) {
let _span = tracy_client::span!("Layout::prepare_for_resize_animation");
match &mut self.monitor_set {
MonitorSet::Normal { monitors, .. } => {
for mon in monitors {
for ws in &mut mon.workspaces {
if ws.has_window(window) {
ws.prepare_for_resize_animation(window);
return;
}
}
}
}
MonitorSet::NoOutputs { workspaces, .. } => {
for ws in workspaces {
if ws.has_window(window) {
ws.prepare_for_resize_animation(window);
return;
}
}
}
}
}
pub fn refresh(&mut self) { pub fn refresh(&mut self) {
let _span = tracy_client::span!("Layout::refresh"); let _span = tracy_client::span!("Layout::refresh");
+6 -9
View File
@@ -1,4 +1,3 @@
use std::cell::RefCell;
use std::cmp::max; use std::cmp::max;
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
@@ -67,7 +66,7 @@ pub struct Tile<W: LayoutElement> {
move_y_animation: Option<MoveAnimation>, move_y_animation: Option<MoveAnimation>,
/// Snapshot of the last render for use in the close animation. /// Snapshot of the last render for use in the close animation.
unmap_snapshot: RefCell<Option<TileRenderSnapshot>>, unmap_snapshot: Option<TileRenderSnapshot>,
/// Extra damage for clipped surface corner radius changes. /// Extra damage for clipped surface corner radius changes.
rounded_corner_damage: RoundedCornerDamage, rounded_corner_damage: RoundedCornerDamage,
@@ -122,7 +121,7 @@ impl<W: LayoutElement> Tile<W> {
resize_animation: None, resize_animation: None,
move_x_animation: None, move_x_animation: None,
move_y_animation: None, move_y_animation: None,
unmap_snapshot: RefCell::new(None), unmap_snapshot: None,
rounded_corner_damage: Default::default(), rounded_corner_damage: Default::default(),
options, options,
} }
@@ -237,9 +236,7 @@ impl<W: LayoutElement> Tile<W> {
|| self.move_y_animation.is_some() || self.move_y_animation.is_some()
} }
pub fn update(&mut self, is_active: bool, mut view_rect: Rectangle<i32, Logical>) { pub fn update(&mut self, is_active: bool, view_rect: Rectangle<i32, Logical>) {
view_rect.loc -= self.render_offset();
let rules = self.window.rules(); let rules = self.window.rules();
let draw_border_with_background = rules let draw_border_with_background = rules
@@ -840,11 +837,11 @@ impl<W: LayoutElement> Tile<W> {
renderer: &mut GlesRenderer, renderer: &mut GlesRenderer,
scale: Scale<f64>, scale: Scale<f64>,
) { ) {
if self.unmap_snapshot.get_mut().is_some() { if self.unmap_snapshot.is_some() {
return; return;
} }
*self.unmap_snapshot.get_mut() = Some(self.render_snapshot(renderer, scale)); self.unmap_snapshot = Some(self.render_snapshot(renderer, scale));
} }
fn render_snapshot( fn render_snapshot(
@@ -881,7 +878,7 @@ impl<W: LayoutElement> Tile<W> {
} }
} }
pub fn take_unmap_snapshot(&self) -> Option<TileRenderSnapshot> { pub fn take_unmap_snapshot(&mut self) -> Option<TileRenderSnapshot> {
self.unmap_snapshot.take() self.unmap_snapshot.take()
} }
} }
+405 -283
View File
File diff suppressed because it is too large Load Diff