Refactor for consistency
This commit is contained in:
parent
d6658dcd48
commit
965d9acd25
3 changed files with 24 additions and 31 deletions
|
@ -184,7 +184,7 @@ impl EventReader {
|
||||||
self.toggle_modifiers(Key(event.code()), event.value()).await;
|
self.toggle_modifiers(Key(event.code()), event.value()).await;
|
||||||
virt_dev.keys.emit(&[event]).unwrap();
|
virt_dev.keys.emit(&[event]).unwrap();
|
||||||
},
|
},
|
||||||
EventType::RELATIVE => virt_dev.relative_axes.emit(&[event]).unwrap(),
|
EventType::RELATIVE => virt_dev.axis.emit(&[event]).unwrap(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ impl EventReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_axis_value(&self, has_signed_axis_value: &str, event: &InputEvent) -> i32 {
|
async fn get_axis_value(&self, has_signed_axis_value: &str, event: &InputEvent) -> i32 {
|
||||||
let rel_value: i32 = match &has_signed_axis_value {
|
let axis_value: i32 = match &has_signed_axis_value {
|
||||||
&"false" => {
|
&"false" => {
|
||||||
let distance_from_center: i32 = event.value() as i32 - 128;
|
let distance_from_center: i32 = event.value() as i32 - 128;
|
||||||
distance_from_center / 10
|
distance_from_center / 10
|
||||||
|
@ -216,7 +216,7 @@ impl EventReader {
|
||||||
event.value() as i32 / 2000
|
event.value() as i32 / 2000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return rel_value
|
return axis_value
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn toggle_modifiers(&self, key: Key, value: i32) {
|
async fn toggle_modifiers(&self, key: Key, value: i32) {
|
||||||
|
@ -248,8 +248,8 @@ impl EventReader {
|
||||||
let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 0, analog_position[0]);
|
let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 0, analog_position[0]);
|
||||||
let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 1, analog_position[1]);
|
let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 1, analog_position[1]);
|
||||||
let mut virt_dev = self.virt_dev.lock().await;
|
let mut virt_dev = self.virt_dev.lock().await;
|
||||||
virt_dev.relative_axes.emit(&[virtual_event_x]).unwrap();
|
virt_dev.axis.emit(&[virtual_event_x]).unwrap();
|
||||||
virt_dev.relative_axes.emit(&[virtual_event_y]).unwrap();
|
virt_dev.axis.emit(&[virtual_event_y]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(polling_rate)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(polling_rate)).await;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::{HashMap, BTreeMap}, sync::Arc, path::Path, env};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
use evdev::{Device, EventStream, Key, uinput::VirtualDeviceBuilder};
|
use evdev::{Device, EventStream, Key};
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
use crate::event_reader::EventReader;
|
use crate::event_reader::EventReader;
|
||||||
use crate::virtual_devices::VirtualDevices;
|
use crate::virtual_devices::VirtualDevices;
|
||||||
|
@ -96,9 +96,7 @@ pub async fn create_new_reader(device: String, config: HashMap<String, Config>,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
let virt_dev: Arc<Mutex<VirtualDevices>> = Arc::new (
|
let virt_dev: Arc<Mutex<VirtualDevices>> = Arc::new(Mutex::new(VirtualDevices::new()));
|
||||||
Mutex::new(new_virtual_devices())
|
|
||||||
);
|
|
||||||
let reader = EventReader::new(config.clone(), stream, virt_dev, modifiers, current_desktop);
|
let reader = EventReader::new(config.clone(), stream, virt_dev, modifiers, current_desktop);
|
||||||
println!("Mapped device detected at {:?}, reading events.", device);
|
println!("Mapped device detected at {:?}, reading events.", device);
|
||||||
tokio::join!(
|
tokio::join!(
|
||||||
|
@ -123,23 +121,6 @@ pub fn get_event_stream(path: &Path, config: HashMap<String, Config>) -> EventSt
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_virtual_devices() -> VirtualDevices {
|
|
||||||
let mut key_capabilities = evdev::AttributeSet::new();
|
|
||||||
for i in 1..334 {key_capabilities.insert(Key(i));};
|
|
||||||
let mut rel_capabilities = evdev::AttributeSet::new();
|
|
||||||
for i in 0..13 {rel_capabilities.insert(evdev::RelativeAxisType(i));};
|
|
||||||
let keys_builder = VirtualDeviceBuilder::new().unwrap()
|
|
||||||
.name("Makima Virtual Keyboard/Mouse")
|
|
||||||
.with_keys(&key_capabilities).unwrap();
|
|
||||||
let rel_builder = VirtualDeviceBuilder::new().unwrap()
|
|
||||||
.name("Makima Virtual Pointer")
|
|
||||||
.with_relative_axes(&rel_capabilities).unwrap();
|
|
||||||
let virtual_device_keys = keys_builder.build().unwrap();
|
|
||||||
let virtual_device_rel = rel_builder.build().unwrap();
|
|
||||||
let virtual_devices = VirtualDevices::new(virtual_device_keys, virtual_device_rel);
|
|
||||||
return virtual_devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_mapped(udev_device: &tokio_udev::Device, config_files: &Vec<Config>) -> bool {
|
pub fn is_mapped(udev_device: &tokio_udev::Device, config_files: &Vec<Config>) -> bool {
|
||||||
match udev_device.devnode() {
|
match udev_device.devnode() {
|
||||||
Some(devnode) => {
|
Some(devnode) => {
|
||||||
|
|
|
@ -1,16 +1,28 @@
|
||||||
use evdev::uinput::VirtualDevice;
|
use evdev::{Key, uinput::{VirtualDevice, VirtualDeviceBuilder}};
|
||||||
|
|
||||||
|
|
||||||
pub struct VirtualDevices {
|
pub struct VirtualDevices {
|
||||||
pub keys: VirtualDevice,
|
pub keys: VirtualDevice,
|
||||||
pub relative_axes: VirtualDevice,
|
pub axis: VirtualDevice,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualDevices {
|
impl VirtualDevices {
|
||||||
pub fn new(keys: VirtualDevice, relative_axes: VirtualDevice) -> Self {
|
pub fn new() -> Self {
|
||||||
|
let mut key_capabilities = evdev::AttributeSet::new();
|
||||||
|
for i in 1..334 {key_capabilities.insert(Key(i));};
|
||||||
|
let mut axis_capabilities = evdev::AttributeSet::new();
|
||||||
|
for i in 0..13 {axis_capabilities.insert(evdev::RelativeAxisType(i));};
|
||||||
|
let keys_builder = VirtualDeviceBuilder::new().unwrap()
|
||||||
|
.name("Makima Virtual Keyboard/Mouse")
|
||||||
|
.with_keys(&key_capabilities).unwrap();
|
||||||
|
let axis_builder = VirtualDeviceBuilder::new().unwrap()
|
||||||
|
.name("Makima Virtual Pointer")
|
||||||
|
.with_relative_axes(&axis_capabilities).unwrap();
|
||||||
|
let virtual_device_keys = keys_builder.build().unwrap();
|
||||||
|
let virtual_device_axis = axis_builder.build().unwrap();
|
||||||
Self {
|
Self {
|
||||||
keys: keys,
|
keys: virtual_device_keys,
|
||||||
relative_axes: relative_axes,
|
axis: virtual_device_axis,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue