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

add monitor detection fallback to skip cap check #102

Merged
merged 3 commits into from
Mar 30, 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
23 changes: 18 additions & 5 deletions src/brightness/ddcutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub struct DdcUtil {

impl DdcUtil {
pub fn new(name: &str, min_brightness: u64) -> Result<Self, Box<dyn Error>> {
let mut display = find_display_by_name(name).ok_or("Unable to find display")?;
let mut display = find_display_by_name(name, true)
.or_else(|| find_display_by_name(name, false))
.ok_or("Unable to find display")?;
let max_brightness = get_max_brightness(&mut display)?;

Ok(Self {
Expand Down Expand Up @@ -63,11 +65,16 @@ fn get_max_brightness(display: &mut Display) -> Result<u64, Box<dyn Error>> {
.maximum() as u64)
}

fn find_display_by_name(name: &str) -> Option<Display> {
fn find_display_by_name(name: &str, check_caps: bool) -> Option<Display> {
let displays = ddc_hi::Display::enumerate()
.into_iter()
.filter_map(|mut display| {
display.update_capabilities().ok().map(|_| {
let caps = if check_caps {
display.update_capabilities()
} else {
Ok(())
};
caps.ok().map(|_| {
let empty = "".to_string();
let merged = format!(
"{} {}",
Expand All @@ -80,15 +87,21 @@ fn find_display_by_name(name: &str) -> Option<Display> {
.collect_vec();

log::debug!(
"Discovered displays: {:?}",
"Discovered displays (check_caps={}): {:?}",
check_caps,
displays.iter().map(|(name, _)| name).collect_vec()
);

displays.into_iter().find_map(|(merged, display)| {
merged
.contains(name)
.then(|| {
log::debug!("Using display '{}' for config '{}'", merged, name);
log::debug!(
"Using display '{}' for config '{}' (check_caps={})",
merged,
name,
check_caps
);
})
.map(|_| display)
})
Expand Down
1 change: 1 addition & 0 deletions src/predictor/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl Data {
Ok(OpenOptions::new()
.create(true)
.write(true)
.truncate(false)
.read(true)
.open(path)?)
}
Expand Down
Loading