File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -662,6 +662,11 @@ impl RawDevice {
662662 Ok ( ( ) )
663663 }
664664
665+ /// Whether the device is currently grabbed for exclusive use or not.
666+ pub fn is_grabbed ( & self ) -> bool {
667+ self . grabbed
668+ }
669+
665670 /// Send an event to the device.
666671 ///
667672 /// Events that are typically sent to devices are
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ use std::{fmt, io};
2727/// If `fetch_events()` isn't called often enough and the kernel drops events from its internal
2828/// buffer, synthetic events will be injected into the iterator returned by `fetch_events()` and
2929/// [`Device::cached_state()`] will be kept up to date when `fetch_events()` is called.
30+ #[ derive( Debug ) ]
3031pub struct Device {
3132 raw : RawDevice ,
3233 prev_state : DeviceState ,
@@ -383,6 +384,11 @@ impl Device {
383384 self . raw . ungrab ( )
384385 }
385386
387+ /// Whether the device is currently grabbed for exclusive use or not.
388+ pub fn is_grabbed ( & self ) -> bool {
389+ self . raw . is_grabbed ( )
390+ }
391+
386392 /// Send an event to the device.
387393 ///
388394 /// Events that are typically sent to devices are
@@ -410,6 +416,14 @@ impl Device {
410416 }
411417}
412418
419+ impl Drop for Device {
420+ fn drop ( & mut self ) {
421+ if let Err ( error) = self . ungrab ( ) {
422+ eprintln ! ( "Failed to ungrab device: {error}" ) ;
423+ }
424+ }
425+ }
426+
413427impl AsFd for Device {
414428 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
415429 self . raw . as_fd ( )
You can’t perform that action at this time.
0 commit comments