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:
parent
22dc88ed3d
commit
da281d6d8f
25 changed files with 331 additions and 367 deletions
|
@ -12,6 +12,7 @@ use sqlez::{
|
|||
statement::Statement,
|
||||
};
|
||||
|
||||
use ui::px;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -77,10 +78,10 @@ impl Bind for SerializedWindowBounds {
|
|||
let next_index = statement.bind(&"Windowed", start_index)?;
|
||||
statement.bind(
|
||||
&(
|
||||
SerializedDevicePixels(bounds.origin.x),
|
||||
SerializedDevicePixels(bounds.origin.y),
|
||||
SerializedDevicePixels(bounds.size.width),
|
||||
SerializedDevicePixels(bounds.size.height),
|
||||
SerializedPixels(bounds.origin.x),
|
||||
SerializedPixels(bounds.origin.y),
|
||||
SerializedPixels(bounds.size.width),
|
||||
SerializedPixels(bounds.size.height),
|
||||
),
|
||||
next_index,
|
||||
)
|
||||
|
@ -89,10 +90,10 @@ impl Bind for SerializedWindowBounds {
|
|||
let next_index = statement.bind(&"Maximized", start_index)?;
|
||||
statement.bind(
|
||||
&(
|
||||
SerializedDevicePixels(bounds.origin.x),
|
||||
SerializedDevicePixels(bounds.origin.y),
|
||||
SerializedDevicePixels(bounds.size.width),
|
||||
SerializedDevicePixels(bounds.size.height),
|
||||
SerializedPixels(bounds.origin.x),
|
||||
SerializedPixels(bounds.origin.y),
|
||||
SerializedPixels(bounds.size.width),
|
||||
SerializedPixels(bounds.size.height),
|
||||
),
|
||||
next_index,
|
||||
)
|
||||
|
@ -101,10 +102,10 @@ impl Bind for SerializedWindowBounds {
|
|||
let next_index = statement.bind(&"FullScreen", start_index)?;
|
||||
statement.bind(
|
||||
&(
|
||||
SerializedDevicePixels(bounds.origin.x),
|
||||
SerializedDevicePixels(bounds.origin.y),
|
||||
SerializedDevicePixels(bounds.size.width),
|
||||
SerializedDevicePixels(bounds.size.height),
|
||||
SerializedPixels(bounds.origin.x),
|
||||
SerializedPixels(bounds.origin.y),
|
||||
SerializedPixels(bounds.size.width),
|
||||
SerializedPixels(bounds.size.height),
|
||||
),
|
||||
next_index,
|
||||
)
|
||||
|
@ -116,40 +117,17 @@ impl Bind for SerializedWindowBounds {
|
|||
impl Column for SerializedWindowBounds {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
let (window_state, next_index) = String::column(statement, start_index)?;
|
||||
let ((x, y, width, height), _): ((i32, i32, i32, i32), _) =
|
||||
Column::column(statement, next_index)?;
|
||||
let bounds = Bounds {
|
||||
origin: point(px(x as f32), px(y as f32)),
|
||||
size: size(px(width as f32), px(height as f32)),
|
||||
};
|
||||
|
||||
let status = match window_state.as_str() {
|
||||
"Windowed" | "Fixed" => {
|
||||
let ((x, y, width, height), _) = Column::column(statement, next_index)?;
|
||||
let x: i32 = x;
|
||||
let y: i32 = y;
|
||||
let width: i32 = width;
|
||||
let height: i32 = height;
|
||||
SerializedWindowBounds(WindowBounds::Windowed(Bounds {
|
||||
origin: point(x.into(), y.into()),
|
||||
size: size(width.into(), height.into()),
|
||||
}))
|
||||
}
|
||||
"Maximized" => {
|
||||
let ((x, y, width, height), _) = Column::column(statement, next_index)?;
|
||||
let x: i32 = x;
|
||||
let y: i32 = y;
|
||||
let width: i32 = width;
|
||||
let height: i32 = height;
|
||||
SerializedWindowBounds(WindowBounds::Maximized(Bounds {
|
||||
origin: point(x.into(), y.into()),
|
||||
size: size(width.into(), height.into()),
|
||||
}))
|
||||
}
|
||||
"FullScreen" => {
|
||||
let ((x, y, width, height), _) = Column::column(statement, next_index)?;
|
||||
let x: i32 = x;
|
||||
let y: i32 = y;
|
||||
let width: i32 = width;
|
||||
let height: i32 = height;
|
||||
SerializedWindowBounds(WindowBounds::Fullscreen(Bounds {
|
||||
origin: point(x.into(), y.into()),
|
||||
size: size(width.into(), height.into()),
|
||||
}))
|
||||
}
|
||||
"Windowed" | "Fixed" => SerializedWindowBounds(WindowBounds::Windowed(bounds)),
|
||||
"Maximized" => SerializedWindowBounds(WindowBounds::Maximized(bounds)),
|
||||
"FullScreen" => SerializedWindowBounds(WindowBounds::Fullscreen(bounds)),
|
||||
_ => bail!("Window State did not have a valid string"),
|
||||
};
|
||||
|
||||
|
@ -158,16 +136,16 @@ impl Column for SerializedWindowBounds {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct SerializedDevicePixels(gpui::DevicePixels);
|
||||
impl sqlez::bindable::StaticColumnCount for SerializedDevicePixels {}
|
||||
struct SerializedPixels(gpui::Pixels);
|
||||
impl sqlez::bindable::StaticColumnCount for SerializedPixels {}
|
||||
|
||||
impl sqlez::bindable::Bind for SerializedDevicePixels {
|
||||
impl sqlez::bindable::Bind for SerializedPixels {
|
||||
fn bind(
|
||||
&self,
|
||||
statement: &sqlez::statement::Statement,
|
||||
start_index: i32,
|
||||
) -> anyhow::Result<i32> {
|
||||
let this: i32 = self.0.into();
|
||||
let this: i32 = self.0 .0 as i32;
|
||||
this.bind(statement, start_index)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ use futures::{
|
|||
};
|
||||
use gpui::{
|
||||
actions, canvas, impl_actions, point, relative, size, Action, AnyElement, AnyView, AnyWeakView,
|
||||
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, DevicePixels, DragMoveEvent,
|
||||
Entity as _, EntityId, EventEmitter, FocusHandle, FocusableView, Global, KeyContext, Keystroke,
|
||||
ManagedView, Model, ModelContext, PathPromptOptions, Point, PromptLevel, Render, Size,
|
||||
Subscription, Task, View, WeakView, WindowBounds, WindowHandle, WindowOptions,
|
||||
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, DragMoveEvent, Entity as _, EntityId,
|
||||
EventEmitter, FocusHandle, FocusableView, Global, KeyContext, Keystroke, ManagedView, Model,
|
||||
ModelContext, PathPromptOptions, Point, PromptLevel, Render, Size, Subscription, Task, View,
|
||||
WeakView, WindowBounds, WindowHandle, WindowOptions,
|
||||
};
|
||||
use item::{
|
||||
FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, PreviewTabsSettings,
|
||||
|
@ -79,7 +79,7 @@ use theme::{ActiveTheme, SystemAppearance, ThemeSettings};
|
|||
pub use toolbar::{Toolbar, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
||||
pub use ui;
|
||||
use ui::{
|
||||
div, h_flex, Context as _, Div, FluentBuilder, InteractiveElement as _, IntoElement,
|
||||
div, h_flex, px, Context as _, Div, FluentBuilder, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Pixels, SharedString, Styled as _, ViewContext, VisualContext as _,
|
||||
WindowContext,
|
||||
};
|
||||
|
@ -96,11 +96,11 @@ use crate::persistence::{
|
|||
use crate::{notifications::NotificationId, persistence::model::LocalPathsOrder};
|
||||
|
||||
lazy_static! {
|
||||
static ref ZED_WINDOW_SIZE: Option<Size<DevicePixels>> = env::var("ZED_WINDOW_SIZE")
|
||||
static ref ZED_WINDOW_SIZE: Option<Size<Pixels>> = env::var("ZED_WINDOW_SIZE")
|
||||
.ok()
|
||||
.as_deref()
|
||||
.and_then(parse_pixel_size_env_var);
|
||||
static ref ZED_WINDOW_POSITION: Option<Point<DevicePixels>> = env::var("ZED_WINDOW_POSITION")
|
||||
static ref ZED_WINDOW_POSITION: Option<Point<Pixels>> = env::var("ZED_WINDOW_POSITION")
|
||||
.ok()
|
||||
.as_deref()
|
||||
.and_then(parse_pixel_position_env_var);
|
||||
|
@ -3981,7 +3981,7 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
|
||||
fn window_bounds_env_override() -> Option<Bounds<DevicePixels>> {
|
||||
fn window_bounds_env_override() -> Option<Bounds<Pixels>> {
|
||||
ZED_WINDOW_POSITION
|
||||
.zip(*ZED_WINDOW_SIZE)
|
||||
.map(|(position, size)| Bounds {
|
||||
|
@ -5158,18 +5158,18 @@ pub fn reload(reload: &Reload, cx: &mut AppContext) {
|
|||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
fn parse_pixel_position_env_var(value: &str) -> Option<Point<DevicePixels>> {
|
||||
fn parse_pixel_position_env_var(value: &str) -> Option<Point<Pixels>> {
|
||||
let mut parts = value.split(',');
|
||||
let x: usize = parts.next()?.parse().ok()?;
|
||||
let y: usize = parts.next()?.parse().ok()?;
|
||||
Some(point((x as i32).into(), (y as i32).into()))
|
||||
Some(point(px(x as f32), px(y as f32)))
|
||||
}
|
||||
|
||||
fn parse_pixel_size_env_var(value: &str) -> Option<Size<DevicePixels>> {
|
||||
fn parse_pixel_size_env_var(value: &str) -> Option<Size<Pixels>> {
|
||||
let mut parts = value.split(',');
|
||||
let width: usize = parts.next()?.parse().ok()?;
|
||||
let height: usize = parts.next()?.parse().ok()?;
|
||||
Some(size((width as i32).into(), (height as i32).into()))
|
||||
Some(size(px(width as f32), px(height as f32)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue