mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-19 03:41:28 +03:00
less unsafe code
This commit is contained in:
@@ -162,12 +162,11 @@ fn start_routine(
|
||||
request_buffer: Arc<Mutex<Vec<ClientUpdate>>>,
|
||||
) {
|
||||
EVENT_TX.replace(Some(event_tx));
|
||||
unsafe {
|
||||
/* communicate thread id */
|
||||
{
|
||||
let (cnd, mtx) = &*ready;
|
||||
let mut ready = mtx.lock().unwrap();
|
||||
*ready = Some(GetCurrentThreadId());
|
||||
*ready = Some(unsafe { GetCurrentThreadId() });
|
||||
cnd.notify_one();
|
||||
}
|
||||
|
||||
@@ -176,10 +175,12 @@ fn start_routine(
|
||||
let window_proc: WNDPROC = Some(window_proc);
|
||||
|
||||
/* register hooks */
|
||||
unsafe {
|
||||
let _ = SetWindowsHookExW(WH_MOUSE_LL, mouse_proc, HINSTANCE::default(), 0).unwrap();
|
||||
let _ = SetWindowsHookExW(WH_KEYBOARD_LL, kybrd_proc, HINSTANCE::default(), 0).unwrap();
|
||||
}
|
||||
|
||||
let instance = GetModuleHandleW(None).unwrap();
|
||||
let instance = unsafe { GetModuleHandleW(None).unwrap() };
|
||||
let window_class: WNDCLASSW = WNDCLASSW {
|
||||
lpfnWndProc: window_proc,
|
||||
hInstance: instance.into(),
|
||||
@@ -193,13 +194,16 @@ fn start_routine(
|
||||
.is_ok()
|
||||
{
|
||||
/* register window class if not yet done so */
|
||||
unsafe {
|
||||
let ret = RegisterClassW(&window_class);
|
||||
if ret == 0 {
|
||||
panic!("RegisterClassW");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* window is used ro receive WM_DISPLAYCHANGE messages */
|
||||
unsafe {
|
||||
CreateWindowExW(
|
||||
Default::default(),
|
||||
w!("lan-mouse-message-window-class"),
|
||||
@@ -215,6 +219,7 @@ fn start_routine(
|
||||
None,
|
||||
)
|
||||
.expect("CreateWindowExW");
|
||||
}
|
||||
|
||||
/* run message loop */
|
||||
loop {
|
||||
@@ -247,6 +252,7 @@ fn start_routine(
|
||||
}
|
||||
} else {
|
||||
/* other messages for window_procs */
|
||||
unsafe {
|
||||
let _ = TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user