Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK: add delay before updating the title #3746

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/apprt/gtk/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ cursor: ?*c.GdkCursor = null,
/// pass it to GTK.
title_text: ?[:0]const u8 = null,

/// The timer used to delay title updates in order to prevent flickering.
update_title_timer: ?c.guint = null,
maciekbartczak marked this conversation as resolved.
Show resolved Hide resolved

/// The core surface backing this surface
core_surface: CoreSurface,

Expand Down Expand Up @@ -894,7 +897,23 @@ pub fn setTitle(self: *Surface, slice: [:0]const u8) !void {
if (self.title_text) |old| alloc.free(old);
self.title_text = copy;

// delay the title update to prevent flickering
if (self.update_title_timer) |timer| {
if (c.g_source_remove(timer) == c.FALSE) {
log.warn("unable to remove update title timer", .{});
}
self.update_title_timer = null;
}
self.update_title_timer = c.g_timeout_add(75, updateTitleTimerExpired, self);
}

fn updateTitleTimerExpired(ctx: ?*anyopaque) callconv(.C) c.gboolean {
const self: *Surface = @ptrCast(@alignCast(ctx));

self.updateTitleLabels();
self.update_title_timer = null;

return c.FALSE;
}

pub fn getTitle(self: *Surface) ?[:0]const u8 {
Expand Down