Skip to content
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
5 changes: 5 additions & 0 deletions src/raw_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ impl RawDevice {
Ok(())
}

/// Whether the device is currently grabbed for exclusive use or not.
pub fn is_grabbed(&self) -> bool {
self.grabbed
}

/// Send an event to the device.
///
/// Events that are typically sent to devices are
Expand Down
14 changes: 14 additions & 0 deletions src/sync_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{fmt, io};
/// If `fetch_events()` isn't called often enough and the kernel drops events from its internal
/// buffer, synthetic events will be injected into the iterator returned by `fetch_events()` and
/// [`Device::cached_state()`] will be kept up to date when `fetch_events()` is called.
#[derive(Debug)]
pub struct Device {
raw: RawDevice,
prev_state: DeviceState,
Expand Down Expand Up @@ -383,6 +384,11 @@ impl Device {
self.raw.ungrab()
}

/// Whether the device is currently grabbed for exclusive use or not.
pub fn is_grabbed(&self) -> bool {
self.raw.is_grabbed()
}

/// Send an event to the device.
///
/// Events that are typically sent to devices are
Expand Down Expand Up @@ -410,6 +416,14 @@ impl Device {
}
}

impl Drop for Device {
fn drop(&mut self) {
if let Err(error) = self.ungrab() {
eprintln!("Failed to ungrab device: {error}");
}
}
}

impl AsFd for Device {
fn as_fd(&self) -> BorrowedFd<'_> {
self.raw.as_fd()
Expand Down
Loading