Skip to content

Commit f9af777

Browse files
dont burn a whole core doing nothing
1 parent 5f301e7 commit f9af777

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ input = "0.8"
1313
libc = "0.2"
1414
input-linux = "0.6"
1515
input-linux-sys = "0.8"
16+
nix = "0.26"

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ use input::{
2929
use libc::{O_RDONLY, O_RDWR, O_WRONLY};
3030
use input_linux::{uinput::UInputHandle, EventKind, Key, SynchronizeKind};
3131
use input_linux_sys::{uinput_setup, input_id, timeval, input_event};
32+
use nix::poll::{poll, PollFd, PollFlags};
3233

3334
const DFR_WIDTH: i32 = 2008;
3435
const DFR_HEIGHT: i32 = 64;
3536
const BUTTON_COLOR_INACTIVE: f64 = 0.267;
3637
const BUTTON_COLOR_ACTIVE: f64 = 0.567;
38+
const TIMEOUT_MS: i32 = 30 * 1000;
3739

3840
struct Card(File);
3941
impl AsFd for Card {
@@ -309,6 +311,7 @@ fn main() {
309311
let mut drm = open_card().unwrap();
310312
let mut input = Libinput::new_with_udev(Interface);
311313
input.udev_assign_seat("seat0").unwrap();
314+
let pollfd = PollFd::new(input.as_raw_fd(), PollFlags::POLLIN);
312315
let mut uinput = UInputHandle::new(OpenOptions::new().write(true).open("/dev/uinput").unwrap());
313316
uinput.set_evbit(EventKind::Key).unwrap();
314317
for button in &layer.buttons {
@@ -344,6 +347,7 @@ fn main() {
344347
map.as_mut()[..data.len()].copy_from_slice(&data);
345348
drm.card.dirty_framebuffer(drm.fb, &[ClipRect{x1: 0, y1: 0, x2: DFR_HEIGHT as u16, y2: DFR_WIDTH as u16}]).unwrap();
346349
}
350+
poll(&mut [pollfd], TIMEOUT_MS).unwrap();
347351
input.dispatch().unwrap();
348352
for event in &mut input {
349353
match event {

0 commit comments

Comments
 (0)