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]]
|
[[package]]
|
||||||
name = "hinoirisetr"
|
name = "hinoirisetr"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libloading",
|
"libloading",
|
||||||
"smol",
|
"smol",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "hinoirisetr"
|
name = "hinoirisetr"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
authors = ["Vladimir Rubin <vavakado@proton.me>"]
|
authors = ["Vladimir Rubin <vavakado@proton.me>"]
|
||||||
description = "A daemon to dim the screen at night"
|
description = "A daemon to dim the screen at night"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||||
pname = "hinoirisetr";
|
pname = "hinoirisetr";
|
||||||
version = "0.2.0";
|
version = "0.3.0";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -26,6 +26,13 @@ pub struct Config {
|
||||||
pub sunrise_end: u8,
|
pub sunrise_end: u8,
|
||||||
|
|
||||||
pub notification_timeout: u32,
|
pub notification_timeout: u32,
|
||||||
|
pub gamma_backend: GammaBackend,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum GammaBackend {
|
||||||
|
Hyprctl,
|
||||||
|
Ddcutil,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
@ -40,6 +47,7 @@ impl Default for Config {
|
||||||
sunrise_start: 4,
|
sunrise_start: 4,
|
||||||
sunrise_end: 7,
|
sunrise_end: 7,
|
||||||
notification_timeout: 5000,
|
notification_timeout: 5000,
|
||||||
|
gamma_backend: GammaBackend::Hyprctl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +59,7 @@ pub enum ConfigError {
|
||||||
InvalidTemperature(String),
|
InvalidTemperature(String),
|
||||||
InvalidTime(String),
|
InvalidTime(String),
|
||||||
InvalidGamma(String),
|
InvalidGamma(String),
|
||||||
|
InvalidGammaBackend(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for ConfigError {
|
impl From<std::io::Error> for ConfigError {
|
||||||
|
@ -92,11 +101,17 @@ impl Config {
|
||||||
|
|
||||||
let value = value.trim().replace('"', "");
|
let value = value.trim().replace('"', "");
|
||||||
match current_section.as_str() {
|
match current_section.as_str() {
|
||||||
"" => {
|
"" => match key_trimmed {
|
||||||
if key_trimmed == "notification_timeout" {
|
"notification_timeout" => {
|
||||||
config.notification_timeout = value.parse::<u32>()?;
|
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 {
|
"gamma" => match key_trimmed {
|
||||||
"day" => {
|
"day" => {
|
||||||
let parsed = value.parse::<u16>()?;
|
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
|
/// 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})");
|
trace!("apply_settings({temp}, {gamma})");
|
||||||
debug!("applying temperature: {temp}");
|
debug!("applying temperature: {temp}");
|
||||||
debug!("applying gamma: {gamma}");
|
debug!("applying gamma: {gamma}");
|
||||||
|
@ -239,8 +254,18 @@ pub fn apply_settings(temp: u16, gamma: u16) {
|
||||||
.output();
|
.output();
|
||||||
trace!("hyprctl hyprsunset temperature {temp}");
|
trace!("hyprctl hyprsunset temperature {temp}");
|
||||||
|
|
||||||
|
match backend {
|
||||||
|
GammaBackend::Hyprctl => {
|
||||||
let _ = Command::new("hyprctl")
|
let _ = Command::new("hyprctl")
|
||||||
.args(["hyprsunset", "gamma", &gamma.to_string()])
|
.args(["hyprsunset", "gamma", &gamma.to_string()])
|
||||||
.output();
|
.output();
|
||||||
trace!("hyprctl hyprsunset gamma {gamma}");
|
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 now = get_time();
|
||||||
let (temp, gamma) = compute_settings(now, &*config_guard().await);
|
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}%");
|
trace!("initial settings applied: {temp}K, {gamma}%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,11 +268,12 @@ fn main() {
|
||||||
apply_settings(
|
apply_settings(
|
||||||
config_guard().await.temp_day,
|
config_guard().await.temp_day,
|
||||||
config_guard().await.gamma_day,
|
config_guard().await.gamma_day,
|
||||||
|
config_guard().await.gamma_backend,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let now = get_time();
|
let now = get_time();
|
||||||
let (temp, gamma) = compute_settings(now, &*config_guard().await);
|
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;
|
let _ = notify_r.recv().await;
|
||||||
|
|
Loading…
Reference in a new issue