Render workspaces separately with gaps between
Browse files at this commit9571d149b2cecd3df8ba3f90f0af296e9f69af6eParent: 99358e35 changed files +232 -86
- niri-config/src/lib.rs +11 -1
- niri-visual-tests/src/cases/layout.rs +1 -0
- src/layout/mod.rs +1 -1
- src/layout/monitor.rs +91 -56
- src/niri.rs +128 -28
niri-config/src/lib.rsmodified+11 -1
| @@ -23,7 +23,8 @@ use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; | ||
| 23 | 23 | use smithay::input::keyboard::{Keysym, XkbConfig}; |
| 24 | 24 | use smithay::reexports::input; |
| 25 | 25 | |
| 26 | -pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.2, 0.2, 0.2, 1.]); | |
| 26 | +pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.25, 0.25, 0.25, 1.]); | |
| 27 | +pub const DEFAULT_BACKDROP_COLOR: Color = Color::from_array_unpremul([0.15, 0.15, 0.15, 1.]); | |
| 27 | 28 | |
| 28 | 29 | pub mod layer_rule; |
| 29 | 30 | |
| @@ -444,6 +445,8 @@ pub struct Output { | ||
| 444 | 445 | pub focus_at_startup: bool, |
| 445 | 446 | #[knuffel(child, default = DEFAULT_BACKGROUND_COLOR)] |
| 446 | 447 | pub background_color: Color, |
| 448 | + #[knuffel(child, default = DEFAULT_BACKDROP_COLOR)] | |
| 449 | + pub backdrop_color: Color, | |
| 447 | 450 | } |
| 448 | 451 | |
| 449 | 452 | impl Output { |
| @@ -472,6 +475,7 @@ impl Default for Output { | ||
| 472 | 475 | mode: None, |
| 473 | 476 | variable_refresh_rate: None, |
| 474 | 477 | background_color: DEFAULT_BACKGROUND_COLOR, |
| 478 | + backdrop_color: DEFAULT_BACKDROP_COLOR, | |
| 475 | 479 | } |
| 476 | 480 | } |
| 477 | 481 | } |
| @@ -4127,6 +4131,12 @@ mod tests { | ||
| 4127 | 4131 | b: 0.4, |
| 4128 | 4132 | a: 1.0, |
| 4129 | 4133 | }, |
| 4134 | + backdrop_color: Color { | |
| 4135 | + r: 0.15, | |
| 4136 | + g: 0.15, | |
| 4137 | + b: 0.15, | |
| 4138 | + a: 1.0, | |
| 4139 | + }, | |
| 4130 | 4140 | }, |
| 4131 | 4141 | ], |
| 4132 | 4142 | ), |
niri-visual-tests/src/cases/layout.rsmodified+1 -0
| @@ -266,6 +266,7 @@ impl TestCase for Layout { | ||
| 266 | 266 | .monitor_for_output(&self.output) |
| 267 | 267 | .unwrap() |
| 268 | 268 | .render_elements(renderer, RenderTarget::Output, true) |
| 269 | + .flat_map(|(_, iter)| iter) | |
| 269 | 270 | .map(|elem| Box::new(elem) as _) |
| 270 | 271 | .collect() |
| 271 | 272 | } |
src/layout/mod.rsmodified+1 -1
| @@ -2279,7 +2279,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2279 | 2279 | ) -> Option<(&W, HitType)> { |
| 2280 | 2280 | if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { |
| 2281 | 2281 | if move_.output == *output { |
| 2282 | - let tile_pos = move_.tile_render_location(1.); | |
| 2282 | + let tile_pos = move_.tile_render_location(); | |
| 2283 | 2283 | HitType::hit_tile(&move_.tile, tile_pos, pos_within_output) |
| 2284 | 2284 | } else { |
| 2285 | 2285 | None |
src/layout/monitor.rsmodified+91 -56
| @@ -25,7 +25,9 @@ use crate::render_helpers::renderer::NiriRenderer; | ||
| 25 | 25 | use crate::render_helpers::RenderTarget; |
| 26 | 26 | use crate::rubber_band::RubberBand; |
| 27 | 27 | use crate::utils::transaction::Transaction; |
| 28 | -use crate::utils::{output_size, ResizeEdge}; | |
| 28 | +use crate::utils::{ | |
| 29 | + output_size, round_logical_in_physical, round_logical_in_physical_max1, ResizeEdge, | |
| 30 | +}; | |
| 29 | 31 | |
| 30 | 32 | /// Amount of touchpad movement to scroll the height of one workspace. |
| 31 | 33 | const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.; |
| @@ -943,6 +945,23 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 943 | 945 | self.active_workspace_ref().active_tile_visual_rectangle() |
| 944 | 946 | } |
| 945 | 947 | |
| 948 | + fn workspace_size(&self, zoom: f64) -> Size<f64, Logical> { | |
| 949 | + let ws_size = self.view_size.upscale(zoom); | |
| 950 | + let scale = self.scale.fractional_scale(); | |
| 951 | + ws_size.to_physical_precise_ceil(scale).to_logical(scale) | |
| 952 | + } | |
| 953 | + | |
| 954 | + fn workspace_gap(&self, zoom: f64) -> f64 { | |
| 955 | + let scale = self.scale.fractional_scale(); | |
| 956 | + let gap = self.view_size.h * 0.1 * zoom; | |
| 957 | + round_logical_in_physical_max1(scale, gap) | |
| 958 | + } | |
| 959 | + | |
| 960 | + fn workspace_size_with_gap(&self, zoom: f64) -> Size<f64, Logical> { | |
| 961 | + let gap = self.workspace_gap(zoom); | |
| 962 | + self.workspace_size(zoom) + Size::from((0., gap)) | |
| 963 | + } | |
| 964 | + | |
| 946 | 965 | pub fn workspace_render_idx(&self) -> f64 { |
| 947 | 966 | if let Some(switch) = &self.workspace_switch { |
| 948 | 967 | switch.current_idx() |
| @@ -953,17 +972,19 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 953 | 972 | |
| 954 | 973 | pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> { |
| 955 | 974 | let scale = self.scale.fractional_scale(); |
| 956 | - let size = self.view_size; | |
| 975 | + let zoom = 1.; | |
| 957 | 976 | |
| 958 | - // Ceil the workspace size in physical pixels. | |
| 959 | - let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale); | |
| 977 | + let ws_size = self.workspace_size(zoom); | |
| 978 | + let gap = self.workspace_gap(zoom); | |
| 979 | + let ws_height_with_gap = ws_size.h + gap; | |
| 960 | 980 | |
| 961 | - let first_ws_y = -self.workspace_render_idx() * ws_size.h; | |
| 981 | + let first_ws_y = -self.workspace_render_idx() * ws_height_with_gap; | |
| 982 | + let first_ws_y = round_logical_in_physical(scale, first_ws_y); | |
| 962 | 983 | |
| 963 | - (0..self.workspaces.len()).map(move |idx| { | |
| 964 | - let y = first_ws_y + idx as f64 * ws_size.h; | |
| 984 | + // Return position for one-past-last workspace too. | |
| 985 | + (0..=self.workspaces.len()).map(move |idx| { | |
| 986 | + let y = first_ws_y + idx as f64 * ws_height_with_gap; | |
| 965 | 987 | let loc = Point::from((0., y)); |
| 966 | - let loc = loc.to_physical_precise_round(scale).to_logical(scale); | |
| 967 | 988 | Rectangle::new(loc, ws_size) |
| 968 | 989 | }) |
| 969 | 990 | } |
| @@ -1031,7 +1052,12 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1031 | 1052 | renderer: &'a mut R, |
| 1032 | 1053 | target: RenderTarget, |
| 1033 | 1054 | focus_ring: bool, |
| 1034 | - ) -> impl Iterator<Item = MonitorRenderElement<R>> + 'a { | |
| 1055 | + ) -> impl Iterator< | |
| 1056 | + Item = ( | |
| 1057 | + Rectangle<f64, Logical>, | |
| 1058 | + impl Iterator<Item = MonitorRenderElement<R>> + 'a, | |
| 1059 | + ), | |
| 1060 | + > { | |
| 1035 | 1061 | let _span = tracy_client::span!("Monitor::render_elements"); |
| 1036 | 1062 | |
| 1037 | 1063 | let scale = self.scale.fractional_scale(); |
| @@ -1072,45 +1098,45 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1072 | 1098 | } |
| 1073 | 1099 | } |
| 1074 | 1100 | |
| 1075 | - self.workspaces_with_render_geo() | |
| 1076 | - .flat_map(move |(ws, geo)| { | |
| 1077 | - let map_ws_contents = move |elem: WorkspaceRenderElement<R>| { | |
| 1101 | + self.workspaces_with_render_geo().map(move |(ws, geo)| { | |
| 1102 | + let map_ws_contents = move |elem: WorkspaceRenderElement<R>| { | |
| 1103 | + let elem = CropRenderElement::from_element(elem, scale, crop_bounds)?; | |
| 1104 | + let elem = MonitorInnerRenderElement::Workspace(elem); | |
| 1105 | + Some(elem) | |
| 1106 | + }; | |
| 1107 | + | |
| 1108 | + let (floating, scrolling) = ws.render_elements(renderer, target, focus_ring); | |
| 1109 | + let floating = floating.filter_map(map_ws_contents); | |
| 1110 | + let scrolling = scrolling.filter_map(map_ws_contents); | |
| 1111 | + | |
| 1112 | + let hint = if matches!(insert_hint, Some((hint_ws_id, _)) if hint_ws_id == ws.id()) { | |
| 1113 | + let iter = insert_hint.take().unwrap().1; | |
| 1114 | + let iter = iter.filter_map(move |elem| { | |
| 1078 | 1115 | let elem = CropRenderElement::from_element(elem, scale, crop_bounds)?; |
| 1079 | - let elem = MonitorInnerRenderElement::Workspace(elem); | |
| 1116 | + let elem = MonitorInnerRenderElement::InsertHint(elem); | |
| 1080 | 1117 | Some(elem) |
| 1081 | - }; | |
| 1082 | - | |
| 1083 | - let (floating, scrolling) = ws.render_elements(renderer, target, focus_ring); | |
| 1084 | - let floating = floating.filter_map(map_ws_contents); | |
| 1085 | - let scrolling = scrolling.filter_map(map_ws_contents); | |
| 1086 | - | |
| 1087 | - let hint = if matches!(insert_hint, Some((hint_ws_id, _)) if hint_ws_id == ws.id()) | |
| 1088 | - { | |
| 1089 | - let iter = insert_hint.take().unwrap().1; | |
| 1090 | - let iter = iter.filter_map(move |elem| { | |
| 1091 | - let elem = CropRenderElement::from_element(elem, scale, crop_bounds)?; | |
| 1092 | - let elem = MonitorInnerRenderElement::InsertHint(elem); | |
| 1093 | - Some(elem) | |
| 1094 | - }); | |
| 1095 | - Some(iter) | |
| 1096 | - } else { | |
| 1097 | - None | |
| 1098 | - }; | |
| 1099 | - let hint = hint.into_iter().flatten(); | |
| 1100 | - | |
| 1101 | - let iter = floating.chain(hint).chain(scrolling); | |
| 1102 | - | |
| 1103 | - iter.map(move |elem| { | |
| 1104 | - RelocateRenderElement::from_element( | |
| 1105 | - elem, | |
| 1106 | - // The offset we get from workspaces_with_render_positions() is already | |
| 1107 | - // rounded to physical pixels, but it's in the logical coordinate | |
| 1108 | - // space, so we need to convert it to physical. | |
| 1109 | - geo.loc.to_physical_precise_round(scale), | |
| 1110 | - Relocate::Relative, | |
| 1111 | - ) | |
| 1112 | - }) | |
| 1113 | - }) | |
| 1118 | + }); | |
| 1119 | + Some(iter) | |
| 1120 | + } else { | |
| 1121 | + None | |
| 1122 | + }; | |
| 1123 | + let hint = hint.into_iter().flatten(); | |
| 1124 | + | |
| 1125 | + let iter = floating.chain(hint).chain(scrolling); | |
| 1126 | + | |
| 1127 | + let iter = iter.map(move |elem| { | |
| 1128 | + RelocateRenderElement::from_element( | |
| 1129 | + elem, | |
| 1130 | + // The offset we get from workspaces_with_render_positions() is already | |
| 1131 | + // rounded to physical pixels, but it's in the logical coordinate | |
| 1132 | + // space, so we need to convert it to physical. | |
| 1133 | + geo.loc.to_physical_precise_round(scale), | |
| 1134 | + Relocate::Relative, | |
| 1135 | + ) | |
| 1136 | + }); | |
| 1137 | + | |
| 1138 | + (geo, iter) | |
| 1139 | + }) | |
| 1114 | 1140 | } |
| 1115 | 1141 | |
| 1116 | 1142 | pub fn workspace_switch_gesture_begin(&mut self, is_touchpad: bool) { |
| @@ -1133,7 +1159,7 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1133 | 1159 | timestamp: Duration, |
| 1134 | 1160 | is_touchpad: bool, |
| 1135 | 1161 | ) -> Option<bool> { |
| 1136 | - let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | |
| 1162 | + let Some(WorkspaceSwitch::Gesture(gesture)) = &self.workspace_switch else { | |
| 1137 | 1163 | return None; |
| 1138 | 1164 | }; |
| 1139 | 1165 | |
| @@ -1141,13 +1167,18 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1141 | 1167 | return None; |
| 1142 | 1168 | } |
| 1143 | 1169 | |
| 1144 | - gesture.tracker.push(delta_y, timestamp); | |
| 1145 | - | |
| 1146 | 1170 | let total_height = if gesture.is_touchpad { |
| 1147 | 1171 | WORKSPACE_GESTURE_MOVEMENT |
| 1148 | 1172 | } else { |
| 1149 | - self.workspaces[0].view_size().h | |
| 1173 | + self.workspace_size_with_gap(1.).h | |
| 1174 | + }; | |
| 1175 | + | |
| 1176 | + let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | |
| 1177 | + return None; | |
| 1150 | 1178 | }; |
| 1179 | + | |
| 1180 | + gesture.tracker.push(delta_y, timestamp); | |
| 1181 | + | |
| 1151 | 1182 | let pos = gesture.tracker.pos() / total_height; |
| 1152 | 1183 | |
| 1153 | 1184 | let (min, max) = gesture.min_max(self.workspaces.len()); |
| @@ -1163,7 +1194,7 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1163 | 1194 | } |
| 1164 | 1195 | |
| 1165 | 1196 | pub fn workspace_switch_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { |
| 1166 | - let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | |
| 1197 | + let Some(WorkspaceSwitch::Gesture(gesture)) = &self.workspace_switch else { | |
| 1167 | 1198 | return false; |
| 1168 | 1199 | }; |
| 1169 | 1200 | |
| @@ -1171,16 +1202,20 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 1171 | 1202 | return false; |
| 1172 | 1203 | } |
| 1173 | 1204 | |
| 1174 | - // Take into account any idle time between the last event and now. | |
| 1175 | - let now = self.clock.now_unadjusted(); | |
| 1176 | - gesture.tracker.push(0., now); | |
| 1177 | - | |
| 1178 | 1205 | let total_height = if gesture.is_touchpad { |
| 1179 | 1206 | WORKSPACE_GESTURE_MOVEMENT |
| 1180 | 1207 | } else { |
| 1181 | - self.workspaces[0].view_size().h | |
| 1208 | + self.workspace_size_with_gap(1.).h | |
| 1209 | + }; | |
| 1210 | + | |
| 1211 | + let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | |
| 1212 | + return false; | |
| 1182 | 1213 | }; |
| 1183 | 1214 | |
| 1215 | + // Take into account any idle time between the last event and now. | |
| 1216 | + let now = self.clock.now_unadjusted(); | |
| 1217 | + gesture.tracker.push(0., now); | |
| 1218 | + | |
| 1184 | 1219 | let mut velocity = gesture.tracker.velocity() / total_height; |
| 1185 | 1220 | let current_pos = gesture.tracker.pos() / total_height; |
| 1186 | 1221 | let pos = gesture.tracker.projected_end_pos() / total_height; |
src/niri.rsmodified+128 -28
| @@ -15,7 +15,7 @@ use anyhow::{bail, ensure, Context}; | ||
| 15 | 15 | use calloop::futures::Scheduler; |
| 16 | 16 | use niri_config::{ |
| 17 | 17 | Config, FloatOrInt, Key, Modifiers, OutputName, PreviewRender, TrackLayout, |
| 18 | - WarpMouseToFocusMode, WorkspaceReference, DEFAULT_BACKGROUND_COLOR, | |
| 18 | + WarpMouseToFocusMode, WorkspaceReference, DEFAULT_BACKDROP_COLOR, DEFAULT_BACKGROUND_COLOR, | |
| 19 | 19 | }; |
| 20 | 20 | use smithay::backend::allocator::Fourcc; |
| 21 | 21 | use smithay::backend::input::Keycode; |
| @@ -26,10 +26,12 @@ use smithay::backend::renderer::element::surface::{ | ||
| 26 | 26 | render_elements_from_surface_tree, WaylandSurfaceRenderElement, |
| 27 | 27 | }; |
| 28 | 28 | use smithay::backend::renderer::element::utils::{ |
| 29 | - select_dmabuf_feedback, Relocate, RelocateRenderElement, | |
| 29 | + select_dmabuf_feedback, CropRenderElement, Relocate, RelocateRenderElement, | |
| 30 | + RescaleRenderElement, | |
| 30 | 31 | }; |
| 31 | 32 | use smithay::backend::renderer::element::{ |
| 32 | - default_primary_scanout_output_compare, Id, Kind, PrimaryScanoutOutput, RenderElementStates, | |
| 33 | + default_primary_scanout_output_compare, Element, Id, Kind, PrimaryScanoutOutput, | |
| 34 | + RenderElementStates, | |
| 33 | 35 | }; |
| 34 | 36 | use smithay::backend::renderer::gles::GlesRenderer; |
| 35 | 37 | use smithay::backend::renderer::sync::SyncPoint; |
| @@ -428,6 +430,7 @@ pub struct OutputState { | ||
| 428 | 430 | /// Solid color buffer for the background that we use instead of clearing to avoid damage |
| 429 | 431 | /// tracking issues and make screenshots easier. |
| 430 | 432 | pub background_buffer: SolidColorBuffer, |
| 433 | + pub backdrop_buffer: SolidColorBuffer, | |
| 431 | 434 | pub lock_render_state: LockRenderState, |
| 432 | 435 | pub lock_surface: Option<LockSurface>, |
| 433 | 436 | pub lock_color_buffer: SolidColorBuffer, |
| @@ -1465,11 +1468,22 @@ impl State { | ||
| 1465 | 1468 | background_color[3] = 1.; |
| 1466 | 1469 | let background_color = Color32F::from(background_color); |
| 1467 | 1470 | |
| 1471 | + let mut backdrop_color = config | |
| 1472 | + .map(|c| c.backdrop_color) | |
| 1473 | + .unwrap_or(DEFAULT_BACKDROP_COLOR) | |
| 1474 | + .to_array_unpremul(); | |
| 1475 | + backdrop_color[3] = 1.; | |
| 1476 | + let backdrop_color = Color32F::from(backdrop_color); | |
| 1477 | + | |
| 1468 | 1478 | if let Some(state) = self.niri.output_state.get_mut(output) { |
| 1469 | 1479 | if state.background_buffer.color() != background_color { |
| 1470 | 1480 | state.background_buffer.set_color(background_color); |
| 1471 | 1481 | recolored_outputs.push(output.clone()); |
| 1472 | 1482 | } |
| 1483 | + if state.backdrop_buffer.color() != backdrop_color { | |
| 1484 | + state.backdrop_buffer.set_color(backdrop_color); | |
| 1485 | + recolored_outputs.push(output.clone()); | |
| 1486 | + } | |
| 1473 | 1487 | } |
| 1474 | 1488 | } |
| 1475 | 1489 | |
| @@ -2640,6 +2654,12 @@ impl Niri { | ||
| 2640 | 2654 | .to_array_unpremul(); |
| 2641 | 2655 | background_color[3] = 1.; |
| 2642 | 2656 | |
| 2657 | + let mut backdrop_color = c | |
| 2658 | + .map(|c| c.backdrop_color) | |
| 2659 | + .unwrap_or(DEFAULT_BACKDROP_COLOR) | |
| 2660 | + .to_array_unpremul(); | |
| 2661 | + backdrop_color[3] = 1.; | |
| 2662 | + | |
| 2643 | 2663 | // FIXME: fix winit damage on other transforms. |
| 2644 | 2664 | if name.connector == "winit" { |
| 2645 | 2665 | transform = Transform::Flipped180; |
| @@ -2673,6 +2693,7 @@ impl Niri { | ||
| 2673 | 2693 | last_drm_sequence: None, |
| 2674 | 2694 | frame_callback_sequence: 0, |
| 2675 | 2695 | background_buffer: SolidColorBuffer::new(size, background_color), |
| 2696 | + backdrop_buffer: SolidColorBuffer::new(size, backdrop_color), | |
| 2676 | 2697 | lock_render_state, |
| 2677 | 2698 | lock_surface: None, |
| 2678 | 2699 | lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED), |
| @@ -2777,6 +2798,7 @@ impl Niri { | ||
| 2777 | 2798 | |
| 2778 | 2799 | if let Some(state) = self.output_state.get_mut(output) { |
| 2779 | 2800 | state.background_buffer.resize(output_size); |
| 2801 | + state.backdrop_buffer.resize(output_size); | |
| 2780 | 2802 | |
| 2781 | 2803 | state.lock_color_buffer.resize(output_size); |
| 2782 | 2804 | if let Some(lock_surface) = &state.lock_surface { |
| @@ -2894,11 +2916,18 @@ impl Niri { | ||
| 2894 | 2916 | layers |
| 2895 | 2917 | .layers_on(layer) |
| 2896 | 2918 | .rev() |
| 2897 | - .find_map(|layer| { | |
| 2898 | - let layer_pos_within_output = | |
| 2899 | - layers.layer_geometry(layer).unwrap().loc.to_f64(); | |
| 2919 | + .find_map(|layer_surface| { | |
| 2920 | + let mut layer_pos_within_output = | |
| 2921 | + layers.layer_geometry(layer_surface).unwrap().loc.to_f64(); | |
| 2922 | + | |
| 2923 | + // Background and bottom layers move together with the workspaces. | |
| 2924 | + let mon = self.layout.monitor_for_output(output)?; | |
| 2925 | + let (_, geo) = mon.workspace_under(pos_within_output)?; | |
| 2926 | + layer_pos_within_output += geo.loc; | |
| 2927 | + | |
| 2900 | 2928 | let surface_type = WindowSurfaceType::POPUP | WindowSurfaceType::SUBSURFACE; |
| 2901 | - layer.surface_under(pos_within_output - layer_pos_within_output, surface_type) | |
| 2929 | + layer_surface | |
| 2930 | + .surface_under(pos_within_output - layer_pos_within_output, surface_type) | |
| 2902 | 2931 | }) |
| 2903 | 2932 | .is_some() |
| 2904 | 2933 | }; |
| @@ -3001,20 +3030,29 @@ impl Niri { | ||
| 3001 | 3030 | layers |
| 3002 | 3031 | .layers_on(layer) |
| 3003 | 3032 | .rev() |
| 3004 | - .find_map(|layer| { | |
| 3005 | - let layer_pos_within_output = | |
| 3006 | - layers.layer_geometry(layer).unwrap().loc.to_f64(); | |
| 3033 | + .find_map(|layer_surface| { | |
| 3034 | + let mut layer_pos_within_output = | |
| 3035 | + layers.layer_geometry(layer_surface).unwrap().loc.to_f64(); | |
| 3036 | + | |
| 3037 | + // Background and bottom layers move together with the workspaces. | |
| 3038 | + if matches!(layer, Layer::Background | Layer::Bottom) { | |
| 3039 | + let mon = self.layout.monitor_for_output(output)?; | |
| 3040 | + let (_, geo) = mon.workspace_under(pos_within_output)?; | |
| 3041 | + layer_pos_within_output += geo.loc; | |
| 3042 | + } | |
| 3043 | + | |
| 3007 | 3044 | let surface_type = if popup { |
| 3008 | 3045 | WindowSurfaceType::POPUP |
| 3009 | 3046 | } else { |
| 3010 | 3047 | WindowSurfaceType::TOPLEVEL |
| 3011 | 3048 | } | WindowSurfaceType::SUBSURFACE; |
| 3012 | - layer | |
| 3049 | + | |
| 3050 | + layer_surface | |
| 3013 | 3051 | .surface_under(pos_within_output - layer_pos_within_output, surface_type) |
| 3014 | 3052 | .map(|(surface, pos_within_layer)| { |
| 3015 | 3053 | ( |
| 3016 | 3054 | (surface, pos_within_layer.to_f64() + layer_pos_within_output), |
| 3017 | - layer, | |
| 3055 | + layer_surface, | |
| 3018 | 3056 | ) |
| 3019 | 3057 | }) |
| 3020 | 3058 | }) |
| @@ -3791,10 +3829,18 @@ impl Niri { | ||
| 3791 | 3829 | return elements; |
| 3792 | 3830 | } |
| 3793 | 3831 | |
| 3794 | - // Prepare the background element. | |
| 3832 | + // Prepare the background elements. | |
| 3795 | 3833 | let state = self.output_state.get(output).unwrap(); |
| 3834 | + let background_buffer = state.background_buffer.clone(); | |
| 3796 | 3835 | let background = SolidColorRenderElement::from_buffer( |
| 3797 | - &state.background_buffer, | |
| 3836 | + &background_buffer, | |
| 3837 | + (0, 0), | |
| 3838 | + output_scale, | |
| 3839 | + 1., | |
| 3840 | + Kind::Unspecified, | |
| 3841 | + ); | |
| 3842 | + let backdrop = SolidColorRenderElement::from_buffer( | |
| 3843 | + &state.backdrop_buffer, | |
| 3798 | 3844 | (0, 0), |
| 3799 | 3845 | output_scale, |
| 3800 | 3846 | 1., |
| @@ -3811,8 +3857,8 @@ impl Niri { | ||
| 3811 | 3857 | .map(OutputRenderElements::from), |
| 3812 | 3858 | ); |
| 3813 | 3859 | |
| 3814 | - // Add the background for outputs that were connected while the screenshot UI was open. | |
| 3815 | - elements.push(background); | |
| 3860 | + // Add the backdrop for outputs that were connected while the screenshot UI was open. | |
| 3861 | + elements.push(backdrop); | |
| 3816 | 3862 | |
| 3817 | 3863 | if self.debug_draw_opaque_regions { |
| 3818 | 3864 | draw_opaque_regions(&mut elements, output_scale); |
| @@ -3831,7 +3877,11 @@ impl Niri { | ||
| 3831 | 3877 | |
| 3832 | 3878 | // Get monitor elements. |
| 3833 | 3879 | let mon = self.layout.monitor_for_output(output).unwrap(); |
| 3834 | - let monitor_elements: Vec<_> = mon.render_elements(renderer, target, focus_ring).collect(); | |
| 3880 | + let zoom = 1.; | |
| 3881 | + let monitor_elements = Vec::from_iter( | |
| 3882 | + mon.render_elements(renderer, target, focus_ring) | |
| 3883 | + .map(|(geo, iter)| (geo, Vec::from_iter(iter))), | |
| 3884 | + ); | |
| 3835 | 3885 | let int_move_elements: Vec<_> = self |
| 3836 | 3886 | .layout |
| 3837 | 3887 | .render_interactive_move_for_output(renderer, output, target) |
| @@ -3854,24 +3904,31 @@ impl Niri { | ||
| 3854 | 3904 | extend_from_layer(&mut layer_elems, Layer::Top); |
| 3855 | 3905 | let top_layer = layer_elems; |
| 3856 | 3906 | |
| 3857 | - // Collect all other layer-shell elements. | |
| 3858 | - let mut layer_elems = SplitElements::default(); | |
| 3859 | - extend_from_layer(&mut layer_elems, Layer::Bottom); | |
| 3860 | - extend_from_layer(&mut layer_elems, Layer::Background); | |
| 3861 | - | |
| 3862 | 3907 | // When rendering above the top layer, we put the regular monitor elements first. |
| 3863 | 3908 | // Otherwise, we will render all layer-shell pop-ups and the top layer on top. |
| 3864 | 3909 | if mon.render_above_top_layer() { |
| 3910 | + // Collect all other layer-shell elements. | |
| 3911 | + let mut layer_elems = SplitElements::default(); | |
| 3912 | + extend_from_layer(&mut layer_elems, Layer::Bottom); | |
| 3913 | + extend_from_layer(&mut layer_elems, Layer::Background); | |
| 3914 | + | |
| 3865 | 3915 | elements.extend( |
| 3866 | 3916 | int_move_elements |
| 3867 | 3917 | .into_iter() |
| 3868 | 3918 | .map(OutputRenderElements::from), |
| 3869 | 3919 | ); |
| 3870 | - elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from)); | |
| 3920 | + elements.extend( | |
| 3921 | + monitor_elements | |
| 3922 | + .into_iter() | |
| 3923 | + .flat_map(|(_ws_geo, iter)| iter) | |
| 3924 | + .map(OutputRenderElements::from), | |
| 3925 | + ); | |
| 3871 | 3926 | |
| 3872 | 3927 | elements.extend(top_layer.into_iter().map(OutputRenderElements::from)); |
| 3873 | 3928 | elements.extend(layer_elems.popups.drain(..).map(OutputRenderElements::from)); |
| 3874 | 3929 | elements.extend(layer_elems.normal.drain(..).map(OutputRenderElements::from)); |
| 3930 | + | |
| 3931 | + elements.push(OutputRenderElements::from(background)); | |
| 3875 | 3932 | } else { |
| 3876 | 3933 | elements.extend(top_layer.into_iter().map(OutputRenderElements::from)); |
| 3877 | 3934 | |
| @@ -3881,15 +3938,40 @@ impl Niri { | ||
| 3881 | 3938 | .map(OutputRenderElements::from), |
| 3882 | 3939 | ); |
| 3883 | 3940 | |
| 3884 | - elements.extend(layer_elems.popups.drain(..).map(OutputRenderElements::from)); | |
| 3941 | + for (ws_geo, ws_elements) in monitor_elements { | |
| 3942 | + // Collect all other layer-shell elements. | |
| 3943 | + let mut layer_elems = SplitElements::default(); | |
| 3944 | + extend_from_layer(&mut layer_elems, Layer::Bottom); | |
| 3945 | + extend_from_layer(&mut layer_elems, Layer::Background); | |
| 3946 | + | |
| 3947 | + elements.extend( | |
| 3948 | + layer_elems | |
| 3949 | + .popups | |
| 3950 | + .into_iter() | |
| 3951 | + .filter_map(|elem| scale_relocate_crop(elem, output_scale, zoom, ws_geo)) | |
| 3952 | + .map(OutputRenderElements::from), | |
| 3953 | + ); | |
| 3885 | 3954 | |
| 3886 | - elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from)); | |
| 3955 | + elements.extend(ws_elements.into_iter().map(OutputRenderElements::from)); | |
| 3887 | 3956 | |
| 3888 | - elements.extend(layer_elems.normal.drain(..).map(OutputRenderElements::from)); | |
| 3957 | + elements.extend( | |
| 3958 | + layer_elems | |
| 3959 | + .normal | |
| 3960 | + .into_iter() | |
| 3961 | + .filter_map(|elem| scale_relocate_crop(elem, output_scale, zoom, ws_geo)) | |
| 3962 | + .map(OutputRenderElements::from), | |
| 3963 | + ); | |
| 3964 | + | |
| 3965 | + if let Some(elem) = | |
| 3966 | + scale_relocate_crop(background.clone(), output_scale, zoom, ws_geo) | |
| 3967 | + { | |
| 3968 | + elements.push(OutputRenderElements::from(elem)); | |
| 3969 | + } | |
| 3970 | + } | |
| 3889 | 3971 | } |
| 3890 | 3972 | |
| 3891 | - // Then the background. | |
| 3892 | - elements.push(background); | |
| 3973 | + // Then the backdrop. | |
| 3974 | + elements.push(backdrop); | |
| 3893 | 3975 | |
| 3894 | 3976 | if self.debug_draw_opaque_regions { |
| 3895 | 3977 | draw_opaque_regions(&mut elements, output_scale); |
| @@ -5712,14 +5794,32 @@ impl ClientData for ClientState { | ||
| 5712 | 5794 | fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {} |
| 5713 | 5795 | } |
| 5714 | 5796 | |
| 5797 | +fn scale_relocate_crop<E: Element>( | |
| 5798 | + elem: E, | |
| 5799 | + output_scale: Scale<f64>, | |
| 5800 | + zoom: f64, | |
| 5801 | + ws_geo: Rectangle<f64, Logical>, | |
| 5802 | +) -> Option<CropRenderElement<RelocateRenderElement<RescaleRenderElement<E>>>> { | |
| 5803 | + let ws_geo = ws_geo.to_physical_precise_round(output_scale); | |
| 5804 | + let elem = RescaleRenderElement::from_element(elem, Point::from((0, 0)), zoom); | |
| 5805 | + let elem = RelocateRenderElement::from_element(elem, ws_geo.loc, Relocate::Relative); | |
| 5806 | + CropRenderElement::from_element(elem, output_scale, ws_geo) | |
| 5807 | +} | |
| 5808 | + | |
| 5715 | 5809 | niri_render_elements! { |
| 5716 | 5810 | OutputRenderElements<R> => { |
| 5717 | 5811 | Monitor = MonitorRenderElement<R>, |
| 5718 | 5812 | Tile = TileRenderElement<R>, |
| 5719 | 5813 | LayerSurface = LayerSurfaceRenderElement<R>, |
| 5814 | + RelocatedLayerSurface = CropRenderElement<RelocateRenderElement<RescaleRenderElement< | |
| 5815 | + LayerSurfaceRenderElement<R> | |
| 5816 | + >>>, | |
| 5720 | 5817 | Wayland = WaylandSurfaceRenderElement<R>, |
| 5721 | 5818 | NamedPointer = MemoryRenderBufferRenderElement<R>, |
| 5722 | 5819 | SolidColor = SolidColorRenderElement, |
| 5820 | + RelocatedSolidColor = CropRenderElement<RelocateRenderElement<RescaleRenderElement< | |
| 5821 | + SolidColorRenderElement | |
| 5822 | + >>>, | |
| 5723 | 5823 | ScreenshotUi = ScreenshotUiRenderElement, |
| 5724 | 5824 | Texture = PrimaryGpuTextureRenderElement, |
| 5725 | 5825 | // Used for the CPU-rendered panels. |