Skip to content

Commit 8635a6a

Browse files
committed
Fixing a few things, x11 overrides wayland.
1 parent c207b56 commit 8635a6a

File tree

11 files changed

+26
-28
lines changed

11 files changed

+26
-28
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ jobs:
2020
include:
2121
- os: ubuntu-latest
2222
headless: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
23-
- os: ubuntu-latest
2423
dependencies: sudo apt-get install libxtst-dev libevdev-dev --assume-yes
24+
test: cargo test --verbose --features=serialize,x11
2525
- os: macos-latest
2626
# TODO: We can't test this on github, we can't set accessibility yet.
2727
test: cargo test --verbose --all-features -- --skip test_listen_and_simulate --skip test_grab
28-
- os: ubuntu-latest
29-
# TODO unstable_grab feature is not supported on Linux.
30-
test: cargo test --verbose --features=serialize,x11
3128
- os: windows-latest
3229
test: cargo test --verbose --all-features
3330

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ serde = {version = "1.0", features = ["derive"], optional=true}
1818
lazy_static = "1.4"
1919

2020
[features]
21-
default = []
21+
default = ["x11"]
2222
serialize = ["serde"]
2323
unstable_grab = ["evdev-rs", "epoll", "inotify"]
2424
wayland = ["input", "input-linux"]
25+
x11 = ["dep:x11"]
2526

2627
[target.'cfg(target_os = "macos")'.dependencies]
2728
cocoa = "0.26"
@@ -33,7 +34,7 @@ dispatch = "0.2"
3334

3435
[target.'cfg(target_os = "linux")'.dependencies]
3536
libc = "0.2"
36-
x11 = {version = "2.18", features = ["xlib", "xrecord", "xinput"]}
37+
x11 = {version = "2.18", features = ["xlib", "xrecord", "xinput"], optional = true}
3738
evdev-rs = {version = "0.6", optional=true}
3839
epoll = {version = "4.1.0", optional=true}
3940
inotify = {version = "0.11", default-features=false, optional=true}

src/linux/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ mod x11;
44
#[cfg(feature = "x11")]
55
pub use x11::*;
66

7-
#[cfg(feature = "wayland")]
7+
#[cfg(all(feature = "wayland", not(feature = "x11")))]
88
mod wayland;
99

10-
#[cfg(feature = "wayland")]
10+
#[cfg(all(feature = "wayland", not(feature = "x11")))]
1111
pub use wayland::*;
1212

1313
#[cfg(not(any(feature = "wayland", feature = "x11")))]

src/linux/wayland/grab.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ where
375375
let (_, event) = match device.next_event(evdev_rs::ReadFlag::NORMAL) {
376376
Ok(event) => event,
377377
Err(_) => {
378-
let device_fd = device.fd().unwrap().into_raw_fd();
378+
let device_fd = device.file().as_raw_fd();
379379
let empty_event = epoll::Event::new(epoll::Events::empty(), 0);
380380
epoll::ctl(epoll_fd, EPOLL_CTL_DEL, device_fd, empty_event)?;
381381
continue 'events;
@@ -469,8 +469,8 @@ where
469469
}
470470

471471
fn inotify_devices() -> io::Result<Inotify> {
472-
let mut inotify = Inotify::init()?;
473-
inotify.add_watch(DEV_PATH, WatchMask::CREATE)?;
472+
let inotify = Inotify::init()?;
473+
inotify.watches().add(DEV_PATH, WatchMask::CREATE)?;
474474
Ok(inotify)
475475
}
476476

@@ -485,7 +485,7 @@ fn add_device_to_epoll_from_inotify_event(
485485
// new plug events
486486
let file = File::open(device_path)?;
487487
let fd = file.as_raw_fd();
488-
let device = Device::new_from_fd(file)?;
488+
let device = Device::new_from_file(file)?;
489489
let event = epoll::Event::new(EPOLLIN, devices.len() as u64);
490490
devices.push(device);
491491
epoll::ctl(epoll_fd, EPOLL_CTL_ADD, fd, event)?;
@@ -501,7 +501,7 @@ fn setup_devices() -> io::Result<(RawFd, Vec<Device>, Vec<UInputDevice>)> {
501501
let epoll_fd = epoll_watch_all(device_files.iter())?;
502502
let devices = device_files
503503
.into_iter()
504-
.map(Device::new_from_fd)
504+
.map(Device::new_from_file)
505505
.collect::<io::Result<Vec<Device>>>()?;
506506
let output_devices = devices
507507
.iter()

src/linux/x11/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::linux::keyboard::Keyboard;
2-
use crate::linux::keycodes::key_from_code;
1+
use super::keyboard::Keyboard;
2+
use super::keycodes::key_from_code;
33
use crate::rdev::{Button, Event, EventType, KeyboardState};
44
use std::convert::TryInto;
55
use std::os::raw::{c_int, c_uchar, c_uint};

src/linux/x11/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::linux::common::Display;
1+
use super::common::Display;
22
use crate::rdev::DisplayError;
33

44
pub fn display_size() -> Result<(u64, u64), DisplayError> {

src/linux/x11/grab.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::linux::common::Display;
2-
use crate::linux::keyboard::Keyboard;
1+
use super::common::Display;
2+
use super::keyboard::Keyboard;
33
use crate::rdev::{Button, Event, EventType, GrabError, Key, KeyboardState};
44
use epoll::ControlOptions::{EPOLL_CTL_ADD, EPOLL_CTL_DEL};
55
use evdev_rs::{

src/linux/x11/keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate x11;
2-
use crate::linux::keycodes::code_from_key;
2+
use super::keycodes::code_from_key;
33
use crate::rdev::{EventType, Key, KeyboardState};
44
use std::ffi::CString;
55
use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void};

src/linux/x11/listen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libc;
22
extern crate x11;
3-
use crate::linux::common::{convert, FALSE, KEYBOARD};
4-
use crate::linux::keyboard::Keyboard;
3+
use super::common::{convert, FALSE, KEYBOARD};
4+
use super::keyboard::Keyboard;
55
use crate::rdev::{Event, ListenError};
66
use std::convert::TryInto;
77
use std::ffi::CStr;

src/linux/x11/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ mod keycodes;
1010
mod listen;
1111
mod simulate;
1212

13-
pub use crate::linux::display::display_size;
13+
pub use display::display_size;
1414
#[cfg(feature = "unstable_grab")]
15-
pub use crate::linux::grab::grab;
16-
pub use crate::linux::keyboard::Keyboard;
17-
pub use crate::linux::listen::listen;
18-
pub use crate::linux::simulate::simulate;
15+
pub use grab::grab;
16+
pub use keyboard::Keyboard;
17+
pub use listen::listen;
18+
pub use simulate::simulate;

0 commit comments

Comments
 (0)