-
Notifications
You must be signed in to change notification settings - Fork 36
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
Use sweep_write when changing brightness #25
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use std::{ | |
sync::Mutex, | ||
}; | ||
|
||
use blight::{change_bl, err::BlibError, Change, Device, Direction}; | ||
use blight::{err::BlibError, Delay, Device, Direction}; | ||
use pulse::volume::Volume; | ||
use pulsectl::controllers::{types::DeviceInfo, DeviceControl, SinkController, SourceController}; | ||
|
||
|
@@ -265,25 +265,20 @@ pub fn change_brightness( | |
.unwrap_or(String::new()) | ||
.parse::<u8>() | ||
.unwrap_or(BRIGHTNESS_CHANGE_DELTA) as u16; | ||
let direction = match change_type { | ||
BrightnessChangeType::Raise => Direction::Inc, | ||
BrightnessChangeType::Lower => { | ||
let device = Device::new(None)?; | ||
let change = device.calculate_change(brightness_delta, Direction::Dec) as f64; | ||
let max = device.max() as f64; | ||
// Limits the lowest brightness to 5% | ||
if change / max < (brightness_delta as f64) * 0.01 { | ||
return Ok(Some(device)); | ||
} | ||
Direction::Dec | ||
} | ||
let mut device = Device::new(None)?; | ||
let change = match change_type { | ||
BrightnessChangeType::Raise => device.calculate_change(brightness_delta, Direction::Inc), | ||
BrightnessChangeType::Lower => device.calculate_change(brightness_delta, Direction::Dec), | ||
}; | ||
match change_bl(brightness_delta, Change::Regular, direction, None) { | ||
match device.sweep_write(change, Delay::default()) { | ||
Comment on lines
-281
to
+273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue with the sweep function is that it's blocking the main thread, i.e. the overlay change gets delayed until the sweep has completed. Did the change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the logic helps, but it doesn't properly change by the amount for some reason. I think you are probably right about blocking the main thread. I'll play around with it sometime when it bothers me more. |
||
Err(e) => { | ||
eprintln!("Brightness Error: {}", e); | ||
Err(e) | ||
} | ||
_ => Ok(Some(Device::new(None)?)), | ||
_ => { | ||
device.reload(); | ||
Ok(Some(device)) | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this doesn't limit the brightness to the lower 5%