Skip to content

Commit

Permalink
fix: ddcutil support for 2+ external screens (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Jan 21, 2022
1 parent 6da576e commit f605553
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ddc-hi = "0.4"
log = "0.4"
env_logger = "0.9"
inotify = "0.10"
lazy_static = "1.4"

[dev-dependencies]
mockall = "0.10"
12 changes: 12 additions & 0 deletions src/brightness/ddcutil.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use ddc_hi::{Ddc, Display, FeatureCode};
use itertools::Itertools;
use lazy_static::lazy_static;
use std::cell::RefCell;
use std::error::Error;
use std::sync::Mutex;

lazy_static! {
static ref DDC_MUTEX: Mutex<()> = Mutex::new(());
}

const DDC_BRIGHTNESS_FEATURE: FeatureCode = 0x10;

Expand All @@ -26,6 +32,9 @@ impl DdcUtil {

impl super::Brightness for DdcUtil {
fn get(&mut self) -> Result<u64, Box<dyn Error>> {
let _lock = DDC_MUTEX
.lock()
.expect("Unable to acquire exclusive access to DDC API");
Ok(self
.display
.borrow_mut()
Expand All @@ -35,6 +44,9 @@ impl super::Brightness for DdcUtil {
}

fn set(&mut self, value: u64) -> Result<u64, Box<dyn Error>> {
let _lock = DDC_MUTEX
.lock()
.expect("Unable to acquire exclusive access to DDC API");
let value = value.max(self.min_brightness).min(self.max_brightness);
self.display
.borrow_mut()
Expand Down

0 comments on commit f605553

Please sign in to comment.