mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
apprt/gtk-ng: update to the new typedaccessor API
This commit is contained in:
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user