mirror of
https://github.com/htrefil/rkvm.git
synced 2024-11-16 07:47:24 +01:00
Remove useless Option
This commit is contained in:
parent
db356da9f4
commit
357f85512a
4 changed files with 14 additions and 22 deletions
|
@ -5,7 +5,7 @@ use crate::event::{Axis, Button, Direction, Event, Key, KeyKind};
|
|||
use crate::linux::glue::{self, input_event, timeval};
|
||||
|
||||
impl Event {
|
||||
pub(crate) fn to_raw(&self) -> Option<input_event> {
|
||||
pub(crate) fn to_raw(&self) -> input_event {
|
||||
let (type_, code, value) = match *self {
|
||||
Event::MouseScroll { delta } => (glue::EV_REL as _, glue::REL_WHEEL as _, delta),
|
||||
Event::MouseMove {
|
||||
|
@ -19,14 +19,14 @@ impl Event {
|
|||
Event::Key {
|
||||
direction: Direction::Up,
|
||||
kind,
|
||||
} => (glue::EV_KEY as _, kind.to_raw()?, 0),
|
||||
} => (glue::EV_KEY as _, kind.to_raw(), 0),
|
||||
Event::Key {
|
||||
direction: Direction::Down,
|
||||
kind,
|
||||
} => (glue::EV_KEY as _, kind.to_raw()?, 1),
|
||||
} => (glue::EV_KEY as _, kind.to_raw(), 1),
|
||||
};
|
||||
|
||||
Some(input_event {
|
||||
input_event {
|
||||
type_,
|
||||
code,
|
||||
value,
|
||||
|
@ -34,7 +34,7 @@ impl Event {
|
|||
tv_sec: 0,
|
||||
tv_usec: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_raw(raw: input_event) -> Option<Self> {
|
||||
|
@ -70,7 +70,7 @@ impl KeyKind {
|
|||
.or_else(|| Button::from_raw(code).map(KeyKind::Button))
|
||||
}
|
||||
|
||||
pub(crate) fn to_raw(&self) -> Option<u16> {
|
||||
pub(crate) fn to_raw(&self) -> u16 {
|
||||
match self {
|
||||
KeyKind::Key(key) => key.to_raw(),
|
||||
KeyKind::Button(button) => button.to_raw(),
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::event::Button;
|
||||
|
||||
impl Button {
|
||||
pub(crate) fn to_raw(&self) -> Option<u16> {
|
||||
pub(crate) fn to_raw(&self) -> u16 {
|
||||
use Button::*;
|
||||
|
||||
let code = match *self {
|
||||
match *self {
|
||||
A => 0x0130,
|
||||
B => 0x0131,
|
||||
Back => 0x0116,
|
||||
|
@ -124,9 +124,7 @@ impl Button {
|
|||
X => 0x0130,
|
||||
Y => 0x0150,
|
||||
Z => 0x0135,
|
||||
};
|
||||
|
||||
Some(code)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_raw(code: u16) -> Option<Self> {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::event::Key;
|
||||
|
||||
impl Key {
|
||||
pub(crate) fn to_raw(&self) -> Option<u16> {
|
||||
pub(crate) fn to_raw(&self) -> u16 {
|
||||
use Key::*;
|
||||
|
||||
let code = match *self {
|
||||
match *self {
|
||||
A => 0x001E,
|
||||
Ab => 0x0196,
|
||||
AddressBook => 0x01AD,
|
||||
|
@ -493,9 +493,7 @@ impl Key {
|
|||
ZoomIn => 0x01A2,
|
||||
ZoomOut => 0x01A3,
|
||||
ZoomReset => 0x01A4,
|
||||
};
|
||||
|
||||
Some(code)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_raw(code: u16) -> Option<Self> {
|
||||
|
|
|
@ -48,14 +48,10 @@ impl EventWriter {
|
|||
}
|
||||
|
||||
pub async fn write(&mut self, event: Event) -> Result<(), Error> {
|
||||
if let Some(event) = event.to_raw() {
|
||||
return self.write_raw(event).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
self.write_raw(event.to_raw())
|
||||
}
|
||||
|
||||
pub(crate) async fn write_raw(&mut self, event: input_event) -> Result<(), Error> {
|
||||
pub(crate) fn write_raw(&mut self, event: input_event) -> Result<(), Error> {
|
||||
// As far as tokio is concerned, the FD never becomes ready for writing, so just write it normally.
|
||||
// If an error happens, it will be propagated to caller and the FD is opened in nonblocking mode anyway,
|
||||
// so it shouldn't be an issue.
|
||||
|
|
Loading…
Reference in a new issue