Skip to content

Commit 81ef1f4

Browse files
authored
Updating clippy warnings. (Narsil#62)
* Updating clippy warnings. * Remove dead import
1 parent 24b2e4f commit 81ef1f4

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

src/linux/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl Display {
9999
}
100100
}
101101

102+
#[cfg(feature = "unstable_grab")]
102103
pub fn get_mouse_pos(&self) -> Option<(u64, u64)> {
103104
unsafe {
104105
let root_window = xlib::XRootWindow(self.display, 0);

src/linux/grab.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,12 @@ fn evdev_event_to_rdev_event(
302302
// }
303303

304304
pub fn grab(callback: GrabCallback) -> Result<(), GrabError> {
305-
let mut kb = Keyboard::new().ok_or_else(|| GrabError::KeyboardError)?;
306-
let display = Display::new().ok_or_else(|| GrabError::MissingDisplayError)?;
307-
let (width, height) = display
308-
.get_size()
309-
.ok_or_else(|| GrabError::MissingDisplayError)?;
305+
let mut kb = Keyboard::new().ok_or(GrabError::KeyboardError)?;
306+
let display = Display::new().ok_or(GrabError::MissingDisplayError)?;
307+
let (width, height) = display.get_size().ok_or(GrabError::MissingDisplayError)?;
310308
let (current_x, current_y) = display
311309
.get_mouse_pos()
312-
.ok_or_else(|| GrabError::MissingDisplayError)?;
310+
.ok_or(GrabError::MissingDisplayError)?;
313311
let mut x = current_x as f64;
314312
let mut y = current_y as f64;
315313
let w = width as f64;
@@ -346,8 +344,7 @@ where
346344
//grab devices
347345
let _grab = devices
348346
.iter_mut()
349-
.map(|device| device.grab(evdev_rs::GrabMode::Grab))
350-
.collect::<io::Result<()>>()?;
347+
.try_for_each(|device| device.grab(evdev_rs::GrabMode::Grab))?;
351348

352349
// create buffer for epoll to fill
353350
let mut epoll_buffer = [epoll::Event::new(epoll::Events::empty(), 0); 4];

src/linux/keyboard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate x11;
22
use crate::linux::keycodes::code_from_key;
33
use crate::rdev::{EventType, Key, KeyboardState};
44
use std::ffi::CString;
5-
use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_ulong, c_void};
5+
use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void};
66
use std::ptr::{null, null_mut, NonNull};
77
use x11::xlib;
88

@@ -156,7 +156,7 @@ impl Keyboard {
156156
return None;
157157
}
158158
const BUF_LEN: usize = 4;
159-
let mut buf = [0 as c_uchar; BUF_LEN];
159+
let mut buf = [0_u8; BUF_LEN];
160160
let key = xlib::XKeyEvent {
161161
display: *self.display,
162162
root: 0,

src/linux/listen.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::linux::keyboard::Keyboard;
55
use crate::rdev::{Callback, Event, ListenError};
66
use std::convert::TryInto;
77
use std::ffi::CStr;
8-
use std::os::raw::{c_char, c_int, c_uchar, c_uint};
8+
use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_ulong};
99
use std::ptr::null;
1010
use x11::xlib;
1111
use x11::xrecord;
@@ -14,10 +14,11 @@ fn default_callback(event: Event) {
1414
println!("Default : Event {:?}", event);
1515
}
1616

17+
static mut RECORD_ALL_CLIENTS: c_ulong = xrecord::XRecordAllClients;
1718
static mut GLOBAL_CALLBACK: Callback = default_callback;
1819

1920
pub fn listen(callback: Callback) -> Result<(), ListenError> {
20-
let keyboard = Keyboard::new().ok_or_else(|| ListenError::KeyboardError)?;
21+
let keyboard = Keyboard::new().ok_or(ListenError::KeyboardError)?;
2122

2223
unsafe {
2324
KEYBOARD = Some(keyboard);
@@ -43,7 +44,7 @@ pub fn listen(callback: Callback) -> Result<(), ListenError> {
4344
let context = xrecord::XRecordCreateContext(
4445
dpy_control,
4546
0,
46-
&mut xrecord::XRecordAllClients,
47+
&mut RECORD_ALL_CLIENTS,
4748
1,
4849
&mut &mut record_range as *mut &mut xrecord::XRecordRange
4950
as *mut *mut xrecord::XRecordRange,

src/macos/keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Keyboard {
9393
let layout = TISGetInputSourceProperty(keyboard, kTISPropertyUnicodeKeyLayoutData);
9494
let layout_ptr = CFDataGetBytePtr(layout);
9595

96-
let mut buff = [0 as UniChar; BUF_LEN];
96+
let mut buff = [0_u16; BUF_LEN];
9797
let kb_type = LMGetKbdType();
9898
let mut length = 0;
9999
let _retval = UCKeyTranslate(

src/windows/keyboard.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::windows::common::{get_code, get_scan_code, FALSE, TRUE};
33
use crate::windows::keycodes::code_from_key;
44
use std::ptr::null_mut;
55
use winapi::shared::minwindef::{BYTE, HKL, LPARAM, UINT};
6-
use winapi::shared::ntdef::WCHAR;
76
use winapi::um::processthreadsapi::GetCurrentThreadId;
87
use winapi::um::winuser;
98
use winapi::um::winuser::{
@@ -45,7 +44,7 @@ impl Keyboard {
4544
}
4645

4746
pub(crate) unsafe fn set_global_state(&mut self) -> Option<()> {
48-
let mut state = [0 as BYTE; 256];
47+
let mut state = [0_u8; 256];
4948
let state_ptr = state.as_mut_ptr();
5049

5150
let _shift = GetKeyState(VK_SHIFT);
@@ -75,7 +74,7 @@ impl Keyboard {
7574
let current_window_thread_id = GetWindowThreadProcessId(GetForegroundWindow(), null_mut());
7675
let state_ptr = self.last_state.as_mut_ptr();
7776
const BUF_LEN: i32 = 32;
78-
let mut buff = [0 as WCHAR; BUF_LEN as usize];
77+
let mut buff = [0_u16; BUF_LEN as usize];
7978
let buff_ptr = buff.as_mut_ptr();
8079
let layout = GetKeyboardLayout(current_window_thread_id);
8180
let len = ToUnicodeEx(code, scan_code, state_ptr, buff_ptr, 8 - 1, 0, layout);
@@ -116,9 +115,9 @@ impl Keyboard {
116115

117116
unsafe fn clear_keyboard_buffer(&self, code: UINT, scan_code: UINT, layout: HKL) {
118117
const BUF_LEN: i32 = 32;
119-
let mut buff = [0 as WCHAR; BUF_LEN as usize];
118+
let mut buff = [0_u16; BUF_LEN as usize];
120119
let buff_ptr = buff.as_mut_ptr();
121-
let mut state = [0 as BYTE; 256];
120+
let mut state = [0_u8; 256];
122121
let state_ptr = state.as_mut_ptr();
123122

124123
let mut len = -1;

0 commit comments

Comments
 (0)