Skip to content

Commit e9d5b36

Browse files
committed
chore(deps): update windows-sys crate to 0.59
1 parent 4e4ab37 commit e9d5b36

4 files changed

Lines changed: 46 additions & 23 deletions

File tree

.changes/windows-sys.0.59.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"win7-notifications": "patch"
3+
---
4+
5+
Update `windows-sys` crate to `0.59`

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ targets = [ "x86_64-pc-windows-msvc" ]
2020
once_cell = "1"
2121

2222
[dependencies.windows-sys]
23-
version = "0.52"
23+
version = "0.59"
2424
features = [
2525
"Win32_Foundation",
2626
"Win32_System_LibraryLoader",

src/notification.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const CLOSE_BTN_RECT_EXTRA: RECT = RECT {
4545
bottom: CLOSE_BTN_RECT.bottom + 8,
4646
};
4747

48-
static ACTIVE_NOTIFICATIONS: Lazy<Mutex<Vec<HWND>>> = Lazy::new(|| Mutex::new(Vec::new()));
48+
static ACTIVE_NOTIFICATIONS: Lazy<Mutex<Vec<isize>>> = Lazy::new(|| Mutex::new(Vec::new()));
4949
static PRIMARY_MONITOR: Lazy<Mutex<MONITORINFOEXW>> =
5050
Lazy::new(|| unsafe { Mutex::new(util::get_monitor_info(util::primary_monitor())) });
5151

@@ -159,18 +159,18 @@ impl Notification {
159159
style: CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
160160
cbClsExtra: 0,
161161
cbWndExtra: 0,
162-
hIcon: 0,
163-
hCursor: 0, // must be null in order for cursor state to work properly
162+
hIcon: std::ptr::null_mut(),
163+
hCursor: std::ptr::null_mut(), // must be null in order for cursor state to work properly
164164
lpszMenuName: ptr::null(),
165-
hIconSm: 0,
165+
hIconSm: std::ptr::null_mut(),
166166
};
167167
RegisterClassExW(&wnd_class);
168168

169169
if let Ok(pm) = PRIMARY_MONITOR.lock() {
170170
let RECT { right, bottom, .. } = pm.monitorInfo.rcWork;
171171

172172
let data = WindowData {
173-
window: 0,
173+
window: std::ptr::null_mut(),
174174
mouse_hovering_close_btn: false,
175175
notification: self.clone(),
176176
};
@@ -184,19 +184,19 @@ impl Notification {
184184
bottom - NH - 15,
185185
NW,
186186
NH,
187-
0,
188-
0,
187+
std::ptr::null_mut(),
188+
std::ptr::null_mut(),
189189
hinstance,
190190
Box::into_raw(Box::new(data)) as _,
191191
);
192192

193-
if hwnd == 0 {
193+
if hwnd.is_null() {
194194
return Err(GetLastError());
195195
}
196196

197197
// reposition active notifications and make room for new one
198198
if let Ok(mut active_notifications) = ACTIVE_NOTIFICATIONS.lock() {
199-
active_notifications.push(hwnd);
199+
active_notifications.push(hwnd as _);
200200
reposition_notifications(&active_notifications, right, bottom)
201201
}
202202

@@ -208,6 +208,7 @@ impl Notification {
208208
}
209209

210210
let timeout = self.timeout;
211+
let hwnd = hwnd as isize;
211212
thread::spawn(move || {
212213
thread::sleep(Duration::from_millis(timeout.into()));
213214
if timeout != Timeout::Never {
@@ -221,15 +222,15 @@ impl Notification {
221222
}
222223
}
223224

224-
unsafe fn close_notification(hwnd: HWND) {
225-
ShowWindow(hwnd, SW_HIDE);
226-
CloseWindow(hwnd);
225+
unsafe fn close_notification(hwnd: isize) {
226+
ShowWindow(hwnd as _, SW_HIDE);
227+
CloseWindow(hwnd as _);
227228

228229
// We can NOT call `DestroyWindow` from this window
229230
// Sending WM_CLOSE will by default make the windows call it on itself.
230231
// Note WM_DESTROY should not be sent directly as it would create a leak
231232
// see https://devblogs.microsoft.com/oldnewthing/20110926-00/?p=9553
232-
SendMessageA(hwnd, WM_CLOSE, 0, 0);
233+
SendMessageA(hwnd as _, WM_CLOSE, 0, 0);
233234

234235
if let Ok(mut active_notifications) = ACTIVE_NOTIFICATIONS.lock() {
235236
if let Some(index) = active_notifications.iter().position(|e| *e == hwnd) {
@@ -249,8 +250,8 @@ unsafe fn reposition_notifications(notifications: &[isize], right: i32, bottom:
249250
let mut i = notifications.len() as i32;
250251
for &hwnd in notifications.iter() {
251252
SetWindowPos(
252-
hwnd,
253-
0,
253+
hwnd as _,
254+
std::ptr::null_mut(),
254255
right - NW - 15,
255256
bottom - 15 - (NH * i) - 10 * (i - 1),
256257
0,
@@ -299,7 +300,7 @@ pub unsafe extern "system" fn window_proc(
299300
fErase: 0,
300301
fIncUpdate: 0,
301302
fRestore: 0,
302-
hdc: 0,
303+
hdc: std::ptr::null_mut(),
303304
rcPaint: RECT {
304305
bottom: 0,
305306
left: 0,
@@ -318,7 +319,17 @@ pub unsafe extern "system" fn window_proc(
318319
notification.icon_width,
319320
notification.icon_height,
320321
);
321-
DrawIconEx(hdc, NM, NM, hicon, NIS, NIS, 0, 0, DI_NORMAL);
322+
DrawIconEx(
323+
hdc,
324+
NM,
325+
NM,
326+
hicon,
327+
NIS,
328+
NIS,
329+
0,
330+
std::ptr::null_mut(),
331+
DI_NORMAL,
332+
);
322333
}
323334

324335
// draw notification close button
@@ -406,7 +417,10 @@ pub unsafe extern "system" fn window_proc(
406417
let (x, y) = (GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
407418
let hit = util::rect_contains(CLOSE_BTN_RECT_EXTRA, x as i32, y as i32);
408419

409-
SetCursor(LoadCursorW(0, if hit { IDC_HAND } else { IDC_ARROW }));
420+
SetCursor(LoadCursorW(
421+
std::ptr::null_mut(),
422+
if hit { IDC_HAND } else { IDC_ARROW },
423+
));
410424
if hit != (*userdata).mouse_hovering_close_btn {
411425
// only trigger redraw if the previous state is different than the new state
412426
InvalidateRect(hwnd, std::ptr::null(), 0);
@@ -420,7 +434,7 @@ pub unsafe extern "system" fn window_proc(
420434
let (x, y) = (GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
421435

422436
if util::rect_contains(CLOSE_BTN_RECT_EXTRA, x as i32, y as i32) {
423-
close_notification(hwnd)
437+
close_notification(hwnd as _)
424438
}
425439

426440
DefWindowProcW(hwnd, msg, wparam, lparam)

src/util.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::{ffi::OsStr, iter::once, os::windows::prelude::OsStrExt};
5+
use std::{
6+
ffi::{c_void, OsStr},
7+
iter::once,
8+
os::windows::prelude::OsStrExt,
9+
};
610

711
use windows_sys::Win32::{
812
Foundation::*,
@@ -103,7 +107,7 @@ pub unsafe fn get_monitor_info(hmonitor: HMONITOR) -> MONITORINFOEXW {
103107
}
104108

105109
/// Returns a tuple of new and old `HFONT` handle
106-
pub unsafe fn set_font(hdc: HDC, name: &str, size: i32, weight: i32) -> (isize, isize) {
110+
pub unsafe fn set_font(hdc: HDC, name: &str, size: i32, weight: i32) -> (*mut c_void, *mut c_void) {
107111
let name = format!("{}\0", name);
108112
let hfont = CreateFontW(
109113
size,
@@ -153,7 +157,7 @@ pub fn get_hicon_from_32bpp_rgba(rgba: Vec<u8>, width: u32, height: u32) -> w32w
153157
assert_eq!(and_mask.len(), pixel_count);
154158
unsafe {
155159
w32wm::CreateIcon(
156-
HMODULE::default(),
160+
std::ptr::null_mut(),
157161
width as i32,
158162
height as i32,
159163
1,

0 commit comments

Comments
 (0)