Skip to content

Commit

Permalink
Update touchbar active layer in real time as conf is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaGarg8 committed Nov 25, 2023
1 parent 587d392 commit 4094e5c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{
fs::{File, OpenOptions, read_to_string},
fs::{File, OpenOptions, read_to_string, self},
os::{
fd::AsRawFd,
unix::{io::OwnedFd, fs::OpenOptionsExt}
},
path::Path,
time::SystemTime,
collections::HashMap,
cmp::min,
mem,
Expand Down Expand Up @@ -343,6 +344,13 @@ fn load_config() -> Config {
}
}

fn get_file_modified_time(path: &str) -> Option<SystemTime> {
fs::metadata(path)
.ok()
.map(|metadata| metadata.modified().ok())
.flatten()
}

fn main() {
let mut drm = DrmBackend::open_card().unwrap();
let _ = panic::catch_unwind(AssertUnwindSafe(|| {
Expand Down Expand Up @@ -398,6 +406,8 @@ fn real_main(drm: &mut DrmBackend) {
let pollfd_tb = PollFd::new(&fd_tb, PollFlags::POLLIN);
let pollfd_main = PollFd::new(&fd_main, PollFlags::POLLIN);
uinput.set_evbit(EventKind::Key).unwrap();
let config_path = "/etc/tiny-dfr/config.toml";
let mut last_modified_time = get_file_modified_time(config_path);
let mut layers = mem::take(&mut cfg.layers);
for layer in &layers {
for button in &layer.buttons {
Expand All @@ -424,6 +434,15 @@ fn real_main(drm: &mut DrmBackend) {
let mut digitizer: Option<InputDevice> = None;
let mut touches = HashMap::new();
loop {
let current_modified_time = get_file_modified_time(config_path);
if current_modified_time != last_modified_time {
cfg = load_config();
layers = mem::take(&mut cfg.layers);
active_layer = 0;
last_modified_time = current_modified_time;
needs_complete_redraw = true;
}

let mut next_timeout_ms = TIMEOUT_MS;

if cfg.enable_pixel_shift {
Expand Down

0 comments on commit 4094e5c

Please sign in to comment.