Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4e92975
Tmp.
Narsil May 3, 2025
cd30831
Fixing the macos flags.
Narsil May 4, 2025
6d9a8cc
Add flake.nix
Narsil May 5, 2025
fed5ec8
Semi working state.
Narsil May 5, 2025
fb1a8a7
Whatever??
Narsil May 5, 2025
d4c1243
Dead code.
Narsil May 5, 2025
2a093c9
Cleaner version for wayland.
Narsil May 20, 2025
74297f5
Cargo fmt.
Narsil May 20, 2025
6cfb37b
Testing X11 for now.
Narsil May 20, 2025
8bd35e9
Fixing a few things, x11 overrides wayland.
Narsil May 20, 2025
f1ff8b9
Attempting to fix macos.
Narsil May 20, 2025
30d8510
Missing linux dep.
Narsil May 20, 2025
642ef40
Adding flake.
Narsil May 20, 2025
b3e99f7
After rebase.
Narsil May 20, 2025
a7dd8b9
Can we add wayland ?
Narsil May 20, 2025
86cb56e
New variant?
Narsil May 20, 2025
b002c33
Adding missing weston.
Narsil May 20, 2025
08fb746
Tmp.
Narsil May 20, 2025
a7ef32c
Put the headless in the background.
Narsil May 20, 2025
424902a
Different deps.
Narsil May 20, 2025
2ddb9b9
Trying stuff.
Narsil May 20, 2025
40894e1
Skipping keyboard state.
Narsil May 20, 2025
a63b8a3
More work on pointer.
Narsil May 21, 2025
6705f71
Semi working state (no absolute mouse movement, no keyboard).
Narsil May 21, 2025
f7a469e
Missing feature for x11/wayland.
Narsil May 21, 2025
b51b0ee
Add x11 to wayland for simplicity.
Narsil May 21, 2025
6c4320d
Uinput.
Narsil May 21, 2025
a62bf34
Adding more perms.
Narsil May 21, 2025
45bf2e4
Is this good?
Narsil May 21, 2025
7814352
Fixing things.
Narsil May 21, 2025
1189a6f
Adding the ruleset.
Narsil May 21, 2025
3ebf1f5
Skipping listen and simulate as we don't have permission.
Narsil May 21, 2025
ab58005
Making keyboard work (hardcoded layout + variant for now).
Narsil May 21, 2025
ddf86e9
Dynamic layout.
Narsil May 21, 2025
6b13e38
Cargo fmt.
Narsil May 21, 2025
ef3392d
We need xkbcommon to build.
Narsil May 21, 2025
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
41 changes: 30 additions & 11 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,45 @@ on:

jobs:
build:

name: build ${{ matrix.variant }}
runs-on: ${{matrix.os}}
env:
DISPLAY: ':99'
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
- variant: ubuntu-x11-latest
os: ubuntu-latest
headless: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- os: ubuntu-latest
dependencies: sudo apt-get install libxtst-dev libevdev-dev --assume-yes
- os: macos-latest
dependencies: sudo apt-get install libxtst-dev libevdev-dev libudev-dev --assume-yes
build: cargo build --verbose --features x11
test: cargo test --verbose --features=serialize,x11
- variant: ubuntu-wayland-latest
os: ubuntu-latest
headless: weston --no-config --socket=wl-test-env --backend=headless &
dependencies: |
sudo apt-get install libxtst-dev libevdev-dev libudev-dev libinput-dev libxkbcommon-dev weston --assume-yes
sudo chown root:input /dev/uinput
sudo chmod g+rw /dev/uinput
id -a
whoami
sudo usermod -aG input runner
echo 'KERNEL=="uinput", MODE="0660", GROUP="input", TAG+="uaccess"' | sudo tee /etc/udev/rules.d/99-uinput.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --attr-match=name="uinput"

build: cargo build --verbose --features wayland
# Keyboard not implemented in wayland
test: WAYLAND_DISPLAY=wl-test-env cargo test --verbose --no-default-features --features=serialize,wayland -- --skip test_grab --skip test_listen_and_simulate
- variant: macos-latest
os: macos-latest
build: cargo build --verbose
# TODO: We can't test this on github, we can't set accessibility yet.
test: cargo test --verbose --all-features -- --skip test_listen_and_simulate --skip test_grab
- os: ubuntu-latest
# TODO unstable_grab feature is not supported on Linux.
test: cargo test --verbose --features=serialize
- os: windows-latest
- variant: windows-latest
os: windows-latest
build: cargo build --verbose
test: cargo test --verbose --all-features

