Skip to content

Commit bb4e648

Browse files
use epoll
1 parent 750b2f0 commit bb4e648

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ input = "0.8"
1818
libc = "0.2"
1919
input-linux = { version = "0.6", features = ["serde"] }
2020
input-linux-sys = "0.8"
21-
nix = { version = "0.27", features = ["poll", "signal", "inotify"] }
21+
nix = { version = "0.27", features = ["event", "signal", "inotify"] }
2222
privdrop = "0.5.3"
2323
serde = { version = "1", features = ["derive"] }
2424
toml = "0.8"

src/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
use std::fs::read_to_string;
1+
use std::{
2+
fs::read_to_string,
3+
os::fd::AsFd
4+
};
25
use anyhow::Error;
36
use cairo::FontFace;
47
use crate::FunctionLayer;
58
use crate::fonts::{FontConfig, Pattern};
69
use freetype::Library as FtLibrary;
710
use input_linux::Key;
8-
use nix::errno::Errno;
9-
use nix::poll::{PollFd, PollFlags};
10-
use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify, WatchDescriptor};
11+
use nix::{
12+
errno::Errno,
13+
sys::inotify::{AddWatchFlags, InitFlags, Inotify, WatchDescriptor}
14+
};
1115
use serde::Deserialize;
1216

1317
const USER_CFG_PATH: &'static str = "/etc/tiny-dfr/config.toml";
@@ -125,7 +129,7 @@ impl ConfigManager {
125129
}
126130
ret
127131
}
128-
pub fn pollfd(&self) -> PollFd {
129-
PollFd::new(&self.inotify_fd, PollFlags::POLLIN)
132+
pub fn fd(&self) -> &impl AsFd {
133+
&self.inotify_fd
130134
}
131135
}

src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use input::{
2424
use libc::{O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY, c_char};
2525
use input_linux::{uinput::UInputHandle, EventKind, Key, SynchronizeKind};
2626
use input_linux_sys::{uinput_setup, input_id, timeval, input_event};
27-
use nix::{
28-
poll::{poll, PollFd, PollFlags},
29-
sys::signal::{Signal, SigSet},
27+
use nix::sys::{
28+
signal::{Signal, SigSet},
29+
epoll::{Epoll, EpollCreateFlags, EpollEvent, EpollFlags}
3030
};
3131
use privdrop::PrivDrop;
3232

@@ -358,10 +358,10 @@ fn real_main(drm: &mut DrmBackend) {
358358
let mut input_main = Libinput::new_with_udev(Interface);
359359
input_tb.udev_assign_seat("seat-touchbar").unwrap();
360360
input_main.udev_assign_seat("seat0").unwrap();
361-
let fd_tb = input_tb.as_fd().try_clone_to_owned().unwrap();
362-
let fd_main = input_main.as_fd().try_clone_to_owned().unwrap();
363-
let pollfd_tb = PollFd::new(&fd_tb, PollFlags::POLLIN);
364-
let pollfd_main = PollFd::new(&fd_main, PollFlags::POLLIN);
361+
let epoll = Epoll::new(EpollCreateFlags::empty()).unwrap();
362+
epoll.add(input_main.as_fd(), EpollEvent::new(EpollFlags::EPOLLIN, 0)).unwrap();
363+
epoll.add(input_tb.as_fd(), EpollEvent::new(EpollFlags::EPOLLIN, 1)).unwrap();
364+
epoll.add(cfg_mgr.fd(), EpollEvent::new(EpollFlags::EPOLLIN, 2)).unwrap();
365365
uinput.set_evbit(EventKind::Key).unwrap();
366366
for layer in &layers {
367367
for button in &layer.buttons {
@@ -415,7 +415,7 @@ fn real_main(drm: &mut DrmBackend) {
415415
needs_complete_redraw = false;
416416
}
417417

418-
poll(&mut [pollfd_tb, pollfd_main, cfg_mgr.pollfd()], next_timeout_ms).unwrap();
418+
epoll.wait(&mut [EpollEvent::new(EpollFlags::EPOLLIN, 0)], next_timeout_ms as isize).unwrap();
419419
input_tb.dispatch().unwrap();
420420
input_main.dispatch().unwrap();
421421
for event in &mut input_tb.clone().chain(input_main.clone()) {

0 commit comments

Comments
 (0)