atomic
This commit is contained in:
parent
4e85841398
commit
3a7d64bf34
@ -36,7 +36,6 @@ struct Input {
|
|||||||
time: i64,
|
time: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut LATEST_INPUT: Input = Input { conn: 0, time: 0 };
|
|
||||||
const KEY_CHAR_START: i32 = 9999;
|
const KEY_CHAR_START: i32 = 9999;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
@ -104,9 +103,11 @@ fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> {
|
|||||||
y,
|
y,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let exclude = unsafe {
|
let exclude = {
|
||||||
if crate::get_time() - LATEST_INPUT.time < 300 {
|
let now = crate::get_time();
|
||||||
LATEST_INPUT.conn
|
let lock = LATEST_INPUT.lock().unwrap();
|
||||||
|
if now - lock.time < 300 {
|
||||||
|
lock.conn
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
@ -160,6 +161,7 @@ lazy_static::lazy_static! {
|
|||||||
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
||||||
static ref KEYS_DOWN: Arc<Mutex<HashMap<i32, Instant>>> = Default::default();
|
static ref KEYS_DOWN: Arc<Mutex<HashMap<i32, Instant>>> = Default::default();
|
||||||
static ref EXITING: Arc<Mutex<bool>> = Default::default();
|
static ref EXITING: Arc<Mutex<bool>> = Default::default();
|
||||||
|
static ref LATEST_INPUT: Arc<Mutex<Input>> = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
// mac key input must be run in main thread, otherwise crash on >= osx 10.15
|
// mac key input must be run in main thread, otherwise crash on >= osx 10.15
|
||||||
@ -324,10 +326,8 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
|||||||
let buttons = evt.mask >> 3;
|
let buttons = evt.mask >> 3;
|
||||||
let evt_type = evt.mask & 0x7;
|
let evt_type = evt.mask & 0x7;
|
||||||
if evt_type == 0 {
|
if evt_type == 0 {
|
||||||
unsafe {
|
let time = crate::get_time();
|
||||||
let time = crate::get_time();
|
*LATEST_INPUT.lock().unwrap() = Input { time, conn };
|
||||||
LATEST_INPUT = Input { time, conn };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let mut en = ENIGO.lock().unwrap();
|
let mut en = ENIGO.lock().unwrap();
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user