mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Accept location in FocusRing
Makes it work more like other elements.
This commit is contained in:
+13
-14
@@ -39,26 +39,21 @@ impl FocusRing {
|
||||
self.inactive_color = config.inactive_color;
|
||||
}
|
||||
|
||||
pub fn update(
|
||||
&mut self,
|
||||
win_pos: Point<i32, Logical>,
|
||||
win_size: Size<i32, Logical>,
|
||||
is_border: bool,
|
||||
) {
|
||||
pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) {
|
||||
if is_border {
|
||||
self.buffers[0].resize((win_size.w + self.width * 2, self.width));
|
||||
self.buffers[1].resize((win_size.w + self.width * 2, self.width));
|
||||
self.buffers[2].resize((self.width, win_size.h));
|
||||
self.buffers[3].resize((self.width, win_size.h));
|
||||
|
||||
self.locations[0] = win_pos + Point::from((-self.width, -self.width));
|
||||
self.locations[1] = win_pos + Point::from((-self.width, win_size.h));
|
||||
self.locations[2] = win_pos + Point::from((-self.width, 0));
|
||||
self.locations[3] = win_pos + Point::from((win_size.w, 0));
|
||||
self.locations[0] = Point::from((-self.width, -self.width));
|
||||
self.locations[1] = Point::from((-self.width, win_size.h));
|
||||
self.locations[2] = Point::from((-self.width, 0));
|
||||
self.locations[3] = Point::from((win_size.w, 0));
|
||||
} else {
|
||||
let size = win_size + Size::from((self.width * 2, self.width * 2));
|
||||
self.buffers[0].resize(size);
|
||||
self.locations[0] = win_pos - Point::from((self.width, self.width));
|
||||
self.locations[0] = Point::from((-self.width, -self.width));
|
||||
}
|
||||
|
||||
self.is_border = is_border;
|
||||
@@ -76,7 +71,11 @@ impl FocusRing {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, scale: Scale<f64>) -> impl Iterator<Item = FocusRingRenderElement> {
|
||||
pub fn render(
|
||||
&self,
|
||||
location: Point<i32, Logical>,
|
||||
scale: Scale<f64>,
|
||||
) -> impl Iterator<Item = FocusRingRenderElement> {
|
||||
let mut rv = ArrayVec::<_, 4>::new();
|
||||
|
||||
if self.is_off {
|
||||
@@ -96,10 +95,10 @@ impl FocusRing {
|
||||
|
||||
if self.is_border {
|
||||
for (buf, loc) in zip(&self.buffers, self.locations) {
|
||||
push(buf, loc);
|
||||
push(buf, location + loc);
|
||||
}
|
||||
} else {
|
||||
push(&self.buffers[0], self.locations[0]);
|
||||
push(&self.buffers[0], location + self.locations[0]);
|
||||
}
|
||||
|
||||
rv.into_iter()
|
||||
|
||||
+13
-34
@@ -3,9 +3,7 @@ use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
|
||||
use smithay::backend::renderer::element::utils::{
|
||||
Relocate, RelocateRenderElement, RescaleRenderElement,
|
||||
};
|
||||
use smithay::backend::renderer::element::utils::RescaleRenderElement;
|
||||
use smithay::backend::renderer::element::{Element, Kind};
|
||||
use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
|
||||
|
||||
@@ -53,7 +51,7 @@ pub struct Tile<W: LayoutElement> {
|
||||
niri_render_elements! {
|
||||
TileRenderElement<R> => {
|
||||
LayoutElement = LayoutElementRenderElement<R>,
|
||||
SolidColor = RelocateRenderElement<SolidColorRenderElement>,
|
||||
SolidColor = SolidColorRenderElement,
|
||||
Offscreen = RescaleRenderElement<OffscreenRenderElement>,
|
||||
}
|
||||
}
|
||||
@@ -86,16 +84,11 @@ impl<W: LayoutElement> Tile<W> {
|
||||
}
|
||||
|
||||
pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
|
||||
let width = self.border.width();
|
||||
self.border.update(
|
||||
(width, width).into(),
|
||||
self.window.size(),
|
||||
self.window.has_ssd(),
|
||||
);
|
||||
self.border
|
||||
.update(self.window.size(), self.window.has_ssd());
|
||||
self.border.set_active(is_active);
|
||||
|
||||
self.focus_ring
|
||||
.update((0, 0).into(), self.tile_size(), self.has_ssd());
|
||||
self.focus_ring.update(self.tile_size(), self.has_ssd());
|
||||
self.focus_ring.set_active(is_active);
|
||||
|
||||
match &mut self.open_animation {
|
||||
@@ -312,39 +305,25 @@ impl<W: LayoutElement> Tile<W> {
|
||||
.into_iter()
|
||||
.map(Into::into);
|
||||
|
||||
let elem = self.effective_border_width().map(|_| {
|
||||
self.border.render(scale).map(move |elem| {
|
||||
RelocateRenderElement::from_element(
|
||||
elem,
|
||||
location.to_physical_precise_round(scale),
|
||||
Relocate::Relative,
|
||||
)
|
||||
.into()
|
||||
})
|
||||
let elem = self.effective_border_width().map(|width| {
|
||||
self.border
|
||||
.render(location + Point::from((width, width)), scale)
|
||||
.map(Into::into)
|
||||
});
|
||||
let rv = rv.chain(elem.into_iter().flatten());
|
||||
|
||||
let elem = focus_ring.then(|| {
|
||||
self.focus_ring.render(scale).map(move |elem| {
|
||||
RelocateRenderElement::from_element(
|
||||
elem,
|
||||
location.to_physical_precise_round(scale),
|
||||
Relocate::Relative,
|
||||
)
|
||||
.into()
|
||||
})
|
||||
});
|
||||
let elem = focus_ring.then(|| self.focus_ring.render(location, scale).map(Into::into));
|
||||
let rv = rv.chain(elem.into_iter().flatten());
|
||||
|
||||
let elem = self.is_fullscreen.then(|| {
|
||||
let elem = SolidColorRenderElement::from_buffer(
|
||||
SolidColorRenderElement::from_buffer(
|
||||
&self.fullscreen_backdrop,
|
||||
location.to_physical_precise_round(scale),
|
||||
scale,
|
||||
1.,
|
||||
Kind::Unspecified,
|
||||
);
|
||||
RelocateRenderElement::from_element(elem, (0, 0), Relocate::Relative).into()
|
||||
)
|
||||
.into()
|
||||
});
|
||||
rv.chain(elem)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user