Skip to content

Commit 4c77be6

Browse files
committed
Fixing the edition warnigns on Windows.
1 parent 2c3fac2 commit 4c77be6

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

src/windows/common.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ lazy_static! {
2424
pub(crate) static ref KEYBOARD: Mutex<Keyboard> = Mutex::new(Keyboard::new().unwrap());
2525
}
2626

27-
pub unsafe fn get_code(lpdata: LPARAM) -> DWORD {
27+
pub unsafe fn get_code(lpdata: LPARAM) -> DWORD { unsafe {
2828
let kb = *(lpdata as *const KBDLLHOOKSTRUCT);
2929
kb.vkCode
30-
}
31-
pub unsafe fn get_scan_code(lpdata: LPARAM) -> DWORD {
30+
}}
31+
pub unsafe fn get_scan_code(lpdata: LPARAM) -> DWORD { unsafe {
3232
let kb = *(lpdata as *const KBDLLHOOKSTRUCT);
3333
kb.scanCode
34-
}
35-
pub unsafe fn get_point(lpdata: LPARAM) -> (LONG, LONG) {
34+
}}
35+
pub unsafe fn get_point(lpdata: LPARAM) -> (LONG, LONG) { unsafe {
3636
let mouse = *(lpdata as *const MSLLHOOKSTRUCT);
3737
(mouse.pt.x, mouse.pt.y)
38-
}
38+
}}
3939
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644986(v=vs.85)
4040
/// confusingly, this function returns a WORD (unsigned), but may be
4141
/// interpreted as either signed or unsigned depending on context
42-
pub unsafe fn get_delta(lpdata: LPARAM) -> WORD {
42+
pub unsafe fn get_delta(lpdata: LPARAM) -> WORD { unsafe {
4343
let mouse = *(lpdata as *const MSLLHOOKSTRUCT);
4444
HIWORD(mouse.mouseData)
45-
}
46-
pub unsafe fn get_button_code(lpdata: LPARAM) -> WORD {
45+
}}
46+
pub unsafe fn get_button_code(lpdata: LPARAM) -> WORD { unsafe {
4747
let mouse = *(lpdata as *const MSLLHOOKSTRUCT);
4848
HIWORD(mouse.mouseData)
49-
}
49+
}}
5050

