Use gdk_screen_get_monitor_plug_name to provide more consistent monitor names on wayland (#1129)

* workaround gdk not providing right monitor informations on wayland

* move gdk workaround for plug name into a separate function

* adjust changelog
This commit is contained in:
Mateusz 2024-08-25 16:03:52 +02:00 committed by GitHub
parent 3342234894
commit 510b824e75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

View File

@ -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)

1
Cargo.lock generated
View File

@ -941,6 +941,7 @@ dependencies = [
"eww_shared_util",
"extend",
"futures",
"gdk-sys",
"gdkx11",
"grass",
"gtk",

View File

@ -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

View File

@ -625,6 +625,18 @@ fn get_gdk_monitor(identifier: Option<MonitorIdentifier>) -> Result<Monitor> {
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<gdk::Monitor> {
@ -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);
}
}