Integrate macOS window controls and fix palette text rendering

Center native window controls in the draggable tab bar. Preserve full text runs during GPUI layout and let AppKit compose text in palette and rename fields.
This commit is contained in:
James Magahern
2026-11-17 14:48:30 -08:00
parent 20ca5447ef
commit 12ba7abdd2
10 changed files with 112 additions and 28 deletions
+14 -2
View File
@@ -43,6 +43,7 @@ pub struct ChromeTab {
pub fn header(
connection: SharedString,
tabs: Vec<ChromeTab>,
reserve_traffic_lights: bool,
on_tab: impl Fn(u64, &mut Window, &mut App) + 'static,
on_new: impl Fn(&mut Window, &mut App) + 'static,
on_close: impl Fn(&mut Window, &mut App) + 'static,
@@ -128,9 +129,17 @@ pub fn header(
.items_center()
.gap(px(10.))
.px(px(12.))
// In fullscreen AppKit reveals the buttons in its own overlay.
.when(reserve_traffic_lights, |row| row.pl(px(86.)))
.flex_1()
.min_h_0()
.on_mouse_down(MouseButton::Left, |_, window, _| window.start_window_move())
.on_mouse_down(MouseButton::Left, |event, window, _| {
if cfg!(target_os = "macos") && event.click_count == 2 {
window.titlebar_double_click();
} else {
window.start_window_move();
}
})
.child(tab_strip)
.child(
div()
@@ -145,7 +154,9 @@ pub fn header(
.child(div().text_ellipsis().child(connection)),
)
.child(control("new-tab", "+", false, on_new))
.child(control("detach-window", "×", true, on_close)),
.when(!cfg!(target_os = "macos"), |row| {
row.child(control("detach-window", "×", true, on_close))
}),
)
}
@@ -198,6 +209,7 @@ mod tests {
active: true,
editor: None,
}],
cfg!(target_os = "macos"),
|_, _, _| {},
|_, _| {},
|_, _| {},
+4 -1
View File
@@ -180,7 +180,10 @@ pub(crate) fn run_gui(socket: PathBuf, remote: Option<String>) -> Result<()> {
window_bounds: Some(WindowBounds::Windowed(bounds)),
titlebar: Some(TitlebarOptions {
title: Some("psyTerm".into()),
..Default::default()
appears_transparent: cfg!(target_os = "macos"),
// GPUI positions the top-left of the 14-point close button.
traffic_light_position: cfg!(target_os = "macos")
.then(|| point(px(12.), px((chrome::HEADER_HEIGHT - 14.) / 2.))),
}),
window_decorations: Some(WindowDecorations::Client),
app_id: Some("dev.buzzert.psyterm".into()),
+7 -4
View File
@@ -12,7 +12,7 @@ use gpui::{
use crate::{
chrome,
commands::{CommandAction, PaletteItem, PaletteItemKind},
pane_name::NameEditor,
pane_name::{NameEditor, use_native_text_input},
};
#[derive(Clone)]
@@ -306,9 +306,12 @@ impl CommandPalette {
}
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
cx.stop_propagation();
let key = &event.keystroke;
let primary = key.modifiers.control || key.modifiers.platform;
if use_native_text_input(key) {
return;
}
cx.stop_propagation();
let primary = key.modifiers.platform || key.modifiers.secondary();
match key.key.as_str() {
"escape" => {
self.back(window, cx);
@@ -371,7 +374,7 @@ impl CommandPalette {
}
_ => {}
},
_ if !primary && !key.modifiers.alt => {
_ if !primary && !key.modifiers.alt && !key.modifiers.control => {
if let Some(text) = &key.key_char {
self.editor.replace(None, text);
}
+37 -4
View File
@@ -2,6 +2,19 @@
//! methods use UTF-16 ranges. Editing never sends bytes to the terminal process.
use std::ops::Range;
/// AppKit's input context combines Option/dead keys and delivers composed text
/// through the focused field's EntityInputHandler.
pub fn use_native_text_input(key: &gpui::Keystroke) -> bool {
cfg!(target_os = "macos")
&& !key.modifiers.platform
&& !key.modifiers.control
&& !key.modifiers.function
&& key
.key_char
.as_ref()
.is_some_and(|text| !text.chars().any(char::is_control))
}
const MAX_CHARACTERS: usize = 512;
#[derive(Debug, Clone)]
@@ -255,10 +268,12 @@ impl RenameField {
}
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
// Parent terminal key handlers must never see keys typed into this field.
cx.stop_propagation();
let key = &event.keystroke;
let command = key.modifiers.control || key.modifiers.platform;
if use_native_text_input(key) {
return;
}
cx.stop_propagation();
let command = key.modifiers.platform || key.modifiers.secondary();
match key.key.as_str() {
"enter" => {
// Enter first accepts active IME composition; a subsequent Enter saves.
@@ -299,7 +314,7 @@ impl RenameField {
}
_ => {}
},
_ if !command && !key.modifiers.alt => {
_ if !command && !key.modifiers.alt && !key.modifiers.control => {
if let Some(text) = &key.key_char {
self.editor.replace(None, text);
}
@@ -612,6 +627,24 @@ mod tests {
assert_eq!(editor.cursor(), 1);
}
#[cfg(target_os = "macos")]
#[test]
fn appkit_composes_option_text_while_editors_handle_shortcuts() {
for (binding, text, native) in [
("a", "a", true),
("alt-2", "€", true),
("alt-e", "´", true),
("cmd-c", "c", false),
("ctrl-c", "c", false),
("enter", "\n", false),
("tab", "\t", false),
] {
let mut key = gpui::Keystroke::parse(binding).unwrap();
key.key_char = Some(text.into());
assert_eq!(use_native_text_input(&key), native, "{binding}");
}
}
#[test]
fn composition_replaces_previous_marked_text_and_commits_once() {
let mut editor = NameEditor::new("old");
+1
View File
@@ -480,6 +480,7 @@ impl Render for Workspace {
let header = chrome::header(
self.connection.clone(),
tabs,
cfg!(target_os = "macos") && !window.is_fullscreen(),
move |tab, _, _| {
let _ = client.send(ClientMessage::FocusTab { tab });
},