This aligns the Windows platform implementation with a code style similar to macOS platform, eliminating most of the `Cell`s and `Mutex`es. This adjustment facilitates potential future porting to a multi-threaded implementation if required. Overall, this PR made the following changes: it segregated all member variables in `WindowsPlatform` and `WindowsWindow`, grouping together variables that remain constant throughout the entire app lifecycle, while placing variables that may change during app runtime into `RefCell`. Edit: During the code refactoring process, a bug was also fixed. **Before**: Close window when file has changed, nothing happen: https://github.com/zed-industries/zed/assets/14981363/0bcda7c1-808c-4b36-8953-a3a3365a314e **After**: Now `should_close` callback is properly handled https://github.com/zed-industries/zed/assets/14981363/c8887b72-9a0b-42ad-b9ab-7d0775d843f5 Release Notes: - N/A
82 lines
2.3 KiB
Rust
82 lines
2.3 KiB
Rust
use std::ffi::{c_uint, c_void};
|
|
|
|
use util::ResultExt;
|
|
use windows::Win32::UI::WindowsAndMessaging::{
|
|
SystemParametersInfoW, SPI_GETWHEELSCROLLCHARS, SPI_GETWHEELSCROLLLINES,
|
|
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS,
|
|
};
|
|
|
|
/// Windows settings pulled from SystemParametersInfo
|
|
/// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow
|
|
#[derive(Default, Debug)]
|
|
pub(crate) struct WindowsPlatformSystemSettings {
|
|
pub(crate) mouse_wheel_settings: MouseWheelSettings,
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone, Copy)]
|
|
pub(crate) struct MouseWheelSettings {
|
|
/// SEE: SPI_GETWHEELSCROLLCHARS
|
|
pub(crate) wheel_scroll_chars: u32,
|
|
/// SEE: SPI_GETWHEELSCROLLLINES
|
|
pub(crate) wheel_scroll_lines: u32,
|
|
}
|
|
|
|
impl WindowsPlatformSystemSettings {
|
|
pub(crate) fn new() -> Self {
|
|
let mut settings = Self::default();
|
|
settings.init();
|
|
settings
|
|
}
|
|
|
|
fn init(&mut self) {
|
|
self.mouse_wheel_settings.update();
|
|
}
|
|
}
|
|
|
|
impl MouseWheelSettings {
|
|
pub(crate) fn update(&mut self) -> (Option<u32>, Option<u32>) {
|
|
(
|
|
self.update_wheel_scroll_chars(),
|
|
self.update_wheel_scroll_lines(),
|
|
)
|
|
}
|
|
|
|
fn update_wheel_scroll_chars(&mut self) -> Option<u32> {
|
|
let mut value = c_uint::default();
|
|
let result = unsafe {
|
|
SystemParametersInfoW(
|
|
SPI_GETWHEELSCROLLCHARS,
|
|
0,
|
|
Some((&mut value) as *mut c_uint as *mut c_void),
|
|
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS::default(),
|
|
)
|
|
};
|
|
|
|
if result.log_err() != None && self.wheel_scroll_chars != value {
|
|
self.wheel_scroll_chars = value;
|
|
Some(value)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
fn update_wheel_scroll_lines(&mut self) -> Option<u32> {
|
|
let mut value = c_uint::default();
|
|
let result = unsafe {
|
|
SystemParametersInfoW(
|
|
SPI_GETWHEELSCROLLLINES,
|
|
0,
|
|
Some((&mut value) as *mut c_uint as *mut c_void),
|
|
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS::default(),
|
|
)
|
|
};
|
|
|
|
if result.log_err() != None && self.wheel_scroll_lines != value {
|
|
self.wheel_scroll_lines = value;
|
|
Some(value)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|