Skip to content

Commit 06b8c8e

Browse files
kekrbyWhatAmISupposedToPutHere
authored andcommitted
Respect the maximum brightness level
1 parent 03a8e1b commit 06b8c8e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/backlight.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::{
22
fs::{File, OpenOptions, self},
33
path::{PathBuf, Path},
44
time::Instant,
5-
io::Write
5+
io::Write,
6+
cmp::min,
67
};
78
use anyhow::{Result, anyhow};
89
use input::event::{
@@ -51,6 +52,7 @@ fn set_backlight(mut file: &File, value: u32) {
5152

5253
pub struct BacklightManager {
5354
last_active: Instant,
55+
max_bl: u32,
5456
current_bl: u32,
5557
lid_state: SwitchState,
5658
bl_file: File,
@@ -65,6 +67,7 @@ impl BacklightManager {
6567
BacklightManager {
6668
bl_file,
6769
lid_state: SwitchState::Off,
70+
max_bl: read_attr(&bl_path, "max_brightness"),
6871
current_bl: read_attr(&bl_path, "brightness"),
6972
last_active: Instant::now(),
7073
display_bl_path
@@ -98,7 +101,7 @@ impl BacklightManager {
98101
}
99102
pub fn update_backlight(&mut self, cfg: &Config) {
100103
let since_last_active = (Instant::now() - self.last_active).as_millis() as u64;
101-
let new_bl = if self.lid_state == SwitchState::On {
104+
let new_bl = min(self.max_bl, if self.lid_state == SwitchState::On {
102105
0
103106
} else if since_last_active < BRIGHTNESS_DIM_TIMEOUT as u64 {
104107
if cfg.adaptive_brightness {
@@ -110,7 +113,7 @@ impl BacklightManager {
110113
DIMMED_BRIGHTNESS
111114
} else {
112115
0
113-
};
116+
});
114117
if self.current_bl != new_bl {
115118
self.current_bl = new_bl;
116119
set_backlight(&self.bl_file, self.current_bl);

0 commit comments

Comments
 (0)