51-
pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option<EventType> {
51+
pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option<EventType> { unsafe {
5252
match param.try_into() {
5353
Ok(WM_KEYDOWN) | Ok(WM_SYSKEYDOWN) => {
5454
let code = get_code(lpdata);
@@ -97,15 +97,15 @@ pub unsafe fn convert(param: WPARAM, lpdata: LPARAM) -> Option<EventType> {
9797
}
9898
_ => None,
9999
}
100-
}
100+
}}
101101

102102
type RawCallback = unsafe extern "system" fn(code: c_int, param: WPARAM, lpdata: LPARAM) -> LRESULT;
103103
pub enum HookError {
104104
Mouse(DWORD),
105105
Key(DWORD),
106106
}
107107

108-
pub unsafe fn set_key_hook(callback: RawCallback) -> Result<(), HookError> {
108+
pub unsafe fn set_key_hook(callback: RawCallback) -> Result<(), HookError> { unsafe {
109109
let hook = SetWindowsHookExA(WH_KEYBOARD_LL, Some(callback), null_mut(), 0);
110110

111111
if hook.is_null() {
@@ -114,14 +114,14 @@ pub unsafe fn set_key_hook(callback: RawCallback) -> Result<(), HookError> {
114114
}
115115
HOOK = hook;
116116
Ok(())
117-
}
117+
}}
118118

119-
pub unsafe fn set_mouse_hook(callback: RawCallback) -> Result<(), HookError> {
119+
pub unsafe fn set_mouse_hook(callback: RawCallback) -> Result<(), HookError> { unsafe {
120120
let hook = SetWindowsHookExA(WH_MOUSE_LL, Some(callback), null_mut(), 0);
121121
if hook.is_null() {
122122
let error = GetLastError();
123123
return Err(HookError::Mouse(error));
124124
}
125125
HOOK = hook;
126126
Ok(())
127-
}
127+
}}

src/windows/grab.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use winapi::um::winuser::{CallNextHookEx, GetMessageA, HC_ACTION};
66

77
static mut GLOBAL_CALLBACK: Option<Box<dyn FnMut(Event) -> Option<Event>>> = None;
88

9-
unsafe extern "system" fn raw_callback(code: i32, param: usize, lpdata: isize) -> isize {
9+
unsafe extern "system" fn raw_callback(code: i32, param: usize, lpdata: isize) -> isize { unsafe {
1010
if code == HC_ACTION {
1111
let opt = convert(param, lpdata);
1212
if let Some(event_type) = opt {
@@ -35,7 +35,7 @@ unsafe extern "system" fn raw_callback(code: i32, param: usize, lpdata: isize) -
3535
}
3636
}
3737
CallNextHookEx(HOOK, code, param, lpdata)
38-
}
38+
}}
3939
impl From<HookError> for GrabError {
4040
fn from(error: HookError) -> Self {
4141
match error {

src/windows/keyboard.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ impl Keyboard {
3333
})
3434
}
3535

36-
pub(crate) unsafe fn get_name(&mut self, lpdata: LPARAM) -> Option<String> {
36+
pub(crate) unsafe fn get_name(&mut self, lpdata: LPARAM) -> Option<String> { unsafe {
3737
// https://gist.github.com/akimsko/2011327
3838
// https://www.experts-exchange.com/questions/23453780/LowLevel-Keystroke-Hook-removes-Accents-on-French-Keyboard.html
3939
let code = get_code(lpdata);
4040
let scan_code = get_scan_code(lpdata);
4141

4242
self.set_global_state()?;
4343
self.get_code_name(code, scan_code)
44-
}
44+
}}
4545

46-
pub(crate) unsafe fn set_global_state(&mut self) -> Option<()> {
46+
pub(crate) unsafe fn set_global_state(&mut self) -> Option<()> { unsafe {
4747
let mut state = [0_u8; 256];
4848
let state_ptr = state.as_mut_ptr();
4949

@@ -68,9 +68,9 @@ impl Keyboard {
6868
}
6969
self.last_state = state;
7070
Some(())
71-
}
71+
}}
7272

73-
pub(crate) unsafe fn get_code_name(&mut self, code: UINT, scan_code: UINT) -> Option<String> {
73+
pub(crate) unsafe fn get_code_name(&mut self, code: UINT, scan_code: UINT) -> Option<String> { unsafe {
7474
let current_window_thread_id = GetWindowThreadProcessId(GetForegroundWindow(), null_mut());
7575
let state_ptr = self.last_state.as_mut_ptr();
7676
const BUF_LEN: i32 = 32;
@@ -111,9 +111,9 @@ impl Keyboard {
111111
self.last_is_dead = is_dead;
112112
}
113113
result
114-
}
114+
}}
115115

116-
unsafe fn clear_keyboard_buffer(&self, code: UINT, scan_code: UINT, layout: HKL) {
116+
unsafe fn clear_keyboard_buffer(&self, code: UINT, scan_code: UINT, layout: HKL) { unsafe {
117117
const BUF_LEN: i32 = 32;
118118
let mut buff = [0_u16; BUF_LEN as usize];
119119
let buff_ptr = buff.as_mut_ptr();
@@ -124,7 +124,7 @@ impl Keyboard {
124124
while len < 0 {
125125
len = ToUnicodeEx(code, scan_code, state_ptr, buff_ptr, BUF_LEN, 0, layout);
126126
}
127-
}
127+
}}
128128
}
129129

130130
impl KeyboardState for Keyboard {

src/windows/keycodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mod test {
158158
if let Some(code2) = code_from_key(key) {
159159
assert_eq!(code, code2)
160160
} else {
161-
assert!(false, "We could not convert back code: {:?}", code);
161+
panic!("We could not convert back code: {:?}", code);
162162
}
163163
}
164164
}

src/windows/listen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl From<HookError> for ListenError {
1717
}
1818
}
1919

20-
unsafe extern "system" fn raw_callback(code: c_int, param: WPARAM, lpdata: LPARAM) -> LRESULT {
20+
unsafe extern "system" fn raw_callback(code: c_int, param: WPARAM, lpdata: LPARAM) -> LRESULT { unsafe {
2121
if code == HC_ACTION {
2222
let opt = convert(param, lpdata);
2323
if let Some(event_type) = opt {
@@ -40,7 +40,7 @@ unsafe extern "system" fn raw_callback(code: c_int, param: WPARAM, lpdata: LPARA
4040
}
4141
}
4242
CallNextHookEx(HOOK, code, param, lpdata)
43-
}
43+
}}
4444

4545
pub fn listen<T>(callback: T) -> Result<(), ListenError>
4646
where

0 commit comments

Comments
 (0)