Skip to content

Commit 7960118

Browse files
committed
backlight: Use constants for brightness and timeouts
1 parent 7704ce9 commit 7960118

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/backlight.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ use input::event::{
1010
};
1111
use crate::TIMEOUT_MS;
1212

13+
const BRIGHTNESS_DIM_TIMEOUT: i32 = TIMEOUT_MS * 1; // should be a multiple of TIMEOUT_MS
14+
const BRIGHTNESS_OFF_TIMEOUT: i32 = TIMEOUT_MS * 2; // should be a multiple of TIMEOUT_MS
15+
const DEFAULT_BRIGHTNESS: u32 = 128;
16+
const DIMMED_BRIGHTNESS: u32 = 1;
17+
1318
fn read_attr(path: &Path, attr: &str) -> u32 {
1419
fs::read_to_string(path.join(attr))
1520
.expect(&format!("Failed to read {attr}"))
@@ -74,10 +79,10 @@ impl BacklightManager {
7479
let since_last_active = (Instant::now() - self.last_active).as_millis() as u64;
7580
let new_bl = if self.lid_state == SwitchState::On {
7681
0
77-
} else if since_last_active < TIMEOUT_MS as u64 {
78-
128
79-
} else if since_last_active < TIMEOUT_MS as u64 * 2 {
80-
1
82+
} else if since_last_active < BRIGHTNESS_DIM_TIMEOUT as u64 {
83+
DEFAULT_BRIGHTNESS
84+
} else if since_last_active < BRIGHTNESS_OFF_TIMEOUT as u64 {
85+
DIMMED_BRIGHTNESS
8186
} else {
8287
0
8388
};

0 commit comments

Comments
 (0)