feat: add ddcutil gamma backend
This commit is contained in:
parent
09b7524827
commit
17dab84395
5 changed files with 39 additions and 13 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -244,7 +244,7 @@ checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
|
|||
|
||||
[[package]]
|
||||
name = "hinoirisetr"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"libloading",
|
||||
"smol",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "hinoirisetr"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["Vladimir Rubin <vavakado@proton.me>"]
|
||||
description = "A daemon to dim the screen at night"
|
||||
license = "MIT"
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "hinoirisetr";
|
||||
version = "0.2.0";
|
||||
version = "0.3.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
|
|
41
src/lib.rs
41
src/lib.rs
|
@ -26,6 +26,13 @@ pub struct Config {
|
|||
pub sunrise_end: u8,
|
||||
|
||||
pub notification_timeout: u32,
|
||||
pub gamma_backend: GammaBackend,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum GammaBackend {
|
||||
Hyprctl,
|
||||
Ddcutil,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -40,6 +47,7 @@ impl Default for Config {
|
|||
sunrise_start: 4,
|
||||
sunrise_end: 7,
|
||||
notification_timeout: 5000,
|
||||
gamma_backend: GammaBackend::Hyprctl,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +59,7 @@ pub enum ConfigError {
|
|||
InvalidTemperature(String),
|
||||
InvalidTime(String),
|
||||
InvalidGamma(String),
|
||||
InvalidGammaBackend(String),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
|
@ -92,11 +101,17 @@ impl Config {
|
|||
|
||||
let value = value.trim().replace('"', "");
|
||||
match current_section.as_str() {
|
||||
"" => {
|
||||
if key_trimmed == "notification_timeout" {
|
||||
"" => match key_trimmed {
|
||||
"notification_timeout" => {
|
||||
config.notification_timeout = value.parse::<u32>()?;
|
||||
}
|
||||
}
|
||||
"gamma_backend" => match value.to_lowercase().as_str() {
|
||||
"hyprctl" => config.gamma_backend = GammaBackend::Hyprctl,
|
||||
"ddcutil" => config.gamma_backend = GammaBackend::Ddcutil,
|
||||
_ => return Err(ConfigError::InvalidGammaBackend(value.to_string())),
|
||||
},
|
||||
_ => {}
|
||||
},
|
||||
"gamma" => match key_trimmed {
|
||||
"day" => {
|
||||
let parsed = value.parse::<u16>()?;
|
||||
|
@ -229,7 +244,7 @@ pub fn compute_settings(now: Time, config: &Config) -> (u16, u16) {
|
|||
}
|
||||
|
||||
/// Apply given temperature (Kelvin) and gamma (%) via hyprctl commands
|
||||
pub fn apply_settings(temp: u16, gamma: u16) {
|
||||
pub fn apply_settings(temp: u16, gamma: u16, backend: GammaBackend) {
|
||||
trace!("apply_settings({temp}, {gamma})");
|
||||
debug!("applying temperature: {temp}");
|
||||
debug!("applying gamma: {gamma}");
|
||||
|
@ -239,8 +254,18 @@ pub fn apply_settings(temp: u16, gamma: u16) {
|
|||
.output();
|
||||
trace!("hyprctl hyprsunset temperature {temp}");
|
||||
|
||||
let _ = Command::new("hyprctl")
|
||||
.args(["hyprsunset", "gamma", &gamma.to_string()])
|
||||
.output();
|
||||
trace!("hyprctl hyprsunset gamma {gamma}");
|
||||
match backend {
|
||||
GammaBackend::Hyprctl => {
|
||||
let _ = Command::new("hyprctl")
|
||||
.args(["hyprsunset", "gamma", &gamma.to_string()])
|
||||
.output();
|
||||
trace!("hyprctl hyprsunset gamma {gamma}");
|
||||
}
|
||||
GammaBackend::Ddcutil => {
|
||||
let _ = Command::new("ddcutil")
|
||||
.args(["setvcp", "10", &gamma.to_string()])
|
||||
.output();
|
||||
trace!("ddcutil setvcp 10 {gamma}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ fn main() {
|
|||
{
|
||||
let now = get_time();
|
||||
let (temp, gamma) = compute_settings(now, &*config_guard().await);
|
||||
apply_settings(temp, gamma);
|
||||
apply_settings(temp, gamma, config_guard().await.gamma_backend);
|
||||
trace!("initial settings applied: {temp}K, {gamma}%");
|
||||
}
|
||||
|
||||
|
@ -268,11 +268,12 @@ fn main() {
|
|||
apply_settings(
|
||||
config_guard().await.temp_day,
|
||||
config_guard().await.gamma_day,
|
||||
config_guard().await.gamma_backend,
|
||||
);
|
||||
} else {
|
||||
let now = get_time();
|
||||
let (temp, gamma) = compute_settings(now, &*config_guard().await);
|
||||
apply_settings(temp, gamma);
|
||||
apply_settings(temp, gamma, config_guard().await.gamma_backend);
|
||||
}
|
||||
|
||||
let _ = notify_r.recv().await;
|
||||
|
|
Loading…
Reference in a new issue