Skip to content

Commit

Permalink
raw operations
Browse files Browse the repository at this point in the history
  • Loading branch information
positiveway committed May 16, 2024
1 parent c3da377 commit b959610
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/virtual_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::thread::{JoinHandle, sleep};
use std::time::{Duration, Instant, SystemTime};
use nix::errno::Errno;
use crossbeam_channel::{Sender, Receiver, bounded};
use libc::gettimeofday;

use crate::*;

Expand Down Expand Up @@ -37,16 +38,16 @@ const SLEEP_BEFORE_RELEASE: Duration = Duration::from_millis(5);

#[inline]
fn convert_event_for_writing(kind: u16, code: u16, value: i32) -> Vec<u8> {
// gettimeofday(&mut event.time, ptr::null_mut());

let input_event = input_event {
let mut input_event = input_event {
time: FIXED_TIME,
kind,
code,
value,
};

unsafe {
// gettimeofday(&mut input_event.time, ptr::null_mut());

let ptr = &input_event as *const _ as *const u8;
let size = mem::size_of_val(&input_event);
let content = slice::from_raw_parts(ptr, size);
Expand Down Expand Up @@ -266,6 +267,23 @@ impl VirtualDevice {
self.write(EV_SYN, SYN_REPORT, 0)
}

#[inline]
pub fn move_mouse_raw_x(&mut self, x: Coord) -> EmptyResult {
self.write(EV_REL, REL_X, x)
}

#[inline]
pub fn move_mouse_raw_y(&mut self, y: Coord) -> EmptyResult {
self.write(EV_REL, REL_Y, -y)
}

#[inline]
pub fn move_mouse_raw(&mut self, x: Coord, y: Coord) -> EmptyResult {
self.write(EV_REL, REL_X, x)?;
self.write(EV_REL, REL_Y, -y)?;
Ok(())
}

#[inline]
pub fn move_mouse_x(&mut self, x: Coord) -> EmptyResult {
self.write(EV_REL, REL_X, x)?;
Expand Down

0 comments on commit b959610

Please sign in to comment.