-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
General brightness improvements: new brightnessctl
backend, set by percentage, and pick device
#60
General brightness improvements: new brightnessctl
backend, set by percentage, and pick device
#60
Conversation
Hi there, @ErikReider ! Can I get some feedback on this one? I'll be happy to make any adjustments! |
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.
Please excuse me for the late review 😅
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.
Other than that, it LGTM :)
src/brightness_backend/mod.rs
Outdated
use self::{brightnessctl::BrightnessCtl, blight::Blight}; | ||
|
||
mod blight; | ||
|
||
mod brightnessctl; | ||
|
||
pub type BrightnessBackendResult = anyhow::Result<Box<dyn BrightnessBackend>>; | ||
|
||
pub trait BrightnessBackendConstructor: BrightnessBackend + Sized + 'static { | ||
fn try_new(device_name: Option<String>) -> anyhow::Result<Self>; | ||
|
||
fn try_new_boxed(device_name: Option<String>) -> BrightnessBackendResult { | ||
let backend = Self::try_new(device_name); | ||
match backend { | ||
Ok(backend) => Ok(Box::new(backend)), | ||
Err(e) => Err(e), | ||
} | ||
} | ||
} | ||
|
||
pub trait BrightnessBackend { | ||
fn get_current(&mut self) -> u32; | ||
fn get_max(&mut self) -> u32; | ||
|
||
fn lower(&mut self, by: u32) -> anyhow::Result<()>; | ||
fn raise(&mut self, by: u32) -> anyhow::Result<()>; | ||
fn set(&mut self, val: u32) -> anyhow::Result<()>; | ||
} | ||
|
||
pub fn get_preferred_backend(device_name: Option<String>) -> BrightnessBackendResult { | ||
println!("Trying BrightnessCtl Backend..."); | ||
BrightnessCtl::try_new_boxed(device_name.clone()).or_else(|_| { | ||
println!("...Command failed! Falling back to Blight"); | ||
Blight::try_new_boxed(device_name) | ||
}) | ||
} |
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.
Make sure to run cargo fmt --all
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.
Addressed in ba06c46
@ErikReider I've addressed the review comments! |
chore: remove debug statements
partially related to ErikReider#37
partially related to ErikReider#27
ba06c46
to
f7751ec
Compare
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.
Thanks for the amazing work! :)
Resolves #56
Resolves #37
Partially Resolves #27
About this PR
This PR separates the code that controls brightness into a new module. This module exports a trait that different backends can implement in order to control brightness like SwayOSD expects.
Besides the existing "blight" backend, a new backend has been introduced, one that is backed by the command line util
brightnessctl
(#56). This backend is attempted first and "blight" serves as a fallback if the command is not available. I've made it this way because "blight" requires some setting up, whilebrightnessctl
requires only the command to be installed.The brightness command also accepts
brightness={val}
to set the brightness directly in percentages (#37).Finally, the PR also allows for the user to pick a different device to have its brightness set, via the already present
--device
parameter. I believe this partially resolves #27 because the user could now make a script to call SwayOSD for each device, which was previously impossible.