Skip to content

Commit 4094e5c

Browse files
committed
Update touchbar active layer in real time as conf is modified
1 parent 587d392 commit 4094e5c

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/main.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::{
2-
fs::{File, OpenOptions, read_to_string},
2+
fs::{File, OpenOptions, read_to_string, self},
33
os::{
44
fd::AsRawFd,
55
unix::{io::OwnedFd, fs::OpenOptionsExt}
66
},
77
path::Path,
8+
time::SystemTime,
89
collections::HashMap,
910
cmp::min,
1011
mem,
@@ -343,6 +344,13 @@ fn load_config() -> Config {
343344
}
344345
}
345346

347+
fn get_file_modified_time(path: &str) -> Option<SystemTime> {
348+
fs::metadata(path)
349+
.ok()
350+
.map(|metadata| metadata.modified().ok())
351+
.flatten()
352+
}
353+
346354
fn main() {
347355
let mut drm = DrmBackend::open_card().unwrap();
348356
let _ = panic::catch_unwind(AssertUnwindSafe(|| {
@@ -398,6 +406,8 @@ fn real_main(drm: &mut DrmBackend) {
398406
let pollfd_tb = PollFd::new(&fd_tb, PollFlags::POLLIN);
399407
let pollfd_main = PollFd::new(&fd_main, PollFlags::POLLIN);
400408
uinput.set_evbit(EventKind::Key).unwrap();
409+
let config_path = "/etc/tiny-dfr/config.toml";
410+
let mut last_modified_time = get_file_modified_time(config_path);
401411
let mut layers = mem::take(&mut cfg.layers);
402412
for layer in &layers {
403413
for button in &layer.buttons {
@@ -424,6 +434,15 @@ fn real_main(drm: &mut DrmBackend) {
424434
let mut digitizer: Option<InputDevice> = None;
425435
let mut touches = HashMap::new();
426436
loop {
437+
let current_modified_time = get_file_modified_time(config_path);
438+
if current_modified_time != last_modified_time {
439+
cfg = load_config();
440+
layers = mem::take(&mut cfg.layers);
441+
active_layer = 0;
442+
last_modified_time = current_modified_time;
443+
needs_complete_redraw = true;
444+
}
445+
427446
let mut next_timeout_ms = TIMEOUT_MS;
428447

429448
if cfg.enable_pixel_shift {

0 commit comments

Comments
 (0)