Skip to content

Commit

Permalink
Allow named monitors on wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Dec 20, 2023
1 parent fff40ce commit 85550cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<primary>`

## [0.4.0] (04.09.2022)

Expand Down
39 changes: 10 additions & 29 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,31 +560,16 @@ fn get_monitor_geometry(identifier: Option<MonitorIdentifier>) -> Result<gdk::Re
let monitor = match identifier {
Some(ident) => {
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()
Expand All @@ -597,12 +582,8 @@ fn get_monitor_geometry(identifier: Option<MonitorIdentifier>) -> Result<gdk::Re
/// Outside of x11, only [MonitorIdentifier::Numeric] is supported
pub fn get_monitor_from_display(display: &gdk::Display, identifier: &MonitorIdentifier) -> Option<gdk::Monitor> {
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()) {
Expand Down
10 changes: 9 additions & 1 deletion crates/yuck/src/config/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
pub enum MonitorIdentifier {
Numeric(i32),
Name(String),
Primary,
}

impl MonitorIdentifier {
Expand All @@ -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, "<primary>"),
}
}
}
Expand All @@ -30,7 +32,13 @@ impl str::FromStr for MonitorIdentifier {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.parse::<i32>() {
Ok(n) => Ok(Self::Numeric(n)),
Err(_) => Ok(Self::Name(s.to_owned())),
Err(_) => {
if &s.to_lowercase() == "<primary>" {
Ok(Self::Primary)
} else {
Ok(Self::Name(s.to_owned()))
}
}
}
}
}

0 comments on commit 85550cc

Please sign in to comment.