tfc/
lib.rs

1//! The core of TFC is the [`Context`]. To start generating fake input events,
2//! you'll need to create a context. The context by itself is basically useless
3//! unless you import the [`traits`]. The trait methods return an [`Error`] if
4//! something goes wrong. Bringing these three things together, we end up with
5//! this.
6//!
7//! ```no_run
8//! use std::{thread, time::Duration};
9//! use tfc::{Context, Error, traits::*};
10//!
11//! fn main() -> Result<(), Error> {
12//!     let mut ctx = Context::new()?;
13//!     // For OS-specific reasons, it's necessary to wait a moment after
14//!     // creating the context before generating events.
15//!     thread::sleep(Duration::from_millis(10));
16//!     ctx.unicode_string("Hello world!")
17//! }
18//! ```
19//!
20//! In addition to the context and its traits, there is also [`Command`]. This
21//! represents an action to perform on the context. It's possible to serialize a
22//! command, send it over a network, deserialize it and then execute it. In
23//! fact, this is what [TFC-server](https://crates.io/crates/tfc-server) does.
24
25mod command;
26#[macro_use]
27mod r#enum;
28mod command_code;
29mod generic_error;
30mod key;
31mod mouse_button;
32mod utils;
33
34pub use command::*;
35pub use r#enum::*;
36pub use command_code::*;
37pub use generic_error::*;
38pub use key::*;
39pub use mouse_button::*;
40
41/// A collection of traits that [`Context`] implements.
42pub mod traits;
43pub use traits::*;
44
45#[cfg(target_os = "linux")]
46mod linux_common;
47
48#[cfg(all(target_os = "linux", not(x11)))]
49mod linux_wayland;
50#[cfg(all(target_os = "linux", not(x11)))]
51pub use linux_wayland::Context;
52
53#[cfg(all(target_os = "linux", x11))]
54mod linux_x11;
55#[cfg(all(target_os = "linux", x11))]
56pub use linux_x11::Context;
57
58#[cfg(target_os = "macos")]
59mod macos;
60#[cfg(target_os = "macos")]
61pub use macos::Context;
62
63#[cfg(target_os = "windows")]
64mod windows;
65#[cfg(target_os = "windows")]
66pub use windows::Context;
67
68/// Convenience type alias for [`GenericError`].
69pub type Error = GenericError<<Context as FallibleContext>::PlatformError>;