Skip to content

Commit

Permalink
fix build on older rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Dec 13, 2020
1 parent 91dbda8 commit 0169a3e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ members = [
"event",
"qemu",
"ddc",
"fd",
"x",
]
4 changes: 4 additions & 0 deletions fd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "screenstub-fd"
version = "0.0.1"
edition = "2018"
24 changes: 24 additions & 0 deletions fd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::os::unix::io::{AsRawFd, RawFd};

pub type FdRef<'a, T> = Fd<&'a T>;

#[derive(Copy, Clone, Debug)]
pub struct Fd<T = RawFd>(pub T);

impl<'a, T: AsRawFd> AsRawFd for Fd<&'a T> {
fn as_raw_fd(&self) -> RawFd {
self.0.as_raw_fd()
}
}

impl AsRawFd for Fd<RawFd> {
fn as_raw_fd(&self) -> RawFd {
self.0
}
}

impl<T> From<T> for Fd<T> {
fn from(fd: T) -> Self {
Self(fd)
}
}
1 change: 1 addition & 0 deletions uinput/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
edition = "2018"

[dependencies]
screenstub-fd = { version = "^0.0.1", path = "../fd" }
input-linux = { version = "^0.4.0", features = ["with-tokio"] }
futures = { version = "^0.3.4", features = ["bilock", "unstable"] }
tokio = { version = "^0.3.3", default-features = false, features = ["macros", "time", "io-util", "rt"] }
Expand Down
29 changes: 11 additions & 18 deletions uinput/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::{self, Read, Write};
use std::{mem, slice};
use std::task::{Poll, Context};
use std::pin::Pin;
use screenstub_fd::{Fd, FdRef};
use input_linux as input;
use input_linux::{
UInputHandle, InputId,
Expand All @@ -20,7 +21,7 @@ use futures::{Sink, Stream, ready};
use bytes::{BytesMut, BufMut};
use log::{trace, debug};

pub type EvdevHandle<'a> = input_linux::EvdevHandle<FdRef<'a, AsyncFd<RawFd>>>;
pub type EvdevHandle<'a> = input_linux::EvdevHandle<FdRef<'a, AsyncFd<Fd>>>;

#[derive(Debug, Default, Clone)]
pub struct Builder {
Expand Down Expand Up @@ -51,14 +52,6 @@ fn io_poll<T>(res: io::Result<T>) -> Poll<io::Result<T>> {
}
}

pub struct FdRef<'a, T>(&'a T);

impl<'a, T: AsRawFd> AsRawFd for FdRef<'a, T> {
fn as_raw_fd(&self) -> RawFd {
self.0.as_raw_fd()
}
}

impl Builder {
pub fn new() -> Self {
Default::default()
Expand Down Expand Up @@ -162,9 +155,9 @@ impl Builder {
open.read(true);
open.write(true);
let file = open.open(FILENAME)?;
let fd = AsyncFd::new(file.as_raw_fd())?;
let fd = AsyncFd::new(file.as_raw_fd().into())?;

let handle = UInputHandle::new(FdRef(&file));
let handle = UInputHandle::new(Fd(&file));

debug!("UInput props {:?}", self.bits_props);
for bit in &self.bits_props {
Expand Down Expand Up @@ -223,7 +216,7 @@ impl Builder {

#[derive(Debug)]
pub struct UInput {
pub fd: AsyncFd<RawFd>,
pub fd: AsyncFd<Fd>,
pub file: File,
pub path: PathBuf,
}
Expand All @@ -234,7 +227,7 @@ impl UInput {
}

pub fn write_events(&mut self, events: &[InputEvent]) -> io::Result<usize> {
UInputHandle::new(FdRef(&self.fd)).write(unsafe { mem::transmute(events) })
UInputHandle::new(Fd(&self.fd)).write(unsafe { mem::transmute(events) })
}

pub fn write_event(&mut self, event: &InputEvent) -> io::Result<usize> {
Expand All @@ -255,7 +248,7 @@ impl UInput {

#[derive(Debug)]
pub struct Evdev {
fd: AsyncFd<RawFd>,
fd: AsyncFd<Fd>,
file: File,
}

Expand All @@ -268,13 +261,13 @@ impl Evdev {
let file = open.open(path)?;

Ok(Evdev {
fd: AsyncFd::new(file.as_raw_fd())?,
fd: AsyncFd::new(file.as_raw_fd().into())?,
file,
})
}

pub fn evdev(&self) -> EvdevHandle {
EvdevHandle::new(FdRef(&self.fd))
EvdevHandle::new(Fd(&self.fd))
}

pub fn to_sink(self) -> io::Result<UInputSink> {
Expand All @@ -291,7 +284,7 @@ impl Evdev {

//#[derive(Debug)]
pub struct UInputSink {
fd: Option<(AsyncFd<RawFd>, File)>,
fd: Option<(AsyncFd<Fd>, File)>,
buffer_write: BytesMut,
buffer_read: BytesMut,
codec: EventCodec,
Expand All @@ -300,7 +293,7 @@ pub struct UInputSink {
impl UInputSink {
pub fn evdev(&self) -> Option<EvdevHandle> {
self.fd.as_ref().map(|(fd, _)|
EvdevHandle::new(FdRef(fd))
EvdevHandle::new(Fd(fd))
)
}

Expand Down
1 change: 1 addition & 0 deletions x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
edition = "2018"

[dependencies]
screenstub-fd = { version = "^0.0.1", path = "../fd" }
futures = { version = "^0.3.4", features = ["bilock", "unstable"] }
tokio = { version = "^0.3.3", default-features = false, features = ["rt-multi-thread"] }
failure = "^0.1.1"
Expand Down
6 changes: 3 additions & 3 deletions x/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use failure::{Error, format_err};
use input_linux::{InputEvent, EventTime, KeyEvent, KeyState, Key, AbsoluteEvent, AbsoluteAxis, SynchronizeEvent};
use tokio::io::unix::AsyncFd;
use tokio::io::Interest;
use std::os::unix::io::RawFd;
use std::task::{Poll, Context, Waker};
use std::pin::Pin;
use log::{trace, warn, info};
use screenstub_fd::Fd;

#[derive(Debug, Clone, Copy, Default)]
struct XState {
Expand Down Expand Up @@ -60,7 +60,7 @@ pub enum XRequest {

pub struct XContext {
conn: xcb::Connection,
fd: AsyncFd<RawFd>,
fd: AsyncFd<Fd>,
window: u32,

keys: xcb::GetKeyboardMappingReply,
Expand All @@ -85,7 +85,7 @@ impl XContext {
let (conn, screen_num) = xcb::Connection::connect(None)?;
let fd = {
let fd = unsafe { xcb::ffi::base::xcb_get_file_descriptor(conn.get_raw_conn()) };
AsyncFd::with_interest(fd, Interest::READABLE)
AsyncFd::with_interest(fd.into(), Interest::READABLE)
}?;
let window = conn.generate_id();
let (keys, mods) = {
Expand Down

0 comments on commit 0169a3e

Please sign in to comment.