Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
shiro committed Dec 10, 2023
1 parent 1599585 commit dd2292b
Show file tree
Hide file tree
Showing 12 changed files with 516 additions and 294 deletions.
2 changes: 1 addition & 1 deletion examples/a_to_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

map2.link([reader, mapper, writer])

mapper.map("a", "b")
mapper.map("a", "b")
2 changes: 1 addition & 1 deletion examples/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
reader.send("Hello world!")

# keep running for 1sec so the event can be processed
time.sleep(1)
time.sleep(1)
26 changes: 18 additions & 8 deletions examples/tests/_setup_integration_tests/setup_integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::Write;

use map2::*;
use map2::python::*;
use map2::*;

#[pyo3_asyncio::tokio::main]
async fn main() -> pyo3::PyResult<()> {
Expand All @@ -10,7 +10,8 @@ async fn main() -> pyo3::PyResult<()> {
// .arg("--")
// .arg("--cfg").arg("test")
// .arg("--cfg").arg("integration")
.arg("--features").arg("integration")
.arg("--features")
.arg("integration")
.output()?;

if !cmd.status.success() {
Expand All @@ -29,8 +30,11 @@ mod integration_tests {
pub fn writer_read(py: Python, module: &PyModule, name: &str) -> Option<EvdevInputEvent> {
let target = module.getattr(name).unwrap().to_object(py);

target.call_method0(py, "__test__read_ev").unwrap()
.extract::<Option<String>>(py).unwrap()
target
.call_method0(py, "__test__read_ev")
.unwrap()
.extract::<Option<String>>(py)
.unwrap()
.and_then(|x| serde_json::from_str(&x).unwrap())
}

Expand All @@ -46,18 +50,24 @@ pub fn reader_send(py: Python, module: &PyModule, name: &str, ev: &EvdevInputEve
let target = module.getattr(name).unwrap().to_object(py);
let ev = serde_json::to_string(ev).unwrap();

target.call_method(py, "__test__write_ev", (ev, ), None).unwrap();
target
.call_method(py, "__test__write_ev", (ev,), None)
.unwrap();
}

pub fn reader_send_all(py: Python, module: &PyModule, name: &str, ev_list: &Vec<EvdevInputEvent>) {
let target = module.getattr(name).unwrap().to_object(py);

for ev in ev_list.iter() {
let ev = serde_json::to_string(ev).unwrap();
target.call_method(py, "__test__write_ev", (ev, ), None).unwrap();
target
.call_method(py, "__test__write_ev", (ev,), None)
.unwrap();
}
}

pub fn keys(input: &str) -> Vec<EvdevInputEvent> {
parse_key_sequence(input, Some(&Default::default())).unwrap().to_input_ev()
}
parse_key_sequence(input, Some(&Default::default()))
.unwrap()
.to_input_ev()
}
41 changes: 30 additions & 11 deletions src/key_defs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use evdev_rs::enums::{EV_SYN, EventCode};
use evdev_rs::enums::{EventCode, EV_SYN};
use evdev_rs::TimeVal;

use crate::*;

pub const INPUT_EV_DUMMY_TIME: TimeVal = TimeVal { tv_sec: 0, tv_usec: 0 };
pub const INPUT_EV_DUMMY_TIME: TimeVal = TimeVal {
tv_sec: 0,
tv_usec: 0,
};

pub static SYN_REPORT: EvdevInputEvent = EvdevInputEvent { event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT), value: 0, time: INPUT_EV_DUMMY_TIME };
pub static SYN_REPORT: EvdevInputEvent = EvdevInputEvent {
event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
value: 0,
time: INPUT_EV_DUMMY_TIME,
};

pub static ALL_KEYS: &'static [evdev_rs::enums::EV_KEY] = &[
KEY_RESERVED,
Expand Down Expand Up @@ -691,19 +698,31 @@ lazy_static! {
m.insert("KEYPAD_9", (KEY_KP9.into(), KeyModifierFlags::new()));
m.insert("LEFT_ALT", (KEY_LEFTALT.into(), KeyModifierFlags::new()));
m.insert("LEFT_CTRL", (KEY_RIGHTCTRL.into(), KeyModifierFlags::new()));
m.insert("LEFT_SHIFT", (KEY_LEFTSHIFT.into(), KeyModifierFlags::new()));
m.insert(
"LEFT_SHIFT",
(KEY_LEFTSHIFT.into(), KeyModifierFlags::new()),
);
m.insert("META", (KEY_LEFTMETA.into(), KeyModifierFlags::new()));
m.insert("PAGE_DOWN", (KEY_PAGEDOWN.into(), KeyModifierFlags::new()));
m.insert("PAGE_UP", (KEY_PAGEUP.into(), KeyModifierFlags::new()));
m.insert("RIGHT_ALT", (KEY_RIGHTALT.into(), KeyModifierFlags::new()));
m.insert("RIGHT_BRACE", (KEY_RIGHTBRACE.into(), KeyModifierFlags::new()));
m.insert("LEFT_BRACE", (KEY_LEFTBRACE.into(), KeyModifierFlags::new()));
m.insert("RIGHT_CTRL", (KEY_RIGHTCTRL.into(), KeyModifierFlags::new()));
m.insert("RIGHT_SHIFT", (KEY_RIGHTSHIFT.into(), KeyModifierFlags::new()));
m.insert(
"RIGHT_BRACE",
(KEY_RIGHTBRACE.into(), KeyModifierFlags::new()),
);
m.insert(
"LEFT_BRACE",
(KEY_LEFTBRACE.into(), KeyModifierFlags::new()),
);
m.insert(
"RIGHT_CTRL",
(KEY_RIGHTCTRL.into(), KeyModifierFlags::new()),
);
m.insert(
"RIGHT_SHIFT",
(KEY_RIGHTSHIFT.into(), KeyModifierFlags::new()),
);
m.insert("SHIFT", (KEY_LEFTSHIFT.into(), KeyModifierFlags::new()));
m
};
}



39 changes: 18 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
#![feature(fn_traits)]
#![feature(type_alias_impl_trait)]

#![recursion_limit = "256"]

#![allow(warnings)]

extern crate core;
#[macro_use]
extern crate lazy_static;
extern crate regex;

use std::{fs, io};
use std::borrow::BorrowMut;
use std::{fs, io};
// #[macro_use]
// use subscriber::linkable;
use std::hash::{DefaultHasher, Hash, Hasher};
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, mpsc, Mutex, RwLock, Weak};
use std::sync::{mpsc, Arc, Mutex, RwLock, Weak};
use std::thread;
use std::time::Duration;

