apprt/gtk-ng: update to the new typedaccessor API

This commit is contained in:
Mitchell Hashimoto
2025-07-19 13:10:07 -07:00
parent 22b2344f50
commit 8220db8ce1
4 changed files with 7 additions and 36 deletions

View File

@ -10,23 +10,6 @@ pub const Window = @import("class/window.zig").Window;
pub const Config = @import("class/config.zig").Config;
pub const Surface = @import("class/surface.zig").Surface;
/// Unrefs the given GObject on the next event loop tick.
///
/// This works around an issue with zig-object where dynamically
/// generated gobjects in property getters can't unref themselves
/// normally: https://github.com/ianprime0509/zig-gobject/issues/108
pub fn unrefLater(obj: anytype) void {
_ = glib.idleAdd((struct {
fn callback(data_: ?*anyopaque) callconv(.c) c_int {
const remove = @intFromBool(glib.SOURCE_REMOVE);
const data = data_ orelse return remove;
const object: *gobject.Object = @ptrCast(@alignCast(data));
object.unref();
return remove;
}
}).callback, obj.as(gobject.Object));
}
/// Common methods for all GObject classes we create.
pub fn Common(
comptime Self: type,

View File

@ -75,7 +75,8 @@ pub const Application = extern struct {
Self,
?*Config,
.{
.getter = Self.getPropConfig,
.getter = Self.getConfig,
.getter_transfer = .full,
},
),
},
@ -495,21 +496,7 @@ pub const Application = extern struct {
///
/// The reference count is increased.
pub fn getConfig(self: *Self) *Config {
var value = gobject.ext.Value.zero;
gobject.Object.getProperty(
self.as(gobject.Object),
properties.config.name,
&value,
);
const obj = value.getObject().?;
return gobject.ext.cast(Config, obj).?;
}
fn getPropConfig(self: *Self) *Config {
// Property return must not increase reference count since
// the gobject getter handles this automatically.
return self.private().config;
return self.private().config.ref();
}
/// Returns the core app associated with this application. This is

View File

@ -8,7 +8,6 @@ const gtk = @import("gtk");
const configpkg = @import("../../../config.zig");
const CoreConfig = configpkg.Config;
const unrefLater = @import("../class.zig").unrefLater;
const Common = @import("../class.zig").Common;
const log = std.log.scoped(.gtk_ghostty_config);
@ -47,6 +46,7 @@ pub const Config = extern struct {
?*gtk.TextBuffer,
.{
.getter = Self.diagnosticsBuffer,
.getter_transfer = .full,
},
),
},
@ -136,7 +136,6 @@ pub const Config = extern struct {
text_buf.insertAtCursor("\n", 1);
}
unrefLater(text_buf); // See unrefLater docs for why this is needed
return text_buf;
}

View File

@ -129,7 +129,9 @@ pub const ConfigErrorsDialog = extern struct {
fn setConfig(self: *Self, config: ?*Config) void {
const priv = self.private();
if (priv.config) |old| old.unref();
if (config) |newv| _ = newv.ref();
// We don't need to increase the reference count because
// the property setter handles it (uses GValue.get vs. take)
priv.config = config;
}