mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-30 11:03:55 +00:00
renderer: emit scrollbar apprt event when scrollbar changes
This commit is contained in:
@@ -983,6 +983,8 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
||||
|
||||
.renderer_health => |health| self.updateRendererHealth(health),
|
||||
|
||||
.scrollbar => |scrollbar| self.updateScrollbar(scrollbar),
|
||||
|
||||
.report_color_scheme => |force| self.reportColorScheme(force),
|
||||
|
||||
.present_surface => try self.presentSurface(),
|
||||
@@ -1459,6 +1461,17 @@ fn updateRendererHealth(self: *Surface, health: rendererpkg.Health) void {
|
||||
};
|
||||
}
|
||||
|
||||
/// Called when the scrollbar state changes.
|
||||
fn updateScrollbar(self: *Surface, scrollbar: terminal.Scrollbar) void {
|
||||
_ = self.rt_app.performAction(
|
||||
.{ .surface = self },
|
||||
.scrollbar,
|
||||
scrollbar,
|
||||
) catch |err| {
|
||||
log.warn("failed to notify app of scrollbar change err={}", .{err});
|
||||
};
|
||||
}
|
||||
|
||||
/// This should be called anytime `config_conditional_state` changes
|
||||
/// so that the apprt can reload the configuration.
|
||||
fn notifyConfigConditionalState(self: *Surface) void {
|
||||
|
||||
@@ -164,6 +164,9 @@ pub const Action = union(Key) {
|
||||
/// The cell size has changed to the given dimensions in pixels.
|
||||
cell_size: CellSize,
|
||||
|
||||
/// The scrollbar is updating.
|
||||
scrollbar: terminal.Scrollbar,
|
||||
|
||||
/// The target should be re-rendered. This usually has a specific
|
||||
/// surface target but if the app is targeted then all active
|
||||
/// surfaces should be redrawn.
|
||||
@@ -324,6 +327,7 @@ pub const Action = union(Key) {
|
||||
reset_window_size,
|
||||
initial_size,
|
||||
cell_size,
|
||||
scrollbar,
|
||||
render,
|
||||
inspector,
|
||||
show_gtk_inspector,
|
||||
|
||||
@@ -104,6 +104,9 @@ pub const Message = union(enum) {
|
||||
/// of the command.
|
||||
stop_command: ?u8,
|
||||
|
||||
/// The scrollbar state changed for the surface.
|
||||
scrollbar: terminal.Scrollbar,
|
||||
|
||||
pub const ReportTitleStyle = enum {
|
||||
csi_21_t,
|
||||
|
||||
|
||||
@@ -1314,6 +1314,15 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||
self.draw_mutex.lock();
|
||||
defer self.draw_mutex.unlock();
|
||||
|
||||
// After the graphics API is complete (so we defer) we want to
|
||||
// update our scrollbar state.
|
||||
defer if (self.scrollbar_dirty) {
|
||||
self.scrollbar_dirty = false;
|
||||
_ = self.surface_mailbox.push(.{
|
||||
.scrollbar = self.scrollbar,
|
||||
}, .{ .forever = {} });
|
||||
};
|
||||
|
||||
// Let our graphics API do any bookkeeping, etc.
|
||||
// that it needs to do before / after `drawFrame`.
|
||||
self.api.drawFrameStart();
|
||||
|
||||
@@ -2110,6 +2110,21 @@ pub const Scrollbar = struct {
|
||||
.len = 0,
|
||||
};
|
||||
|
||||
// Sync with: ghostty_action_scrollbar_s
|
||||
pub const C = extern struct {
|
||||
total: u64,
|
||||
offset: u64,
|
||||
len: u64,
|
||||
};
|
||||
|
||||
pub fn cval(self: Scrollbar) C {
|
||||
return .{
|
||||
.total = @intCast(self.total),
|
||||
.offset = @intCast(self.offset),
|
||||
.len = @intCast(self.len),
|
||||
};
|
||||
}
|
||||
|
||||
/// Comparison for scrollbars.
|
||||
pub fn eql(self: Scrollbar, other: Scrollbar) bool {
|
||||
return self.total == other.total and
|
||||
|
||||
Reference in New Issue
Block a user