windows: Fix autohide taskbar dosen't automatically appear when Zed is maximized (#16806)
Closes #12313 This PR introduces the following improvements: 1. Fixed the issue where the auto-hide taskbar wouldn't automatically appear when Zed is maximized. 2. Refactored the `WM_NCCALCSIZE` code, making it more human-readable. Release Notes: - Fixed auto-hide taskbar would refuse to show itself when `Zed` is maximized on Winodws([#12313](https://github.com/zed-industries/zed/issues/12313)). --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
77c6243aa8
commit
403fdd6018
3 changed files with 230 additions and 49 deletions
|
@ -1,16 +1,24 @@
|
|||
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,
|
||||
use ::util::ResultExt;
|
||||
use windows::Win32::UI::{
|
||||
Shell::{SHAppBarMessage, ABM_GETSTATE, ABM_GETTASKBARPOS, ABS_AUTOHIDE, APPBARDATA},
|
||||
WindowsAndMessaging::{
|
||||
SystemParametersInfoW, SPI_GETWHEELSCROLLCHARS, SPI_GETWHEELSCROLLLINES,
|
||||
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::*;
|
||||
|
||||
use super::WindowsDisplay;
|
||||
|
||||
/// Windows settings pulled from SystemParametersInfo
|
||||
/// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub(crate) struct WindowsSystemSettings {
|
||||
pub(crate) mouse_wheel_settings: MouseWheelSettings,
|
||||
pub(crate) auto_hide_taskbar_position: Option<AutoHideTaskbarPosition>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
|
@ -22,19 +30,20 @@ pub(crate) struct MouseWheelSettings {
|
|||
}
|
||||
|
||||
impl WindowsSystemSettings {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(display: WindowsDisplay) -> Self {
|
||||
let mut settings = Self::default();
|
||||
settings.init();
|
||||
settings.update(display);
|
||||
settings
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
pub(crate) fn update(&mut self, display: WindowsDisplay) {
|
||||
self.mouse_wheel_settings.update();
|
||||
self.auto_hide_taskbar_position = AutoHideTaskbarPosition::new(display).log_err().flatten();
|
||||
}
|
||||
}
|
||||
|
||||
impl MouseWheelSettings {
|
||||
pub(crate) fn update(&mut self) {
|
||||
fn update(&mut self) {
|
||||
self.update_wheel_scroll_chars();
|
||||
self.update_wheel_scroll_lines();
|
||||
}
|
||||
|
@ -71,3 +80,100 @@ impl MouseWheelSettings {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub(crate) enum AutoHideTaskbarPosition {
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
#[default]
|
||||
Bottom,
|
||||
}
|
||||
|
||||
impl AutoHideTaskbarPosition {
|
||||
fn new(display: WindowsDisplay) -> anyhow::Result<Option<Self>> {
|
||||
if !check_auto_hide_taskbar_enable() {
|
||||
// If auto hide taskbar is not enable, we do nothing in this case.
|
||||
return Ok(None);
|
||||
}
|
||||
let mut info = APPBARDATA {
|
||||
cbSize: std::mem::size_of::<APPBARDATA>() as u32,
|
||||
..Default::default()
|
||||
};
|
||||
let ret = unsafe { SHAppBarMessage(ABM_GETTASKBARPOS, &mut info) };
|
||||
if ret == 0 {
|
||||
anyhow::bail!(
|
||||
"Unable to retrieve taskbar position: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
}
|
||||
let taskbar_bounds: Bounds<DevicePixels> = Bounds::new(
|
||||
point(info.rc.left.into(), info.rc.top.into()),
|
||||
size(
|
||||
(info.rc.right - info.rc.left).into(),
|
||||
(info.rc.bottom - info.rc.top).into(),
|
||||
),
|
||||
);
|
||||
let display_bounds = display.physical_bounds();
|
||||
if display_bounds.intersect(&taskbar_bounds) != taskbar_bounds {
|
||||
// This case indicates that taskbar is not on the current monitor.
|
||||
return Ok(None);
|
||||
}
|
||||
if taskbar_bounds.bottom() == display_bounds.bottom()
|
||||
&& taskbar_bounds.right() == display_bounds.right()
|
||||
{
|
||||
if taskbar_bounds.size.height < display_bounds.size.height
|
||||
&& taskbar_bounds.size.width == display_bounds.size.width
|
||||
{
|
||||
return Ok(Some(Self::Bottom));
|
||||
}
|
||||
if taskbar_bounds.size.width < display_bounds.size.width
|
||||
&& taskbar_bounds.size.height == display_bounds.size.height
|
||||
{
|
||||
return Ok(Some(Self::Right));
|
||||
}
|
||||
log::error!(
|
||||
"Unrecognized taskbar bounds {:?} give display bounds {:?}",
|
||||
taskbar_bounds,
|
||||
display_bounds
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
if taskbar_bounds.top() == display_bounds.top()
|
||||
&& taskbar_bounds.left() == display_bounds.left()
|
||||
{
|
||||
if taskbar_bounds.size.height < display_bounds.size.height
|
||||
&& taskbar_bounds.size.width == display_bounds.size.width
|
||||
{
|
||||
return Ok(Some(Self::Top));
|
||||
}
|
||||
if taskbar_bounds.size.width < display_bounds.size.width
|
||||
&& taskbar_bounds.size.height == display_bounds.size.height
|
||||
{
|
||||
return Ok(Some(Self::Left));
|
||||
}
|
||||
log::error!(
|
||||
"Unrecognized taskbar bounds {:?} give display bounds {:?}",
|
||||
taskbar_bounds,
|
||||
display_bounds
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
log::error!(
|
||||
"Unrecognized taskbar bounds {:?} give display bounds {:?}",
|
||||
taskbar_bounds,
|
||||
display_bounds
|
||||
);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if auto hide taskbar is enable or not.
|
||||
fn check_auto_hide_taskbar_enable() -> bool {
|
||||
let mut info = APPBARDATA {
|
||||
cbSize: std::mem::size_of::<APPBARDATA>() as u32,
|
||||
..Default::default()
|
||||
};
|
||||
let ret = unsafe { SHAppBarMessage(ABM_GETSTATE, &mut info) } as u32;
|
||||
ret == ABS_AUTOHIDE
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue