Skip to content

Commit

Permalink
Merge pull request #24 from srithon/topic-23-configurable-nightlight
Browse files Browse the repository at this point in the history
Add configuration options for xrandr gamma and redshift color temperature
  • Loading branch information
srithon committed Sep 5, 2020
2 parents 9140f42 + 8473b83 commit 1cdec47
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "brightness_control"
version = "1.4.6"
version = "1.4.7"
authors = ["Sridaran Thoniyil <sri7thon@gmail.com>"]
edition = "2018"

Expand Down
15 changes: 14 additions & 1 deletion config_template.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.4.5
# v1.4.7
# ^ KEEP THIS IN THE TEMPLATE
# Every time the template is updated, the current version is put at the top
# You can delete it in your own config, but this should stay in the template
Expand All @@ -24,6 +24,19 @@ use_redshift = false
# to that display
auto_reconfigure = true

[nightlight_options]
# When use_redshift is set to false, BrightnessControl uses xrandr --gamma to
# emulate a nightlight
# The format is R:G:B, where each number is a multiplier for its corresponding
# color
# This default value was obtained through testing
xrandr_gamma = "1.0:0.7:0.45"

# Redshift has a -o flag that takes in the desired color temperature in Kelvin
# Lower values are "warmer" and higher values are "cooler"
# https://en.wikipedia.org/wiki/Color_temperature
redshift_temperature = 1400

[fade_options]
# the highest brightness shift that does not use fading automatically
# to disable automatic fading altogether, set this to 100
Expand Down
15 changes: 11 additions & 4 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ impl FileUtils {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
struct NightlightOptions {
xrandr_gamma: String,
redshift_temperature: u32
}

#[derive(Serialize, Deserialize, Debug, Clone)]
struct FadeOptions {
threshold: u8,
Expand All @@ -278,7 +284,8 @@ struct FadeOptions {
struct DaemonOptions {
use_redshift: bool,
auto_reconfigure: bool,
fade_options: FadeOptions
fade_options: FadeOptions,
nightlight_options: NightlightOptions
}

impl DaemonOptions {
Expand Down Expand Up @@ -498,7 +505,7 @@ impl Daemon {
// turn on redshift
let mut redshift_enable = Command::new("redshift");
redshift_enable.arg("-O");
redshift_enable.arg("1400");
redshift_enable.arg(format!("{}", self.config.nightlight_options.redshift_temperature));
redshift_enable.spawn()?;
Ok(())
}
Expand Down Expand Up @@ -776,7 +783,7 @@ impl Daemon {
{
if self.mode {
xrandr_call.arg("--gamma")
.arg("1.0:0.7:0.45");
.arg(&self.config.nightlight_options.xrandr_gamma);
}
}

Expand Down Expand Up @@ -929,7 +936,7 @@ fn get_configuration_from_file(configuration_file: &mut File) -> std::result::Re
}

// TODO figure out how to use derive macro for this
overwrite_values!(use_redshift, auto_reconfigure, fade_options);
overwrite_values!(use_redshift, auto_reconfigure, fade_options, nightlight_options);

return Ok(config);
}
Expand Down

0 comments on commit 1cdec47

Please sign in to comment.