Cross-platform titlebar (#9405)

This PR reverts https://github.com/zed-industries/zed/pull/9392 and
fixes the regressions that led to the reversion.

Release Notes:

- N/A

---------

Co-authored-by: Ezekiel Warren <ezekiel@seaube.com>
This commit is contained in:
Mikayla Maki
2024-03-15 10:40:58 -07:00
committed by GitHub
co-authored by Ezekiel Warren
parent 44ac6ca45c
commit 328aa2cc95
17 changed files with 719 additions and 156 deletions
@@ -182,10 +182,6 @@ impl platform::Window for StatusItem {
self.0.borrow().scale_factor()
}
fn titlebar_height(&self) -> f32 {
0.
}
fn appearance(&self) -> platform::Appearance {
unsafe {
let appearance: id =
+16 -8
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,10 @@ impl PlatformWindow for MacWindow {
self.0.as_ref().lock().bounds()
}
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()
}
@@ -724,10 +736,6 @@ impl PlatformWindow for MacWindow {
self.0.as_ref().lock().scale_factor()
}
fn titlebar_height(&self) -> Pixels {
self.0.as_ref().lock().titlebar_height()
}
fn appearance(&self) -> WindowAppearance {
unsafe {
let appearance: id = msg_send![self.0.lock().native_window, effectiveAppearance];
@@ -968,7 +976,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 +1199,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 +1212,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 {