diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8ad175..fbc6c7e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add trigonometric functions (`sin`, `cos`, `tan`, `cot`) and degree/radian conversions (`degtorad`, `radtodeg`) (By: end-4) - Add `substring` function to simplexpr - Add `--duration` flag to `eww open` +- Add support for referring to monitor with `` ## [0.4.0] (04.09.2022) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 3b306be7..42b65d01 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -560,31 +560,16 @@ fn get_monitor_geometry(identifier: Option) -> Result { let mon = get_monitor_from_display(&display, &ident); - - #[cfg(feature = "x11")] - { - mon.with_context(|| { - let head = format!("Failed to get monitor {}\nThe available monitors are:", ident); - let mut body = String::new(); - for m in 0..display.n_monitors() { - if let Some(model) = display.monitor(m).and_then(|x| x.model()) { - body.push_str(format!("\n\t[{}] {}", m, model).as_str()); - } - } - format!("{}{}", head, body) - })? - } - - #[cfg(not(feature = "x11"))] - { - mon.with_context(|| { - if ident.is_numeric() { - format!("Failed to get monitor {}", ident) - } else { - format!("Using ouput names (\"{}\" in the configuration) is not supported outside of x11 yet", ident) + mon.with_context(|| { + let head = format!("Failed to get monitor {}\nThe available monitors are:", ident); + let mut body = String::new(); + for m in 0..display.n_monitors() { + if let Some(model) = display.monitor(m).and_then(|x| x.model()) { + body.push_str(format!("\n\t[{}] {}", m, model).as_str()); } - })? - } + } + format!("{}{}", head, body) + })? } None => display .primary_monitor() @@ -597,12 +582,8 @@ fn get_monitor_geometry(identifier: Option) -> Result Option { match identifier { + MonitorIdentifier::Primary => display.primary_monitor(), MonitorIdentifier::Numeric(num) => display.monitor(*num), - - #[cfg(not(feature = "x11"))] - MonitorIdentifier::Name(_) => return None, - - #[cfg(feature = "x11")] MonitorIdentifier::Name(name) => { for m in 0..display.n_monitors() { if let Some(model) = display.monitor(m).and_then(|x| x.model()) { diff --git a/crates/yuck/src/config/monitor.rs b/crates/yuck/src/config/monitor.rs index 53d6a393..e023096a 100644 --- a/crates/yuck/src/config/monitor.rs +++ b/crates/yuck/src/config/monitor.rs @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize}; pub enum MonitorIdentifier { Numeric(i32), Name(String), + Primary, } impl MonitorIdentifier { @@ -20,6 +21,7 @@ impl fmt::Display for MonitorIdentifier { match self { Self::Numeric(n) => write!(f, "{}", n), Self::Name(n) => write!(f, "{}", n), + Self::Primary => write!(f, ""), } } } @@ -30,7 +32,13 @@ impl str::FromStr for MonitorIdentifier { fn from_str(s: &str) -> Result { match s.parse::() { Ok(n) => Ok(Self::Numeric(n)), - Err(_) => Ok(Self::Name(s.to_owned())), + Err(_) => { + if &s.to_lowercase() == "" { + Ok(Self::Primary) + } else { + Ok(Self::Name(s.to_owned())) + } + } } } }