apprt/gtk: get rid of title label option, we can infer it on container

This commit is contained in:
Mitchell Hashimoto
2023-11-01 22:05:51 -07:00
parent 00c02e88d2
commit 14570b8a6c
2 changed files with 11 additions and 28 deletions

View File

@ -37,10 +37,6 @@ pub const Options = struct {
/// The GL area that this surface should draw to. /// The GL area that this surface should draw to.
gl_area: *c.GtkGLArea, gl_area: *c.GtkGLArea,
/// The label to use as the title of this surface. This will be
/// modified with setTitle.
title_label: ?*c.GtkLabel = null,
/// A font size to set on the surface once it is initialized. /// A font size to set on the surface once it is initialized.
font_size: ?font.face.DesiredSize = null, font_size: ?font.face.DesiredSize = null,
@ -84,12 +80,6 @@ pub const Container = union(enum) {
} }
}; };
/// Where the title of this surface will go.
const Title = union(enum) {
none: void,
label: *c.GtkLabel,
};
/// Whether the surface has been realized or not yet. When a surface is /// Whether the surface has been realized or not yet. When a surface is
/// "realized" it means that the OpenGL context is ready and the core /// "realized" it means that the OpenGL context is ready and the core
/// surface has been initialized. /// surface has been initialized.
@ -114,9 +104,6 @@ gl_area: *c.GtkGLArea,
/// Any active cursor we may have /// Any active cursor we may have
cursor: ?*c.GdkCursor = null, cursor: ?*c.GdkCursor = null,
/// Our title label (if there is one).
title: Title,
/// Our title. The raw value of the title. This will be kept up to date and /// Our title. The raw value of the title. This will be kept up to date and
/// .title will be updated if we have focus. /// .title will be updated if we have focus.
/// When set the text in this buf will be null-terminated, because we need to /// When set the text in this buf will be null-terminated, because we need to
@ -206,9 +193,6 @@ pub fn init(self: *Surface, app: *App, opts: Options) !void {
.container = .{ .tab_ = opts.tab }, .container = .{ .tab_ = opts.tab },
.parent = opts.parent, .parent = opts.parent,
.gl_area = opts.gl_area, .gl_area = opts.gl_area,
.title = if (opts.title_label) |label| .{
.label = label,
} else .{ .none = {} },
.title_text_buf = undefined, .title_text_buf = undefined,
.title_text_buf_len = 0, .title_text_buf_len = 0,
.core_surface = undefined, .core_surface = undefined,
@ -537,18 +521,18 @@ pub fn grabFocus(self: *Surface) void {
} }
fn updateTitleLabels(self: *Surface) void { fn updateTitleLabels(self: *Surface) void {
switch (self.title) { // If we have no title, then we have nothing to update.
.none => {}, if (self.title_text_buf_len == 0) return;
.label => |label| { const slice: []u8 = self.title_text_buf[0..self.title_text_buf_len];
if (self.title_text_buf_len == 0) return;
const slice: []u8 = self.title_text_buf[0..self.title_text_buf_len]; // If we have a tab, then we have to update the tab
c.gtk_label_set_text(label, @as([*c]const u8, @ptrCast(slice))); if (self.container.tab()) |tab| {
c.gtk_window_set_title( c.gtk_label_set_text(tab.label_text, slice.ptr);
self.container.window().?.window, // TODO: messy }
c.gtk_label_get_text(label),
); // If we have a window, then we have to update the window title.
}, if (self.container.window()) |window| {
c.gtk_window_set_title(window.window, slice.ptr);
} }
} }

View File

@ -174,7 +174,6 @@ pub fn newSurface(self: *Tab, parent_: ?*CoreSurface) !*Surface {
}, },
.parentSurface = parent_ != null, .parentSurface = parent_ != null,
.gl_area = @ptrCast(gl_area), .gl_area = @ptrCast(gl_area),
.title_label = @ptrCast(self.label_text),
.font_size = font_size, .font_size = font_size,
}); });