Skip to content

Commit 276b1b0

Browse files
Configurable brightness
1 parent 9a4dc60 commit 276b1b0

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

share/tiny-dfr/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ FontTemplate = ":bold"
2929
# screen's brightness
3030
AdaptiveBrightness = true
3131

32+
# With adaptive brightness disabled this is used as the brightness
33+
# in the active state
34+
# With it enabled, this is the maximum point on the brightness curve
35+
# Accepted values are 0-255
36+
ActiveBrightness = 128
37+
3238
# This key defines the contents of the primary layer
3339
# (the one with F{number} keys)
3440
# You can change the individual buttons, add, or remove them

src/backlight.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const MAX_DISPLAY_BRIGHTNESS: u32 = 509;
1515
const MAX_TOUCH_BAR_BRIGHTNESS: u32 = 255;
1616
const BRIGHTNESS_DIM_TIMEOUT: i32 = TIMEOUT_MS * 3; // should be a multiple of TIMEOUT_MS
1717
const BRIGHTNESS_OFF_TIMEOUT: i32 = TIMEOUT_MS * 6; // should be a multiple of TIMEOUT_MS
18-
const DEFAULT_BRIGHTNESS: u32 = 128;
1918
const DIMMED_BRIGHTNESS: u32 = 1;
2019

2120
fn read_attr(path: &Path, attr: &str) -> u32 {
@@ -71,10 +70,10 @@ impl BacklightManager {
7170
display_bl_path
7271
}
7372
}
74-
fn display_to_touchbar(display: u32) -> u32 {
73+
fn display_to_touchbar(display: u32, active_brightness: u32) -> u32 {
7574
let normalized = display as f64 / MAX_DISPLAY_BRIGHTNESS as f64;
7675
// Add one so that the touch bar does not turn off
77-
let adjusted = (normalized.powf(0.5) * MAX_TOUCH_BAR_BRIGHTNESS as f64) as u32 + 1;
76+
let adjusted = (normalized.powf(0.5) * active_brightness as f64) as u32 + 1;
7877
adjusted.min(MAX_TOUCH_BAR_BRIGHTNESS) // Clamp the value to the maximum allowed brightness
7978
}
8079
pub fn process_event(&mut self, event: &Event) {
@@ -103,9 +102,9 @@ impl BacklightManager {
103102
0
104103
} else if since_last_active < BRIGHTNESS_DIM_TIMEOUT as u64 {
105104
if cfg.adaptive_brightness {
106-
BacklightManager::display_to_touchbar(read_attr(&self.display_bl_path, "brightness"))
105+
BacklightManager::display_to_touchbar(read_attr(&self.display_bl_path, "brightness"), cfg.active_brightness)
107106
} else {
108-
DEFAULT_BRIGHTNESS
107+
cfg.active_brightness
109108
}
110109
} else if since_last_active < BRIGHTNESS_OFF_TIMEOUT as u64 {
111110
DIMMED_BRIGHTNESS

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Config {
2121
pub enable_pixel_shift: bool,
2222
pub font_face: FontFace,
2323
pub adaptive_brightness: bool,
24+
pub active_brightness: u32,
2425
}
2526

2627
#[derive(Deserialize)]
@@ -31,6 +32,7 @@ struct ConfigProxy {
3132
enable_pixel_shift: Option<bool>,
3233
font_template: Option<String>,
3334
adaptive_brightness: Option<bool>,
35+
active_brightness: Option<u32>,
3436
primary_layer_keys: Option<Vec<ButtonConfig>>,
3537
media_layer_keys: Option<Vec<ButtonConfig>>
3638
}
@@ -71,6 +73,7 @@ fn load_config() -> (Config, [FunctionLayer; 2]) {
7173
base.adaptive_brightness = user.adaptive_brightness.or(base.adaptive_brightness);
7274
base.media_layer_keys = user.media_layer_keys.or(base.media_layer_keys);
7375
base.primary_layer_keys = user.primary_layer_keys.or(base.primary_layer_keys);
76+
base.active_brightness = user.active_brightness.or(base.active_brightness);
7477
};
7578
let media_layer = FunctionLayer::with_config(base.media_layer_keys.unwrap());
7679
let fkey_layer = FunctionLayer::with_config(base.primary_layer_keys.unwrap());
@@ -80,6 +83,7 @@ fn load_config() -> (Config, [FunctionLayer; 2]) {
8083
enable_pixel_shift: base.enable_pixel_shift.unwrap(),
8184
adaptive_brightness: base.adaptive_brightness.unwrap(),
8285
font_face: load_font(&base.font_template.unwrap()),
86+
active_brightness: base.active_brightness.unwrap()
8387
};
8488
(cfg, layers)
8589
}

0 commit comments

Comments
 (0)