
~~work in progress. not ready for review. made for visibility only, but feel free to comment :)~~ TODO: - [x] add close/min/max buttons (to be rendered with gpui) - [x] snap layout support - [x] fix issues with clicking items in titlebar - [x] cleanup/document Release Notes: - Added custom windows titlebar  --------- Co-authored-by: Mikayla <mikayla@zed.dev>
75 lines
1.7 KiB
Rust
75 lines
1.7 KiB
Rust
use windows::Win32::{
|
|
Foundation::{HWND, LPARAM, WPARAM},
|
|
UI::WindowsAndMessaging::{
|
|
GetWindowLongPtrW, GetWindowLongW, SetWindowLongPtrW, SetWindowLongW, WINDOW_LONG_PTR_INDEX,
|
|
},
|
|
};
|
|
|
|
pub(crate) trait HiLoWord {
|
|
fn hiword(&self) -> u16;
|
|
fn loword(&self) -> u16;
|
|
fn signed_hiword(&self) -> i16;
|
|
fn signed_loword(&self) -> i16;
|
|
}
|
|
|
|
impl HiLoWord for WPARAM {
|
|
fn hiword(&self) -> u16 {
|
|
((self.0 >> 16) & 0xFFFF) as u16
|
|
}
|
|
|
|
fn loword(&self) -> u16 {
|
|
(self.0 & 0xFFFF) as u16
|
|
}
|
|
|
|
fn signed_hiword(&self) -> i16 {
|
|
((self.0 >> 16) & 0xFFFF) as i16
|
|
}
|
|
|
|
fn signed_loword(&self) -> i16 {
|
|
(self.0 & 0xFFFF) as i16
|
|
}
|
|
}
|
|
|
|
impl HiLoWord for LPARAM {
|
|
fn hiword(&self) -> u16 {
|
|
((self.0 >> 16) & 0xFFFF) as u16
|
|
}
|
|
|
|
fn loword(&self) -> u16 {
|
|
(self.0 & 0xFFFF) as u16
|
|
}
|
|
|
|
fn signed_hiword(&self) -> i16 {
|
|
((self.0 >> 16) & 0xFFFF) as i16
|
|
}
|
|
|
|
fn signed_loword(&self) -> i16 {
|
|
(self.0 & 0xFFFF) as i16
|
|
}
|
|
}
|
|
|
|
pub(crate) unsafe fn get_window_long(hwnd: HWND, nindex: WINDOW_LONG_PTR_INDEX) -> isize {
|
|
#[cfg(target_pointer_width = "64")]
|
|
unsafe {
|
|
GetWindowLongPtrW(hwnd, nindex)
|
|
}
|
|
#[cfg(target_pointer_width = "32")]
|
|
unsafe {
|
|
GetWindowLongW(hwnd, nindex) as isize
|
|
}
|
|
}
|
|
|
|
pub(crate) unsafe fn set_window_long(
|
|
hwnd: HWND,
|
|
nindex: WINDOW_LONG_PTR_INDEX,
|
|
dwnewlong: isize,
|
|
) -> isize {
|
|
#[cfg(target_pointer_width = "64")]
|
|
unsafe {
|
|
SetWindowLongPtrW(hwnd, nindex, dwnewlong)
|
|
}
|
|
#[cfg(target_pointer_width = "32")]
|
|
unsafe {
|
|
SetWindowLongW(hwnd, nindex, dwnewlong as i32) as isize
|
|
}
|
|
}
|