windows: better looking titlebar (#9053)

~~work in progress. not ready for review. made for visibility only, but
feel free to comment :)~~

TODO:
- [x] add close/min/max buttons (to be rendered with gpui)
- [x] snap layout support
- [x] fix issues with clicking items in titlebar
- [x] cleanup/document

Release Notes:

- Added custom windows titlebar

![](https://media.discordapp.net/attachments/1208481909676576818/1216985375969378324/caption-buttons-working.gif?ex=660260f4&is=65efebf4&hm=53a17af6e2f233eba54302a5adb9efe23900f4d6f6d1d854bec887120789130c&=)

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Ezekiel Warren
2024-03-14 17:20:30 -07:00
committed by GitHub
co-authored by Mikayla
parent 6bbc5e2efa
commit 948b3827c8
15 changed files with 694 additions and 122 deletions
+17 -4
View File
@@ -324,7 +324,7 @@ struct MacWindowState {
renderer: renderer::Renderer,
kind: WindowKind,
request_frame_callback: Option<Box<dyn FnMut()>>,
event_callback: Option<Box<dyn FnMut(PlatformInput) -> bool>>,
event_callback: Option<Box<dyn FnMut(PlatformInput) -> crate::DispatchEventResult>>,
activate_callback: Option<Box<dyn FnMut(bool)>>,
resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
fullscreen_callback: Option<Box<dyn FnMut(bool)>>,
@@ -411,6 +411,14 @@ impl MacWindowState {
self.display_link = None;
}
fn is_maximized(&self) -> bool {
unsafe {
let bounds = self.bounds();
let screen_size = self.native_window.screen().visibleFrame().into();
bounds.size == screen_size
}
}
fn is_fullscreen(&self) -> bool {
unsafe {
let style_mask = self.native_window.styleMask();
@@ -716,6 +724,11 @@ impl PlatformWindow for MacWindow {
self.0.as_ref().lock().bounds()
}
// todo(mac)
fn is_maximized(&self) -> bool {
self.0.as_ref().lock().is_maximized()
}
fn content_size(&self) -> Size<Pixels> {
self.0.as_ref().lock().content_size()
}
@@ -968,7 +981,7 @@ impl PlatformWindow for MacWindow {
self.0.as_ref().lock().request_frame_callback = Some(callback);
}
fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>) {
fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> crate::DispatchEventResult>) {
self.0.as_ref().lock().event_callback = Some(callback);
}
@@ -1191,7 +1204,7 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
window_state.lock().previous_keydown_inserted_text = Some(text.clone());
if let Some(callback) = callback.as_mut() {
event.keystroke.ime_key = Some(text.clone());
handled = callback(PlatformInput::KeyDown(event));
handled = !callback(PlatformInput::KeyDown(event)).propagate;
}
}
}
@@ -1204,7 +1217,7 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
let is_held = event.is_held;
if let Some(callback) = callback.as_mut() {
handled = callback(PlatformInput::KeyDown(event));
handled = !callback(PlatformInput::KeyDown(event)).propagate;
}
if !handled && is_held {