forge
Explore
Log in

Don't you dare go Hollow

f58e56d65ab0c41facc72b75e8a85d64b54963efIvan MolodetskikhParent: 51df1ab
src/layout.rsmodified+59 -19
@@ -33,17 +33,20 @@ use std::cmp::{max, min};
33 use std::mem;33 use std::mem;
34 use std::time::Duration;34 use std::time::Duration;
35 35
36+use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
36 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;37 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
37 use smithay::backend::renderer::element::utils::{38 use smithay::backend::renderer::element::utils::{
38 CropRenderElement, Relocate, RelocateRenderElement,39 CropRenderElement, Relocate, RelocateRenderElement,
39 };40 };
40-use smithay::backend::renderer::element::AsRenderElements;41+use smithay::backend::renderer::element::{AsRenderElements, Kind};
41 use smithay::backend::renderer::gles::GlesRenderer;42 use smithay::backend::renderer::gles::GlesRenderer;
43+use smithay::backend::renderer::ImportAll;
42 use smithay::desktop::space::SpaceElement;44 use smithay::desktop::space::SpaceElement;
43 use smithay::desktop::Window;45 use smithay::desktop::Window;
44 use smithay::output::Output;46 use smithay::output::Output;
45 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;47 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
46 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;48 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
49+use smithay::render_elements;
47 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};50 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
48 use smithay::wayland::compositor::{with_states, SurfaceData};51 use smithay::wayland::compositor::{with_states, SurfaceData};
49 use smithay::wayland::dmabuf::DmabufFeedback;52 use smithay::wayland::dmabuf::DmabufFeedback;
@@ -52,6 +55,9 @@ use smithay::wayland::shell::xdg::SurfaceCachedState;
52 use crate::animation::Animation;55 use crate::animation::Animation;
53 56
54 const PADDING: i32 = 16;57 const PADDING: i32 = 16;
58+const FOCUS_RING_PADDING: i32 = 4;
59+const FOCUS_RING_ACTIVE_COLOR: [f32; 4] = [0.5, 0.8, 1.0, 1.0];
60+const FOCUS_RING_INACTIVE_COLOR: [f32; 4] = [0.3, 0.3, 0.3, 1.0];
55 const WIDTH_PROPORTIONS: [ColumnWidth; 3] = [61 const WIDTH_PROPORTIONS: [ColumnWidth; 3] = [
56 ColumnWidth::Proportion(1. / 3.),62 ColumnWidth::Proportion(1. / 3.),
57 ColumnWidth::Proportion(0.5),63 ColumnWidth::Proportion(0.5),
@@ -61,7 +67,12 @@ const WIDTH_PROPORTIONS: [ColumnWidth; 3] = [
61 #[derive(Debug, Clone, PartialEq, Eq)]67 #[derive(Debug, Clone, PartialEq, Eq)]
62 pub struct OutputId(String);68 pub struct OutputId(String);
63 69
64-pub type WorkspaceRenderElement<R> = WaylandSurfaceRenderElement<R>;70+render_elements! {
71+ #[derive(Debug)]
72+ pub WorkspaceRenderElement<R> where R: ImportAll;
73+ Wayland = WaylandSurfaceRenderElement<R>,
74+ FocusRing = SolidColorRenderElement,
75+}
65 pub type MonitorRenderElement<R> =76 pub type MonitorRenderElement<R> =
66 RelocateRenderElement<CropRenderElement<WorkspaceRenderElement<R>>>;77 RelocateRenderElement<CropRenderElement<WorkspaceRenderElement<R>>>;
67 78
@@ -140,6 +151,9 @@ pub struct Workspace<W: LayoutElement> {
140 /// Index of the currently active column, if any.151 /// Index of the currently active column, if any.
141 active_column_idx: usize,152 active_column_idx: usize,
142 153
154+ /// The solid color buffer for the focus ring.
155+ focus_ring: SolidColorBuffer,
156+
143 /// Offset of the view computed from the active column.157 /// Offset of the view computed from the active column.
144 view_offset: i32,158 view_offset: i32,
145 159
@@ -643,16 +657,6 @@ impl<W: LayoutElement> MonitorSet<W> {
643 monitors.iter().find(|monitor| &monitor.output == output)657 monitors.iter().find(|monitor| &monitor.output == output)
644 }658 }
645 659
646- pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {
647- let MonitorSet::Normal { monitors, .. } = self else {
648- return None;
649- };
650-
651- monitors
652- .iter_mut()
653- .find(|monitor| &monitor.output == output)
654- }
655-
656 pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {660 pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {
657 let monitors = if let MonitorSet::Normal { monitors, .. } = self {661 let monitors = if let MonitorSet::Normal { monitors, .. } = self {
658 &monitors[..]662 &monitors[..]
@@ -852,14 +856,18 @@ impl<W: LayoutElement> MonitorSet<W> {
852 856
853 pub fn advance_animations(&mut self, current_time: Duration) {857 pub fn advance_animations(&mut self, current_time: Duration) {
854 match self {858 match self {
855- MonitorSet::Normal { monitors, .. } => {859+ MonitorSet::Normal {
856- for mon in monitors {860+ monitors,
857- mon.advance_animations(current_time);861+ active_monitor_idx,
862+ ..
863+ } => {
864+ for (idx, mon) in monitors.iter_mut().enumerate() {
865+ mon.advance_animations(current_time, idx == *active_monitor_idx);
858 }866 }
859 }867 }
860 MonitorSet::NoOutputs(workspaces) => {868 MonitorSet::NoOutputs(workspaces) => {
861 for ws in workspaces {869 for ws in workspaces {
862- ws.advance_animations(current_time);870+ ws.advance_animations(current_time, false);
863 }871 }
864 }872 }
865 }873 }
@@ -1213,7 +1221,7 @@ impl<W: LayoutElement> Monitor<W> {
1213 Some(&column.windows[column.active_window_idx])1221 Some(&column.windows[column.active_window_idx])
1214 }1222 }
1215 1223
1216- pub fn advance_animations(&mut self, current_time: Duration) {1224+ pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
1217 if let Some(anim) = &mut self.workspace_idx_anim {1225 if let Some(anim) = &mut self.workspace_idx_anim {
1218 anim.set_current_time(current_time);1226 anim.set_current_time(current_time);
1219 if anim.is_done() {1227 if anim.is_done() {
@@ -1223,7 +1231,7 @@ impl<W: LayoutElement> Monitor<W> {
1223 }1231 }
1224 1232
1225 for ws in &mut self.workspaces {1233 for ws in &mut self.workspaces {
1226- ws.advance_animations(current_time);1234+ ws.advance_animations(current_time, is_active);
1227 }1235 }
1228 }1236 }
1229 1237
@@ -1311,6 +1319,7 @@ impl<W: LayoutElement> Workspace<W> {
1311 output: Some(output),1319 output: Some(output),
1312 columns: vec![],1320 columns: vec![],
1313 active_column_idx: 0,1321 active_column_idx: 0,
1322+ focus_ring: SolidColorBuffer::new((0, 0), FOCUS_RING_ACTIVE_COLOR),
1314 view_offset: 0,1323 view_offset: 0,
1315 view_offset_anim: None,1324 view_offset_anim: None,
1316 activate_prev_column_on_removal: false,1325 activate_prev_column_on_removal: false,
@@ -1324,13 +1333,14 @@ impl<W: LayoutElement> Workspace<W> {
1324 view_size: Size::from((1280, 720)),1333 view_size: Size::from((1280, 720)),
1325 columns: vec![],1334 columns: vec![],
1326 active_column_idx: 0,1335 active_column_idx: 0,
1336+ focus_ring: SolidColorBuffer::new((0, 0), FOCUS_RING_ACTIVE_COLOR),
1327 view_offset: 0,1337 view_offset: 0,
1328 view_offset_anim: None,1338 view_offset_anim: None,
1329 activate_prev_column_on_removal: false,1339 activate_prev_column_on_removal: false,
1330 }1340 }
1331 }1341 }
1332 1342
1333- pub fn advance_animations(&mut self, current_time: Duration) {1343+ pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
1334 match &mut self.view_offset_anim {1344 match &mut self.view_offset_anim {
1335 Some(anim) => {1345 Some(anim) => {
1336 anim.set_current_time(current_time);1346 anim.set_current_time(current_time);
@@ -1341,6 +1351,21 @@ impl<W: LayoutElement> Workspace<W> {
1341 }1351 }
1342 None => (),1352 None => (),
1343 }1353 }
1354+
1355+ // This shall one day become a proper animation.
1356+ if !self.columns.is_empty() {
1357+ let col = &self.columns[self.active_column_idx];
1358+ let active_win = &col.windows[col.active_window_idx];
1359+ let geom = active_win.geometry();
1360+ self.focus_ring
1361+ .resize(geom.size + Size::from((FOCUS_RING_PADDING * 2, FOCUS_RING_PADDING * 2)));
1362+
1363+ self.focus_ring.set_color(if is_active {
1364+ FOCUS_RING_ACTIVE_COLOR
1365+ } else {
1366+ FOCUS_RING_INACTIVE_COLOR
1367+ });
1368+ }
1344 }1369 }
1345 1370
1346 fn windows(&self) -> impl Iterator<Item = &W> + '_ {1371 fn windows(&self) -> impl Iterator<Item = &W> + '_ {
@@ -1882,6 +1907,8 @@ impl Workspace<Window> {
1882 // FIXME: fullscreen windows are missing left padding1907 // FIXME: fullscreen windows are missing left padding
1883 win_pos.x -= PADDING;1908 win_pos.x -= PADDING;
1884 }1909 }
1910+
1911+ // Draw the window itself.
1885 rv.extend(active_win.render_elements(1912 rv.extend(active_win.render_elements(
1886 renderer,1913 renderer,
1887 win_pos.to_physical_precise_round(output_scale),1914 win_pos.to_physical_precise_round(output_scale),
@@ -1889,6 +1916,19 @@ impl Workspace<Window> {
1889 1.,1916 1.,
1890 ));1917 ));
1891 1918
1919+ // Draw the focus ring.
1920+ rv.push(
1921+ SolidColorRenderElement::from_buffer(
1922+ &self.focus_ring,
1923+ (win_pos + geom.loc - Point::from((FOCUS_RING_PADDING, FOCUS_RING_PADDING)))
1924+ .to_physical_precise_round(output_scale),
1925+ output_scale,
1926+ 1.,
1927+ Kind::Unspecified,
1928+ )
1929+ .into(),
1930+ );
1931+
1892 let mut x = PADDING;1932 let mut x = PADDING;
1893 for col in &self.columns {1933 for col in &self.columns {
1894 let mut y = PADDING;1934 let mut y = PADDING;
src/niri.rsmodified+1 -2
@@ -951,8 +951,7 @@ impl Niri {
951 assert!(!state.waiting_for_vblank);951 assert!(!state.waiting_for_vblank);
952 952
953 // Advance the animations.953 // Advance the animations.
954- let mon = self.monitor_set.monitor_for_output_mut(output).unwrap();954+ self.monitor_set.advance_animations(presentation_time);
955- mon.advance_animations(presentation_time);
956 955
957 // Render the elements.956 // Render the elements.
958 let elements = self.render(backend.renderer(), output, true);957 let elements = self.render(backend.renderer(), output, true);