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
+11 -7
View File
@@ -2,25 +2,29 @@ use anyhow::Result;
use uuid::Uuid;
use x11rb::{connection::Connection as _, xcb_ffi::XCBConnection};
use crate::{Bounds, DevicePixels, DisplayId, PlatformDisplay, Size};
use crate::{px, Bounds, DisplayId, Pixels, PlatformDisplay, Size};
#[derive(Debug)]
pub(crate) struct X11Display {
x_screen_index: usize,
bounds: Bounds<DevicePixels>,
bounds: Bounds<Pixels>,
uuid: Uuid,
}
impl X11Display {
pub(crate) fn new(xc: &XCBConnection, x_screen_index: usize) -> Option<Self> {
pub(crate) fn new(
xc: &XCBConnection,
scale_factor: f32,
x_screen_index: usize,
) -> Option<Self> {
let screen = xc.setup().roots.get(x_screen_index).unwrap();
Some(Self {
x_screen_index: x_screen_index,
x_screen_index,
bounds: Bounds {
origin: Default::default(),
size: Size {
width: DevicePixels(screen.width_in_pixels as i32),
height: DevicePixels(screen.height_in_pixels as i32),
width: px(screen.width_in_pixels as f32 / scale_factor),
height: px(screen.height_in_pixels as f32 / scale_factor),
},
},
uuid: Uuid::from_bytes([0; 16]),
@@ -37,7 +41,7 @@ impl PlatformDisplay for X11Display {
Ok(self.uuid)
}
fn bounds(&self) -> Bounds<DevicePixels> {
fn bounds(&self) -> Bounds<Pixels> {
self.bounds
}
}