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:
+1
-1
@@ -42,7 +42,7 @@ nix = { version = "0.29", features = ["event", "poll", "signal", "user"] }
|
|||||||
# GPUI's zed-async-tar uses xattr 0.2.3, whose Linux ENOATTR alias was removed
|
# GPUI's zed-async-tar uses xattr 0.2.3, whose Linux ENOATTR alias was removed
|
||||||
# from libc. Keep the compatibility fix local; see vendor/xattr/PATCH.md.
|
# from libc. Keep the compatibility fix local; see vendor/xattr/PATCH.md.
|
||||||
xattr = { path = "vendor/xattr" }
|
xattr = { path = "vendor/xattr" }
|
||||||
# Wake Wayland presentation after idle without continuously rendering.
|
# Local window and text layout fixes are documented in vendor/gpui/PATCH.md.
|
||||||
gpui = { path = "vendor/gpui" }
|
gpui = { path = "vendor/gpui" }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|||||||
@@ -40,4 +40,4 @@ stack transitions use this curve; text scrolling has a separate spring in Neovid
|
|||||||
|
|
||||||
`vendor/gpui` contains the published GPUI 0.2.2 crate, licensed under Apache-2.0.
|
`vendor/gpui` contains the published GPUI 0.2.2 crate, licensed under Apache-2.0.
|
||||||
The original [license](vendor/gpui/LICENSE-APACHE) and source metadata are retained.
|
The original [license](vendor/gpui/LICENSE-APACHE) and source metadata are retained.
|
||||||
Changes for Wayland idle redraw are documented in [PATCH.md](vendor/gpui/PATCH.md).
|
Local patches are documented in [PATCH.md](vendor/gpui/PATCH.md).
|
||||||
|
|||||||
+14
-2
@@ -43,6 +43,7 @@ pub struct ChromeTab {
|
|||||||
pub fn header(
|
pub fn header(
|
||||||
connection: SharedString,
|
connection: SharedString,
|
||||||
tabs: Vec<ChromeTab>,
|
tabs: Vec<ChromeTab>,
|
||||||
|
reserve_traffic_lights: bool,
|
||||||
on_tab: impl Fn(u64, &mut Window, &mut App) + 'static,
|
on_tab: impl Fn(u64, &mut Window, &mut App) + 'static,
|
||||||
on_new: impl Fn(&mut Window, &mut App) + 'static,
|
on_new: impl Fn(&mut Window, &mut App) + 'static,
|
||||||
on_close: 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()
|
.items_center()
|
||||||
.gap(px(10.))
|
.gap(px(10.))
|
||||||
.px(px(12.))
|
.px(px(12.))
|
||||||
|
// In fullscreen AppKit reveals the buttons in its own overlay.
|
||||||
|
.when(reserve_traffic_lights, |row| row.pl(px(86.)))
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.min_h_0()
|
.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(tab_strip)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
@@ -145,7 +154,9 @@ pub fn header(
|
|||||||
.child(div().text_ellipsis().child(connection)),
|
.child(div().text_ellipsis().child(connection)),
|
||||||
)
|
)
|
||||||
.child(control("new-tab", "+", false, on_new))
|
.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,
|
active: true,
|
||||||
editor: None,
|
editor: None,
|
||||||
}],
|
}],
|
||||||
|
cfg!(target_os = "macos"),
|
||||||
|_, _, _| {},
|
|_, _, _| {},
|
||||||
|_, _| {},
|
|_, _| {},
|
||||||
|_, _| {},
|
|_, _| {},
|
||||||
|
|||||||
+4
-1
@@ -180,7 +180,10 @@ pub(crate) fn run_gui(socket: PathBuf, remote: Option<String>) -> Result<()> {
|
|||||||
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
titlebar: Some(TitlebarOptions {
|
titlebar: Some(TitlebarOptions {
|
||||||
title: Some("psyTerm".into()),
|
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),
|
window_decorations: Some(WindowDecorations::Client),
|
||||||
app_id: Some("dev.buzzert.psyterm".into()),
|
app_id: Some("dev.buzzert.psyterm".into()),
|
||||||
|
|||||||
+7
-4
@@ -12,7 +12,7 @@ use gpui::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
chrome,
|
chrome,
|
||||||
commands::{CommandAction, PaletteItem, PaletteItemKind},
|
commands::{CommandAction, PaletteItem, PaletteItemKind},
|
||||||
pane_name::NameEditor,
|
pane_name::{NameEditor, use_native_text_input},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -306,9 +306,12 @@ impl CommandPalette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
cx.stop_propagation();
|
|
||||||
let key = &event.keystroke;
|
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() {
|
match key.key.as_str() {
|
||||||
"escape" => {
|
"escape" => {
|
||||||
self.back(window, cx);
|
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 {
|
if let Some(text) = &key.key_char {
|
||||||
self.editor.replace(None, text);
|
self.editor.replace(None, text);
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-4
@@ -2,6 +2,19 @@
|
|||||||
//! methods use UTF-16 ranges. Editing never sends bytes to the terminal process.
|
//! methods use UTF-16 ranges. Editing never sends bytes to the terminal process.
|
||||||
use std::ops::Range;
|
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;
|
const MAX_CHARACTERS: usize = 512;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -255,10 +268,12 @@ impl RenameField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
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 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() {
|
match key.key.as_str() {
|
||||||
"enter" => {
|
"enter" => {
|
||||||
// Enter first accepts active IME composition; a subsequent Enter saves.
|
// 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 {
|
if let Some(text) = &key.key_char {
|
||||||
self.editor.replace(None, text);
|
self.editor.replace(None, text);
|
||||||
}
|
}
|
||||||
@@ -612,6 +627,24 @@ mod tests {
|
|||||||
assert_eq!(editor.cursor(), 1);
|
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]
|
#[test]
|
||||||
fn composition_replaces_previous_marked_text_and_commits_once() {
|
fn composition_replaces_previous_marked_text_and_commits_once() {
|
||||||
let mut editor = NameEditor::new("old");
|
let mut editor = NameEditor::new("old");
|
||||||
|
|||||||
@@ -480,6 +480,7 @@ impl Render for Workspace {
|
|||||||
let header = chrome::header(
|
let header = chrome::header(
|
||||||
self.connection.clone(),
|
self.connection.clone(),
|
||||||
tabs,
|
tabs,
|
||||||
|
cfg!(target_os = "macos") && !window.is_fullscreen(),
|
||||||
move |tab, _, _| {
|
move |tab, _, _| {
|
||||||
let _ = client.send(ClientMessage::FocusTab { tab });
|
let _ = client.send(ClientMessage::FocusTab { tab });
|
||||||
},
|
},
|
||||||
|
|||||||
Vendored
+19
-6
@@ -1,8 +1,9 @@
|
|||||||
# GPUI 0.2.2 Wayland idle redraw patch
|
# Local GPUI 0.2.2 patches
|
||||||
|
|
||||||
This directory vendors the published `gpui` 0.2.2 crate unchanged except for
|
This directory vendors the published `gpui` 0.2.2 crate with the patches below.
|
||||||
`src/window.rs`, `src/app.rs`, and this note. Upstream source and Apache-2.0
|
The upstream license and revision are in `LICENSE-APACHE` and `.cargo_vcs_info.json`.
|
||||||
license are retained; see `LICENSE-APACHE` and `.cargo_vcs_info.json`.
|
|
||||||
|
## Wayland idle redraw
|
||||||
|
|
||||||
Wayland compositors can withhold a pending frame callback after GPUI skips
|
Wayland compositors can withhold a pending frame callback after GPUI skips
|
||||||
presenting a clean frame. Later asynchronous view notifications make the scene
|
presenting a clean frame. Later asynchronous view notifications make the scene
|
||||||
@@ -14,9 +15,21 @@ of an app effect cycle, an invalidated idle window draws and presents once,
|
|||||||
clearing the idle flag. Normal compositor callbacks then resume. Dirty active
|
clearing the idle flag. Normal compositor callbacks then resume. Dirty active
|
||||||
windows remain callback-paced; clean idle windows submit no frames. The flag
|
windows remain callback-paced; clean idle windows submit no frames. The flag
|
||||||
starts false, avoiding presentation before the initial Wayland configure.
|
starts false, avoiding presentation before the initial Wayland configure.
|
||||||
Other platform backends are unchanged. No foreign Wayland connection or raw
|
|
||||||
surface manipulation is used.
|
|
||||||
|
|
||||||
The optional `scripts/check-wayland-idle.py` exercises an actual headless Weston
|
The optional `scripts/check-wayland-idle.py` exercises an actual headless Weston
|
||||||
window and verifies output repaints after an idle interval without pointer
|
window and verifies output repaints after an idle interval without pointer
|
||||||
input or screenshots waking the compositor.
|
input or screenshots waking the compositor.
|
||||||
|
|
||||||
|
## macOS titlebar dragging
|
||||||
|
|
||||||
|
The macOS implementation of `start_window_move` passes the current mouse
|
||||||
|
event to AppKit's `performWindowDragWithEvent:`. This lets applications
|
||||||
|
initiate native dragging from a custom titlebar. The implementation follows
|
||||||
|
[upstream GPUI](https://github.com/zed-industries/zed/blob/main/crates/gpui_macos/src/window.rs).
|
||||||
|
|
||||||
|
## Text truncation during layout
|
||||||
|
|
||||||
|
Flex layout can measure a label at a narrow width before allocating its final
|
||||||
|
width. Each truncation now starts from the original styled text runs, and the
|
||||||
|
measurement cache includes the width used for truncation. This preserves the
|
||||||
|
full command titles in the palette when there is room to display them.
|
||||||
|
|||||||
Vendored
+17
-9
@@ -316,6 +316,7 @@ struct TextLayoutInner {
|
|||||||
lines: SmallVec<[WrappedLine; 1]>,
|
lines: SmallVec<[WrappedLine; 1]>,
|
||||||
line_height: Pixels,
|
line_height: Pixels,
|
||||||
wrap_width: Option<Pixels>,
|
wrap_width: Option<Pixels>,
|
||||||
|
truncate_width: Option<Pixels>,
|
||||||
size: Option<Size<Pixels>>,
|
size: Option<Size<Pixels>>,
|
||||||
bounds: Option<Bounds<Pixels>>,
|
bounds: Option<Bounds<Pixels>>,
|
||||||
}
|
}
|
||||||
@@ -334,7 +335,7 @@ impl TextLayout {
|
|||||||
.line_height
|
.line_height
|
||||||
.to_pixels(font_size.into(), window.rem_size());
|
.to_pixels(font_size.into(), window.rem_size());
|
||||||
|
|
||||||
let mut runs = if let Some(runs) = runs {
|
let runs = if let Some(runs) = runs {
|
||||||
runs
|
runs
|
||||||
} else {
|
} else {
|
||||||
vec![text_style.to_run(text.len())]
|
vec![text_style.to_run(text.len())]
|
||||||
@@ -372,19 +373,24 @@ impl TextLayout {
|
|||||||
|
|
||||||
if let Some(text_layout) = element_state.0.borrow().as_ref()
|
if let Some(text_layout) = element_state.0.borrow().as_ref()
|
||||||
&& text_layout.size.is_some()
|
&& text_layout.size.is_some()
|
||||||
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
|
&& wrap_width == text_layout.wrap_width
|
||||||
|
&& truncate_width == text_layout.truncate_width
|
||||||
{
|
{
|
||||||
return text_layout.size.unwrap();
|
return text_layout.size.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut line_wrapper = cx.text_system().line_wrapper(text_style.font(), font_size);
|
// Flex layout may measure the same element at several widths. Each
|
||||||
|
// measurement needs the original runs, including their full lengths.
|
||||||
|
let mut runs = std::borrow::Cow::Borrowed(&runs);
|
||||||
let text = if let Some(truncate_width) = truncate_width {
|
let text = if let Some(truncate_width) = truncate_width {
|
||||||
line_wrapper.truncate_line(
|
cx.text_system()
|
||||||
text.clone(),
|
.line_wrapper(text_style.font(), font_size)
|
||||||
truncate_width,
|
.truncate_line(
|
||||||
&truncation_suffix,
|
text.clone(),
|
||||||
&mut runs,
|
truncate_width,
|
||||||
)
|
&truncation_suffix,
|
||||||
|
runs.to_mut(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
text.clone()
|
text.clone()
|
||||||
};
|
};
|
||||||
@@ -406,6 +412,7 @@ impl TextLayout {
|
|||||||
len: 0,
|
len: 0,
|
||||||
line_height,
|
line_height,
|
||||||
wrap_width,
|
wrap_width,
|
||||||
|
truncate_width,
|
||||||
size: Some(Size::default()),
|
size: Some(Size::default()),
|
||||||
bounds: None,
|
bounds: None,
|
||||||
});
|
});
|
||||||
@@ -424,6 +431,7 @@ impl TextLayout {
|
|||||||
len,
|
len,
|
||||||
line_height,
|
line_height,
|
||||||
wrap_width,
|
wrap_width,
|
||||||
|
truncate_width,
|
||||||
size: Some(size),
|
size: Some(size),
|
||||||
bounds: None,
|
bounds: None,
|
||||||
});
|
});
|
||||||
|
|||||||
+11
@@ -1498,6 +1498,17 @@ impl PlatformWindow for MacWindow {
|
|||||||
.detach()
|
.detach()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_window_move(&self) {
|
||||||
|
let window = self.0.lock().native_window;
|
||||||
|
unsafe {
|
||||||
|
let app = NSApplication::sharedApplication(nil);
|
||||||
|
let event: id = msg_send![app, currentEvent];
|
||||||
|
if !event.is_null() {
|
||||||
|
let _: () = msg_send![window, performWindowDragWithEvent: event];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn titlebar_double_click(&self) {
|
fn titlebar_double_click(&self) {
|
||||||
let this = self.0.lock();
|
let this = self.0.lock();
|
||||||
let window = this.native_window;
|
let window = this.native_window;
|
||||||
|
|||||||
Reference in New Issue
Block a user