diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-18 16:31:04 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-18 16:31:04 +0400 |
| commit | edafa139f6296ec8b23906978f4798338877f28d (patch) | |
| tree | 088e1774ea1e47618ca232541572fd62a9b0f753 /src/dbus | |
| parent | fa9b3ed10616e7039e2b0e2c4b797f396b74995f (diff) | |
| download | niri-edafa139f6296ec8b23906978f4798338877f28d.tar.gz niri-edafa139f6296ec8b23906978f4798338877f28d.tar.bz2 niri-edafa139f6296ec8b23906978f4798338877f28d.zip | |
portal: Name and sort monitors, fix session restore
xdp-gnome restores by a combination of model + make + serial. We
currently can't set those reliably (until libdisplay-info most monitors
will have them unknown) so pass the connector name instead. This will
work as expected in most cases.
Diffstat (limited to 'src/dbus')
| -rw-r--r-- | src/dbus/mutter_display_config.rs | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/dbus/mutter_display_config.rs b/src/dbus/mutter_display_config.rs index 361abea0..e22736a2 100644 --- a/src/dbus/mutter_display_config.rs +++ b/src/dbus/mutter_display_config.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex}; use serde::Serialize; use smithay::output::Output; use zbus::fdo::RequestNameFlags; -use zbus::zvariant::{OwnedValue, Type}; +use zbus::zvariant::{self, OwnedValue, Type}; use zbus::{dbus_interface, fdo}; use super::Start; @@ -53,18 +53,49 @@ impl DisplayConfig { HashMap<String, OwnedValue>, )> { // Construct the DBus response. - let monitors: Vec<Monitor> = self + let mut monitors: Vec<Monitor> = self .enabled_outputs .lock() .unwrap() .keys() - .map(|c| Monitor { - names: (c.clone(), String::new(), String::new(), String::new()), - modes: vec![], - properties: HashMap::new(), + .map(|c| { + // Loosely matches the check in Mutter. + let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-")); + + // FIXME: use proper serial when we have libdisplay-info. + // A serial is required for correct session restore by xdp-gnome. + let serial = c.clone(); + + let mut properties = HashMap::new(); + if is_laptop_panel { + properties.insert( + String::from("display-name"), + OwnedValue::from(zvariant::Str::from_static("Built-in display")), + ); + } + properties.insert( + String::from("is-builtin"), + OwnedValue::from(is_laptop_panel), + ); + + Monitor { + names: (c.clone(), String::new(), String::new(), serial), + modes: vec![], + properties, + } }) .collect(); + // Sort the built-in monitor first, then by connector name. + monitors.sort_unstable_by(|a, b| { + let a_is_builtin = a.properties.contains_key("display-name"); + let b_is_builtin = b.properties.contains_key("display-name"); + a_is_builtin + .cmp(&b_is_builtin) + .reverse() + .then_with(|| a.names.0.cmp(&b.names.0)) + }); + let logical_monitors = monitors .iter() .map(|m| LogicalMonitor { |
