mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-16 14:01:27 +03:00
windows: fix panic when recreating input-capture
RegisterWindowClassW fails when called again
This commit is contained in:
@@ -8,7 +8,7 @@ use std::ptr::{addr_of, addr_of_mut};
|
|||||||
|
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::sync::atomic::{AtomicU32, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||||
use std::sync::{mpsc, Mutex};
|
use std::sync::{mpsc, Mutex};
|
||||||
use std::task::ready;
|
use std::task::ready;
|
||||||
use std::{pin::Pin, thread};
|
use std::{pin::Pin, thread};
|
||||||
@@ -493,6 +493,8 @@ fn get_msg() -> Option<MSG> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WINDOW_CLASS_REGISTERED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
fn message_thread(ready_tx: mpsc::Sender<()>) {
|
fn message_thread(ready_tx: mpsc::Sender<()>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
set_event_tid(GetCurrentThreadId());
|
set_event_tid(GetCurrentThreadId());
|
||||||
@@ -513,9 +515,13 @@ fn message_thread(ready_tx: mpsc::Sender<()>) {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = RegisterClassW(&window_class);
|
|
||||||
if ret == 0 {
|
if WINDOW_CLASS_REGISTERED.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_ok() {
|
||||||
panic!("RegisterClassW");
|
/* register window class if not yet done so */
|
||||||
|
let ret = RegisterClassW(&window_class);
|
||||||
|
if ret == 0 {
|
||||||
|
panic!("RegisterClassW");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* window is used ro receive WM_DISPLAYCHANGE messages */
|
/* window is used ro receive WM_DISPLAYCHANGE messages */
|
||||||
|
|||||||
Reference in New Issue
Block a user