Fix issues where screen and window sizes contained Pixels, but were declared as DevicePixels (#12991)

On most platforms, things were working correctly, but had the wrong
type. On X11, there were some problems with window and display size
calculations.

Release Notes:

- Fixed issues with window positioning on X11

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-06-13 10:48:37 -07:00 committed by GitHub
parent 22dc88ed3d
commit da281d6d8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 331 additions and 367 deletions

View file

@ -52,8 +52,7 @@ mod prompts;
pub use prompts::*;
pub(crate) const DEFAULT_WINDOW_SIZE: Size<DevicePixels> =
size(DevicePixels(1024), DevicePixels(700));
pub(crate) const DEFAULT_WINDOW_SIZE: Size<Pixels> = size(px(1024.), px(700.));
/// Represents the two different phases when dispatching events.
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
@ -581,8 +580,8 @@ pub(crate) struct ElementStateBox {
pub(crate) type_name: &'static str,
}
fn default_bounds(display_id: Option<DisplayId>, cx: &mut AppContext) -> Bounds<DevicePixels> {
const DEFAULT_WINDOW_OFFSET: Point<DevicePixels> = point(DevicePixels(0), DevicePixels(35));
fn default_bounds(display_id: Option<DisplayId>, cx: &mut AppContext) -> Bounds<Pixels> {
const DEFAULT_WINDOW_OFFSET: Point<Pixels> = point(px(0.), px(35.));
cx.active_window()
.and_then(|w| w.update(cx, |_, cx| cx.bounds()).ok())
@ -594,9 +593,7 @@ fn default_bounds(display_id: Option<DisplayId>, cx: &mut AppContext) -> Bounds<
display
.map(|display| display.default_bounds())
.unwrap_or_else(|| {
Bounds::new(point(DevicePixels(0), DevicePixels(0)), DEFAULT_WINDOW_SIZE)
})
.unwrap_or_else(|| Bounds::new(point(px(0.), px(0.)), DEFAULT_WINDOW_SIZE))
})
}
@ -1145,7 +1142,7 @@ impl<'a> WindowContext<'a> {
}
/// Returns the bounds of the current window in the global coordinate space, which could span across multiple displays.
pub fn bounds(&self) -> Bounds<DevicePixels> {
pub fn bounds(&self) -> Bounds<Pixels> {
self.window.platform_window.bounds()
}