aboutsummaryrefslogtreecommitdiff
path: root/src/layout.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-11 11:56:38 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-11 11:56:38 +0400
commitb283f546aafd767aeb065c14ff891c9d8f4a09ab (patch)
treef8c094d3e74cd76507954fa9328a8c31dc809c18 /src/layout.rs
parent15b6c84af02d2a35eb591af7290d354f48cc67da (diff)
downloadniri-b283f546aafd767aeb065c14ff891c9d8f4a09ab.tar.gz
niri-b283f546aafd767aeb065c14ff891c9d8f4a09ab.tar.bz2
niri-b283f546aafd767aeb065c14ff891c9d8f4a09ab.zip
layout: Store location in FocusRing
Diffstat (limited to 'src/layout.rs')
-rw-r--r--src/layout.rs31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/layout.rs b/src/layout.rs
index 85d90bfb..e4d6bbe4 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -189,6 +189,7 @@ pub struct Workspace<W: LayoutElement> {
#[derive(Debug)]
struct FocusRing {
buffer: SolidColorBuffer,
+ location: Point<i32, Logical>,
is_off: bool,
width: i32,
active_color: Color,
@@ -335,6 +336,11 @@ impl FocusRing {
self.buffer.resize(size);
}
+ fn reposition(&mut self, win_pos: Point<i32, Logical>) {
+ let offset = Point::from((self.width, self.width));
+ self.location = win_pos - offset;
+ }
+
fn set_active(&mut self, is_active: bool) {
self.buffer.set_color(if is_active {
self.active_color.into()
@@ -343,19 +349,14 @@ impl FocusRing {
});
}
- fn render(
- &self,
- loc: Point<i32, Logical>,
- scale: Scale<f64>,
- ) -> Option<SolidColorRenderElement> {
+ fn render(&self, scale: Scale<f64>) -> Option<SolidColorRenderElement> {
if self.is_off {
return None;
}
- let offset = Point::from((self.width, self.width));
Some(SolidColorRenderElement::from_buffer(
&self.buffer,
- (loc - offset).to_physical_precise_round(scale),
+ self.location.to_physical_precise_round(scale),
scale,
1.,
Kind::Unspecified,
@@ -367,6 +368,7 @@ impl FocusRing {
fn new(config: config::FocusRing) -> Self {
Self {
buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.]),
+ location: Point::from((0, 0)),
is_off: config.off,
width: config.width.into(),
active_color: config.active_color,
@@ -1670,11 +1672,20 @@ impl<W: LayoutElement> Workspace<W> {
None => (),
}
+ let view_pos = self.view_pos();
+
// This shall one day become a proper animation.
if !self.columns.is_empty() {
let col = &self.columns[self.active_column_idx];
let active_win = &col.windows[col.active_window_idx];
let geom = active_win.geometry();
+
+ let win_pos = Point::from((
+ self.column_x(self.active_column_idx) - view_pos,
+ col.window_y(col.active_window_idx),
+ ));
+
+ self.focus_ring.reposition(win_pos);
self.focus_ring.resize(geom.size);
self.focus_ring.set_active(is_active);
}
@@ -2276,11 +2287,7 @@ impl Workspace<Window> {
));
// Draw the focus ring.
- rv.extend(
- self.focus_ring
- .render(win_pos, output_scale)
- .map(Into::into),
- );
+ rv.extend(self.focus_ring.render(output_scale).map(Into::into));
let mut x = -view_pos;
for col in &self.columns {