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

@ -23,9 +23,9 @@ mod windows;
use crate::{
Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels,
DispatchEventResult, Font, FontId, FontMetrics, FontRun, ForegroundExecutor, GlobalPixels,
GlyphId, Keymap, LineLayout, Pixels, PlatformInput, Point, RenderGlyphParams,
RenderImageParams, RenderSvgParams, Scene, SharedString, Size, Task, TaskLabel, WindowContext,
DispatchEventResult, Font, FontId, FontMetrics, FontRun, ForegroundExecutor, GlyphId, Keymap,
LineLayout, Pixels, PlatformInput, Point, RenderGlyphParams, RenderImageParams,
RenderSvgParams, Scene, SharedString, Size, Task, TaskLabel, WindowContext,
};
use anyhow::Result;
use async_task::Runnable;
@ -152,7 +152,7 @@ pub trait PlatformDisplay: Send + Sync + Debug {
fn uuid(&self) -> Result<Uuid>;
/// Get the bounds for this display
fn bounds(&self) -> Bounds<GlobalPixels>;
fn bounds(&self) -> Bounds<DevicePixels>;
}
/// An opaque identifier for a hardware display
@ -168,7 +168,7 @@ impl Debug for DisplayId {
unsafe impl Send for DisplayId {}
pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
fn bounds(&self) -> Bounds<GlobalPixels>;
fn bounds(&self) -> Bounds<DevicePixels>;
fn is_maximized(&self) -> bool;
fn is_minimized(&self) -> bool;
fn content_size(&self) -> Size<Pixels>;
@ -508,8 +508,9 @@ pub trait InputHandler: 'static {
/// The variables that can be configured when creating a new window
#[derive(Debug)]
pub struct WindowOptions {
/// The bounds of the window in screen coordinates.
/// None -> inherit, Some(bounds) -> set bounds
pub bounds: Option<Bounds<GlobalPixels>>,
pub bounds: Option<Bounds<DevicePixels>>,
/// The titlebar configuration of the window
pub titlebar: Option<TitlebarOptions>,
@ -529,7 +530,8 @@ pub struct WindowOptions {
/// Whether the window should be movable by the user
pub is_movable: bool,
/// The display to create the window on
/// 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>,
}
@ -537,7 +539,7 @@ pub struct WindowOptions {
#[derive(Debug)]
pub(crate) struct WindowParams {
///
pub bounds: Bounds<GlobalPixels>,
pub bounds: Bounds<DevicePixels>,
/// The titlebar configuration of the window
pub titlebar: Option<TitlebarOptions>,
@ -552,7 +554,6 @@ pub(crate) struct WindowParams {
pub show: bool,
/// The display to create the window on
pub display_id: Option<DisplayId>,
}
@ -599,10 +600,6 @@ pub enum WindowKind {
PopUp,
}
/// Platform level interface
/// bounds: Bounds<GlobalPixels>
/// fullscreen: bool
/// The appearance of the window, as defined by the operating system.
///
/// On macOS, this corresponds to named [`NSAppearance`](https://developer.apple.com/documentation/appkit/nsappearance)