forge
Explore
Log in

Don't you dare go Hollow

Add option to rotate outputs

Browse files at this commit

962e159db61dc6c7822aa899b1d9dc86fb6a0de5axtlossParent: 11bff3a
niri-config/src/lib.rsmodified+54 -0
@@ -187,6 +187,8 @@ pub struct Output {
187 pub name: String,187 pub name: String,
188 #[knuffel(child, unwrap(argument), default = 1.)]188 #[knuffel(child, unwrap(argument), default = 1.)]
189 pub scale: f64,189 pub scale: f64,
190+ #[knuffel(child, unwrap(argument, str), default = Transform::Normal)]
191+ pub transform: Transform,
190 #[knuffel(child)]192 #[knuffel(child)]
191 pub position: Option<Position>,193 pub position: Option<Position>,
192 #[knuffel(child, unwrap(argument, str))]194 #[knuffel(child, unwrap(argument, str))]
@@ -199,12 +201,62 @@ impl Default for Output {
199 off: false,201 off: false,
200 name: String::new(),202 name: String::new(),
201 scale: 1.,203 scale: 1.,
204+ transform: Transform::Normal,
202 position: None,205 position: None,
203 mode: None,206 mode: None,
204 }207 }
205 }208 }
206 }209 }
207 210
211+/// Output transform, which goes counter-clockwise.
212+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
213+pub enum Transform {
214+ Normal,
215+ _90,
216+ _180,
217+ _270,
218+ Flipped,
219+ Flipped90,
220+ Flipped180,
221+ Flipped270,
222+}
223+
224+impl FromStr for Transform {
225+ type Err = miette::Error;
226+
227+ fn from_str(s: &str) -> Result<Self, Self::Err> {
228+ match s {
229+ "normal" => Ok(Self::Normal),
230+ "90" => Ok(Self::_90),
231+ "180" => Ok(Self::_180),
232+ "270" => Ok(Self::_270),
233+ "flipped" => Ok(Self::Flipped),
234+ "flipped-90" => Ok(Self::Flipped90),
235+ "flipped-180" => Ok(Self::Flipped180),
236+ "flipped-270" => Ok(Self::Flipped270),
237+ _ => Err(miette!(concat!(
238+ r#"invalid transform, can be "90", "180", "270", "#,
239+ r#""flipped", "flipped-90", "flipped-180" or "flipped-270""#
240+ ))),
241+ }
242+ }
243+}
244+
245+impl From<Transform> for smithay::utils::Transform {
246+ fn from(value: Transform) -> Self {
247+ match value {
248+ Transform::Normal => Self::Normal,
249+ Transform::_90 => Self::_90,
250+ Transform::_180 => Self::_180,
251+ Transform::_270 => Self::_270,
252+ Transform::Flipped => Self::Flipped,
253+ Transform::Flipped90 => Self::Flipped90,
254+ Transform::Flipped180 => Self::Flipped180,
255+ Transform::Flipped270 => Self::Flipped270,
256+ }
257+ }
258+}
259+
208 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq, Eq)]260 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq, Eq)]
209 pub struct Position {261 pub struct Position {
210 #[knuffel(property)]262 #[knuffel(property)]
@@ -726,6 +778,7 @@ mod tests {
726 778
727 output "eDP-1" {779 output "eDP-1" {
728 scale 2.0780 scale 2.0
781+ transform "flipped-90"
729 position x=10 y=20782 position x=10 y=20
730 mode "1920x1080@144"783 mode "1920x1080@144"
731 }784 }
@@ -826,6 +879,7 @@ mod tests {
826 off: false,879 off: false,
827 name: "eDP-1".to_owned(),880 name: "eDP-1".to_owned(),
828 scale: 2.,881 scale: 2.,
882+ transform: Transform::Flipped90,
829 position: Some(Position { x: 10, y: 20 }),883 position: Some(Position { x: 10, y: 20 }),
830 mode: Some(Mode {884 mode: Some(Mode {
831 width: 1920,885 width: 1920,
resources/default-config.kdlmodified+4 -0
@@ -65,6 +65,10 @@ input {
65 // Scale is a floating-point number, but at the moment only integer values work.65 // Scale is a floating-point number, but at the moment only integer values work.
66 scale 2.066 scale 2.0
67 67
68+ // Transform allows to rotate the output counter-clockwise, valid values are:
69+ // normal, 90, 180, 270, flipped, flipped-90, flipped-180 and flipped-270.
70+ transform "normal"
71+
68 // Resolution and, optionally, refresh rate of the output.72 // Resolution and, optionally, refresh rate of the output.
69 // The format is "<width>x<height>" or "<width>x<height>@<refresh rate>".73 // The format is "<width>x<height>" or "<width>x<height>@<refresh rate>".
70 // If the refresh rate is omitted, niri will pick the highest refresh rate74 // If the refresh rate is omitted, niri will pick the highest refresh rate
src/niri.rsmodified+64 -33
@@ -648,20 +648,22 @@ impl State {
648 let mut resized_outputs = vec![];648 let mut resized_outputs = vec![];
649 for output in self.niri.global_space.outputs() {649 for output in self.niri.global_space.outputs() {
650 let name = output.name();650 let name = output.name();
651- let scale = self651+ let config = self.niri.config.borrow_mut();
652- .niri652+ let config = config.outputs.iter().find(|o| o.name == name);
653- .config653+
654- .borrow()654+ let scale = config.map(|c| c.scale).unwrap_or(1.);
655- .outputs
656- .iter()
657- .find(|o| o.name == name)
658- .map(|c| c.scale)
659- .unwrap_or(1.);
660 let scale = scale.clamp(1., 10.).ceil() as i32;655 let scale = scale.clamp(1., 10.).ceil() as i32;
661- if output.current_scale().integer_scale() != scale {656+
657+ let transform = config
658+ .map(|c| c.transform.into())
659+ .unwrap_or(Transform::Normal);
660+
661+ if output.current_scale().integer_scale() != scale
662+ || output.current_transform() != transform
663+ {
662 output.change_current_state(664 output.change_current_state(
663 None,665 None,
664- None,666+ Some(transform),
665 Some(output::Scale::Integer(scale)),667 Some(output::Scale::Integer(scale)),
666 None,668 None,
667 );669 );
@@ -1172,18 +1174,21 @@ impl Niri {
1172 let global = output.create_global::<State>(&self.display_handle);1174 let global = output.create_global::<State>(&self.display_handle);
1173 1175
1174 let name = output.name();1176 let name = output.name();
1175- let scale = self1177+
1176- .config1178+ let config = self.config.borrow();
1177- .borrow()1179+ let c = config.outputs.iter().find(|o| o.name == name);
1178- .outputs1180+ let scale = c.map(|c| c.scale).unwrap_or(1.);
1179- .iter()
1180- .find(|o| o.name == name)
1181- .map(|c| c.scale)
1182- .unwrap_or(1.);
1183 let scale = scale.clamp(1., 10.).ceil() as i32;1181 let scale = scale.clamp(1., 10.).ceil() as i32;
1182+ let transform = c.map(|c| c.transform.into()).unwrap_or(Transform::Normal);
1183+ drop(config);
1184 1184
1185- // Set scale before adding to the layout since that will read the output size.1185+ // Set scale and transform before adding to the layout since that will read the output size.
1186- output.change_current_state(None, None, Some(output::Scale::Integer(scale)), None);1186+ output.change_current_state(
1187+ None,
1188+ Some(transform),
1189+ Some(output::Scale::Integer(scale)),
1190+ None,
1191+ );
1187 1192
1188 self.layout.add_output(output.clone());1193 self.layout.add_output(output.clone());
1189 1194
@@ -1300,14 +1305,16 @@ impl Niri {
1300 }1305 }
1301 1306
1302 // If the output size changed with an open screenshot UI, close the screenshot UI.1307 // If the output size changed with an open screenshot UI, close the screenshot UI.
1303- if let Some((old_size, old_scale)) = self.screenshot_ui.output_size(&output) {1308+ if let Some((old_size, old_scale, old_transform)) = self.screenshot_ui.output_size(&output)
1304- let output_transform = output.current_transform();1309+ {
1310+ let transform = output.current_transform();
1305 let output_mode = output.current_mode().unwrap();1311 let output_mode = output.current_mode().unwrap();
1306- let size = output_transform.transform_size(output_mode.size);1312+ let size = transform.transform_size(output_mode.size);
1307 let scale = output.current_scale().integer_scale();1313 let scale = output.current_scale().integer_scale();
1308- // FIXME: scale changes shouldn't matter but they currently do since I haven't quite1314+ // FIXME: scale changes and transform flips shouldn't matter but they currently do since
1309- // figured out how to draw the screenshot textures in physical coordinates.1315+ // I haven't quite figured out how to draw the screenshot textures in
1310- if old_size != size || old_scale != scale {1316+ // physical coordinates.
1317+ if old_size != size || old_scale != scale || old_transform != transform {
1311 self.screenshot_ui.close();1318 self.screenshot_ui.close();
1312 self.cursor_manager1319 self.cursor_manager
1313 .set_cursor_image(CursorImageStatus::default_named());1320 .set_cursor_image(CursorImageStatus::default_named());
@@ -1747,7 +1754,9 @@ impl Niri {
1747 // FIXME we basically need to pick the largest scale factor across the overlapping1754 // FIXME we basically need to pick the largest scale factor across the overlapping
1748 // outputs, this is how it's usually done in clients as well.1755 // outputs, this is how it's usually done in clients as well.
1749 let mut cursor_scale = 1;1756 let mut cursor_scale = 1;
1757+ let mut cursor_transform = Transform::Normal;
1750 let mut dnd_scale = 1;1758 let mut dnd_scale = 1;
1759+ let mut dnd_transform = Transform::Normal;
1751 for output in self.global_space.outputs() {1760 for output in self.global_space.outputs() {
1752 let geo = self.global_space.output_geometry(output).unwrap();1761 let geo = self.global_space.output_geometry(output).unwrap();
1753 1762
@@ -1755,6 +1764,9 @@ impl Niri {
1755 if let Some(mut overlap) = geo.intersection(bbox) {1764 if let Some(mut overlap) = geo.intersection(bbox) {
1756 overlap.loc -= surface_pos;1765 overlap.loc -= surface_pos;
1757 cursor_scale = cursor_scale.max(output.current_scale().integer_scale());1766 cursor_scale = cursor_scale.max(output.current_scale().integer_scale());
1767+ // FIXME: using the largest overlapping or "primary" output transform would
1768+ // make more sense here.
1769+ cursor_transform = output.current_transform();
1758 output_update(output, Some(overlap), surface);1770 output_update(output, Some(overlap), surface);
1759 } else {1771 } else {
1760 output_update(output, None, surface);1772 output_update(output, None, surface);
@@ -1765,6 +1777,9 @@ impl Niri {
1765 if let Some(mut overlap) = geo.intersection(bbox) {1777 if let Some(mut overlap) = geo.intersection(bbox) {
1766 overlap.loc -= surface_pos;1778 overlap.loc -= surface_pos;
1767 dnd_scale = dnd_scale.max(output.current_scale().integer_scale());1779 dnd_scale = dnd_scale.max(output.current_scale().integer_scale());
1780+ // FIXME: using the largest overlapping or "primary" output transform
1781+ // would make more sense here.
1782+ dnd_transform = output.current_transform();
1768 output_update(output, Some(overlap), surface);1783 output_update(output, Some(overlap), surface);
1769 } else {1784 } else {
1770 output_update(output, None, surface);1785 output_update(output, None, surface);
@@ -1773,11 +1788,11 @@ impl Niri {
1773 }1788 }
1774 1789
1775 with_states(surface, |data| {1790 with_states(surface, |data| {
1776- send_surface_state(surface, data, cursor_scale, Transform::Normal);1791+ send_surface_state(surface, data, cursor_scale, cursor_transform);
1777 });1792 });
1778 if let Some((surface, _)) = dnd {1793 if let Some((surface, _)) = dnd {
1779 with_states(surface, |data| {1794 with_states(surface, |data| {
1780- send_surface_state(surface, data, dnd_scale, Transform::Normal);1795+ send_surface_state(surface, data, dnd_scale, dnd_transform);
1781 });1796 });
1782 }1797 }
1783 }1798 }
@@ -1794,6 +1809,7 @@ impl Niri {
1794 };1809 };
1795 1810
1796 let mut dnd_scale = 1;1811 let mut dnd_scale = 1;
1812+ let mut dnd_transform = Transform::Normal;
1797 for output in self.global_space.outputs() {1813 for output in self.global_space.outputs() {
1798 let geo = self.global_space.output_geometry(output).unwrap();1814 let geo = self.global_space.output_geometry(output).unwrap();
1799 1815
@@ -1815,15 +1831,18 @@ impl Niri {
1815 if let Some(mut overlap) = geo.intersection(bbox) {1831 if let Some(mut overlap) = geo.intersection(bbox) {
1816 overlap.loc -= surface_pos;1832 overlap.loc -= surface_pos;
1817 dnd_scale = dnd_scale.max(output.current_scale().integer_scale());1833 dnd_scale = dnd_scale.max(output.current_scale().integer_scale());
1834+ // FIXME: using the largest overlapping or "primary" output transform would
1835+ // make more sense here.
1836+ dnd_transform = output.current_transform();
1818 output_update(output, Some(overlap), surface);1837 output_update(output, Some(overlap), surface);
1819 } else {1838 } else {
1820 output_update(output, None, surface);1839 output_update(output, None, surface);
1821 }1840 }
1822-
1823- with_states(surface, |data| {
1824- send_surface_state(surface, data, dnd_scale, Transform::Normal);
1825- });
1826 }1841 }
1842+
1843+ with_states(surface, |data| {
1844+ send_surface_state(surface, data, dnd_scale, dnd_transform);
1845+ });
1827 }1846 }
1828 }1847 }
1829 }1848 }
@@ -2409,6 +2428,9 @@ impl Niri {
2409 let _span = tracy_client::span!("Niri::render_for_screen_cast");2428 let _span = tracy_client::span!("Niri::render_for_screen_cast");
2410 2429
2411 let size = output.current_mode().unwrap().size;2430 let size = output.current_mode().unwrap().size;
2431+ let transform = output.current_transform();
2432+ let size = transform.transform_size(size);
2433+
2412 let scale = Scale::from(output.current_scale().fractional_scale());2434 let scale = Scale::from(output.current_scale().fractional_scale());
2413 2435
2414 let mut elements = None;2436 let mut elements = None;
@@ -2531,6 +2553,9 @@ impl Niri {
2531 .cloned()2553 .cloned()
2532 .filter_map(|output| {2554 .filter_map(|output| {
2533 let size = output.current_mode().unwrap().size;2555 let size = output.current_mode().unwrap().size;
2556+ let transform = output.current_transform();
2557+ let size = transform.transform_size(size);
2558+
2534 let scale = Scale::from(output.current_scale().fractional_scale());2559 let scale = Scale::from(output.current_scale().fractional_scale());
2535 let elements = self.render::<GlesRenderer>(renderer, &output, true);2560 let elements = self.render::<GlesRenderer>(renderer, &output, true);
2536 2561
@@ -2558,6 +2583,9 @@ impl Niri {
2558 let _span = tracy_client::span!("Niri::screenshot");2583 let _span = tracy_client::span!("Niri::screenshot");
2559 2584
2560 let size = output.current_mode().unwrap().size;2585 let size = output.current_mode().unwrap().size;
2586+ let transform = output.current_transform();
2587+ let size = transform.transform_size(size);
2588+
2561 let scale = Scale::from(output.current_scale().fractional_scale());2589 let scale = Scale::from(output.current_scale().fractional_scale());
2562 let elements = self.render::<GlesRenderer>(renderer, output, true);2590 let elements = self.render::<GlesRenderer>(renderer, output, true);
2563 let pixels = render_to_vec(renderer, size, scale, Fourcc::Abgr8888, &elements)?;2591 let pixels = render_to_vec(renderer, size, scale, Fourcc::Abgr8888, &elements)?;
@@ -2679,6 +2707,9 @@ impl Niri {
2679 let geom = geom.to_physical(output_scale);2707 let geom = geom.to_physical(output_scale);
2680 2708
2681 let size = geom.size;2709 let size = geom.size;
2710+ let transform = output.current_transform();
2711+ let size = transform.transform_size(size);
2712+
2682 let elements = self.render::<GlesRenderer>(renderer, &output, include_pointer);2713 let elements = self.render::<GlesRenderer>(renderer, &output, include_pointer);
2683 let pixels = render_to_vec(2714 let pixels = render_to_vec(
2684 renderer,2715 renderer,
src/pw_utils.rsmodified+2 -0
@@ -112,6 +112,8 @@ impl PipeWire {
112 112
113 let mode = output.current_mode().unwrap();113 let mode = output.current_mode().unwrap();
114 let size = mode.size;114 let size = mode.size;
115+ let transform = output.current_transform();
116+ let size = transform.transform_size(size);
115 let refresh = mode.refresh;117 let refresh = mode.refresh;
116 118
117 let stream = Stream::new(&self.core, "niri-screen-cast-src", Properties::new())119 let stream = Stream::new(&self.core, "niri-screen-cast-src", Properties::new())
src/screenshot_ui.rsmodified+7 -4
@@ -42,6 +42,7 @@ pub enum ScreenshotUi {
42 pub struct OutputData {42 pub struct OutputData {
43 size: Size<i32, Physical>,43 size: Size<i32, Physical>,
44 scale: i32,44 scale: i32,
45+ transform: Transform,
45 texture: GlesTexture,46 texture: GlesTexture,
46 texture_buffer: TextureBuffer<GlesTexture>,47 texture_buffer: TextureBuffer<GlesTexture>,
47 buffers: [SolidColorBuffer; 8],48 buffers: [SolidColorBuffer; 8],
@@ -94,6 +95,7 @@ impl ScreenshotUi {
94 )95 )
95 }96 }
96 };97 };
98+
97 let scale = selection.0.current_scale().integer_scale();99 let scale = selection.0.current_scale().integer_scale();
98 let selection = (100 let selection = (
99 selection.0,101 selection.0,
@@ -104,9 +106,9 @@ impl ScreenshotUi {
104 let output_data = screenshots106 let output_data = screenshots
105 .into_iter()107 .into_iter()
106 .map(|(output, texture)| {108 .map(|(output, texture)| {
107- let output_transform = output.current_transform();109+ let transform = output.current_transform();
108 let output_mode = output.current_mode().unwrap();110 let output_mode = output.current_mode().unwrap();
109- let size = output_transform.transform_size(output_mode.size);111+ let size = transform.transform_size(output_mode.size);
110 let scale = output.current_scale().integer_scale();112 let scale = output.current_scale().integer_scale();
111 let texture_buffer = TextureBuffer::from_texture(113 let texture_buffer = TextureBuffer::from_texture(
112 renderer,114 renderer,
@@ -129,6 +131,7 @@ impl ScreenshotUi {
129 let data = OutputData {131 let data = OutputData {
130 size,132 size,
131 scale,133 scale,
134+ transform,
132 texture,135 texture,
133 texture_buffer,136 texture_buffer,
134 buffers,137 buffers,
@@ -333,10 +336,10 @@ impl ScreenshotUi {
333 }336 }
334 }337 }
335 338
336- pub fn output_size(&self, output: &Output) -> Option<(Size<i32, Physical>, i32)> {339+ pub fn output_size(&self, output: &Output) -> Option<(Size<i32, Physical>, i32, Transform)> {
337 if let Self::Open { output_data, .. } = self {340 if let Self::Open { output_data, .. } = self {
338 let data = output_data.get(output)?;341 let data = output_data.get(output)?;
339- Some((data.size, data.scale))342+ Some((data.size, data.scale, data.transform))
340 } else {343 } else {
341 None344 None
342 }345 }