Skip to content

Commit

Permalink
Use gdk_screen_get_monitor_plug_name to provide more consistent monit…
Browse files Browse the repository at this point in the history
…or 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
  • Loading branch information
dragonnn authored Aug 25, 2024
1 parent 3342234 commit 510b824
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/eww/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 510b824

Please sign in to comment.