Skip to content

Commit

Permalink
Remove mutable types
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenswasser committed Feb 5, 2022
1 parent 23b7663 commit 5755b7c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/platform_impl/windows/dark_mode.rs
Expand Up @@ -80,7 +80,7 @@ pub fn try_theme(hwnd: HWND, preferred_theme: Option<Theme>) -> Theme {
Theme::Light => LIGHT_THEME_NAME.as_ptr(),
};

let status = unsafe { SetWindowTheme(hwnd, theme_name, ptr::null_mut()) };
let status = unsafe { SetWindowTheme(hwnd, theme_name, ptr::null()) };

if status == S_OK && set_dark_mode_for_window(hwnd, is_dark_mode) {
return theme;
Expand Down Expand Up @@ -168,7 +168,7 @@ fn is_high_contrast() -> bool {
let mut hc = HIGHCONTRASTA {
cbSize: 0,
dwFlags: 0,
lpszDefaultScheme: ptr::null_mut(),
lpszDefaultScheme: ptr::null(),
};

let ok = unsafe {
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/windows/drop_handler.rs
Expand Up @@ -180,18 +180,18 @@ impl FileDropHandler {
let hdrop = medium.Anonymous.hGlobal;

// The second parameter (0xFFFFFFFF) instructs the function to return the item count
let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null_mut(), 0);
let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null(), 0);

for i in 0..item_count {
// Get the length of the path string NOT including the terminating null character.
// Previously, this was using a fixed size array of MAX_PATH length, but the
// Windows API allows longer paths under certain circumstances.
let character_count = DragQueryFileW(hdrop, i, ptr::null_mut(), 0) as usize;
let character_count = DragQueryFileW(hdrop, i, ptr::null(), 0) as usize;
let str_len = character_count + 1;

// Fill path_buf with the null-terminated file name
let mut path_buf = Vec::with_capacity(str_len);
DragQueryFileW(hdrop, i, path_buf.as_mut_ptr(), str_len as u32);
DragQueryFileW(hdrop, i, path_buf.as_ptr(), str_len as u32);
path_buf.set_len(str_len);

callback(OsString::from_wide(&path_buf[0..character_count]).into());
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/event.rs
Expand Up @@ -119,12 +119,12 @@ pub fn get_pressed_keys() -> impl Iterator<Item = VIRTUAL_KEY> {
}

unsafe fn get_char(keyboard_state: &[u8; 256], v_key: u32, hkl: HKL) -> Option<char> {
let mut unicode_bytes = [0u16; 5];
let unicode_bytes = [0u16; 5];
let len = ToUnicodeEx(
v_key,
0,
keyboard_state.as_ptr(),
unicode_bytes.as_mut_ptr(),
unicode_bytes.as_ptr(),
unicode_bytes.len() as _,
0,
hkl,
Expand Down
10 changes: 5 additions & 5 deletions src/platform_impl/windows/event_loop.rs
Expand Up @@ -635,11 +635,11 @@ fn create_event_target_window<T: 'static>() -> HWND {
lpfnWndProc: Some(thread_event_target_callback::<T>),
cbClsExtra: 0,
cbWndExtra: 0,
hInstance: GetModuleHandleW(ptr::null_mut()),
hInstance: GetModuleHandleW(ptr::null()),
hIcon: 0,
hCursor: 0, // must be null in order for cursor state to work properly
hbrBackground: 0,
lpszMenuName: ptr::null_mut(),
lpszMenuName: ptr::null(),
lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(),
hIconSm: 0,
};
Expand All @@ -661,16 +661,16 @@ fn create_event_target_window<T: 'static>() -> HWND {
// It is unclear why the bug is triggered by waiting for several hours.
| WS_EX_TOOLWINDOW,
THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(),
ptr::null_mut(),
ptr::null(),
WS_OVERLAPPED,
0,
0,
0,
0,
0,
0,
GetModuleHandleW(ptr::null_mut()),
ptr::null_mut(),
GetModuleHandleW(ptr::null()),
ptr::null(),
);

super::set_window_long(
Expand Down
10 changes: 5 additions & 5 deletions src/platform_impl/windows/icon.rs
Expand Up @@ -22,11 +22,11 @@ impl Pixel {

impl RgbaIcon {
fn into_windows_icon(self) -> Result<WinIcon, BadIcon> {
let mut rgba = self.rgba;
let rgba = self.rgba;
let pixel_count = rgba.len() / PIXEL_SIZE;
let mut and_mask = Vec::with_capacity(pixel_count);
let pixels =
unsafe { std::slice::from_raw_parts_mut(rgba.as_mut_ptr() as *mut Pixel, pixel_count) };
unsafe { std::slice::from_raw_parts_mut(rgba.as_ptr() as *mut Pixel, pixel_count) };
for pixel in pixels {
and_mask.push(pixel.a.wrapping_sub(std::u8::MAX)); // invert alpha channel
pixel.to_bgra();
Expand Down Expand Up @@ -81,12 +81,12 @@ impl WinIcon {
// width / height of 0 along with LR_DEFAULTSIZE tells windows to load the default icon size
let (width, height) = size.map(Into::into).unwrap_or((0, 0));

let mut wide_path = util::encode_wide(path.as_ref());
let wide_path = util::encode_wide(path.as_ref());

let handle = unsafe {
LoadImageW(
0,
wide_path.as_mut_ptr(),
wide_path.as_ptr(),
IMAGE_ICON,
width as i32,
height as i32,
Expand All @@ -108,7 +108,7 @@ impl WinIcon {
let (width, height) = size.map(Into::into).unwrap_or((0, 0));
let handle = unsafe {
LoadImageW(
GetModuleHandleW(ptr::null_mut()),
GetModuleHandleW(ptr::null()),
resource_id as PWSTR,
IMAGE_ICON,
width as i32,
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/monitor.rs
Expand Up @@ -217,8 +217,8 @@ impl MonitorHandle {

loop {
unsafe {
let mut monitor_info = get_monitor_info(self.0).unwrap();
let device_name = monitor_info.szDevice.as_mut_ptr();
let monitor_info = get_monitor_info(self.0).unwrap();
let device_name = monitor_info.szDevice.as_ptr();
let mut mode: DEVMODEW = mem::zeroed();
mode.dmSize = mem::size_of_val(&mode) as u16;
if EnumDisplaySettingsExW(device_name, i, &mut mode, 0) == false.into() {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/raw_input.rs
Expand Up @@ -116,7 +116,7 @@ pub fn get_raw_input_device_name(handle: HANDLE) -> Option<String> {
GetRawInputDeviceInfoW(
handle,
RIDI_DEVICENAME,
name.as_mut_ptr() as _,
name.as_ptr() as _,
&mut minimum_size,
)
};
Expand Down
33 changes: 16 additions & 17 deletions src/platform_impl/windows/window.rs
Expand Up @@ -101,9 +101,9 @@ impl Window {
}

pub fn set_title(&self, text: &str) {
let mut wide_text = util::encode_wide(text);
let wide_text = util::encode_wide(text);
unsafe {
SetWindowTextW(self.hwnd(), wide_text.as_mut_ptr());
SetWindowTextW(self.hwnd(), wide_text.as_ptr());
}
}

Expand Down Expand Up @@ -428,7 +428,7 @@ impl Window {
&native_video_mode,
0,
CDS_FULLSCREEN,
ptr::null_mut(),
ptr::null(),
)
};

Expand All @@ -442,11 +442,11 @@ impl Window {
| (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => {
let res = unsafe {
ChangeDisplaySettingsExW(
ptr::null_mut(),
ptr::null_mut(),
ptr::null(),
ptr::null(),
0,
CDS_FULLSCREEN,
ptr::null_mut(),
ptr::null(),
)
};

Expand Down Expand Up @@ -862,10 +862,9 @@ unsafe fn init<T>(
where
T: 'static,
{
let mut title = util::encode_wide(&attributes.title);
let title = util::encode_wide(&attributes.title);

let mut class_name =
register_window_class::<T>(&attributes.window_icon, &pl_attribs.taskbar_icon);
let class_name = register_window_class::<T>(&attributes.window_icon, &pl_attribs.taskbar_icon);

let mut window_flags = WindowFlags::empty();
window_flags.set(WindowFlags::DECORATIONS, attributes.decorations);
Expand Down Expand Up @@ -907,16 +906,16 @@ where
let (style, ex_style) = window_flags.to_window_styles();
let handle = CreateWindowExW(
ex_style,
class_name.as_mut_ptr(),
title.as_mut_ptr(),
class_name.as_ptr(),
title.as_ptr(),
style,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
parent.unwrap_or(0),
pl_attribs.menu.unwrap_or(0),
GetModuleHandleW(ptr::null_mut()),
GetModuleHandleW(ptr::null()),
&mut initdata as *mut _ as *mut _,
);

Expand All @@ -938,7 +937,7 @@ unsafe fn register_window_class<T: 'static>(
window_icon: &Option<Icon>,
taskbar_icon: &Option<Icon>,
) -> Vec<u16> {
let mut class_name = util::encode_wide("Window Class");
let class_name = util::encode_wide("Window Class");

let h_icon = taskbar_icon
.as_ref()
Expand All @@ -955,12 +954,12 @@ unsafe fn register_window_class<T: 'static>(
lpfnWndProc: Some(super::event_loop::public_window_callback::<T>),
cbClsExtra: 0,
cbWndExtra: 0,
hInstance: GetModuleHandleW(ptr::null_mut()),
hInstance: GetModuleHandleW(ptr::null()),
hIcon: h_icon,
hCursor: 0, // must be null in order for cursor state to work properly
hbrBackground: 0,
lpszMenuName: ptr::null_mut(),
lpszClassName: class_name.as_mut_ptr(),
lpszMenuName: ptr::null(),
lpszClassName: class_name.as_ptr(),
hIconSm: h_icon_small,
};

Expand All @@ -983,7 +982,7 @@ impl Drop for ComInitialized {
thread_local! {
static COM_INITIALIZED: ComInitialized = {
unsafe {
CoInitializeEx(ptr::null_mut(), COINIT_APARTMENTTHREADED);
CoInitializeEx(ptr::null(), COINIT_APARTMENTTHREADED);
ComInitialized(ptr::null_mut())
}
};
Expand Down

0 comments on commit 5755b7c

Please sign in to comment.