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

@ -1,6 +1,6 @@
use crate::{
platform::blade::{BladeRenderer, BladeSurfaceConfig},
size, AnyWindowHandle, Bounds, DevicePixels, ForegroundExecutor, Modifiers, Pixels,
px, size, AnyWindowHandle, Bounds, DevicePixels, ForegroundExecutor, Modifiers, Pixels,
PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,
PromptLevel, Scene, Size, WindowAppearance, WindowBackgroundAppearance, WindowBounds,
WindowKind, WindowParams, X11ClientStatePtr,
@ -162,7 +162,7 @@ pub struct X11WindowState {
atoms: XcbAtoms,
x_root_window: xproto::Window,
_raw: RawWindow,
bounds: Bounds<i32>,
bounds: Bounds<Pixels>,
scale_factor: f32,
renderer: BladeRenderer,
display: Rc<dyn PlatformDisplay>,
@ -273,10 +273,10 @@ impl X11WindowState {
visual.depth,
x_window,
visual_set.root,
params.bounds.origin.x.0 as i16,
params.bounds.origin.y.0 as i16,
params.bounds.size.width.0 as u16,
params.bounds.size.height.0 as u16,
(params.bounds.origin.x.0 * scale_factor) as i16,
(params.bounds.origin.y.0 * scale_factor) as i16,
(params.bounds.size.width.0 * scale_factor) as u16,
(params.bounds.size.height.0 * scale_factor) as u16,
0,
xproto::WindowClass::INPUT_OUTPUT,
visual.id,
@ -370,10 +370,12 @@ impl X11WindowState {
Ok(Self {
client,
executor,
display: Rc::new(X11Display::new(xcb_connection, x_screen_index).unwrap()),
display: Rc::new(
X11Display::new(xcb_connection, scale_factor, x_screen_index).unwrap(),
),
_raw: raw,
x_root_window: visual_set.root,
bounds: params.bounds.map(|v| v.0),
bounds: params.bounds,
scale_factor,
renderer: BladeRenderer::new(gpu, config),
atoms: *atoms,
@ -627,6 +629,7 @@ impl X11WindowStatePtr {
let is_resize;
{
let mut state = self.state.borrow_mut();
let bounds = bounds.map(|f| px(f as f32 / state.scale_factor));
is_resize = bounds.size.width != state.bounds.size.width
|| bounds.size.height != state.bounds.size.height;
@ -641,9 +644,10 @@ impl X11WindowStatePtr {
let gpu_size = query_render_extent(&self.xcb_connection, self.x_window);
if state.renderer.viewport_size() != gpu_size {
state
.renderer
.update_drawable_size(size(gpu_size.width as f64, gpu_size.height as f64));
state.renderer.update_drawable_size(size(
DevicePixels(gpu_size.width as i32),
DevicePixels(gpu_size.height as i32),
));
resize_args = Some((state.content_size(), state.scale_factor));
}
}
@ -678,8 +682,8 @@ impl X11WindowStatePtr {
}
impl PlatformWindow for X11Window {
fn bounds(&self) -> Bounds<DevicePixels> {
self.0.state.borrow().bounds.map(|v| v.into())
fn bounds(&self) -> Bounds<Pixels> {
self.0.state.borrow().bounds
}
fn is_maximized(&self) -> bool {
@ -693,7 +697,11 @@ impl PlatformWindow for X11Window {
fn window_bounds(&self) -> WindowBounds {
let state = self.0.state.borrow();
WindowBounds::Windowed(state.bounds.map(|p| DevicePixels(p)))
if self.is_maximized() {
WindowBounds::Maximized(state.bounds)
} else {
WindowBounds::Windowed(state.bounds)
}
}
fn content_size(&self) -> Size<Pixels> {