mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk-ng: create the privateObjFieldAccessor helper to unref
This commit is contained in:
@ -46,6 +46,84 @@ pub fn Common(
|
|||||||
}
|
}
|
||||||
}).private else {};
|
}).private else {};
|
||||||
|
|
||||||
|
/// A helper that can be used to create a property that reads and
|
||||||
|
/// writes a private boxed gobject field type.
|
||||||
|
///
|
||||||
|
/// Reading the property will result in allocating a pointer and
|
||||||
|
/// setting it will free the previous pointer.
|
||||||
|
///
|
||||||
|
/// The object class (Self) must still free the private field
|
||||||
|
/// in finalize!
|
||||||
|
pub fn privateBoxedFieldAccessor(
|
||||||
|
comptime name: []const u8,
|
||||||
|
) gobject.ext.Accessor(
|
||||||
|
Self,
|
||||||
|
@FieldType(Private.?, name),
|
||||||
|
) {
|
||||||
|
return .{
|
||||||
|
.getter = &struct {
|
||||||
|
fn get(self: *Self, value: *gobject.Value) void {
|
||||||
|
gobject.ext.Value.set(
|
||||||
|
value,
|
||||||
|
@field(private(self), name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}.get,
|
||||||
|
.setter = &struct {
|
||||||
|
fn set(self: *Self, value: *const gobject.Value) void {
|
||||||
|
const priv = private(self);
|
||||||
|
if (@field(priv, name)) |v| {
|
||||||
|
glib.ext.destroy(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T = @TypeOf(@field(priv, name));
|
||||||
|
@field(
|
||||||
|
priv,
|
||||||
|
name,
|
||||||
|
) = gobject.ext.Value.dup(value, T);
|
||||||
|
}
|
||||||
|
}.set,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper that can be used to create a property that reads and
|
||||||
|
/// writes a private field gobject field type (reference counted).
|
||||||
|
///
|
||||||
|
/// Reading the property will result in taking a reference to the
|
||||||
|
/// value and writing the property will unref the previous value.
|
||||||
|
///
|
||||||
|
/// The object class (Self) must still free the private field
|
||||||
|
/// in finalize!
|
||||||
|
pub fn privateObjFieldAccessor(
|
||||||
|
comptime name: []const u8,
|
||||||
|
) gobject.ext.Accessor(
|
||||||
|
Self,
|
||||||
|
@FieldType(Private.?, name),
|
||||||
|
) {
|
||||||
|
return .{
|
||||||
|
.getter = &struct {
|
||||||
|
fn get(self: *Self, value: *gobject.Value) void {
|
||||||
|
gobject.ext.Value.set(
|
||||||
|
value,
|
||||||
|
@field(private(self), name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}.get,
|
||||||
|
.setter = &struct {
|
||||||
|
fn set(self: *Self, value: *const gobject.Value) void {
|
||||||
|
const priv = private(self);
|
||||||
|
if (@field(priv, name)) |v| v.unref();
|
||||||
|
|
||||||
|
const T = @TypeOf(@field(priv, name));
|
||||||
|
@field(
|
||||||
|
priv,
|
||||||
|
name,
|
||||||
|
) = gobject.ext.Value.dup(value, T);
|
||||||
|
}
|
||||||
|
}.set,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// A helper that can be used to create a property that reads and
|
/// A helper that can be used to create a property that reads and
|
||||||
/// writes a private `?[:0]const u8` field type.
|
/// writes a private `?[:0]const u8` field type.
|
||||||
///
|
///
|
||||||
|
@ -59,12 +59,7 @@ pub const ClipboardConfirmationDialog = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Request",
|
.nick = "Request",
|
||||||
.blurb = "The clipboard request.",
|
.blurb = "The clipboard request.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateBoxedFieldAccessor("request"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"request",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -78,12 +73,7 @@ pub const ClipboardConfirmationDialog = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Clipboard Contents",
|
.nick = "Clipboard Contents",
|
||||||
.blurb = "The clipboard contents being read/written.",
|
.blurb = "The clipboard contents being read/written.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateObjFieldAccessor("clipboard_contents"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"clipboard_contents",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -50,12 +50,7 @@ pub const Surface = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Config",
|
.nick = "Config",
|
||||||
.blurb = "The configuration that this surface is using.",
|
.blurb = "The configuration that this surface is using.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateObjFieldAccessor("config"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"config",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -89,12 +84,7 @@ pub const Surface = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Desired Font Size",
|
.nick = "Desired Font Size",
|
||||||
.blurb = "The desired font size, only affects initialization.",
|
.blurb = "The desired font size, only affects initialization.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateBoxedFieldAccessor("font_size_request"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"font_size_request",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -42,12 +42,7 @@ const SurfaceChildExitedBanner = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Data",
|
.nick = "Data",
|
||||||
.blurb = "The child exit data.",
|
.blurb = "The child exit data.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateBoxedFieldAccessor("data"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"data",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -69,12 +69,7 @@ pub const Window = extern struct {
|
|||||||
.{
|
.{
|
||||||
.nick = "Config",
|
.nick = "Config",
|
||||||
.blurb = "The configuration that this surface is using.",
|
.blurb = "The configuration that this surface is using.",
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
.accessor = C.privateObjFieldAccessor("config"),
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"config",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user