forge
Explore
Log in

Don't you dare go Hollow

portal: Name and sort monitors, fix session restore

Browse files at this commit

edafa139f6296ec8b23906978f4798338877f28dIvan MolodetskikhParent: fa9b3ed
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.
src/dbus/mutter_display_config.rsmodified+37 -6
@@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
4 use serde::Serialize;4 use serde::Serialize;
5 use smithay::output::Output;5 use smithay::output::Output;
6 use zbus::fdo::RequestNameFlags;6 use zbus::fdo::RequestNameFlags;
7-use zbus::zvariant::{OwnedValue, Type};7+use zbus::zvariant::{self, OwnedValue, Type};
8 use zbus::{dbus_interface, fdo};8 use zbus::{dbus_interface, fdo};
9 9
10 use super::Start;10 use super::Start;
@@ -53,18 +53,49 @@ impl DisplayConfig {
53 HashMap<String, OwnedValue>,53 HashMap<String, OwnedValue>,
54 )> {54 )> {
55 // Construct the DBus response.55 // Construct the DBus response.
56- let monitors: Vec<Monitor> = self56+ let mut monitors: Vec<Monitor> = self
57 .enabled_outputs57 .enabled_outputs
58 .lock()58 .lock()
59 .unwrap()59 .unwrap()
60 .keys()60 .keys()
61- .map(|c| Monitor {61+ .map(|c| {
62- names: (c.clone(), String::new(), String::new(), String::new()),62+ // Loosely matches the check in Mutter.
63- modes: vec![],63+ let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-"));
64- properties: HashMap::new(),64+
65+ // FIXME: use proper serial when we have libdisplay-info.
66+ // A serial is required for correct session restore by xdp-gnome.
67+ let serial = c.clone();
68+
69+ let mut properties = HashMap::new();
70+ if is_laptop_panel {
71+ properties.insert(
72+ String::from("display-name"),
73+ OwnedValue::from(zvariant::Str::from_static("Built-in display")),
74+ );
75+ }
76+ properties.insert(
77+ String::from("is-builtin"),
78+ OwnedValue::from(is_laptop_panel),
79+ );
80+
81+ Monitor {
82+ names: (c.clone(), String::new(), String::new(), serial),
83+ modes: vec![],
84+ properties,
85+ }
65 })86 })
66 .collect();87 .collect();
67 88
89+ // Sort the built-in monitor first, then by connector name.
90+ monitors.sort_unstable_by(|a, b| {
91+ let a_is_builtin = a.properties.contains_key("display-name");
92+ let b_is_builtin = b.properties.contains_key("display-name");
93+ a_is_builtin
94+ .cmp(&b_is_builtin)
95+ .reverse()
96+ .then_with(|| a.names.0.cmp(&b.names.0))
97+ });
98+
68 let logical_monitors = monitors99 let logical_monitors = monitors
69 .iter()100 .iter()
70 .map(|m| LogicalMonitor {101 .map(|m| LogicalMonitor {