diff --git a/CHANGELOG.md b/CHANGELOG.md index 87dc54b5..2f9d2051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Fix the gtk `stack` widget (By: ovalkonia) - Fix values in the `EWW_NET` variable (By: mario-kr) - Fix the gtk `expander` widget (By: ovalkonia) +- Fix wayland monitor names support (By: dragonnn) ### Features - Update rust toolchain to 1.80.1 (By: w-lfchen) diff --git a/Cargo.lock b/Cargo.lock index 3a1ac66e..b44e5a0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -941,6 +941,7 @@ dependencies = [ "eww_shared_util", "extend", "futures", + "gdk-sys", "gdkx11", "grass", "gtk", diff --git a/crates/eww/Cargo.toml b/crates/eww/Cargo.toml index 4c7a4448..d934c455 100644 --- a/crates/eww/Cargo.toml +++ b/crates/eww/Cargo.toml @@ -23,9 +23,12 @@ notifier_host.workspace = true gtk-layer-shell = { version = "0.8.1", optional = true } gdkx11 = { version = "0.18", optional = true } x11rb = { version = "0.13.1", features = ["randr"], optional = true } +gdk-sys = "0.18.0" ordered-stream = "0.2.0" + +grass.workspace = true anyhow.workspace = true bincode.workspace = true chrono.workspace = true @@ -35,7 +38,6 @@ codespan-reporting.workspace = true derive_more.workspace = true extend.workspace = true futures.workspace = true -grass.workspace = true gtk.workspace = true itertools.workspace = true libc.workspace = true diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 965d86ca..2da4ab2e 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -625,6 +625,18 @@ fn get_gdk_monitor(identifier: Option) -> Result { Ok(monitor) } +/// Get the name of monitor plug for given monitor number +/// workaround gdk not providing this information on wayland in regular calls +/// gdk_screen_get_monitor_plug_name is deprecated but works fine for that case +fn get_monitor_plug_name(display: &gdk::Display, monitor_num: i32) -> Option<&str> { + unsafe { + use glib::translate::ToGlibPtr; + let plug_name_pointer = gdk_sys::gdk_screen_get_monitor_plug_name(display.default_screen().to_glib_none().0, monitor_num); + use std::ffi::CStr; + CStr::from_ptr(plug_name_pointer).to_str().ok() + } +} + /// Returns the [Monitor][gdk::Monitor] structure corresponding to the identifer. /// Outside of x11, only [MonitorIdentifier::Numeric] is supported pub fn get_monitor_from_display(display: &gdk::Display, identifier: &MonitorIdentifier) -> Option { @@ -642,7 +654,7 @@ pub fn get_monitor_from_display(display: &gdk::Display, identifier: &MonitorIden MonitorIdentifier::Name(name) => { for m in 0..display.n_monitors() { if let Some(model) = display.monitor(m).and_then(|x| x.model()) { - if model == *name { + if model == *name || Some(name.as_str()) == get_monitor_plug_name(display, m) { return display.monitor(m); } }