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

@ -51,6 +51,9 @@ mod prompts;
pub use prompts::*;
pub(crate) const DEFAULT_WINDOW_SIZE: Size<DevicePixels> =
size(DevicePixels(1024), DevicePixels(700));
/// Represents the two different phases when dispatching events.
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
pub enum DispatchPhase {
@ -573,7 +576,6 @@ pub(crate) struct ElementStateBox {
}
fn default_bounds(display_id: Option<DisplayId>, cx: &mut AppContext) -> Bounds<DevicePixels> {
const DEFAULT_WINDOW_SIZE: Size<DevicePixels> = size(DevicePixels(1024), DevicePixels(700));
const DEFAULT_WINDOW_OFFSET: Point<DevicePixels> = point(DevicePixels(0), DevicePixels(35));
cx.active_window()
@ -585,12 +587,7 @@ fn default_bounds(display_id: Option<DisplayId>, cx: &mut AppContext) -> Bounds<
.unwrap_or_else(|| cx.primary_display());
display
.map(|display| {
let center = display.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)
})
.map(|display| display.default_bounds())
.unwrap_or_else(|| {
Bounds::new(point(DevicePixels(0), DevicePixels(0)), DEFAULT_WINDOW_SIZE)
})