windows: Support multi-monitor (#11699)

Zed can detect changes in monitor connections and disconnections and
provide corresponding feedback. For example, if the current window's
display monitor is disconnected, the window will be moved to the primary
monitor. And now Zed always opens on the monitor specified in
`WindowParams`.

Release Notes:

- N/A
This commit is contained in:
张小白 2024-05-15 01:54:18 +08:00 committed by GitHub
parent 5154910c64
commit 491c04e176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 90 additions and 15 deletions

View file

@ -25,10 +25,11 @@ mod test;
mod windows;
use crate::{
Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels,
point, Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels,
DispatchEventResult, Font, FontId, FontMetrics, FontRun, ForegroundExecutor, GlyphId, Keymap,
LineLayout, Pixels, PlatformInput, Point, RenderGlyphParams, RenderImageParams,
RenderSvgParams, Scene, SharedString, Size, Task, TaskLabel, WindowContext,
DEFAULT_WINDOW_SIZE,
};
use anyhow::Result;
use async_task::Runnable;
@ -167,6 +168,14 @@ pub trait PlatformDisplay: Send + Sync + Debug {
/// Get the bounds for this display
fn bounds(&self) -> Bounds<DevicePixels>;
/// Get the default bounds for this display to place a window
fn default_bounds(&self) -> Bounds<DevicePixels> {
let center = self.bounds().center();
let offset = DEFAULT_WINDOW_SIZE / 2;
let origin = point(center.x - offset.width, center.y - offset.height);
Bounds::new(origin, DEFAULT_WINDOW_SIZE)
}
}
/// An opaque identifier for a hardware display