Make scale use FloatOrInt
Browse files at this commit986f2c14abad1b7a0663439bddee4e73d59dbd1aParent: 793e1bd4 changed files +21 -12
- niri-config/src/lib.rs +3 -3
- resources/default-config.kdl +1 -1
- src/niri.rs +13 -8
- wiki/Configuration:-Outputs.md +4 -0
niri-config/src/lib.rsmodified+3 -3
| @@ -298,7 +298,7 @@ pub struct Output { | |||
| 298 | #[knuffel(argument)] | 298 | #[knuffel(argument)] |
| 299 | pub name: String, | 299 | pub name: String, |
| 300 | #[knuffel(child, unwrap(argument))] | 300 | #[knuffel(child, unwrap(argument))] |
| 301 | - pub scale: Option<f64>, | 301 | + pub scale: Option<FloatOrInt<0, 10>>, |
| 302 | #[knuffel(child, unwrap(argument, str), default = Transform::Normal)] | 302 | #[knuffel(child, unwrap(argument, str), default = Transform::Normal)] |
| 303 | pub transform: Transform, | 303 | pub transform: Transform, |
| 304 | #[knuffel(child)] | 304 | #[knuffel(child)] |
| @@ -2462,7 +2462,7 @@ mod tests { | |||
| 2462 | } | 2462 | } |
| 2463 | 2463 | ||
| 2464 | output "eDP-1" { | 2464 | output "eDP-1" { |
| 2465 | - scale 2.0 | 2465 | + scale 2 |
| 2466 | transform "flipped-90" | 2466 | transform "flipped-90" |
| 2467 | position x=10 y=20 | 2467 | position x=10 y=20 |
| 2468 | mode "1920x1080@144" | 2468 | mode "1920x1080@144" |
| @@ -2636,7 +2636,7 @@ mod tests { | |||
| 2636 | outputs: vec![Output { | 2636 | outputs: vec![Output { |
| 2637 | off: false, | 2637 | off: false, |
| 2638 | name: "eDP-1".to_owned(), | 2638 | name: "eDP-1".to_owned(), |
| 2639 | - scale: Some(2.), | 2639 | + scale: Some(FloatOrInt(2.)), |
| 2640 | transform: Transform::Flipped90, | 2640 | transform: Transform::Flipped90, |
| 2641 | position: Some(Position { x: 10, y: 20 }), | 2641 | position: Some(Position { x: 10, y: 20 }), |
| 2642 | mode: Some(ConfiguredMode { | 2642 | mode: Some(ConfiguredMode { |
resources/default-config.kdlmodified+1 -1
| @@ -66,7 +66,7 @@ input { | |||
| 66 | mode "1920x1080@120.030" | 66 | mode "1920x1080@120.030" |
| 67 | 67 | ||
| 68 | // You can use integer or fractional scale, for example use 1.5 for 150% scale. | 68 | // You can use integer or fractional scale, for example use 1.5 for 150% scale. |
| 69 | - scale 2.0 | 69 | + scale 2 |
| 70 | 70 | ||
| 71 | // Transform allows to rotate the output counter-clockwise, valid values are: | 71 | // Transform allows to rotate the output counter-clockwise, valid values are: |
| 72 | // normal, 90, 180, 270, flipped, flipped-90, flipped-180 and flipped-270. | 72 | // normal, 90, 180, 270, flipped, flipped-90, flipped-180 and flipped-270. |
src/niri.rsmodified+13 -8
| @@ -11,7 +11,9 @@ use std::{env, mem, thread}; | |||
| 11 | use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as KdeDecorationsMode; | 11 | use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as KdeDecorationsMode; |
| 12 | use anyhow::{ensure, Context}; | 12 | use anyhow::{ensure, Context}; |
| 13 | use calloop::futures::Scheduler; | 13 | use calloop::futures::Scheduler; |
| 14 | -use niri_config::{Config, Key, Modifiers, PreviewRender, TrackLayout, WorkspaceReference}; | 14 | +use niri_config::{ |
| 15 | + Config, FloatOrInt, Key, Modifiers, PreviewRender, TrackLayout, WorkspaceReference, | ||
| 16 | +}; | ||
| 15 | use niri_ipc::Workspace; | 17 | use niri_ipc::Workspace; |
| 16 | use smithay::backend::allocator::Fourcc; | 18 | use smithay::backend::allocator::Fourcc; |
| 17 | use smithay::backend::renderer::damage::OutputDamageTracker; | 19 | use smithay::backend::renderer::damage::OutputDamageTracker; |
| @@ -1048,11 +1050,14 @@ impl State { | |||
| 1048 | .iter() | 1050 | .iter() |
| 1049 | .find(|o| o.name.eq_ignore_ascii_case(&name)); | 1051 | .find(|o| o.name.eq_ignore_ascii_case(&name)); |
| 1050 | 1052 | ||
| 1051 | - let scale = config.and_then(|c| c.scale).unwrap_or_else(|| { | 1053 | + let scale = config |
| 1052 | - let size_mm = output.physical_properties().size; | 1054 | + .and_then(|c| c.scale) |
| 1053 | - let resolution = output.current_mode().unwrap().size; | 1055 | + .map(|s| s.0) |
| 1054 | - guess_monitor_scale(size_mm, resolution) | 1056 | + .unwrap_or_else(|| { |
| 1055 | - }); | 1057 | + let size_mm = output.physical_properties().size; |
| 1058 | + let resolution = output.current_mode().unwrap().size; | ||
| 1059 | + guess_monitor_scale(size_mm, resolution) | ||
| 1060 | + }); | ||
| 1056 | let scale = closest_representable_scale(scale.clamp(0.1, 10.)); | 1061 | let scale = closest_representable_scale(scale.clamp(0.1, 10.)); |
| 1057 | 1062 | ||
| 1058 | let mut transform = config | 1063 | let mut transform = config |
| @@ -1118,7 +1123,7 @@ impl State { | |||
| 1118 | niri_ipc::OutputAction::Scale { scale } => { | 1123 | niri_ipc::OutputAction::Scale { scale } => { |
| 1119 | config.scale = match scale { | 1124 | config.scale = match scale { |
| 1120 | niri_ipc::ScaleToSet::Automatic => None, | 1125 | niri_ipc::ScaleToSet::Automatic => None, |
| 1121 | - niri_ipc::ScaleToSet::Specific(scale) => Some(scale), | 1126 | + niri_ipc::ScaleToSet::Specific(scale) => Some(FloatOrInt(scale)), |
| 1122 | } | 1127 | } |
| 1123 | } | 1128 | } |
| 1124 | niri_ipc::OutputAction::Transform { transform } => config.transform = transform, | 1129 | niri_ipc::OutputAction::Transform { transform } => config.transform = transform, |
| @@ -1731,7 +1736,7 @@ impl Niri { | |||
| 1731 | .outputs | 1736 | .outputs |
| 1732 | .iter() | 1737 | .iter() |
| 1733 | .find(|o| o.name.eq_ignore_ascii_case(&name)); | 1738 | .find(|o| o.name.eq_ignore_ascii_case(&name)); |
| 1734 | - let scale = c.and_then(|c| c.scale).unwrap_or_else(|| { | 1739 | + let scale = c.and_then(|c| c.scale).map(|s| s.0).unwrap_or_else(|| { |
| 1735 | let size_mm = output.physical_properties().size; | 1740 | let size_mm = output.physical_properties().size; |
| 1736 | let resolution = output.current_mode().unwrap().size; | 1741 | let resolution = output.current_mode().unwrap().size; |
| 1737 | guess_monitor_scale(size_mm, resolution) | 1742 | guess_monitor_scale(size_mm, resolution) |
wiki/Configuration:-Outputs.mdmodified+4 -0
| @@ -72,6 +72,10 @@ Set the scale of the monitor. | |||
| 72 | 72 | ||
| 73 | <sup>Since: 0.1.7</sup> You can use fractional scale values, for example `scale 1.5` for 150% scale. | 73 | <sup>Since: 0.1.7</sup> You can use fractional scale values, for example `scale 1.5` for 150% scale. |
| 74 | 74 | ||
| 75 | +<sup>Since: 0.1.7</sup> Dot is no longer needed for integer scale, for example you can write `scale 2` instead of `scale 2.0`. | ||
| 76 | + | ||
| 77 | +<sup>Since: 0.1.7</sup> Scale below 0 and above 10 will now fail during config parsing. Scale was previously clamped to these values anyway. | ||
| 78 | + | ||
| 75 | ``` | 79 | ``` |
| 76 | output "eDP-1" { | 80 | output "eDP-1" { |
| 77 | scale 2.0 | 81 | scale 2.0 |