mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-19 19:41:27 +00:00
core: detect inputs that result in surface close and avoid segfault
Fixes #965 When processing keybindings that closed the surface (`close_surface`, `close_window`), the surface and associated runtime structures would be freed so we could segfault. This PR introduces a new enum result for input events (only key for now) that returns whether an event resulted in a close. In this case, callers can properly return immediately and avoid writing to deallocated memory.
This commit is contained in:
@@ -794,7 +794,7 @@ pub const Surface = struct {
|
||||
} else .invalid;
|
||||
|
||||
// Invoke the core Ghostty logic to handle this input.
|
||||
const consumed = self.core_surface.keyCallback(.{
|
||||
const effect = self.core_surface.keyCallback(.{
|
||||
.action = action,
|
||||
.key = key,
|
||||
.physical_key = physical_key,
|
||||
@@ -808,11 +808,15 @@ pub const Surface = struct {
|
||||
return;
|
||||
};
|
||||
|
||||
// If we consume the key then we want to reset the dead key state.
|
||||
if (consumed and is_down) {
|
||||
self.keymap_state = .{};
|
||||
self.core_surface.preeditCallback(null) catch {};
|
||||
return;
|
||||
switch (effect) {
|
||||
.closed => return,
|
||||
.ignored => {},
|
||||
.consumed => if (is_down) {
|
||||
// If we consume the key then we want to reset the dead
|
||||
// key state.
|
||||
self.keymap_state = .{};
|
||||
self.core_surface.preeditCallback(null) catch {};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user