Clippy fixes (#2011)
* windows: bump winapi version * windows: address dark_mode FIXMEs use now available winapi structures * clippy: fix clippy::upper_case_acronyms warnings * clippy: fix needless_arbitrary_self_type warnings * clippy: fix clone_on_copy warnings * clippy: fix unnecessary_mut_passed warnings * clippy: fix identity_op warnings * clippy: fix misc warnings * prefix rustdoc lints with rustdoc:: the prefix was introduced in Rust 1.52 * windows: silence file_drop_handler is never read warning * clippy: fix from_over_into warnings and a bit of naming simplification * clippy: fix missing_safety_doc warnings * make dummy() functions const
This commit is contained in:
parent
9e72396709
commit
1b3b82a3c1
22 changed files with 119 additions and 143 deletions
|
|
@ -6,38 +6,24 @@ use std::os::windows::ffi::OsStrExt;
|
|||
use winapi::{
|
||||
shared::{
|
||||
basetsd::SIZE_T,
|
||||
minwindef::{BOOL, DWORD, FALSE, UINT, ULONG, WORD},
|
||||
ntdef::{LPSTR, NTSTATUS, NT_SUCCESS, PVOID, WCHAR},
|
||||
minwindef::{BOOL, DWORD, FALSE, WORD},
|
||||
ntdef::{NTSTATUS, NT_SUCCESS, PVOID},
|
||||
windef::HWND,
|
||||
winerror::S_OK,
|
||||
},
|
||||
um::{libloaderapi, uxtheme, winuser},
|
||||
um::{libloaderapi, uxtheme, winnt, winuser},
|
||||
};
|
||||
|
||||
use crate::window::Theme;
|
||||
|
||||
lazy_static! {
|
||||
static ref WIN10_BUILD_VERSION: Option<DWORD> = {
|
||||
// FIXME: RtlGetVersion is a documented windows API,
|
||||
// should be part of winapi!
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[repr(C)]
|
||||
struct OSVERSIONINFOW {
|
||||
dwOSVersionInfoSize: ULONG,
|
||||
dwMajorVersion: ULONG,
|
||||
dwMinorVersion: ULONG,
|
||||
dwBuildNumber: ULONG,
|
||||
dwPlatformId: ULONG,
|
||||
szCSDVersion: [WCHAR; 128],
|
||||
}
|
||||
|
||||
type RtlGetVersion = unsafe extern "system" fn (*mut OSVERSIONINFOW) -> NTSTATUS;
|
||||
type RtlGetVersion = unsafe extern "system" fn (*mut winnt::OSVERSIONINFOW) -> NTSTATUS;
|
||||
let handle = get_function!("ntdll.dll", RtlGetVersion);
|
||||
|
||||
if let Some(rtl_get_version) = handle {
|
||||
unsafe {
|
||||
let mut vi = OSVERSIONINFOW {
|
||||
let mut vi = winnt::OSVERSIONINFOW {
|
||||
dwOSVersionInfoSize: 0,
|
||||
dwMajorVersion: 0,
|
||||
dwMinorVersion: 0,
|
||||
|
|
@ -108,11 +94,12 @@ fn set_dark_mode_for_window(hwnd: HWND, is_dark_mode: bool) -> bool {
|
|||
type SetWindowCompositionAttribute =
|
||||
unsafe extern "system" fn(HWND, *mut WINDOWCOMPOSITIONATTRIBDATA) -> BOOL;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
type WINDOWCOMPOSITIONATTRIB = u32;
|
||||
const WCA_USEDARKMODECOLORS: WINDOWCOMPOSITIONATTRIB = 26;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[repr(C)]
|
||||
struct WINDOWCOMPOSITIONATTRIBDATA {
|
||||
Attrib: WINDOWCOMPOSITIONATTRIB,
|
||||
|
|
@ -181,21 +168,8 @@ fn should_apps_use_dark_mode() -> bool {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
// FIXME: This definition was missing from winapi. Can remove from
|
||||
// here and use winapi once the following PR is released:
|
||||
// https://github.com/retep998/winapi-rs/pull/815
|
||||
#[repr(C)]
|
||||
#[allow(non_snake_case)]
|
||||
struct HIGHCONTRASTA {
|
||||
cbSize: UINT,
|
||||
dwFlags: DWORD,
|
||||
lpszDefaultScheme: LPSTR,
|
||||
}
|
||||
|
||||
const HCF_HIGHCONTRASTON: DWORD = 1;
|
||||
|
||||
fn is_high_contrast() -> bool {
|
||||
let mut hc = HIGHCONTRASTA {
|
||||
let mut hc = winuser::HIGHCONTRASTA {
|
||||
cbSize: 0,
|
||||
dwFlags: 0,
|
||||
lpszDefaultScheme: std::ptr::null_mut(),
|
||||
|
|
@ -210,7 +184,7 @@ fn is_high_contrast() -> bool {
|
|||
)
|
||||
};
|
||||
|
||||
ok != FALSE && (HCF_HIGHCONTRASTON & hc.dwFlags) == 1
|
||||
ok != FALSE && (winuser::HCF_HIGHCONTRASTON & hc.dwFlags) == 1
|
||||
}
|
||||
|
||||
fn widestring(src: &'static str) -> Vec<u16> {
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ impl FileDropHandler {
|
|||
},
|
||||
};
|
||||
|
||||
let mut drop_format = FORMATETC {
|
||||
let drop_format = FORMATETC {
|
||||
cfFormat: CF_HDROP as CLIPFORMAT,
|
||||
ptd: ptr::null(),
|
||||
dwAspect: DVASPECT_CONTENT,
|
||||
|
|
@ -190,7 +190,7 @@ impl FileDropHandler {
|
|||
};
|
||||
|
||||
let mut medium = std::mem::zeroed();
|
||||
let get_data_result = (*data_obj).GetData(&mut drop_format, &mut medium);
|
||||
let get_data_result = (*data_obj).GetData(&drop_format, &mut medium);
|
||||
if SUCCEEDED(get_data_result) {
|
||||
let hglobal = (*medium.u).hGlobal();
|
||||
let hdrop = (*hglobal) as shellapi::HDROP;
|
||||
|
|
@ -213,15 +213,15 @@ impl FileDropHandler {
|
|||
callback(OsString::from_wide(&path_buf[0..character_count]).into());
|
||||
}
|
||||
|
||||
return Some(hdrop);
|
||||
Some(hdrop)
|
||||
} else if get_data_result == DV_E_FORMATETC {
|
||||
// If the dropped item is not a file this error will occur.
|
||||
// In this case it is OK to return without taking further action.
|
||||
debug!("Error occured while processing dropped/hovered item: item is not a file.");
|
||||
return None;
|
||||
None
|
||||
} else {
|
||||
debug!("Unexpected error occured while processing dropped/hovered item.");
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ pub fn get_key_mods() -> ModifiersState {
|
|||
bitflags! {
|
||||
#[derive(Default)]
|
||||
pub struct ModifiersStateSide: u32 {
|
||||
const LSHIFT = 0b010 << 0;
|
||||
const RSHIFT = 0b001 << 0;
|
||||
const LSHIFT = 0b010;
|
||||
const RSHIFT = 0b001;
|
||||
|
||||
const LCTRL = 0b010 << 3;
|
||||
const RCTRL = 0b001 << 3;
|
||||
|
|
@ -343,7 +343,7 @@ pub fn handle_extended_keys(
|
|||
extended: bool,
|
||||
) -> Option<(c_int, UINT)> {
|
||||
// Welcome to hell https://blog.molecular-matters.com/2011/09/05/properly-handling-keyboard-input/
|
||||
scancode = if extended { 0xE000 } else { 0x0000 } | scancode;
|
||||
scancode |= if extended { 0xE000 } else { 0x0000 };
|
||||
let vkey = match vkey {
|
||||
winuser::VK_SHIFT => unsafe {
|
||||
winuser::MapVirtualKeyA(scancode, winuser::MAPVK_VSC_TO_VK_EX) as _
|
||||
|
|
@ -369,7 +369,7 @@ pub fn handle_extended_keys(
|
|||
// Don't emit anything for the LeftControl event in the pair...
|
||||
0xE01D if vkey == winuser::VK_PAUSE => return None,
|
||||
// ...and emit the Pause event for the second event in the pair.
|
||||
0x45 if vkey == winuser::VK_PAUSE || vkey == 0xFF as _ => {
|
||||
0x45 if vkey == winuser::VK_PAUSE || vkey == 0xFF => {
|
||||
scancode = 0xE059;
|
||||
winuser::VK_PAUSE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ lazy_static! {
|
|||
pub(crate) struct WindowData<T: 'static> {
|
||||
pub window_state: Arc<Mutex<WindowState>>,
|
||||
pub event_loop_runner: EventLoopRunnerShared<T>,
|
||||
pub file_drop_handler: Option<FileDropHandler>,
|
||||
pub _file_drop_handler: Option<FileDropHandler>,
|
||||
pub userdata_removed: Cell<bool>,
|
||||
pub recurse_depth: Cell<u32>,
|
||||
}
|
||||
|
|
@ -217,8 +217,8 @@ impl<T: 'static> EventLoop<T> {
|
|||
if 0 == winuser::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) {
|
||||
break 'main;
|
||||
}
|
||||
winuser::TranslateMessage(&mut msg);
|
||||
winuser::DispatchMessageW(&mut msg);
|
||||
winuser::TranslateMessage(&msg);
|
||||
winuser::DispatchMessageW(&msg);
|
||||
|
||||
if let Err(payload) = runner.take_panic_error() {
|
||||
runner.reset_runner();
|
||||
|
|
@ -345,15 +345,15 @@ fn wait_thread(parent_thread_id: DWORD, msg_window_id: HWND) {
|
|||
|
||||
if wait_until_opt.is_some() {
|
||||
if 0 != winuser::PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, winuser::PM_REMOVE) {
|
||||
winuser::TranslateMessage(&mut msg);
|
||||
winuser::DispatchMessageW(&mut msg);
|
||||
winuser::TranslateMessage(&msg);
|
||||
winuser::DispatchMessageW(&msg);
|
||||
}
|
||||
} else {
|
||||
if 0 == winuser::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) {
|
||||
break 'main;
|
||||
} else {
|
||||
winuser::TranslateMessage(&mut msg);
|
||||
winuser::DispatchMessageW(&mut msg);
|
||||
winuser::TranslateMessage(&msg);
|
||||
winuser::DispatchMessageW(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -714,8 +714,8 @@ unsafe fn flush_paint_messages<T: 'static>(
|
|||
return;
|
||||
}
|
||||
|
||||
winuser::TranslateMessage(&mut msg);
|
||||
winuser::DispatchMessageW(&mut msg);
|
||||
winuser::TranslateMessage(&msg);
|
||||
winuser::DispatchMessageW(&msg);
|
||||
});
|
||||
true
|
||||
} else {
|
||||
|
|
@ -938,7 +938,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
|
|||
winuser::MonitorFromRect(&new_rect, winuser::MONITOR_DEFAULTTONULL);
|
||||
match fullscreen {
|
||||
Fullscreen::Borderless(ref mut fullscreen_monitor) => {
|
||||
if new_monitor != ptr::null_mut()
|
||||
if !new_monitor.is_null()
|
||||
&& fullscreen_monitor
|
||||
.as_ref()
|
||||
.map(|monitor| new_monitor != monitor.inner.hmonitor())
|
||||
|
|
@ -1020,8 +1020,8 @@ unsafe fn public_window_callback_inner<T: 'static>(
|
|||
winuser::WM_CHAR | winuser::WM_SYSCHAR => {
|
||||
use crate::event::WindowEvent::ReceivedCharacter;
|
||||
use std::char;
|
||||
let is_high_surrogate = 0xD800 <= wparam && wparam <= 0xDBFF;
|
||||
let is_low_surrogate = 0xDC00 <= wparam && wparam <= 0xDFFF;
|
||||
let is_high_surrogate = (0xD800..=0xDBFF).contains(&wparam);
|
||||
let is_low_surrogate = (0xDC00..=0xDFFF).contains(&wparam);
|
||||
|
||||
if is_high_surrogate {
|
||||
userdata.window_state.lock().high_surrogate = Some(wparam as u16);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ unsafe impl Sync for Cursor {}
|
|||
pub struct DeviceId(u32);
|
||||
|
||||
impl DeviceId {
|
||||
pub unsafe fn dummy() -> Self {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
DeviceId(0)
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ unsafe impl Send for WindowId {}
|
|||
unsafe impl Sync for WindowId {}
|
||||
|
||||
impl WindowId {
|
||||
pub unsafe fn dummy() -> Self {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
use std::ptr::null_mut;
|
||||
|
||||
WindowId(null_mut())
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ where
|
|||
}
|
||||
|
||||
pub fn wchar_to_string(wchar: &[wchar_t]) -> String {
|
||||
String::from_utf16_lossy(wchar).to_string()
|
||||
String::from_utf16_lossy(wchar)
|
||||
}
|
||||
|
||||
pub fn wchar_ptr_to_string(wchar: *const wchar_t) -> String {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ impl Window {
|
|||
event_loop::WindowData {
|
||||
window_state: win.window_state.clone(),
|
||||
event_loop_runner: event_loop.runner_shared.clone(),
|
||||
file_drop_handler,
|
||||
_file_drop_handler: file_drop_handler,
|
||||
userdata_removed: Cell::new(false),
|
||||
recurse_depth: Cell::new(0),
|
||||
}
|
||||
|
|
@ -455,7 +455,7 @@ impl Window {
|
|||
// string, so add it
|
||||
display_name.push(0);
|
||||
|
||||
let mut native_video_mode = video_mode.video_mode.native_video_mode.clone();
|
||||
let mut native_video_mode = video_mode.video_mode.native_video_mode;
|
||||
|
||||
let res = unsafe {
|
||||
winuser::ChangeDisplaySettingsExW(
|
||||
|
|
@ -896,7 +896,7 @@ unsafe fn post_init<T: 'static>(
|
|||
win.set_maximized(true);
|
||||
}
|
||||
|
||||
if let Some(_) = attributes.fullscreen {
|
||||
if attributes.fullscreen.is_some() {
|
||||
win.set_fullscreen(attributes.fullscreen);
|
||||
force_window_active(win.window.0);
|
||||
}
|
||||
|
|
@ -986,7 +986,7 @@ unsafe fn taskbar_mark_fullscreen(handle: HWND, fullscreen: bool) {
|
|||
TASKBAR_LIST.with(|task_bar_list_ptr| {
|
||||
let mut task_bar_list = task_bar_list_ptr.get();
|
||||
|
||||
if task_bar_list == ptr::null_mut() {
|
||||
if task_bar_list.is_null() {
|
||||
use winapi::{shared::winerror::S_OK, Interface};
|
||||
|
||||
let hr = combaseapi::CoCreateInstance(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue