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
co-authored by Conrad Irwin Mikayla
parent 22dc88ed3d
commit da281d6d8f
25 changed files with 331 additions and 367 deletions
+4 -8
View File
@@ -1,12 +1,11 @@
use crate::{px, Bounds, DisplayId, Pixels, PlatformDisplay, Point};
use anyhow::{Ok, Result};
use crate::{Bounds, DevicePixels, DisplayId, PlatformDisplay, Point};
#[derive(Debug)]
pub(crate) struct TestDisplay {
id: DisplayId,
uuid: uuid::Uuid,
bounds: Bounds<DevicePixels>,
bounds: Bounds<Pixels>,
}
impl TestDisplay {
@@ -14,10 +13,7 @@ impl TestDisplay {
TestDisplay {
id: DisplayId(1),
uuid: uuid::Uuid::new_v4(),
bounds: Bounds::from_corners(
Point::default(),
Point::new(DevicePixels(1920), DevicePixels(1080)),
),
bounds: Bounds::from_corners(Point::default(), Point::new(px(1920.), px(1080.))),
}
}
}
@@ -31,7 +27,7 @@ impl PlatformDisplay for TestDisplay {
Ok(self.uuid)
}
fn bounds(&self) -> crate::Bounds<crate::DevicePixels> {
fn bounds(&self) -> crate::Bounds<crate::Pixels> {
self.bounds
}
}
+8 -8
View File
@@ -1,8 +1,8 @@
use crate::{
AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, DevicePixels,
DispatchEventResult, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,
PlatformInputHandler, PlatformWindow, Point, Size, TestPlatform, TileId, WindowAppearance,
WindowBackgroundAppearance, WindowBounds, WindowParams,
AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, DispatchEventResult, Pixels,
PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,
Size, TestPlatform, TileId, WindowAppearance, WindowBackgroundAppearance, WindowBounds,
WindowParams,
};
use collections::HashMap;
use parking_lot::Mutex;
@@ -13,7 +13,7 @@ use std::{
};
pub(crate) struct TestWindowState {
pub(crate) bounds: Bounds<DevicePixels>,
pub(crate) bounds: Bounds<Pixels>,
pub(crate) handle: AnyWindowHandle,
display: Rc<dyn PlatformDisplay>,
pub(crate) title: Option<String>,
@@ -79,7 +79,7 @@ impl TestWindow {
let Some(mut callback) = lock.resize_callback.take() else {
return;
};
lock.bounds.size = size.map(|pixels| (pixels.0 as i32).into());
lock.bounds.size = size;
drop(lock);
callback(size, scale_factor);
self.0.lock().resize_callback = Some(callback);
@@ -108,7 +108,7 @@ impl TestWindow {
}
impl PlatformWindow for TestWindow {
fn bounds(&self) -> Bounds<DevicePixels> {
fn bounds(&self) -> Bounds<Pixels> {
self.0.lock().bounds
}
@@ -121,7 +121,7 @@ impl PlatformWindow for TestWindow {
}
fn content_size(&self) -> Size<Pixels> {
self.bounds().size.into()
self.bounds().size
}
fn scale_factor(&self) -> f32 {