Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #2108

Merged
merged 2 commits into from Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/cursor.rs
Expand Up @@ -43,7 +43,6 @@ fn main() {
..
} => {
*control_flow = ControlFlow::Exit;
return;
}
_ => (),
}
Expand Down
6 changes: 3 additions & 3 deletions examples/fullscreen.rs
Expand Up @@ -15,7 +15,7 @@ fn main() {

let mut num = String::new();
stdin().read_line(&mut num).unwrap();
let num = num.trim().parse().ok().expect("Please enter a number");
let num = num.trim().parse().expect("Please enter a number");

let fullscreen = Some(match num {
1 => Fullscreen::Exclusive(prompt_for_video_mode(&prompt_for_monitor(&event_loop))),
Expand Down Expand Up @@ -85,7 +85,7 @@ fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle {

let mut num = String::new();
stdin().read_line(&mut num).unwrap();
let num = num.trim().parse().ok().expect("Please enter a number");
let num = num.trim().parse().expect("Please enter a number");
let monitor = event_loop
.available_monitors()
.nth(num)
Expand All @@ -106,7 +106,7 @@ fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode {

let mut num = String::new();
stdin().read_line(&mut num).unwrap();
let num = num.trim().parse().ok().expect("Please enter a number");
let num = num.trim().parse().expect("Please enter a number");
let video_mode = monitor
.video_modes()
.nth(num)
Expand Down
19 changes: 8 additions & 11 deletions examples/multithreaded.rs
Expand Up @@ -34,18 +34,18 @@ fn main() {
// We need to update our chosen video mode if the window
// was moved to an another monitor, so that the window
// appears on this monitor instead when we go fullscreen
let previous_video_mode = video_modes.iter().cloned().nth(video_mode_id);
let previous_video_mode = video_modes.get(video_mode_id).cloned();
video_modes = window.current_monitor().unwrap().video_modes().collect();
video_mode_id = video_mode_id.min(video_modes.len());
let video_mode = video_modes.iter().nth(video_mode_id);
let video_mode = video_modes.get(video_mode_id);

// Different monitors may support different video modes,
// and the index we chose previously may now point to a
// completely different video mode, so notify the user
if video_mode != previous_video_mode.as_ref() {
println!(
"Window moved to another monitor, picked video mode: {}",
video_modes.iter().nth(video_mode_id).unwrap()
video_modes.get(video_mode_id).unwrap()
);
}
}
Expand Down Expand Up @@ -77,16 +77,13 @@ fn main() {
Right => (video_modes.len() - 1).min(video_mode_id + 1),
_ => unreachable!(),
};
println!(
"Picking video mode: {}",
video_modes.iter().nth(video_mode_id).unwrap()
);
println!("Picking video mode: {}", video_modes[video_mode_id]);
}
F => window.set_fullscreen(match (state, modifiers.alt()) {
(true, false) => Some(Fullscreen::Borderless(None)),
(true, true) => Some(Fullscreen::Exclusive(
video_modes.iter().nth(video_mode_id).unwrap().clone(),
)),
(true, true) => {
Some(Fullscreen::Exclusive(video_modes[video_mode_id].clone()))
}
(false, _) => None,
}),
G => window.set_cursor_grab(state).unwrap(),
Expand Down Expand Up @@ -173,7 +170,7 @@ fn main() {
}
}
},
_ => (),
_ => {}
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/multiwindow.rs
Expand Up @@ -41,7 +41,7 @@ fn main() {
},
..
} => {
let window = Window::new(&event_loop).unwrap();
let window = Window::new(event_loop).unwrap();
windows.insert(window.id(), window);
}
_ => (),
Expand Down
1 change: 0 additions & 1 deletion examples/set_ime_position.rs
Expand Up @@ -46,7 +46,6 @@ fn main() {
..
} => {
*control_flow = ControlFlow::Exit;
return;
}
_ => (),
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform_impl/linux/mod.rs
Expand Up @@ -118,9 +118,9 @@ impl fmt::Display for OsError {
#[cfg(feature = "x11")]
OsError::XError(ref e) => _f.pad(&e.description),
#[cfg(feature = "x11")]
OsError::XMisc(ref e) => _f.pad(e),
OsError::XMisc(e) => _f.pad(e),
#[cfg(feature = "wayland")]
OsError::WaylandMisc(ref e) => _f.pad(e),
OsError::WaylandMisc(e) => _f.pad(e),
}
}
}
Expand Down Expand Up @@ -409,7 +409,7 @@ impl Window {
#[cfg(feature = "x11")]
Window::X(ref w) => w.set_always_on_top(_always_on_top),
#[cfg(feature = "wayland")]
_ => (),
Window::Wayland(_) => (),
}
}

