Open new windows with a default size and position (#9204)

This PR changes GPUI to open windows with a default size and location,
and to otherwise inherit from their spawning window.

Note: The linux build now crashes on startup.

Release Notes:

- N/A

---------

Co-authored-by: Nathan <nathan@zed.dev>
Co-authored-by: Ezekiel Warren <zaucy@users.noreply.github.com>
This commit is contained in:
Mikayla Maki 2024-03-12 21:19:51 -07:00 committed by GitHub
parent 9a2dceeea1
commit e792c1a5c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 443 additions and 347 deletions

View file

@ -48,7 +48,7 @@ use windows::{
WindowsAndMessaging::{
CreateWindowExW, DefWindowProcW, GetWindowLongPtrW, LoadCursorW, PostQuitMessage,
RegisterClassW, SetWindowLongPtrW, SetWindowTextW, ShowWindow, CREATESTRUCTW,
CW_USEDEFAULT, GWLP_USERDATA, HMENU, IDC_ARROW, SW_MAXIMIZE, SW_SHOW, WHEEL_DELTA,
GWLP_USERDATA, HMENU, IDC_ARROW, SW_MAXIMIZE, SW_SHOW, WHEEL_DELTA,
WINDOW_EX_STYLE, WINDOW_LONG_PTR_INDEX, WM_CHAR, WM_CLOSE, WM_DESTROY, WM_KEYDOWN,
WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP,
WM_MOUSEHWHEEL, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOVE, WM_NCCREATE, WM_NCDESTROY,
@ -65,7 +65,7 @@ use crate::{
KeyUpEvent, Keystroke, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
NavigationDirection, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,
PlatformInputHandler, PlatformWindow, Point, PromptLevel, Scene, ScrollDelta, Size, TouchPhase,
WindowAppearance, WindowBounds, WindowOptions, WindowsDisplay, WindowsPlatformInner,
WindowAppearance, WindowParams, WindowsDisplay, WindowsPlatformInner,
};
#[derive(PartialEq)]
@ -614,7 +614,7 @@ impl WindowsWindow {
pub(crate) fn new(
platform_inner: Rc<WindowsPlatformInner>,
handle: AnyWindowHandle,
options: WindowOptions,
options: WindowParams,
) -> Self {
let dwexstyle = WINDOW_EX_STYLE::default();
let classname = register_wnd_class();
@ -627,20 +627,10 @@ impl WindowsWindow {
.unwrap_or(""),
);
let dwstyle = WS_OVERLAPPEDWINDOW & !WS_VISIBLE;
let mut x = CW_USEDEFAULT;
let mut y = CW_USEDEFAULT;
let mut nwidth = CW_USEDEFAULT;
let mut nheight = CW_USEDEFAULT;
match options.bounds {
WindowBounds::Fullscreen => {}
WindowBounds::Maximized => {}
WindowBounds::Fixed(bounds) => {
x = bounds.origin.x.0 as i32;
y = bounds.origin.y.0 as i32;
nwidth = bounds.size.width.0 as i32;
nheight = bounds.size.height.0 as i32;
}
};
let x = options.bounds.origin.x.0 as i32;
let y = options.bounds.origin.y.0 as i32;
let nwidth = options.bounds.size.width.0 as i32;
let nheight = options.bounds.size.height.0 as i32;
let hwndparent = HWND::default();
let hmenu = HMENU::default();
let hinstance = HINSTANCE::default();
@ -684,11 +674,7 @@ impl WindowsWindow {
.window_handle_values
.borrow_mut()
.insert(wnd.inner.hwnd.0);
match options.bounds {
WindowBounds::Fullscreen => wnd.toggle_full_screen(),
WindowBounds::Maximized => wnd.maximize(),
WindowBounds::Fixed(_) => {}
}
unsafe { ShowWindow(wnd.inner.hwnd, SW_SHOW) };
wnd
}
@ -728,11 +714,11 @@ impl Drop for WindowsWindow {
}
impl PlatformWindow for WindowsWindow {
fn bounds(&self) -> WindowBounds {
WindowBounds::Fixed(Bounds {
fn bounds(&self) -> Bounds<GlobalPixels> {
Bounds {
origin: self.inner.origin.get(),
size: self.inner.size.get(),
})
}
}
// todo(windows)
@ -887,6 +873,11 @@ impl PlatformWindow for WindowsWindow {
// todo(windows)
fn toggle_full_screen(&self) {}
// todo(windows)
fn is_full_screen(&self) -> bool {
false
}
// todo(windows)
fn on_request_frame(&self, callback: Box<dyn FnMut()>) {
self.inner.callbacks.borrow_mut().request_frame = Some(callback);