Skip to content

Commit a86ffb4

Browse files
committed
Update linux.
1 parent 7bbba26 commit a86ffb4

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

src/linux/grab.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ where
375375
let (_, event) = match device.next_event(evdev_rs::ReadFlag::NORMAL) {
376376
Ok(event) => event,
377377
Err(_) => {
378-
let device_fd = device.fd().unwrap().into_raw_fd();
378+
let device_fd = device.file().unwrap().into_raw_fd();
379379
let empty_event = epoll::Event::new(epoll::Events::empty(), 0);
380380
epoll::ctl(epoll_fd, EPOLL_CTL_DEL, device_fd, empty_event)?;
381381
continue 'events;
@@ -405,7 +405,7 @@ where
405405
}
406406

407407
static DEV_PATH: &str = "/dev/input";
408-
const INOTIFY_DATA: u64 = u64::max_value();
408+
const INOTIFY_DATA: u64 = u64::MAX;
409409
const EPOLLIN: epoll::Events = epoll::Events::EPOLLIN;
410410

411411
/// Whether to continue grabbing events or to stop
@@ -470,7 +470,7 @@ where
470470

471471
fn inotify_devices() -> io::Result<Inotify> {
472472
let mut inotify = Inotify::init()?;
473-
inotify.add_watch(DEV_PATH, WatchMask::CREATE)?;
473+
inotify.watches().add(DEV_PATH, WatchMask::CREATE)?;
474474
Ok(inotify)
475475
}
476476

@@ -485,7 +485,7 @@ fn add_device_to_epoll_from_inotify_event(
485485
// new plug events
486486
let file = File::open(device_path)?;
487487
let fd = file.as_raw_fd();
488-
let device = Device::new_from_fd(file)?;
488+
let device = Device::new_from_file(file)?;
489489
let event = epoll::Event::new(EPOLLIN, devices.len() as u64);
490490
devices.push(device);
491491
epoll::ctl(epoll_fd, EPOLL_CTL_ADD, fd, event)?;
@@ -501,7 +501,7 @@ fn setup_devices() -> io::Result<(RawFd, Vec<Device>, Vec<UInputDevice>)> {
501501
let epoll_fd = epoll_watch_all(device_files.iter())?;
502502
let devices = device_files
503503
.into_iter()
504-
.map(Device::new_from_fd)
504+
.map(Device::new_from_file)
505505
.collect::<io::Result<Vec<Device>>>()?;
506506
let output_devices = devices
507507
.iter()

src/linux/keyboard.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,10 @@ impl KeyboardState for Keyboard {
220220
unsafe { self.name_from_code(keycode, state) }
221221
}
222222
},
223-
EventType::KeyRelease(key) => match key {
224-
Key::ShiftLeft | Key::ShiftRight => {
225-
self.state.shift = false;
226-
None
227-
}
228-
_ => None,
229-
},
223+
EventType::KeyRelease(Key::ShiftLeft | Key::ShiftRight) => {
224+
self.state.shift = false;
225+
None
226+
}
230227
_ => None,
231228
}
232229
}

src/linux/listen.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ where
4040
record_range.device_events.last = xlib::MotionNotify as c_uchar;
4141

4242
// Create context
43+
let ptr = &raw mut RECORD_ALL_CLIENTS;
4344
let context = xrecord::XRecordCreateContext(
4445
dpy_control,
4546
0,
46-
&mut RECORD_ALL_CLIENTS,
47+
&mut *ptr,
4748
1,
4849
&mut &mut record_range as *mut &mut xrecord::XRecordRange
4950
as *mut *mut xrecord::XRecordRange,
@@ -105,8 +106,10 @@ unsafe extern "C" fn record_callback(
105106
let x = xdatum.root_x as f64;
106107
let y = xdatum.root_y as f64;
107108

108-
if let Some(event) = convert(&mut KEYBOARD, code, type_, x, y) {
109-
if let Some(callback) = &mut GLOBAL_CALLBACK {
109+
let ptr = &raw mut KEYBOARD;
110+
if let Some(event) = convert(&mut &ptr, code, type_, x, y) {
111+
let ptr = &raw mut GLOBAL_CALLBACK;
112+
if let Some(callback) = &mut *ptr {
110113
callback(event);
111114
}
112115
}

src/linux/simulate.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,23 @@ unsafe fn send_native(event_type: &EventType, display: *mut xlib::Display) -> Op
2121
Button::Left => xtest::XTestFakeButtonEvent(display, 1, TRUE, 0),
2222
Button::Middle => xtest::XTestFakeButtonEvent(display, 2, TRUE, 0),
2323
Button::Right => xtest::XTestFakeButtonEvent(display, 3, TRUE, 0),
24-
Button::Unknown(code) => {
25-
xtest::XTestFakeButtonEvent(display, (*code).try_into().ok()?, TRUE, 0)
26-
}
24+
Button::Unknown(code) => xtest::XTestFakeButtonEvent(display, (*code).into(), TRUE, 0),
2725
},
2826
EventType::ButtonRelease(button) => match button {
2927
Button::Left => xtest::XTestFakeButtonEvent(display, 1, FALSE, 0),
3028
Button::Middle => xtest::XTestFakeButtonEvent(display, 2, FALSE, 0),
3129
Button::Right => xtest::XTestFakeButtonEvent(display, 3, FALSE, 0),
32-
Button::Unknown(code) => {
33-
xtest::XTestFakeButtonEvent(display, (*code).try_into().ok()?, FALSE, 0)
34-
}
30+
Button::Unknown(code) => xtest::XTestFakeButtonEvent(display, (*code).into(), FALSE, 0),
3531
},
3632
EventType::MouseMove { x, y } => {
3733
//TODO: replace with clamp if it is stabalized
3834
let x = if x.is_finite() {
39-
x.min(c_int::max_value().into())
40-
.max(c_int::min_value().into())
41-
.round() as c_int
35+
x.min(c_int::MAX.into()).max(c_int::MIN.into()).round() as c_int
4236
} else {
4337
0
4438
};
4539
let y = if y.is_finite() {
46-
y.min(c_int::max_value().into())
47-
.max(c_int::min_value().into())
48-
.round() as c_int
40+
y.min(c_int::MAX.into()).max(c_int::MIN.into()).round() as c_int
4941
} else {
5042
0
5143
};

0 commit comments

Comments
 (0)