Search for connector duplicates across all devices
Browse files at this commit098c826095cf985c541194498adf9ac6552d46ecParent: befbdc31 changed file +34 -23
- src/backend/tty.rs +34 -23
src/backend/tty.rsmodified+34 -23
| @@ -641,6 +641,7 @@ impl Tty { | |||
| 641 | } | 641 | } |
| 642 | }; | 642 | }; |
| 643 | 643 | ||
| 644 | + let mut added = Vec::new(); | ||
| 644 | let mut removed = Vec::new(); | 645 | let mut removed = Vec::new(); |
| 645 | for event in scan_result { | 646 | for event in scan_result { |
| 646 | match event { | 647 | match event { |
| @@ -649,37 +650,16 @@ impl Tty { | |||
| 649 | crtc: Some(crtc), | 650 | crtc: Some(crtc), |
| 650 | } => { | 651 | } => { |
| 651 | let connector_name = format_connector_name(&connector); | 652 | let connector_name = format_connector_name(&connector); |
| 652 | - let mut name = | 653 | + let name = make_output_name(&device.drm, connector.handle(), connector_name); |
| 653 | - make_output_name(&device.drm, connector.handle(), connector_name); | ||
| 654 | debug!( | 654 | debug!( |
| 655 | "new connector: {} \"{}\"", | 655 | "new connector: {} \"{}\"", |
| 656 | &name.connector, | 656 | &name.connector, |
| 657 | name.format_make_model_serial(), | 657 | name.format_make_model_serial(), |
| 658 | ); | 658 | ); |
| 659 | 659 | ||
| 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 | - | ||
| 680 | // Assign an id to this crtc. | 660 | // Assign an id to this crtc. |
| 681 | let id = OutputId::next(); | 661 | let id = OutputId::next(); |
| 682 | - device.known_crtcs.insert(crtc, CrtcInfo { id, name }); | 662 | + added.push((crtc, CrtcInfo { id, name })); |
| 683 | } | 663 | } |
| 684 | DrmScanEvent::Disconnected { | 664 | DrmScanEvent::Disconnected { |
| 685 | crtc: Some(crtc), .. | 665 | crtc: Some(crtc), .. |
| @@ -705,6 +685,37 @@ impl Tty { | |||
| 705 | } | 685 | } |
| 706 | } | 686 | } |
| 707 | 687 | ||
| 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 | + | ||
| 708 | // This will connect any new connectors if needed, and apply other changes, such as | 719 | // This will connect any new connectors if needed, and apply other changes, such as |
| 709 | // connecting back the internal laptop monitor once it becomes the only monitor left. | 720 | // connecting back the internal laptop monitor once it becomes the only monitor left. |
| 710 | // | 721 | // |