Expand All @@ -419,7 +419,7 @@ impl Window {
#[cfg(feature = "x11")]
Window::X(ref w) => w.set_window_icon(_window_icon),
#[cfg(feature = "wayland")]
_ => (),
Window::Wayland(_) => (),
}
}

Expand All @@ -434,7 +434,7 @@ impl Window {
#[cfg(feature = "x11")]
Window::X(ref w) => w.focus_window(),
#[cfg(feature = "wayland")]
_ => (),
Window::Wayland(_) => (),
}
}
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Expand Up @@ -536,12 +536,12 @@ impl<T: 'static> EventLoop<T> {
}

fn loop_dispatch<D: Into<Option<std::time::Duration>>>(&mut self, timeout: D) -> IOResult<()> {
let mut state = match &mut self.window_target.p {
let state = match &mut self.window_target.p {
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
#[cfg(feature = "x11")]
_ => unreachable!(),
};

self.event_loop.dispatch(timeout, &mut state)
self.event_loop.dispatch(timeout, state)
}
}
13 changes: 5 additions & 8 deletions src/platform_impl/linux/x11/event_processor.rs
Expand Up @@ -45,7 +45,7 @@ impl<T: 'static> EventProcessor<T> {
let mut devices = self.devices.borrow_mut();
if let Some(info) = DeviceInfo::get(&wt.xconn, device) {
for info in info.iter() {
devices.insert(DeviceId(info.deviceid), Device::new(&self, info));
devices.insert(DeviceId(info.deviceid), Device::new(self, info));
}
}
}
Expand Down Expand Up @@ -925,7 +925,7 @@ impl<T: 'static> EventProcessor<T> {

// Issue key press events for all pressed keys
Self::handle_pressed_keys(
&wt,
wt,
window_id,
ElementState::Pressed,
&self.mod_keymap,
Expand All @@ -949,7 +949,7 @@ impl<T: 'static> EventProcessor<T> {

// Issue key release events for all pressed keys
Self::handle_pressed_keys(
&wt,
wt,
window_id,
ElementState::Released,
&self.mod_keymap,
Expand Down Expand Up @@ -1220,11 +1220,8 @@ impl<T: 'static> EventProcessor<T> {
}
}

match self.ime_receiver.try_recv() {
Ok((window_id, x, y)) => {
wt.ime.borrow_mut().send_xim_spot(window_id, x, y);
}
Err(_) => (),
if let Ok((window_id, x, y)) = self.ime_receiver.try_recv() {
wt.ime.borrow_mut().send_xim_spot(window_id, x, y);
}
}

Expand Down
33 changes: 19 additions & 14 deletions src/platform_impl/linux/x11/ime/callbacks.rs
Expand Up @@ -62,14 +62,15 @@ pub unsafe fn set_destroy_callback(
inner: &ImeInner,
) -> Result<(), XError> {
xim_set_callback(
&xconn,
xconn,
im,
ffi::XNDestroyCallback_0.as_ptr() as *const _,
&inner.destroy_callback as *const _ as *mut _,
)
}

