From baedd79f624d015380fe03d045f122b972028780 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 29 Oct 2024 12:13:44 +0100 Subject: [PATCH] sculpt_manager: fb unplug, sanitize conn. model This patch explicitly handles the unplugging of displays, avoiding the use of stale connectors for defining the panorama. It also makes the import of the connectors model robust against intermediate states reported by the driver (a connector reported as connector but without any mode), and discards the use of any information of non-present connectors as merge info. Issue #5286 --- .../src/app/sculpt_manager/model/fb_config.h | 36 ++++++++++--------- .../app/sculpt_manager/model/fb_connectors.h | 3 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/repos/gems/src/app/sculpt_manager/model/fb_config.h b/repos/gems/src/app/sculpt_manager/model/fb_config.h index da00f925a9..aaca4ed9a6 100644 --- a/repos/gems/src/app/sculpt_manager/model/fb_config.h +++ b/repos/gems/src/app/sculpt_manager/model/fb_config.h @@ -218,6 +218,14 @@ struct Sculpt::Fb_config }); }); + /* detect unplugging */ + for (Entry &entry : _entries) { + bool connected = false; + connectors.with_connector(entry.name, [&] (auto &) { connected = true; }); + if (!connected) + entry.present = false; + } + connectors._merged.for_each([&] (Fb_connectors::Connector const &conn) { if (!_known(conn.name)) _add_unknown_merged(Entry::from_connector(conn)); }); @@ -328,28 +336,22 @@ struct Sculpt::Fb_config void with_merge_info(auto const &fn) const { - Merge_info info { }; - /* merged screen size and name corresponds to first enabled connector */ for (unsigned i = 0; i < _num_merged; i++) { - info = { .name = _entries[i].name, - .px = _entries[i].mode_attr.px }; - if (info.px.valid() && _entries[i].present) - break; - } - - /* if all merged connectors are switched of, use name of first one */ - if (!info.px.valid()) { - for (unsigned i = 0; i < _num_merged; i++) { - info = { .name = _entries[i].name, - .px = _entries[i].mode_attr.px }; - if (_entries[i].present) - break; + if (_entries[i].present && _entries[i].mode_attr.px.valid()) { + fn({ .name = _entries[i].name, + .px = _entries[i].mode_attr.px }); + return; } } - if (info.name.length() > 1) - fn(info); + /* if all merged connectors are switched off, use name of first present one */ + for (unsigned i = 0; i < _num_merged; i++) { + if (_entries[i].present) { + fn({ .name = _entries[i].name, .px = { }}); + return; + } + } }; void _gen_merge_node(Xml_generator &xml) const diff --git a/repos/gems/src/app/sculpt_manager/model/fb_connectors.h b/repos/gems/src/app/sculpt_manager/model/fb_connectors.h index ed8b3a0081..596214ad07 100644 --- a/repos/gems/src/app/sculpt_manager/model/fb_connectors.h +++ b/repos/gems/src/app/sculpt_manager/model/fb_connectors.h @@ -207,7 +207,8 @@ struct Sculpt::Fb_connectors : private Noncopyable static bool type_matches(Xml_node const &node) { return node.has_type("connector") - && node.attribute_value("connected", false); + && node.attribute_value("connected", false) + && node.has_sub_node("mode"); } };