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