steps:
Expand All @@ -44,7 +63,7 @@ jobs:
rustup component add rustfmt
cargo fmt -- --check
- name: Build
run: cargo build --verbose
run: ${{ matrix.build }}
- name: Run tests
run: ${{matrix.test}}
- name: Linter
Expand Down
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ serde = {version = "1.0", features = ["derive"], optional=true}
lazy_static = "1.4"

[features]
default = []
serialize = ["serde"]
unstable_grab = ["evdev-rs", "epoll", "inotify"]
wayland = ["input", "input-linux", "xkbcommon"]
x11 = ["dep:x11"]

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.26"
Expand All @@ -31,10 +34,13 @@ dispatch = "0.2"

[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2"
x11 = {version = "2.18", features = ["xlib", "xrecord", "xinput"]}
x11 = {version = "2.18", features = ["xlib", "xrecord", "xinput"], optional = true}
evdev-rs = {version = "0.6", optional=true}
epoll = {version = "4.1.0", optional=true}
inotify = {version = "0.11", default-features=false, optional=true}
input = {version = "0.9", optional=true}
input-linux = { version = "0.7.1", optional = true }
xkbcommon = { version = "0.5.0", optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winuser", "errhandlingapi", "processthreadsapi"] }
Expand All @@ -57,7 +63,7 @@ required-features = ["unstable_grab"]

[[example]]
name = "tokio_channel"
required-features = ["unstable_grab"]
required-features = []

[[test]]
name = "grab"
Expand Down
11 changes: 10 additions & 1 deletion examples/simulate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use rdev::{simulate, Button, EventType, Key, SimulateError};
use std::{thread, time};
use std::{
thread,
time::{self, Duration},
};

fn send(event_type: &EventType) {
let delay = time::Duration::from_millis(20);
Expand All @@ -14,8 +17,14 @@ fn send(event_type: &EventType) {
}

fn main() {
send(&EventType::MouseMove { x: 0.0, y: 0.0 });
thread::sleep(Duration::from_millis(1000));
send(&EventType::KeyPress(Key::KeyS));
send(&EventType::KeyRelease(Key::KeyS));
send(&EventType::KeyPress(Key::KeyA));
send(&EventType::KeyRelease(Key::KeyA));
send(&EventType::KeyPress(Key::KeyB));
send(&EventType::KeyRelease(Key::KeyB));

send(&EventType::MouseMove { x: 0.0, y: 0.0 });
send(&EventType::MouseMove { x: 400.0, y: 400.0 });
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

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

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
++ (
if stdenv.isLinux then
[
xkbmon
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libXtst
libevdev
libnotify
libinput
libxkbcommon
udev
]
else
[ ]
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ pub use crate::rdev::{
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use crate::macos::{set_is_main_thread, Keyboard};
#[cfg(target_os = "macos")]
use crate::macos::{display_size as _display_size, listen as _listen, simulate as _simulate};
#[cfg(target_os = "macos")]
pub use crate::macos::{set_is_main_thread, Keyboard};

#[cfg(target_os = "linux")]
mod linux;
Expand Down Expand Up @@ -305,7 +305,8 @@ where
/// }
/// ```
pub fn simulate(event_type: &EventType) -> Result<(), SimulateError> {
_simulate(event_type)
_simulate(event_type)?;
Ok(())
}

/// Returns the size in pixels of the main screen.
Expand Down
28 changes: 12 additions & 16 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
extern crate libc;
extern crate x11;
#[cfg(feature = "x11")]
mod x11;

mod common;
mod display;
#[cfg(feature = "unstable_grab")]
mod grab;
mod keyboard;
mod keycodes;
mod listen;
mod simulate;
#[cfg(feature = "x11")]
pub use x11::*;

pub use crate::linux::display::display_size;
#[cfg(feature = "unstable_grab")]
pub use crate::linux::grab::grab;
pub use crate::linux::keyboard::Keyboard;
pub use crate::linux::listen::listen;
pub use crate::linux::simulate::simulate;
#[cfg(all(feature = "wayland", not(feature = "x11")))]
mod wayland;

#[cfg(all(feature = "wayland", not(feature = "x11")))]
pub use wayland::*;

#[cfg(not(any(feature = "wayland", feature = "x11")))]
compile_error!("Need to activate either wayland or x11 feature on linux");
1 change: 1 addition & 0 deletions src/linux/wayland/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions src/linux/wayland/display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::rdev::DisplayError;

pub fn display_size() -> Result<(u64, u64), DisplayError> {
todo!("Not implemented");
// let display = Display::new().ok_or(DisplayError::NoDisplay)?;
// display.get_size().ok_or(DisplayError::NoDisplay)
}
Loading