Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/backend/kms/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
backend::render::{output_elements, CursorMode, GlMultiRenderer, CLEAR_COLOR},
config::{AdaptiveSync, OutputConfig, OutputState},
config::{AdaptiveSync, EdidProduct, OutputConfig, OutputState},
shell::Shell,
utils::prelude::*,
wayland::protocols::screencopy::Frame as ScreencopyFrame,
Expand Down Expand Up @@ -739,7 +739,7 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
.ok();
let (phys_w, phys_h) = conn_info.size().unwrap_or((0, 0));

Ok(Output::new(
let output = Output::new(
interface,
PhysicalProperties {
size: (phys_w as i32, phys_h as i32).into(),
Expand All @@ -760,7 +760,13 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
.and_then(|info| info.model())
.unwrap_or_else(|| String::from("Unknown")),
},
))
);
if let Some(edid) = edid_info.as_ref().and_then(|x| x.edid()) {
output
.user_data()
.insert_if_missing(|| EdidProduct::from(edid.vendor_product()));
}
Ok(output)
}

fn populate_modes(
Expand Down
96 changes: 89 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
};
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap},
collections::{BTreeMap, BTreeSet, HashMap},
fs::OpenOptions,
io::Write,
path::PathBuf,
Expand Down Expand Up @@ -73,23 +73,104 @@

#[derive(Debug, Deserialize, Serialize)]
pub struct OutputsConfig {
pub config: HashMap<Vec<OutputInfo>, Vec<OutputConfig>>,
pub config: HashMap<BTreeSet<OutputInfo>, Vec<OutputConfig>>,
}

impl OutputsConfig {
fn match_configs(&self, infos: &BTreeSet<OutputInfo>) -> Option<&Vec<OutputConfig>> {
if let Some(exact_match) = self.config.get(infos) {
return Some(exact_match);
}
// TODO: disambiguate multiple matches by connector?
for (config_infos, configs) in &self.config {
if config_infos.len() == infos.len()
&& config_infos
.iter()
.zip(infos)
.all(|(config_info, info)| config_info.matches_info(info))
{
return Some(configs);
}
}
None
}
}

// Fields are ordered so derived order will prioritize edid, and consider connector last.
// TODO: custom eq/ord?
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct OutputInfo {
pub connector: String,
pub edid: Option<EdidProduct>,
pub make: String,
pub model: String,
pub connector: String,
}

impl OutputInfo {
/// An output matches this if it has the exact same edid manufacturer/product
/// information, or it has no edid information but has the same connector name
/// as the output's name.
fn matches_output(&self, output: &Output) -> bool {

Check warning on line 113 in src/config/mod.rs

View workflow job for this annotation

GitHub Actions / test

methods `matches_output` and `find_output_match` are never used
let output_edid = output.edid();
self.edid == output_edid && (self.edid.is_some() || self.connector == output.name())
}

fn matches_info(&self, other_info: &Self) -> bool {
self.edid == other_info.edid
&& (self.edid.is_some() || self.connector == other_info.connector)
}

fn find_output_match<'a>(&self, outputs: &'a [Output]) -> Option<&'a Output> {
let matches: Vec<&Output> = outputs
.into_iter()
.filter(|o| self.matches_output(o))
.collect();
if matches.len() > 1 {
// If there are multiple edid matches, favor output with the same
// connector.
//
// Even identical monitors *should* differ by serial number, but
// implementations vary.
if let Some(output) = matches.iter().find(|o| o.name() == self.connector) {
return Some(*output);
}
}
matches.into_iter().next()
}
}

impl From<Output> for OutputInfo {
fn from(o: Output) -> OutputInfo {
let physical = o.physical_properties();
let edid = o.edid();
OutputInfo {
connector: o.name(),
make: physical.make,
model: physical.model,
edid,
}
}
}

#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EdidProduct {
pub manufacturer: [char; 3],
pub product: u16,
pub serial: Option<u32>,
pub manufacture_week: i32,
pub manufacture_year: i32,
pub model_year: Option<i32>,
}

impl From<libdisplay_info::edid::VendorProduct> for EdidProduct {
fn from(vp: libdisplay_info::edid::VendorProduct) -> Self {
Self {
manufacturer: vp.manufacturer,
product: vp.product,
serial: vp.serial,
manufacture_week: vp.manufacture_week,
manufacture_year: vp.manufacture_year,
model_year: vp.model_year,
}
}
}
Expand All @@ -106,6 +187,7 @@
Enabled,
#[serde(rename = "false")]
Disabled,
// TODO store edid info, for better matching?
Mirroring(String),
}

Expand Down Expand Up @@ -459,13 +541,13 @@
clock: &Clock<Monotonic>,
) {
let outputs = output_state.outputs().collect::<Vec<_>>();
let mut infos = outputs
let infos = outputs
.iter()
.cloned()
.map(Into::<crate::config::OutputInfo>::into)
.collect::<Vec<_>>();
infos.sort();
if let Some(configs) = self.dynamic_conf.outputs().config.get(&infos).cloned() {
.collect::<BTreeSet<_>>();
// XXX only matches exact config? as `Vec<OutputInfo>`
if let Some(configs) = self.dynamic_conf.outputs().match_configs(&infos).cloned() {
let known_good_configs = outputs
.iter()
.map(|output| {
Expand Down
1 change: 1 addition & 0 deletions src/shell/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub struct Workspace {
pub handle: WorkspaceHandle,
pub focus_stack: FocusStacks,
pub screencopy: ScreencopySessions,
// TODO edid info
pub output_stack: VecDeque<String>,
pub pending_tokens: HashSet<XdgActivationToken>,
pub(super) backdrop_id: Id,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use crate::shell::{SeatExt, Shell, Workspace};
pub use crate::state::{Common, State};
pub use crate::wayland::handlers::xdg_shell::popup::update_reactive_popups;
use crate::{
config::{AdaptiveSync, OutputConfig, OutputState},
config::{AdaptiveSync, EdidProduct, OutputConfig, OutputState},
shell::zoom::OutputZoomState,
};

Expand All @@ -35,6 +35,8 @@ pub trait OutputExt {
fn is_enabled(&self) -> bool;
fn config(&self) -> Ref<'_, OutputConfig>;
fn config_mut(&self) -> RefMut<'_, OutputConfig>;

fn edid(&self) -> Option<EdidProduct>;
}

struct Vrr(AtomicU8);
Expand Down Expand Up @@ -158,4 +160,8 @@ impl OutputExt for Output {
.unwrap()
.borrow_mut()
}

fn edid(&self) -> Option<EdidProduct> {
self.user_data().get().copied()
}
}
Loading