collab ui: Fix notification windows on external monitors (#9817)

Sharing a project displays a notification (window) on every screen.
Previously there was an issue with the positioning of windows on all
screens except the primary screen.

As you can see here:


![image](https://github.com/zed-industries/zed/assets/53836821/314cf367-8c70-4e8e-bc4a-dcbb99cb4f71)

Now:


![image](https://github.com/zed-industries/zed/assets/53836821/42af9ef3-8af9-453a-ad95-147b5f9d90ba)

@mikayla-maki and I also decided to refactor the `WindowOptions` a bit. 
Previously you could specify bounds which controlled the positioning and
size of the window in the global coordinate space, while also providing
a display id (which screen to show the window on). This can lead to
unusual behavior because you could theoretically specify a global bound
which does not even belong to the display id which was provided.

Therefore we changed the api to this:
```rust
struct WindowOptions {
    /// The bounds of the window in screen coordinates
    /// None -> inherit, Some(bounds) -> set bounds.
    pub bounds: Option<Bounds<DevicePixels>>,

    /// The display to create the window on, if this is None,
    /// the window will be created on the main display
    pub display_id: Option<DisplayId>,
}
```

This lets you specify a display id, which maps to the screen where the
window should be created and bounds relative to the upper left of the
screen.

Release Notes:

- Fixed positioning of popup windows (e.g. when sharing a project) when
using multiple external displays.

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Bennet Bo Fenner 2024-03-26 21:07:38 +01:00 committed by GitHub
parent ffd698be14
commit e272acd1bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 331 additions and 352 deletions

View file

@ -59,7 +59,7 @@ impl sqlez::bindable::Column for SerializedAxis {
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct SerializedWindowsBounds(pub(crate) Bounds<gpui::GlobalPixels>);
pub(crate) struct SerializedWindowsBounds(pub(crate) Bounds<gpui::DevicePixels>);
impl StaticColumnCount for SerializedWindowsBounds {
fn column_count() -> usize {
@ -73,10 +73,10 @@ impl Bind for SerializedWindowsBounds {
statement.bind(
&(
SerializedGlobalPixels(self.0.origin.x),
SerializedGlobalPixels(self.0.origin.y),
SerializedGlobalPixels(self.0.size.width),
SerializedGlobalPixels(self.0.size.height),
SerializedDevicePixels(self.0.origin.x),
SerializedDevicePixels(self.0.origin.y),
SerializedDevicePixels(self.0.size.width),
SerializedDevicePixels(self.0.size.height),
),
next_index,
)
@ -89,10 +89,10 @@ impl Column for SerializedWindowsBounds {
let bounds = match window_state.as_str() {
"Fixed" => {
let ((x, y, width, height), _) = Column::column(statement, next_index)?;
let x: f64 = x;
let y: f64 = y;
let width: f64 = width;
let height: f64 = height;
let x: i32 = x;
let y: i32 = y;
let width: i32 = width;
let height: i32 = height;
SerializedWindowsBounds(Bounds {
origin: point(x.into(), y.into()),
size: size(width.into(), height.into()),
@ -106,17 +106,16 @@ impl Column for SerializedWindowsBounds {
}
#[derive(Clone, Debug, PartialEq)]
struct SerializedGlobalPixels(gpui::GlobalPixels);
impl sqlez::bindable::StaticColumnCount for SerializedGlobalPixels {}
struct SerializedDevicePixels(gpui::DevicePixels);
impl sqlez::bindable::StaticColumnCount for SerializedDevicePixels {}
impl sqlez::bindable::Bind for SerializedGlobalPixels {
impl sqlez::bindable::Bind for SerializedDevicePixels {
fn bind(
&self,
statement: &sqlez::statement::Statement,
start_index: i32,
) -> anyhow::Result<i32> {
let this: f64 = self.0.into();
let this: f32 = this as _;
let this: i32 = self.0.into();
this.bind(statement, start_index)
}
}