Skip to content

Commit ab3f42b

Browse files
committed
Add EdidProduct, as user data for kms Outputs
This is the same as `libdisplay_info::edid::VendorProduct`, but with implementations for `Serialize`, `Eq`, etc.
1 parent c072538 commit ab3f42b

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/backend/kms/device.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::{
44
backend::render::{output_elements, CursorMode, GlMultiRenderer, CLEAR_COLOR},
5-
config::{AdaptiveSync, OutputConfig, OutputState, ScreenFilter},
5+
config::{AdaptiveSync, EdidProduct, OutputConfig, OutputState, ScreenFilter},
66
shell::Shell,
77
utils::prelude::*,
88
wayland::protocols::screencopy::Frame as ScreencopyFrame,
@@ -743,7 +743,7 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
743743
.ok();
744744
let (phys_w, phys_h) = conn_info.size().unwrap_or((0, 0));
745745

746-
Ok(Output::new(
746+
let output = Output::new(
747747
interface,
748748
PhysicalProperties {
749749
size: (phys_w as i32, phys_h as i32).into(),
@@ -764,7 +764,13 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
764764
.and_then(|info| info.model())
765765
.unwrap_or_else(|| String::from("Unknown")),
766766
},
767-
))
767+
);
768+
if let Some(edid) = edid_info.as_ref().and_then(|x| x.edid()) {
769+
output
770+
.user_data()
771+
.insert_if_missing(|| EdidProduct::from(edid.vendor_product()));
772+
}
773+
Ok(output)
768774
}
769775

770776
fn populate_modes(

src/config/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ impl From<Output> for OutputInfo {
9494
}
9595
}
9696

97+
#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
98+
pub struct EdidProduct {
99+
pub manufacturer: [char; 3],
100+
pub product: u16,
101+
pub serial: Option<u32>,
102+
pub manufacture_week: i32,
103+
pub manufacture_year: i32,
104+
pub model_year: Option<i32>,
105+
}
106+
107+
impl From<libdisplay_info::edid::VendorProduct> for EdidProduct {
108+
fn from(vp: libdisplay_info::edid::VendorProduct) -> Self {
109+
Self {
110+
manufacturer: vp.manufacturer,
111+
product: vp.product,
112+
serial: vp.serial,
113+
manufacture_week: vp.manufacture_week,
114+
manufacture_year: vp.manufacture_year,
115+
model_year: vp.model_year,
116+
}
117+
}
118+
}
119+
97120
#[derive(Default, Debug, Deserialize, Serialize)]
98121
pub struct NumlockStateConfig {
99122
pub last_state: bool,

src/utils/prelude.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use crate::shell::{SeatExt, Shell, Workspace};
99
pub use crate::state::{Common, State};
1010
pub use crate::wayland::handlers::xdg_shell::popup::update_reactive_popups;
1111
use crate::{
12-
config::{AdaptiveSync, OutputConfig, OutputState},
12+
config::{AdaptiveSync, EdidProduct, OutputConfig, OutputState},
1313
shell::zoom::OutputZoomState,
1414
};
1515

@@ -35,6 +35,8 @@ pub trait OutputExt {
3535
fn is_enabled(&self) -> bool;
3636
fn config(&self) -> Ref<'_, OutputConfig>;
3737
fn config_mut(&self) -> RefMut<'_, OutputConfig>;
38+
39+
fn edid(&self) -> Option<&EdidProduct>;
3840
}
3941

4042
struct Vrr(AtomicU8);
@@ -158,4 +160,8 @@ impl OutputExt for Output {
158160
.unwrap()
159161
.borrow_mut()
160162
}
163+
164+
fn edid(&self) -> Option<&EdidProduct> {
165+
self.user_data().get()
166+
}
161167
}

0 commit comments

Comments
 (0)