Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdisplay-info integration #1522

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
16 changes: 12 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ use smithay::{
},
};
use smithay_drm_extras::{
display_info,
drm_scanner::{DrmScanEvent, DrmScanner},
edid::EdidInfo,
};
use tracing::{debug, error, info, trace, warn};

Expand Down Expand Up @@ -929,9 +929,17 @@ impl AnvilState<UdevData> {
})
.unwrap_or(false);

let (make, model) = EdidInfo::for_connector(&device.drm, connector.handle())
.map(|info| (info.manufacturer, info.model))
.unwrap_or_else(|| ("Unknown".into(), "Unknown".into()));
let display_info = display_info::for_connector(&device.drm, connector.handle());

let make = display_info
.as_ref()
.and_then(|info| info.make())
.unwrap_or_else(|| "Unknown".into());

let model = display_info
.as_ref()
.and_then(|info| info.model())
.unwrap_or_else(|| "Unknown".into());

if non_desktop {
info!("Connector {} is non-desktop, setting up for leasing", output_name);
Expand Down
9 changes: 3 additions & 6 deletions smithay-drm-extras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ license = "MIT"
authors = ["Bartłomiej Maryńczak <marynczakbartlomiej@gmail.com>"]

[dependencies]
edid-rs = "0.1.0"
libdisplay-info = { version = "0.1.0", optional = true }
drm = { version = "0.12.0" }

[features]
default = []
generate-hwdata = ["pkg-config"]
default = ["display-info"]
display-info = ["libdisplay-info"]

[dev-dependencies.smithay]
path = "../"

[build-dependencies]
pkg-config = { version = "0.3.26", optional = true }
2 changes: 1 addition & 1 deletion smithay-drm-extras/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This crate contains some extra abstractions and helpers over DRM

- `edid` module is responsible for extraction of information from DRM connectors (`model` and `manufacturer`)
- `display_info` module is responsible for extraction of information from DRM connectors (`model` and `manufacturer`)
- `drm_scanner` module contains helpers for detecting connector connected and disconnected events as well as mapping crtc to them.
- `ConnectorScanner` is responsible for tracking connected/disconnected events.
- `CrtcMapper` trait and `SimpleCrtcMapper` are meant for mapping crtc to connector.
Expand Down
59 changes: 0 additions & 59 deletions smithay-drm-extras/build.rs

This file was deleted.

22 changes: 17 additions & 5 deletions smithay-drm-extras/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::HashMap, path::PathBuf, time::Duration};

use ::drm::control::{connector, crtc};
use smithay_drm_extras::{
display_info,
drm_scanner::{self, DrmScanEvent},
edid::EdidInfo,
};

use smithay::{
Expand Down Expand Up @@ -135,9 +135,17 @@ impl State {
if let Some(device) = self.devices.get_mut(&node) {
let name = format!("{}-{}", connector.interface().as_str(), connector.interface_id());

let (manufacturer, model) = EdidInfo::for_connector(&device.drm, connector.handle())
.map(|info| (info.manufacturer, info.model))
.unwrap_or_else(|| ("Unknown".into(), "Unknown".into()));
let display_info = display_info::for_connector(&device.drm, connector.handle());

let manufacturer = display_info
.as_ref()
.and_then(|info| info.make())
.unwrap_or_else(|| "Unknown".into());

let model = display_info
.as_ref()
.and_then(|info| info.model())
.unwrap_or_else(|| "Unknown".into());

println!("Connected:");
dbg!(name);
Expand Down Expand Up @@ -166,7 +174,11 @@ impl State {
return;
};

for event in device.drm_scanner.scan_connectors(&device.drm) {
for event in device
.drm_scanner
.scan_connectors(&device.drm)
.expect("failed to scan connectors")
{
match event {
DrmScanEvent::Connected {
connector,
Expand Down
37 changes: 37 additions & 0 deletions smithay-drm-extras/src/display_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! # EDID - Extended Display Identification Data
//!
//! This module is meant to help with extraction of EDID data from connectors
//!
//! ```no_run
//! # mod helpers { include!("./docs/doctest_helpers.rs"); };
//! # let drm_device: helpers::FakeDevice = todo!();
//! # let connector = todo!();
//! use smithay_drm_extras::display_info;
//!
//! let info = display_info::for_connector(&drm_device, connector).unwrap();
//!
//! println!("Monitor name: {}", info.model());
//! println!("Manufacturer name: {}", info.make());
//! ```

use drm::control::{connector, Device as ControlDevice};
use libdisplay_info::info::Info;

/// Try to read the [`Info`] from the connector EDID property
pub fn for_connector(device: &impl ControlDevice, connector: connector::Handle) -> Option<Info> {
let props = device.get_properties(connector).ok()?;

let (info, value) = props
.into_iter()
.filter_map(|(handle, value)| {
let info = device.get_property(handle).ok()?;

Some((info, value))
})
.find(|(info, _)| info.name().to_str() == Ok("EDID"))?;

let blob = info.value_type().convert_value(value).as_blob()?;
let data = device.get_property_blob(blob).ok()?;

Info::parse_edid(&data).ok()
}
89 changes: 0 additions & 89 deletions smithay-drm-extras/src/edid.rs

This file was deleted.

Loading
Loading