Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linux): limit event reading #1510

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kanata/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Kanata {

loop {
let events = kbd_in.read().map_err(|e| anyhow!("failed read: {}", e))?;
log::trace!("{events:?}");
log::trace!("event count: {}\nevents:\n{events:?}", events.len());

for in_event in events.iter().copied() {
let key_event = match KeyEvent::try_from(in_event) {
Expand Down
11 changes: 7 additions & 4 deletions src/oskbd/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ impl KbdIn {
return Ok(vec![]);
}

const EVENT_LIMIT: usize = 48;

let mut do_rediscover = false;
for event in &self.events {
if let Some((device, _)) = self.devices.get_mut(&event.token()) {
if let Err(e) = device
.fetch_events()
.map(|evs| evs.into_iter().for_each(|ev| input_events.push(ev)))
{
if let Err(e) = device.fetch_events().map(|evs| {
evs.into_iter()
.take(EVENT_LIMIT)
.for_each(|ev| input_events.push(ev))
}) {
// Currently the kind() is uncategorized... not helpful, need to match
// on os error. code 19 is ENODEV, "no such device".
match e.raw_os_error() {
Expand Down