mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Make missing scale = automatic selection
That was the intention, but I missed it before.
This commit is contained in:
@@ -243,8 +243,8 @@ pub struct Output {
|
||||
pub off: bool,
|
||||
#[knuffel(argument)]
|
||||
pub name: String,
|
||||
#[knuffel(child, unwrap(argument), default = 1.)]
|
||||
pub scale: f64,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub scale: Option<f64>,
|
||||
#[knuffel(child, unwrap(argument, str), default = Transform::Normal)]
|
||||
pub transform: Transform,
|
||||
#[knuffel(child)]
|
||||
@@ -260,7 +260,7 @@ impl Default for Output {
|
||||
Self {
|
||||
off: false,
|
||||
name: String::new(),
|
||||
scale: 1.,
|
||||
scale: None,
|
||||
transform: Transform::Normal,
|
||||
position: None,
|
||||
mode: None,
|
||||
@@ -2291,7 +2291,7 @@ mod tests {
|
||||
outputs: vec![Output {
|
||||
off: false,
|
||||
name: "eDP-1".to_owned(),
|
||||
scale: 2.,
|
||||
scale: Some(2.),
|
||||
transform: Transform::Flipped90,
|
||||
position: Some(Position { x: 10, y: 20 }),
|
||||
mode: Some(ConfiguredMode {
|
||||
|
||||
+24
-2
@@ -278,9 +278,9 @@ pub enum OutputAction {
|
||||
},
|
||||
/// Set the output scale.
|
||||
Scale {
|
||||
/// Scale factor to set.
|
||||
/// Scale factor to set, or "auto" for automatic selection.
|
||||
#[cfg_attr(feature = "clap", arg())]
|
||||
scale: f64,
|
||||
scale: ScaleToSet,
|
||||
},
|
||||
/// Set the output transform.
|
||||
Transform {
|
||||
@@ -329,6 +329,15 @@ pub struct ConfiguredMode {
|
||||
pub refresh: Option<f64>,
|
||||
}
|
||||
|
||||
/// Output scale to set.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
pub enum ScaleToSet {
|
||||
/// Niri will pick the scale automatically.
|
||||
Automatic,
|
||||
/// Specific scale.
|
||||
Specific(f64),
|
||||
}
|
||||
|
||||
/// Output position to set.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::Subcommand))]
|
||||
@@ -560,3 +569,16 @@ impl FromStr for ConfiguredMode {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ScaleToSet {
|
||||
type Err = &'static str;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s.eq_ignore_ascii_case("auto") {
|
||||
return Ok(Self::Automatic);
|
||||
}
|
||||
|
||||
let scale = s.parse().map_err(|_| "error parsing scale")?;
|
||||
Ok(Self::Specific(scale))
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -1014,7 +1014,7 @@ impl State {
|
||||
let config = self.niri.config.borrow_mut();
|
||||
let config = config.outputs.iter().find(|o| o.name == name);
|
||||
|
||||
let scale = config.map(|c| c.scale).unwrap_or_else(|| {
|
||||
let scale = config.and_then(|c| c.scale).unwrap_or_else(|| {
|
||||
let size_mm = output.physical_properties().size;
|
||||
let resolution = output.current_mode().unwrap().size;
|
||||
guess_monitor_scale(size_mm, resolution)
|
||||
@@ -1077,7 +1077,12 @@ impl State {
|
||||
niri_ipc::ModeToSet::Specific(mode) => Some(mode),
|
||||
}
|
||||
}
|
||||
niri_ipc::OutputAction::Scale { scale } => config.scale = scale,
|
||||
niri_ipc::OutputAction::Scale { scale } => {
|
||||
config.scale = match scale {
|
||||
niri_ipc::ScaleToSet::Automatic => None,
|
||||
niri_ipc::ScaleToSet::Specific(scale) => Some(scale),
|
||||
}
|
||||
}
|
||||
niri_ipc::OutputAction::Transform { transform } => config.transform = transform,
|
||||
niri_ipc::OutputAction::Position { position } => {
|
||||
config.position = match position {
|
||||
@@ -1666,7 +1671,7 @@ impl Niri {
|
||||
|
||||
let config = self.config.borrow();
|
||||
let c = config.outputs.iter().find(|o| o.name == name);
|
||||
let scale = c.map(|c| c.scale).unwrap_or_else(|| {
|
||||
let scale = c.and_then(|c| c.scale).unwrap_or_else(|| {
|
||||
let size_mm = output.physical_properties().size;
|
||||
let resolution = output.current_mode().unwrap().size;
|
||||
guess_monitor_scale(size_mm, resolution)
|
||||
|
||||
Reference in New Issue
Block a user