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

Use sweep_write when changing brightness #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
25 changes: 10 additions & 15 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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));
}
Comment on lines -274 to -277
Copy link
Owner

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%

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
Copy link
Owner

Choose a reason for hiding this comment

The 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 sweep_write fix #12 or was it the logic above?

Copy link
Author

Choose a reason for hiding this comment

The 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))
}
}
}

Expand Down