gtk: implement bell

Co-authored-by: Jeffrey C. Ollie <jeff@ocjtech.us>
This commit is contained in:
Leah Amelia Chen
2025-04-14 21:43:02 +08:00
parent 17ba0252e8
commit a0760cabd6
8 changed files with 32 additions and 3 deletions

View File

@@ -601,6 +601,7 @@ typedef enum {
GHOSTTY_ACTION_RELOAD_CONFIG,
GHOSTTY_ACTION_CONFIG_CHANGE,
GHOSTTY_ACTION_CLOSE_WINDOW,
GHOSTTY_ACTION_RING_BELL,
} ghostty_action_tag_e;
typedef union {

View File

@@ -932,6 +932,16 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
.present_surface => try self.presentSurface(),
.password_input => |v| try self.passwordInput(v),
.ring_bell => {
_ = self.rt_app.performAction(
.{ .surface = self },
.ring_bell,
{},
) catch |err| {
log.warn("apprt failed to ring bell={}", .{err});
};
},
}
}

View File

@@ -244,6 +244,8 @@ pub const Action = union(Key) {
/// Closes the currently focused window.
close_window,
ring_bell,
/// Sync with: ghostty_action_tag_e
pub const Key = enum(c_int) {
quit,
@@ -287,6 +289,7 @@ pub const Action = union(Key) {
reload_config,
config_change,
close_window,
ring_bell,
};
/// Sync with: ghostty_action_u

View File

@@ -246,6 +246,7 @@ pub const App = struct {
.toggle_maximize,
.prompt_title,
.reset_window_size,
.ring_bell,
=> {
log.info("unimplemented action={}", .{action});
return false;

View File

@@ -484,6 +484,7 @@ pub fn performAction(
.prompt_title => try self.promptTitle(target),
.toggle_quick_terminal => return try self.toggleQuickTerminal(),
.secure_input => self.setSecureInput(target, value),
.ring_bell => try self.ringBell(target),
// Unimplemented
.close_all_windows,
@@ -775,6 +776,13 @@ fn toggleQuickTerminal(self: *App) !bool {
return true;
}
fn ringBell(_: *App, target: apprt.Target) !void {
switch (target) {
.app => {},
.surface => |surface| try surface.rt_surface.ringBell(),
}
}
fn quitTimer(self: *App, mode: apprt.action.QuitTimer) void {
switch (mode) {
.start => self.startQuitTimer(),

View File

@@ -2439,3 +2439,7 @@ pub fn setSecureInput(self: *Surface, value: apprt.action.SecureInput) void {
.toggle => self.is_secure_input = !self.is_secure_input,
}
}
pub fn ringBell(self: *Surface) !void {
}
}

View File

@@ -81,6 +81,9 @@ pub const Message = union(enum) {
/// The terminal has reported a change in the working directory.
pwd_change: WriteReq,
/// The terminal encountered a bell character.
ring_bell,
pub const ReportTitleStyle = enum {
csi_21_t,

View File

@@ -325,9 +325,8 @@ pub const StreamHandler = struct {
try self.terminal.printRepeat(count);
}
pub fn bell(self: StreamHandler) !void {
_ = self;
log.info("BELL", .{});
pub fn bell(self: *StreamHandler) !void {
self.surfaceMessageWriter(.ring_bell);
}
pub fn backspace(self: *StreamHandler) !void {