util.rs

 1use windows::Win32::{Foundation::*, UI::WindowsAndMessaging::*};
 2
 3pub(crate) trait HiLoWord {
 4    fn hiword(&self) -> u16;
 5    fn loword(&self) -> u16;
 6    fn signed_hiword(&self) -> i16;
 7    fn signed_loword(&self) -> i16;
 8}
 9
10impl HiLoWord for WPARAM {
11    fn hiword(&self) -> u16 {
12        ((self.0 >> 16) & 0xFFFF) as u16
13    }
14
15    fn loword(&self) -> u16 {
16        (self.0 & 0xFFFF) as u16
17    }
18
19    fn signed_hiword(&self) -> i16 {
20        ((self.0 >> 16) & 0xFFFF) as i16
21    }
22
23    fn signed_loword(&self) -> i16 {
24        (self.0 & 0xFFFF) as i16
25    }
26}
27
28impl HiLoWord for LPARAM {
29    fn hiword(&self) -> u16 {
30        ((self.0 >> 16) & 0xFFFF) as u16
31    }
32
33    fn loword(&self) -> u16 {
34        (self.0 & 0xFFFF) as u16
35    }
36
37    fn signed_hiword(&self) -> i16 {
38        ((self.0 >> 16) & 0xFFFF) as i16
39    }
40
41    fn signed_loword(&self) -> i16 {
42        (self.0 & 0xFFFF) as i16
43    }
44}
45
46pub(crate) unsafe fn get_window_long(hwnd: HWND, nindex: WINDOW_LONG_PTR_INDEX) -> isize {
47    #[cfg(target_pointer_width = "64")]
48    unsafe {
49        GetWindowLongPtrW(hwnd, nindex)
50    }
51    #[cfg(target_pointer_width = "32")]
52    unsafe {
53        GetWindowLongW(hwnd, nindex) as isize
54    }
55}
56
57pub(crate) unsafe fn set_window_long(
58    hwnd: HWND,
59    nindex: WINDOW_LONG_PTR_INDEX,
60    dwnewlong: isize,
61) -> isize {
62    #[cfg(target_pointer_width = "64")]
63    unsafe {
64        SetWindowLongPtrW(hwnd, nindex, dwnewlong)
65    }
66    #[cfg(target_pointer_width = "32")]
67    unsafe {
68        SetWindowLongW(hwnd, nindex, dwnewlong as i32) as isize
69    }
70}
71
72pub(crate) fn windows_credentials_target_name(url: &str) -> String {
73    format!("zed:url={}", url)
74}