pub use evdev_rs::enums::EV_ABS::*;
pub use evdev_rs::enums::EV_KEY::*;
pub use evdev_rs::enums::EV_REL::*;
pub use evdev_rs::enums::EV_ABS::*;
pub use key_primitives::Key;
pub use parsing::*;

Expand All @@ -48,32 +46,31 @@ pub use crate::key_defs::*;
use crate::key_primitives::*;
use crate::state::*;

pub mod key_defs;
pub mod state;
pub mod key_primitives;
pub mod parsing;
pub mod capabilities;
pub mod device;
pub mod event_handlers;
pub mod logging;
pub mod event_loop;
pub mod event;
pub mod subscriber;
pub mod encoding;
pub mod xkb;
pub mod xkb_transformer_registry;
pub mod error;
pub mod event;
pub mod event_handlers;
pub mod event_loop;
pub mod global;
pub mod key_defs;
pub mod key_primitives;
pub mod logging;
pub mod parsing;
pub mod platform;
pub mod state;
pub mod subscriber;
pub mod subscriber_map;
pub mod capabilities;
pub mod xkb;
pub mod xkb_transformer_registry;

#[cfg(feature = "integration")]
pub mod testing;


pub mod mapper;
pub mod python;
pub mod reader;
pub mod mapper;
pub mod writer;
pub mod virtual_writer;
pub mod window;
pub mod window;
pub mod writer;
Loading

0 comments on commit dd2292b

Please sign in to comment.