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

fix: ddcutil can handle one query only in parallel #36

Merged
merged 4 commits into from
Jan 21, 2022
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
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