Skip to content

Commit

Permalink
move gdk workaround for plug name into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonnn committed Jul 1, 2024
1 parent f1c2545 commit af5363b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,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 @@ -643,15 +655,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()) {
let plug_name;
unsafe {
use glib::translate::ToGlibPtr;
let plug_name_pointer =
gdk_sys::gdk_screen_get_monitor_plug_name(display.default_screen().to_glib_none().0, m);
use std::ffi::CStr;
plug_name = CStr::from_ptr(plug_name_pointer).to_str().unwrap();
}
if model == *name || name == plug_name {
if model == *name || Some(name.as_str()) == get_monitor_plug_name(display, m) {
return display.monitor(m);
}
}
Expand Down

0 comments on commit af5363b

Please sign in to comment.