mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/embedded: utf8 encoding buffer lifetime must extend beyond call
Fixes #6821 UTF8 translation using KeymapDarwin requires a buffer and the buffer was stack allocated in the coreKeyEvent call and returned from the function. We need the buffer to live longer than this. Long term, we're removing KeymapDarwin (there is a whole TODO comment in there about how to do it), but this fixes a real problem today.
This commit is contained in:
@ -1693,7 +1693,7 @@ pub fn keyCallback(
|
|||||||
self: *Surface,
|
self: *Surface,
|
||||||
event: input.KeyEvent,
|
event: input.KeyEvent,
|
||||||
) !InputEffect {
|
) !InputEffect {
|
||||||
// log.debug("text keyCallback event={}", .{event});
|
// log.warn("text keyCallback event={}", .{event});
|
||||||
|
|
||||||
// Crash metadata in case we crash in here
|
// Crash metadata in case we crash in here
|
||||||
crash.sentry.thread_state = self.crashThreadState();
|
crash.sentry.thread_state = self.crashThreadState();
|
||||||
|
@ -149,8 +149,17 @@ pub const App = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a C key event into a Zig key event.
|
/// Convert a C key event into a Zig key event.
|
||||||
|
///
|
||||||
|
/// The buffer is needed for possibly storing translated UTF-8 text.
|
||||||
|
/// This buffer may (or may not) be referenced by the resulting KeyEvent
|
||||||
|
/// so it should be valid for the lifetime of the KeyEvent.
|
||||||
|
///
|
||||||
|
/// The size of the buffer doesn't need to be large, we always
|
||||||
|
/// used to hardcode 128 bytes and never ran into issues. If it isn't
|
||||||
|
/// large enough an error will be returned.
|
||||||
fn coreKeyEvent(
|
fn coreKeyEvent(
|
||||||
self: *App,
|
self: *App,
|
||||||
|
buf: []u8,
|
||||||
target: KeyTarget,
|
target: KeyTarget,
|
||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) !?input.KeyEvent {
|
) !?input.KeyEvent {
|
||||||
@ -217,7 +226,6 @@ pub const App = struct {
|
|||||||
// Translate our key using the keymap for our localized keyboard layout.
|
// Translate our key using the keymap for our localized keyboard layout.
|
||||||
// We only translate for keydown events. Otherwise, we only care about
|
// We only translate for keydown events. Otherwise, we only care about
|
||||||
// the raw keycode.
|
// the raw keycode.
|
||||||
var buf: [128]u8 = undefined;
|
|
||||||
const result: input.Keymap.Translation = if (is_down) translate: {
|
const result: input.Keymap.Translation = if (is_down) translate: {
|
||||||
// If the event provided us with text, then we use this as a result
|
// If the event provided us with text, then we use this as a result
|
||||||
// and do not do manual translation.
|
// and do not do manual translation.
|
||||||
@ -226,7 +234,7 @@ pub const App = struct {
|
|||||||
.composing = event.composing,
|
.composing = event.composing,
|
||||||
.mods = translate_mods,
|
.mods = translate_mods,
|
||||||
} else try self.keymap.translate(
|
} else try self.keymap.translate(
|
||||||
&buf,
|
buf,
|
||||||
switch (target) {
|
switch (target) {
|
||||||
.app => &self.keymap_state,
|
.app => &self.keymap_state,
|
||||||
.surface => |surface| &surface.keymap_state,
|
.surface => |surface| &surface.keymap_state,
|
||||||
@ -360,7 +368,9 @@ pub const App = struct {
|
|||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) !bool {
|
) !bool {
|
||||||
// Convert our C key event into a Zig one.
|
// Convert our C key event into a Zig one.
|
||||||
|
var buf: [128]u8 = undefined;
|
||||||
const input_event: input.KeyEvent = (try self.coreKeyEvent(
|
const input_event: input.KeyEvent = (try self.coreKeyEvent(
|
||||||
|
&buf,
|
||||||
target,
|
target,
|
||||||
event,
|
event,
|
||||||
)) orelse return false;
|
)) orelse return false;
|
||||||
@ -1425,7 +1435,9 @@ pub const CAPI = struct {
|
|||||||
app: *App,
|
app: *App,
|
||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) bool {
|
) bool {
|
||||||
|
var buf: [128]u8 = undefined;
|
||||||
const core_event = app.coreKeyEvent(
|
const core_event = app.coreKeyEvent(
|
||||||
|
&buf,
|
||||||
.app,
|
.app,
|
||||||
event.keyEvent(),
|
event.keyEvent(),
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
@ -1677,7 +1689,9 @@ pub const CAPI = struct {
|
|||||||
surface: *Surface,
|
surface: *Surface,
|
||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) bool {
|
) bool {
|
||||||
|
var buf: [128]u8 = undefined;
|
||||||
const core_event = surface.app.coreKeyEvent(
|
const core_event = surface.app.coreKeyEvent(
|
||||||
|
&buf,
|
||||||
// Note: this "app" target here looks like a bug, but it is
|
// Note: this "app" target here looks like a bug, but it is
|
||||||
// intentional. coreKeyEvent uses the target only as a way to
|
// intentional. coreKeyEvent uses the target only as a way to
|
||||||
// trigger preedit callbacks for keymap translation and we don't
|
// trigger preedit callbacks for keymap translation and we don't
|
||||||
|
@ -70,8 +70,10 @@ pub fn init(b: *std.Build) !Config {
|
|||||||
|
|
||||||
// If we're building for macOS and we're on macOS, we need to
|
// If we're building for macOS and we're on macOS, we need to
|
||||||
// use a generic target to workaround compilation issues.
|
// use a generic target to workaround compilation issues.
|
||||||
if (result.result.os.tag == .macos and builtin.target.isDarwin()) {
|
if (result.result.os.tag == .macos and
|
||||||
result = genericMacOSTarget(b, null);
|
builtin.target.os.tag.isDarwin())
|
||||||
|
{
|
||||||
|
result = genericMacOSTarget(b, result.query.cpu_arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have no minimum OS version, we set the default based on
|
// If we have no minimum OS version, we set the default based on
|
||||||
|
Reference in New Issue
Block a user