#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
enum ReplaceImError {
MethodOpenFailed(PotentialInputMethods),
ContextCreationFailed(ImeContextCreationError),
Expand Down Expand Up @@ -136,13 +137,17 @@ pub unsafe extern "C" fn xim_instantiate_callback(
let inner: *mut ImeInner = client_data as _;
if !inner.is_null() {
let xconn = &(*inner).xconn;
let result = replace_im(inner);
if result.is_ok() {
let _ = unset_instantiate_callback(xconn, client_data);
(*inner).is_fallback = false;
} else if result.is_err() && (*inner).is_destroyed {
// We have no usable input methods!
result.expect("Failed to reopen input method");
match replace_im(inner) {
Ok(()) => {
let _ = unset_instantiate_callback(xconn, client_data);
(*inner).is_fallback = false;
}
Err(err) => {
if (*inner).is_destroyed {
// We have no usable input methods!
panic!("Failed to reopen input method: {:?}", err);
maroider marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
Expand All @@ -163,12 +168,12 @@ pub unsafe extern "C" fn xim_destroy_callback(
if !(*inner).is_fallback {
let _ = set_instantiate_callback(xconn, client_data);
// Attempt to open fallback input method.
let result = replace_im(inner);
if result.is_ok() {
(*inner).is_fallback = true;
} else {
// We have no usable input methods!
result.expect("Failed to open fallback input method");
match replace_im(inner) {
Ok(()) => (*inner).is_fallback = true,
Err(err) => {
// We have no usable input methods!
panic!("Failed to open fallback input method: {:?}", err);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/ime/context.rs
Expand Up @@ -58,7 +58,7 @@ impl ImeContext {

Ok(ImeContext {
ic,
ic_spot: ic_spot.unwrap_or_else(|| ffi::XPoint { x: 0, y: 0 }),
ic_spot: ic_spot.unwrap_or(ffi::XPoint { x: 0, y: 0 }),
})
}

Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/linux/x11/ime/inner.rs
Expand Up @@ -58,10 +58,8 @@ impl ImeInner {
}

pub unsafe fn destroy_all_contexts_if_necessary(&self) -> Result<bool, XError> {
for context in self.contexts.values() {
if let &Some(ref context) = context {
self.destroy_ic_if_necessary(context.ic)?;
}
for context in self.contexts.values().flatten() {
self.destroy_ic_if_necessary(context.ic)?;
}
Ok(!self.is_destroyed)
}
Expand Down
14 changes: 4 additions & 10 deletions src/platform_impl/linux/x11/ime/input_method.rs
Expand Up @@ -63,11 +63,7 @@ pub enum InputMethodResult {

impl InputMethodResult {
pub fn is_fallback(&self) -> bool {
if let &InputMethodResult::Fallback(_) = self {
true
} else {
false
}
matches!(self, InputMethodResult::Fallback(_))
}

pub fn ok(self) -> Option<InputMethod> {
Expand Down Expand Up @@ -249,7 +245,7 @@ impl PotentialInputMethods {
pub fn open_im(
&mut self,
xconn: &Arc<XConnection>,
callback: Option<&dyn Fn() -> ()>,
callback: Option<&dyn Fn()>,
) -> InputMethodResult {
use self::InputMethodResult::*;

Expand All @@ -259,10 +255,8 @@ impl PotentialInputMethods {
let im = input_method.open_im(xconn);
if let Some(im) = im {
return XModifiers(im);
} else {
if let Some(ref callback) = callback {
callback();
}
} else if let Some(ref callback) = callback {
callback();
}
}

Expand Down
56 changes: 25 additions & 31 deletions src/platform_impl/linux/x11/mod.rs
Expand Up @@ -634,25 +634,22 @@ impl Device {
// Identify scroll axes
for class_ptr in Device::classes(info) {
let class = unsafe { &**class_ptr };
match class._type {
ffi::XIScrollClass => {
let info = unsafe {
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIScrollClassInfo>(class)
};
scroll_axes.push((
info.number,
ScrollAxis {
increment: info.increment,
orientation: match info.scroll_type {
ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal,
ffi::XIScrollTypeVertical => ScrollOrientation::Vertical,
_ => unreachable!(),
},
position: 0.0,
if class._type == ffi::XIScrollClass {
let info = unsafe {
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIScrollClassInfo>(class)
};
scroll_axes.push((
info.number,
ScrollAxis {
increment: info.increment,
orientation: match info.scroll_type {
ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal,
ffi::XIScrollTypeVertical => ScrollOrientation::Vertical,
_ => unreachable!(),
},
));
}
_ => {}
position: 0.0,
},
));
}
}
}
Expand All @@ -670,20 +667,17 @@ impl Device {
if Device::physical_device(info) {
for class_ptr in Device::classes(info) {
let class = unsafe { &**class_ptr };
match class._type {
ffi::XIValuatorClass => {
let info = unsafe {
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIValuatorClassInfo>(class)
};
if let Some(&mut (_, ref mut axis)) = self
.scroll_axes
.iter_mut()
.find(|&&mut (axis, _)| axis == info.number)
{
axis.position = info.value;
}
if class._type == ffi::XIValuatorClass {
let info = unsafe {
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIValuatorClassInfo>(class)
};
if let Some(&mut (_, ref mut axis)) = self
.scroll_axes
.iter_mut()
.find(|&&mut (axis, _)| axis == info.number)
{
axis.position = info.value;
}
_ => {}
}
}
}
Expand Down