forge
Explore
Log in

Don't you dare go Hollow

Search for connector duplicates across all devices

Browse files at this commit

098c826095cf985c541194498adf9ac6552d46ecIvan MolodetskikhParent: befbdc3
src/backend/tty.rsmodified+34 -23
@@ -641,6 +641,7 @@ impl Tty {
641641 }
642642 };
643643
644+ let mut added = Vec::new();
644645 let mut removed = Vec::new();
645646 for event in scan_result {
646647 match event {
@@ -649,37 +650,16 @@ impl Tty {
649650 crtc: Some(crtc),
650651 } => {
651652 let connector_name = format_connector_name(&connector);
652- let mut name =
653- make_output_name(&device.drm, connector.handle(), connector_name);
653+ let name = make_output_name(&device.drm, connector.handle(), connector_name);
654654 debug!(
655655 "new connector: {} \"{}\"",
656656 &name.connector,
657657 name.format_make_model_serial(),
658658 );
659659
660- // Make/model/serial can match exactly between different physical monitors. This
661- // doesn't happen often, but our Layout does not support such duplicates and
662- // will panic.
663- //
664- // As a workaround, search for duplicates, and unname the current connector if
665- // one is found. Connector names are always unique.
666- let formatted = name.format_make_model_serial_or_connector();
667- for info in device.known_crtcs.values() {
668- if info.name.matches(&formatted) {
669- warn!("connector make/model/serial duplicates existing, unnaming");
670- name = OutputName {
671- connector: name.connector,
672- make: None,
673- model: None,
674- serial: None,
675- };
676- break;
677- }
678- }
679-
680660 // Assign an id to this crtc.
681661 let id = OutputId::next();
682- device.known_crtcs.insert(crtc, CrtcInfo { id, name });
662+ added.push((crtc, CrtcInfo { id, name }));
683663 }
684664 DrmScanEvent::Disconnected {
685665 crtc: Some(crtc), ..
@@ -705,6 +685,37 @@ impl Tty {
705685 }
706686 }
707687
688+ for (crtc, mut info) in added {
689+ // Make/model/serial can match exactly between different physical monitors. This doesn't
690+ // happen often, but our Layout does not support such duplicates and will panic.
691+ //
692+ // As a workaround, search for duplicates, and unname the new connectors if one is
693+ // found. Connector names are always unique.
694+ let name = &mut info.name;
695+ let formatted = name.format_make_model_serial_or_connector();
696+ for info in self.devices.values().flat_map(|d| d.known_crtcs.values()) {
697+ if info.name.matches(&formatted) {
698+ let connector = mem::take(&mut name.connector);
699+ warn!(
700+ "new connector {connector} duplicates make/model/serial \
701+ of existing connector {}, unnaming",
702+ info.name.connector,
703+ );
704+ *name = OutputName {
705+ connector,
706+ make: None,
707+ model: None,
708+ serial: None,
709+ };
710+ break;
711+ }
712+ }
713+
714+ // Insert it right away so next added connector will check against this one too.
715+ let device = self.devices.get_mut(&node).unwrap();
716+ device.known_crtcs.insert(crtc, info);
717+ }
718+
708719 // This will connect any new connectors if needed, and apply other changes, such as
709720 // connecting back the internal laptop monitor once it becomes the only monitor left.
710721 //