Skip to content

Commit

Permalink
Merge pull request #130 from haimgel/fix-rust71-compat
Browse files Browse the repository at this point in the history
Fix Rust 1.71.0+ compatibility
  • Loading branch information
haimgel committed Oct 29, 2023
2 parents d041246 + e260e5b commit e13c471
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.70.0
1.73.0
4 changes: 2 additions & 2 deletions src/platform/pnp_detect_libusb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl<T: UsbContext> rusb::Hotplug<T> for PnPDetectLibusb {
}

impl PnPDetectLibusb {
pub fn new(callback: Box<dyn UsbCallback + Send>) -> Self {
PnPDetectLibusb { callback }
pub fn new(callback: Box<dyn UsbCallback + Send>) -> Box<Self> {
Box::new(PnPDetectLibusb { callback })
}

pub fn detect(self) -> Result<()> {
Expand Down
13 changes: 6 additions & 7 deletions src/platform/pnp_detect_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub struct PnPDetectWindows {
}

impl PnPDetectWindows {
pub fn new(callback: Box<dyn UsbCallback>) -> Self {
let mut pnp_detect = Self {
pub fn new(callback: Box<dyn UsbCallback>) -> Box<Self> {
let mut pnp_detect = Box::new(Self {
callback,
current_devices: Self::read_device_list().unwrap_or_default(),
hwnd: std::ptr::null_mut(),
};
});
pnp_detect.create_window();
return pnp_detect;
}
Expand Down Expand Up @@ -95,8 +95,8 @@ impl PnPDetectWindows {
PostQuitMessage(0);
}
WM_DEVICECHANGE => {
let self_ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut Self;
let window_state: &mut Self = self_ptr.as_mut().unwrap();
let self_ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA);
let window_state: &mut Self = &mut *(self_ptr as *mut Self);
window_state.handle_hotplug_event();
}
_ => return DefWindowProcW(hwnd, msg, wparam, lparam),
Expand Down Expand Up @@ -146,8 +146,7 @@ impl PnPDetectWindows {
std::ptr::null_mut(),
std::ptr::null_mut(),
hinstance,
self as *mut Self as *mut winapi::ctypes::c_void,
//std::ptr::null_mut(),
self as *mut _ as *mut _,
)
};

Expand Down
9 changes: 6 additions & 3 deletions src/platform/wake_displays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub fn wake_displays() -> Result<()> {
use std::{thread, time};
use uinput::event::controller::Controller::Mouse;
use uinput::event::controller::Mouse::Left;
use uinput::event::Event::{Controller, Relative};
use uinput::event::relative::Position::X;
use uinput::event::relative::Relative::Position;
use uinput::event::Event::{Controller, Relative};

let mut device = uinput::default()?
.name("display-switch")?
Expand All @@ -54,7 +54,6 @@ pub fn wake_displays() -> Result<()> {
.event(Relative(Position(X)))?
.create()?;


// This sleep appears to be necessary based on testing.
// Possibly X does not immediately recognize the new device?
thread::sleep(time::Duration::from_secs(1));
Expand All @@ -75,7 +74,11 @@ mod tests {
fn test_wake_displays() {
let waked = wake_displays();
if let Err(err) = &waked {
assert!(err.to_string() == "Permission denied", "Couldn't wake displays: {:?}", err);
assert!(
err.to_string() == "Permission denied",
"Couldn't wake displays: {:?}",
err
);
}
}
}

0 comments on commit e13c471

Please sign in to comment.