diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 2782dd7d6a..3fc3a8128b 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -28,6 +28,7 @@ "cmd-h": "zed::Hide", "alt-cmd-h": "zed::HideOthers", "cmd-m": "zed::Minimize", + "ctrl-cmd-f": "zed::ToggleFullScreen", "cmd-n": "workspace::NewFile", "cmd-shift-n": "workspace::NewWindow", "cmd-o": "workspace::Open", diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 9071f98dfe..accb4d43c1 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1319,6 +1319,11 @@ impl MutableAppContext { window.zoom(); } + pub fn toggle_window_full_screen(&self, window_id: usize) { + let (_, window) = &self.presenters_and_platform_windows[&window_id]; + window.toggle_full_screen(); + } + fn prompt( &self, window_id: usize, @@ -3683,6 +3688,10 @@ impl<'a, T: View> ViewContext<'a, T> { self.app.zoom_window(self.window_id) } + pub fn toggle_full_screen(&self) { + self.app.toggle_window_full_screen(self.window_id) + } + pub fn prompt( &self, level: PromptLevel, diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index b5fcfe8f0d..38e8348ac3 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -123,6 +123,7 @@ pub trait Window: WindowContext { fn show_character_palette(&self); fn minimize(&self); fn zoom(&self); + fn toggle_full_screen(&self); } pub trait WindowContext { diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 60b079c266..b597dfb778 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -601,6 +601,18 @@ impl platform::Window for Window { }) .detach(); } + + fn toggle_full_screen(&self) { + let this = self.0.borrow(); + let window = this.native_window; + this.executor + .spawn(async move { + unsafe { + window.toggleFullScreen_(nil); + } + }) + .detach(); + } } impl platform::WindowContext for Window { diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index f75cff78e8..519ba931d1 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -294,6 +294,8 @@ impl super::Window for Window { fn minimize(&self) {} fn zoom(&self) {} + + fn toggle_full_screen(&self) {} } pub fn platform() -> Platform { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 3a5dd18c1c..9976f7a033 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -51,6 +51,7 @@ actions!( ShowAll, Minimize, Zoom, + ToggleFullScreen, Quit, DebugElements, OpenSettings, @@ -88,6 +89,11 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.zoom_window(); }, ); + cx.add_action( + |_: &mut Workspace, _: &ToggleFullScreen, cx: &mut ViewContext| { + cx.toggle_full_screen(); + }, + ); cx.add_global_action(quit); cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url)); cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {