Maximize new windows

This commit is contained in:
Max Brunsfeld 2021-11-23 10:13:08 -08:00
parent a0287920e5
commit 091ed9ab47
4 changed files with 38 additions and 14 deletions

View file

@ -12,7 +12,7 @@ use crate::{
fonts::{FontId, GlyphId, Metrics as FontMetrics, Properties as FontProperties}, fonts::{FontId, GlyphId, Metrics as FontMetrics, Properties as FontProperties},
geometry::{ geometry::{
rect::{RectF, RectI}, rect::{RectF, RectI},
vector::{vec2f, Vector2F}, vector::Vector2F,
}, },
text_layout::{LineLayout, RunStyle}, text_layout::{LineLayout, RunStyle},
AnyAction, ClipboardItem, Menu, Scene, AnyAction, ClipboardItem, Menu, Scene,
@ -105,13 +105,20 @@ pub trait WindowContext {
fn present_scene(&mut self, scene: Scene); fn present_scene(&mut self, scene: Scene);
} }
#[derive(Debug)]
pub struct WindowOptions<'a> { pub struct WindowOptions<'a> {
pub bounds: RectF, pub bounds: WindowBounds,
pub title: Option<&'a str>, pub title: Option<&'a str>,
pub titlebar_appears_transparent: bool, pub titlebar_appears_transparent: bool,
pub traffic_light_position: Option<Vector2F>, pub traffic_light_position: Option<Vector2F>,
} }
#[derive(Debug)]
pub enum WindowBounds {
Maximized,
Fixed(RectF),
}
pub struct PathPromptOptions { pub struct PathPromptOptions {
pub files: bool, pub files: bool,
pub directories: bool, pub directories: bool,
@ -157,7 +164,7 @@ pub trait FontSystem: Send + Sync {
impl<'a> Default for WindowOptions<'a> { impl<'a> Default for WindowOptions<'a> {
fn default() -> Self { fn default() -> Self {
Self { Self {
bounds: RectF::new(Default::default(), vec2f(1024.0, 768.0)), bounds: WindowBounds::Maximized,
title: Default::default(), title: Default::default(),
titlebar_appears_transparent: Default::default(), titlebar_appears_transparent: Default::default(),
traffic_light_position: Default::default(), traffic_light_position: Default::default(),

View file

@ -1,8 +1,11 @@
use crate::{ use crate::{
executor, executor,
geometry::vector::Vector2F, geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
keymap::Keystroke, keymap::Keystroke,
platform::{self, Event, WindowContext}, platform::{self, Event, WindowBounds, WindowContext},
Scene, Scene,
}; };
use block::ConcreteBlock; use block::ConcreteBlock;
@ -25,7 +28,6 @@ use objc::{
runtime::{Class, Object, Protocol, Sel, BOOL, NO, YES}, runtime::{Class, Object, Protocol, Sel, BOOL, NO, YES},
sel, sel_impl, sel, sel_impl,
}; };
use pathfinder_geometry::vector::vec2f;
use smol::Timer; use smol::Timer;
use std::{ use std::{
any::Any, any::Any,
@ -158,7 +160,11 @@ impl Window {
unsafe { unsafe {
let pool = NSAutoreleasePool::new(nil); let pool = NSAutoreleasePool::new(nil);
let frame = options.bounds.to_ns_rect(); let frame = match options.bounds {
WindowBounds::Maximized => RectF::new(Default::default(), vec2f(1024., 768.)),
WindowBounds::Fixed(rect) => rect,
}
.to_ns_rect();
let mut style_mask = NSWindowStyleMask::NSClosableWindowMask let mut style_mask = NSWindowStyleMask::NSClosableWindowMask
| NSWindowStyleMask::NSMiniaturizableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask
| NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSResizableWindowMask
@ -177,6 +183,11 @@ impl Window {
); );
assert!(!native_window.is_null()); assert!(!native_window.is_null());
if matches!(options.bounds, WindowBounds::Maximized) {
let screen = native_window.screen();
native_window.setFrame_display_(screen.visibleFrame(), YES);
}
let device = let device =
metal::Device::system_default().expect("could not find default metal device"); metal::Device::system_default().expect("could not find default metal device");

View file

@ -1,8 +1,10 @@
use super::CursorStyle; use super::{CursorStyle, WindowBounds};
use crate::{AnyAction, ClipboardItem}; use crate::{
geometry::vector::{vec2f, Vector2F},
AnyAction, ClipboardItem,
};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use parking_lot::Mutex; use parking_lot::Mutex;
use pathfinder_geometry::vector::Vector2F;
use std::{ use std::{
any::Any, any::Any,
cell::RefCell, cell::RefCell,
@ -112,7 +114,10 @@ impl super::Platform for Platform {
options: super::WindowOptions, options: super::WindowOptions,
_executor: Rc<super::executor::Foreground>, _executor: Rc<super::executor::Foreground>,
) -> Box<dyn super::Window> { ) -> Box<dyn super::Window> {
Box::new(Window::new(options.bounds.size())) Box::new(Window::new(match options.bounds {
WindowBounds::Maximized => vec2f(1024., 768.),
WindowBounds::Fixed(rect) => rect.size(),
}))
} }
fn key_window_id(&self) -> Option<usize> { fn key_window_id(&self) -> Option<usize> {

View file

@ -10,9 +10,9 @@ pub use client;
pub use editor; pub use editor;
use gpui::{ use gpui::{
action, action,
geometry::{rect::RectF, vector::vec2f}, geometry::vector::vec2f,
keymap::Binding, keymap::Binding,
platform::WindowOptions, platform::{WindowBounds, WindowOptions},
ModelHandle, MutableAppContext, PathPromptOptions, Task, ViewContext, ModelHandle, MutableAppContext, PathPromptOptions, Task, ViewContext,
}; };
pub use lsp; pub use lsp;
@ -122,6 +122,7 @@ fn open_paths(action: &OpenPaths, cx: &mut MutableAppContext) -> Task<()> {
let (_, workspace) = cx.add_window(window_options(), |cx| { let (_, workspace) = cx.add_window(window_options(), |cx| {
build_workspace(&WorkspaceParams::from(app_state.as_ref()), cx) build_workspace(&WorkspaceParams::from(app_state.as_ref()), cx)
}); });
// cx.resize_window(window_id);
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace.open_paths(&action.0.paths, cx) workspace.open_paths(&action.0.paths, cx)
}) })
@ -164,7 +165,7 @@ fn build_workspace(params: &WorkspaceParams, cx: &mut ViewContext<Workspace>) ->
fn window_options() -> WindowOptions<'static> { fn window_options() -> WindowOptions<'static> {
WindowOptions { WindowOptions {
bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)), bounds: WindowBounds::Maximized,
title: None, title: None,
titlebar_appears_transparent: true, titlebar_appears_transparent: true,
traffic_light_position: Some(vec2f(8., 8.)), traffic_light_position: Some(vec2f(8., 8.)),