glib

package
v0.0.0-...-aefa52a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: MPL-2.0, ISC Imports: 14 Imported by: 0

Documentation

Overview

Package glib provides some hand-written GObject and GLib bindings.

Index

Constants

View Source
const (
	ParamReadable       ParamFlags = C.G_PARAM_READABLE
	ParamWritable                  = C.G_PARAM_WRITABLE
	ParamReadWrite                 = C.G_PARAM_READABLE | C.G_PARAM_WRITABLE
	ParamConstruct                 = C.G_PARAM_CONSTRUCT
	ParamConstructOnly             = C.G_PARAM_CONSTRUCT_ONLY
	ParamLaxValidation             = C.G_PARAM_LAX_VALIDATION
	ParamStaticName                = C.G_PARAM_STATIC_NAME
	ParamStaticNick                = C.G_PARAM_STATIC_NICK
	ParamStaticBlurb               = C.G_PARAM_STATIC_BLURB
	ParamExplicitNotify            = C.G_PARAM_EXPLICIT_NOTIFY
	ParamDeprecated                = C.G_PARAM_DEPRECATED
)

Variables

View Source
var (
	VariantTypeBoolean         = newVariantType(C.G_VARIANT_TYPE_BOOLEAN)
	VariantTypeByte            = newVariantType(C.G_VARIANT_TYPE_BYTE)
	VariantTypeInt16           = newVariantType(C.G_VARIANT_TYPE_INT16)
	VariantTypeUint16          = newVariantType(C.G_VARIANT_TYPE_UINT16)
	VariantTypeInt32           = newVariantType(C.G_VARIANT_TYPE_INT32)
	VariantTypeUint32          = newVariantType(C.G_VARIANT_TYPE_UINT32)
	VariantTypeInt64           = newVariantType(C.G_VARIANT_TYPE_INT64)
	VariantTypeUint64          = newVariantType(C.G_VARIANT_TYPE_UINT64)
	VariantTypeHandle          = newVariantType(C.G_VARIANT_TYPE_HANDLE)
	VariantTypeDouble          = newVariantType(C.G_VARIANT_TYPE_DOUBLE)
	VariantTypeString          = newVariantType(C.G_VARIANT_TYPE_STRING)
	VariantTypeObjectPath      = newVariantType(C.G_VARIANT_TYPE_OBJECT_PATH)
	VariantTypeSignature       = newVariantType(C.G_VARIANT_TYPE_SIGNATURE)
	VariantTypeVariant         = newVariantType(C.G_VARIANT_TYPE_VARIANT)
	VariantTypeAny             = newVariantType(C.G_VARIANT_TYPE_ANY)
	VariantTypeBasic           = newVariantType(C.G_VARIANT_TYPE_BASIC)
	VariantTypeMaybe           = newVariantType(C.G_VARIANT_TYPE_MAYBE)
	VariantTypeArray           = newVariantType(C.G_VARIANT_TYPE_ARRAY)
	VariantTypeTuple           = newVariantType(C.G_VARIANT_TYPE_TUPLE)
	VariantTypeUnit            = newVariantType(C.G_VARIANT_TYPE_UNIT)
	VariantTypeDictEntry       = newVariantType(C.G_VARIANT_TYPE_DICT_ENTRY)
	VariantTypeDictionary      = newVariantType(C.G_VARIANT_TYPE_DICTIONARY)
	VariantTypeStringArray     = newVariantType(C.G_VARIANT_TYPE_STRING_ARRAY)
	VariantTypeObjectPathArray = newVariantType(C.G_VARIANT_TYPE_OBJECT_PATH_ARRAY)
	VariantTypeBytestring      = newVariantType(C.G_VARIANT_TYPE_BYTESTRING)
	VariantTypeBytestringArray = newVariantType(C.G_VARIANT_TYPE_BYTESTRING_ARRAY)
	VariantTypeVardict         = newVariantType(C.G_VARIANT_TYPE_VARDICT)
)

Variant types for comparison. Note that variant types cannot be compared by value; use VariantType.Equal instead.

View Source
var (
	// InvalidValue is returned from Value methods, such as GoValue, to indicate
	// that the value obtained is invalid.
	InvalidValue = invalidValueType{}
)

Functions

func CastObject deprecated

func CastObject(obj *Object) interface{}

CastObject casts the given object pointer to the Go concrete type. The caller is responsible for recasting the interface to the wanted type.

Deprecated: Use obj.Cast() instead.

func ConnectedGeneratedClosure

func ConnectedGeneratedClosure(closureData uintptr) *closure.FuncStack

ConnectedGeneratedClosure returns the function from the given user_data pointer that's set by ConnectGeneratedClosure's GClosure instance.

func Destroy

func Destroy(objector Objector)

Destroy destroys the Go reference to the given object. The object must not be used ever again; it is the caller's responsibility to ensure that it will never be used again. Resurrecting the object again is undefined behavior.

func InitI18n

func InitI18n(domain, dir string)

InitI18n initializes the i18n subsystem. It runs the following C code:

setlocale(LC_ALL, "");
bindtextdomain(domain, dir);
bind_textdomain_codeset(domain, "UTF-8");
textdomain(domain);

func Local

func Local(input string) string

Local localizes a string using gettext.

func NewClosure

func NewClosure(v *Object, f interface{}) unsafe.Pointer

NewClosure creates a new closure for the given object.

func ObjectEq

func ObjectEq(obj1, obj2 Objector) bool

ObjectEq returns true if both obj1 and obj2 point to the same GObject pointers.

func Overrides

func Overrides[OverridesT any](obj Objector) OverridesT

Overrides gets the XOverrides instance associated with the given object's parent. The instance will have already been modified by the subclass if it did.

func OverridesFromObj

func OverridesFromObj[OverridesT any](obj *Object) OverridesT

OverridesFromObj is like Overrides, except it specifically takes the base object. The GType is asked for instead of using the underlying Go type.

func ParentOverrides

func ParentOverrides[OverridesT any](obj Objector) OverridesT

ParentOverrides is similar to Overrides, except the object's parent type is used instead of the object's type.

func PeekParentClass

func PeekParentClass(obj Objector) unsafe.Pointer

PeekParentClass returns the C.TClass type using peek_parent, which is free of any subclassing changes.

func RegisterClassInfo

func RegisterClassInfo[InstanceT Objector, ClassT, OverridesT any](
	gtype Type,
	initClassFunc func(gclass unsafe.Pointer, overrides OverridesT, initFunc func(ClassT)),
	wrapClassFunc func(*Object) InstanceT,
	overridesFunc func(InstanceT) OverridesT,
)

RegisterClassInfo registers the given class type info. This function is NOT thread-safe; only call it in init().

func RegisterGValueMarshaler

func RegisterGValueMarshaler(t Type, f GValueMarshaler)

RegisterGValueMarshaler registers a single GValue marshaler. If the function has already been called before on the same Type, then it does nothing, and the new function is ignored.

func RegisterGValueMarshalers

func RegisterGValueMarshalers(marshalers []TypeMarshaler)

RegisterGValueMarshalers adds marshalers for several types to the internal marshalers map. Once registered, calling GoValue on any Value with a registered type will return the data returned by the marshaler.

func SourceRemove

func SourceRemove(src SourceHandle) bool

SourceRemove is a wrapper around g_source_remove()

func VariantTypeStringIsValid

func VariantTypeStringIsValid(typeString string) bool

VariantTypeStringIsValid is a wrapper around g_variant_type_string_is_valid.

func WeakRefObject

func WeakRefObject(obj Objector, notify func())

WeakRefObject is like SetFinalizer, except it's not thread-safe (so notify SHOULD NOT REFERENCE OBJECT). It is best that you just do not use this at all.

func WipeAllClosures deprecated

func WipeAllClosures(objector Objector)

WipeAllClosures wipes all the Go closures associated with the given object away. BE EXTREMELY CAREFUL WHEN USING THIS FUNCTION! If not careful, your program WILL crash!

There is only one specific use case for this function: if your object has closures connected to it where these closures capture the object itself, then it might create a cyclic dependency on the GC, preventing its finalizer from ever running. This will cause the program to leak memory. As a temporary hack, this function is introduced for cases where the programmer knows for sure that the object will never be used again, and it is significant enough of a leak that having a workaround is better than not.

Deprecated: this function is dangerous and should not be used. Using this function now causes a panic.

Types

type AnyClosure

type AnyClosure interface{}

AnyClosure describes any function type. If AnyClosure does not contain a function type, the consumer function is allowed to panic.

type GValueMarshaler

type GValueMarshaler func(uintptr) (interface{}, error)

GValueMarshaler is a marshal function to convert a GValue into an appropriate Go type. The uintptr parameter is a *C.GValue.

type GeneratedClosure deprecated

type GeneratedClosure struct {
	Func interface{}
}

GeneratedClosure boxes around any function value to be given to FuncStack.

The user should never use this struct. The code generator should use it like so:

obj.Connect("signal", externglib.GeneratedClosure{Func: v})

There are a few differences in behavior that we have to make in goMarshal(), and we want a clean way to differentiate manual Connect() calls with traditional closures and autogenerated ones that are far more consistent.

Deprecated: this isn't used anywhere anymore.

type InitiallyUnowned

type InitiallyUnowned struct {
	*Object
}

InitiallyUnowned is a representation of GLib's GInitiallyUnowned.

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is a representation of GLib's GObject. Object types cannot be compared; pointer comparisons must be done using the Eq method.

func AssumeOwnership

func AssumeOwnership(ptr unsafe.Pointer) *Object

AssumeOwnership is similar to Take, except the function does not take a reference. This is usually used for newly constructed objects that for some reason does not have an initial floating reference.

To be clear, this should often be used when Gtk says "transfer full", as it means the ownership is transferred to us (Go), so we can assume that much. This is in contrary to Take, which is used when Gtk says "transfer none", as we're now referencing an object that might possibly be kept by C, so we should take our own.

func BaseObject

func BaseObject(obj Objector) *Object

BaseObject gets the internal Object type. This is used for calling methods not in the Objector.

func InternObject deprecated

func InternObject(obj Objector) *Object

InternObject calls BaseObject.

Deprecated: Use BaseObject.

func Take

func Take(ptr unsafe.Pointer) *Object

Take wraps a unsafe.Pointer as a Object, taking ownership of it. This function is exported for visibility in other gotk3 packages and is not meant to be used by applications.

To be clear, this should mostly be used when Gtk says "transfer none". Refer to AssumeOwnership for more details.

func (*Object) Cast

func (v *Object) Cast() Objector

Cast casts v to the concrete Go type (e.g. *Object to *gtk.Entry).

func (*Object) CastType

func (v *Object) CastType(gtype Type) Objector

CastType casts v to a concrete Go type that is associated with the given GType.

func (*Object) Connect

func (v *Object) Connect(detailedSignal string, f interface{}) SignalHandle

Connect is a wrapper around g_signal_connect_closure(). f must be a function with at least one parameter matching the type it is connected to.

It is optional to list the rest of the required types from GTK, as values that don't fit into the function parameter will simply be ignored; however, extraneous types will trigger a runtime panic. Arguments for f must be a matching Go equivalent type for the C callback, or an interface type which the value may be packed in. If the type is not suitable, a runtime panic will occur when the signal is emitted.

func (*Object) ConnectAfter

func (v *Object) ConnectAfter(detailedSignal string, f interface{}) SignalHandle

ConnectAfter is a wrapper around g_signal_connect_closure(). The difference between Connect and ConnectAfter is that the latter will be invoked after the default handler, not before. For more information, refer to Connect.

func (*Object) Emit

func (v *Object) Emit(s string, args ...interface{}) interface{}

Emit emits the signal specified by the string s to an Object. Arguments to callback functions connected to this signal must be specified in args. Emit returns an interface{} which must be type asserted to an equivalent Go type. The return value is the return value for the native C callback.

Note that this code is unsafe in that the types of values in args are not checked against whether they are suitable for the callback.

func (*Object) Eq

func (v *Object) Eq(other Objector) bool

Eq returns true if v's GObject pointer matches other's.

func (*Object) FreezeNotify

func (v *Object) FreezeNotify()

FreezeNotify increases the freeze count on object. If the freeze count is non-zero, the emission of “notify” signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one GObject::notify signal is emitted for each property modified while the object is frozen.

This is necessary for accessors that modify multiple properties to prevent premature notification while the object is still being modified.

func (*Object) HandlerBlock

func (v *Object) HandlerBlock(handle SignalHandle)

HandlerBlock is a wrapper around g_signal_handler_block().

func (*Object) HandlerDisconnect

func (v *Object) HandlerDisconnect(handle SignalHandle)

HandlerDisconnect is a wrapper around g_signal_handler_disconnect().

func (*Object) HandlerUnblock

func (v *Object) HandlerUnblock(handle SignalHandle)

HandlerUnblock is a wrapper around g_signal_handler_unblock().

func (*Object) IsA

func (v *Object) IsA(typ Type) bool

IsA is a wrapper around g_type_is_a().

func (*Object) Native

func (v *Object) Native() uintptr

Native returns a pointer to the underlying GObject.

func (*Object) NotifyProperty

func (v *Object) NotifyProperty(property string, f func()) SignalHandle

NotifyProperty adds a handler that's called when the object's property is updated.

func (*Object) ObjectProperty

func (v *Object) ObjectProperty(name string) interface{}

ObjectProperty is a wrapper around g_object_get_property(). If the property's type cannot be resolved to a Go type, then InvalidValue is returned.

func (*Object) PropertyType

func (v *Object) PropertyType(name string) Type

PropertyType returns the Type of a property of the underlying GObject. If the property is missing, it will return TypeInvalid.

func (*Object) SetObjectProperty

func (v *Object) SetObjectProperty(name string, value interface{})

SetObjectProperty is a wrapper around g_object_set_property().

func (*Object) StopEmission

func (v *Object) StopEmission(s string)

StopEmission stops a signal’s current emission. It is a wrapper around g_signal_stop_emission_by_name().

func (*Object) ThawNotify

func (v *Object) ThawNotify()

ThawNotify reverts the effect of a previous call to g_object_freeze_notify(). The freeze count is decreased on object and when it reaches zero, queued “notify” signals are emitted.

Duplicate notifications for each property are squashed so that at most one GObject::notify signal is emitted for each property, in the reverse order in which they have been queued.

It is an error to call this function when the freeze count is zero.

func (*Object) Type

func (v *Object) Type() Type

Type aliases to TypeFromInstance.

func (*Object) TypeFromInstance

func (v *Object) TypeFromInstance() Type

TypeFromInstance is a wrapper around g_type_from_instance().

func (*Object) WalkCast

func (v *Object) WalkCast(f func(Objector) bool) (object Objector)

WalkCast is like Cast, except the user is walked through the object's entire inheritance tree as well as all its interfaces. This is used in the code generator for type assertions.

type ObjectOverrides

type ObjectOverrides struct {
	// Init is called during init_instance, which is actually when a
	// GTypeInstance is instantiated, not GObject.
	Init func()
	// Dispose is called during GObject's dispose.
	Dispose func()
}

ObjectOverrides contains optional virtual methods hookable onto the Object type.

type Objector

type Objector interface {
	HandlerBlock(SignalHandle)
	HandlerUnblock(SignalHandle)
	HandlerDisconnect(SignalHandle)

	NotifyProperty(string, func()) SignalHandle
	ObjectProperty(string) interface{}
	SetObjectProperty(string, interface{})
	FreezeNotify()
	ThawNotify()
	StopEmission(string)
	// contains filtered or unexported methods
}

Objector is an interface that describes the Object type's methods. Only this package's Object types and types that embed it can satisfy this interface.

type ParamFlags

type ParamFlags int

ParamFlags is a go cast of GParamFlags.

func (ParamFlags) Has

func (p ParamFlags) Has(b ParamFlags) bool

Has returns true if these flags contain the provided ones.

type ParamSpec

type ParamSpec struct {
	// contains filtered or unexported fields
}

ParamSpec is a go representation of a C GParamSpec

func NewBoolParam

func NewBoolParam(name, nick, blurb string, defaultValue bool, flags ParamFlags) *ParamSpec

NewBoolParam creates a new ParamSpec that will hold a boolean value.

func NewBoxedParam

func NewBoxedParam(name, nick, blurb string, boxedType Type, flags ParamFlags) *ParamSpec

NewBoxedParam creates a new ParamSpec containing a boxed type.

func NewFloat32Param

func NewFloat32Param(name, nick, blurb string, min, max, defaultValue float32, flags ParamFlags) *ParamSpec

NewFloat32Param creates a new ParamSpec that will hold a 32-bit float value.

func NewFloat64Param

func NewFloat64Param(name, nick, blurb string, min, max, defaultValue float64, flags ParamFlags) *ParamSpec

NewFloat64Param creates a new ParamSpec that will hold a 64-bit float value.

func NewInt64Param

func NewInt64Param(name, nick, blurb string, min, max, defaultValue int64, flags ParamFlags) *ParamSpec

NewInt64Param creates a new ParamSpec that will hold a signed 64-bit integer value.

func NewIntParam

func NewIntParam(name, nick, blurb string, min, max, defaultValue int32, flags ParamFlags) *ParamSpec

NewIntParam creates a new ParamSpec that will hold a signed integer value.

func NewStringParam

func NewStringParam(name, nick, blurb string, defaultValue string, flags ParamFlags) *ParamSpec

NewStringParam returns a new ParamSpec that will hold a string value.

func NewUint64Param

func NewUint64Param(name, nick, blurb string, min, max, defaultValue uint64, flags ParamFlags) *ParamSpec

NewUint64Param creates a new ParamSpec that will hold an unsigned 64-bit integer value.

func NewUintParam

func NewUintParam(name, nick, blurb string, min, max, defaultValue uint32, flags ParamFlags) *ParamSpec

NewUintParam creates a new ParamSpec that will hold an unsigned integer value.

func ParamSpecFromNative

func ParamSpecFromNative(ptr unsafe.Pointer) *ParamSpec

ParamSpecFromNative wraps ptr into a ParamSpec.

func ParamSpecTake

func ParamSpecTake(ptr unsafe.Pointer, take bool) *ParamSpec

ParamSpecTake wraps ptr into a ParamSpec and ensures that it's properly GC'd.

func (*ParamSpec) Blurb

func (p *ParamSpec) Blurb() string

Blurb returns the blurb for this parameter.

func (*ParamSpec) Flags

func (p *ParamSpec) Flags() ParamFlags

Flags returns the flags for this parameter.

func (*ParamSpec) Name

func (p *ParamSpec) Name() string

Name returns the name of this parameter.

func (*ParamSpec) OwnerType

func (p *ParamSpec) OwnerType() Type

OwnerType returns the Gtype for the owner of this parameter.

func (*ParamSpec) Unref

func (p *ParamSpec) Unref()

Unref the underlying paramater spec.

func (*ParamSpec) ValueType

func (p *ParamSpec) ValueType() Type

ValueType returns the GType for the value inside this parameter.

type Priority

type Priority int

Priority is the enumerated type for GLib priority event sources.

const (
	PriorityHigh        Priority = C.G_PRIORITY_HIGH
	PriorityDefault     Priority = C.G_PRIORITY_DEFAULT // TimeoutAdd
	PriorityHighIdle    Priority = C.G_PRIORITY_HIGH_IDLE
	PriorityDefaultIdle Priority = C.G_PRIORITY_DEFAULT_IDLE // IdleAdd
	PriorityLow         Priority = C.G_PRIORITY_LOW
)

type Property

type Property[T any] struct {
	// contains filtered or unexported fields
}

Property describes a Go GObject property. It is used as an alternative to manually written property getter/setters.

func (*Property[T]) Get

func (p *Property[T]) Get() T

Get gets the value of the property.

func (*Property[T]) Notify

func (p *Property[T]) Notify(f func(T)) SignalHandle

Notify calls f everytime the property changes.

func (*Property[T]) Set

func (p *Property[T]) Set(v T)

Set sets the new property.

type RegisterOptsFunc

type RegisterOptsFunc func(*registerOpts)

RegisterOptsFunc is a function type that modifies the behavior of a RegisterSubclass call.

func WithClassInit

func WithClassInit[ClassT any](f func(ClassT)) RegisterOptsFunc

WithClassInit adds a custom ClassInit function. Use this method to add a function that, for example, takes in a WidgetClass.

func WithGTypeName

func WithGTypeName(gtypeName string) RegisterOptsFunc

WithGTypeName overrides the autogenerated GLib type name, which is the namespace concatenated with the Go type name.

func WithOverrides

func WithOverrides[T Objector, OverridesT any](f func(T) OverridesT) RegisterOptsFunc

WithOverrides adds one XOverrides instance into the subclass. The user can use this to override any particular virtual method of any of its parent classes.

func WithParamSpecs

func WithParamSpecs(paramSpecs []*ParamSpec) RegisterOptsFunc

WithParamSpecs adds additional ParamSpecs into a type for its properties.

type RegisteredSubclass

type RegisteredSubclass[T any] registeredSubclass

RegisteredSubclass is a type that described a registered Go subclass type.

func RegisterSubclass

func RegisterSubclass[T Objector](opts ...RegisterOptsFunc) *RegisteredSubclass[T]

RegisterSubclass is RegisterSubclassWithConstructor, but a zero-value instance of T is automatically created.

func RegisterSubclassWithConstructor

func RegisterSubclassWithConstructor[T Objector](ctor func() T, opts ...RegisterOptsFunc) *RegisteredSubclass[T]

RegisterSubclassWithConstructor registers a new type T that is a subclass of its parent type, which is the first field that must be embedded.

ctor has to be idempotent (i.e. can be called multiple times w/o side effects).

func (*RegisteredSubclass[T]) New

func (r *RegisteredSubclass[T]) New() T

New creates an instance of the subclass object with no properties.

func (*RegisteredSubclass[T]) NewWithProperties

func (r *RegisteredSubclass[T]) NewWithProperties(properties map[string]any) T

NewWithProperties creates an instance of the subclass object with the given properties.

func (*RegisteredSubclass[T]) Type

func (r *RegisteredSubclass[T]) Type() Type

Type returns the GType of the registered Go subclass.

type SList

type SList struct {
	// contains filtered or unexported fields
}

SList is a representation of Glib's GSList. A SList must be manually freed by either calling Free() or FreeFull()

func WrapSList

func WrapSList(obj uintptr) *SList

func (*SList) Append

func (v *SList) Append(data uintptr) *SList

func (*SList) Data

func (v *SList) Data() interface{}

Data acts the same as data struct field, but it returns raw unsafe.Pointer as interface. TODO: Align with List struct and add member + logic for `dataWrap func(unsafe.Pointer) interface{}`?

func (*SList) DataRaw

func (v *SList) DataRaw() unsafe.Pointer

DataRaw is a wrapper around the data struct field

func (*SList) DataWrapper

func (v *SList) DataWrapper(fn func(unsafe.Pointer) interface{})

DataWapper sets wrap functions, which is called during NthData() and Data(). It's used to cast raw C data into appropriate Go structures and types every time that data is retreived.

func (*SList) Foreach

func (v *SList) Foreach(fn func(item interface{}))

Foreach acts the same as g_slist_foreach(). No user_data argument is implemented because of Go clojure capabilities.

func (*SList) Free

func (v *SList) Free()

Free is a wrapper around g_slist_free().

func (*SList) FreeFull

func (v *SList) FreeFull()

FreeFull is a wrapper around g_slist_free_full().

func (*SList) Length

func (v *SList) Length() uint

Length is a wrapper around g_slist_length().

func (*SList) Native

func (v *SList) Native() uintptr

func (*SList) Next

func (v *SList) Next() *SList

Next is a wrapper around the next struct field

type SignalHandle

type SignalHandle uint

SignalHandle is the ID of a signal handler.

func ConnectGeneratedClosure

func ConnectGeneratedClosure(
	obj Objector,
	signal string, after bool,
	tramp unsafe.Pointer, f interface{}) SignalHandle

ConnectGeneratedClosure connects the exported trampoline function and a Go closure (in f) to the given signal.

type SourceHandle

type SourceHandle uint

func IdleAdd

func IdleAdd(f interface{}) SourceHandle

IdleAdd adds an idle source to the default main event loop context with the DefaultIdle priority. If f is not a function with no parameter, then IdleAdd will panic.

After running once, the source func will be removed from the main event loop, unless f returns a single bool true.

func IdleAddPriority

func IdleAddPriority(priority Priority, f interface{}) SourceHandle

IdleAddPriority adds an idle source to the default main event loop context with the given priority. Its behavior is the same as IdleAdd.

func TimeoutAdd

func TimeoutAdd(milliseconds uint, f interface{}) SourceHandle

TimeoutAdd adds an timeout source to the default main event loop context. Timeout is in milliseconds. If f is not a function with no parameter, then it will panic.

After running once, the source func will be removed from the main event loop, unless f returns a single bool true.

func TimeoutAddPriority

func TimeoutAddPriority(milliseconds uint, priority Priority, f interface{}) SourceHandle

TimeoutAddPriority is similar to TimeoutAdd with the given priority. Refer to TimeoutAdd for more information.

func TimeoutSecondsAdd

func TimeoutSecondsAdd(seconds uint, f interface{}) SourceHandle

TimeoutSecondsAdd is similar to TimeoutAdd, except with seconds granularity.

func TimeoutSecondsAddPriority

func TimeoutSecondsAddPriority(seconds uint, priority Priority, f interface{}) SourceHandle

TimeoutSecondsAddPriority adds a timeout source with the given priority. Refer to TimeoutSecondsAdd for more information.

type Type

type Type uint

Type is a representation of GLib's GType.

const (
	TypeInvalid   Type = C.G_TYPE_INVALID
	TypeNone      Type = C.G_TYPE_NONE
	TypeInterface Type = C.G_TYPE_INTERFACE
	TypeChar      Type = C.G_TYPE_CHAR
	TypeUchar     Type = C.G_TYPE_UCHAR
	TypeBoolean   Type = C.G_TYPE_BOOLEAN
	TypeInt       Type = C.G_TYPE_INT
	TypeUint      Type = C.G_TYPE_UINT
	TypeLong      Type = C.G_TYPE_LONG
	TypeUlong     Type = C.G_TYPE_ULONG
	TypeInt64     Type = C.G_TYPE_INT64
	TypeUint64    Type = C.G_TYPE_UINT64
	TypeEnum      Type = C.G_TYPE_ENUM
	TypeFlags     Type = C.G_TYPE_FLAGS
	TypeFloat     Type = C.G_TYPE_FLOAT
	TypeDouble    Type = C.G_TYPE_DOUBLE
	TypeString    Type = C.G_TYPE_STRING
	TypePointer   Type = C.G_TYPE_POINTER
	TypeBoxed     Type = C.G_TYPE_BOXED
	TypeParam     Type = C.G_TYPE_PARAM
	TypeObject    Type = C.G_TYPE_OBJECT
	TypeVariant   Type = C.G_TYPE_VARIANT
)

func FundamentalType

func FundamentalType(actual Type) Type

FundamentalType returns the fundamental type of the given actual type.

func TypeFromName

func TypeFromName(typeName string) Type

TypeFromName is a wrapper around g_type_from_name().

func TypeNextBase

func TypeNextBase(leafType, rootType Type) Type

TypeNextBase is a wrapper around g_type_next_base.

func (Type) Depth

func (t Type) Depth() uint

Depth is a wrapper around g_type_depth().

func (Type) Interfaces

func (t Type) Interfaces() []Type

Interfaces returns the interfaces of the given type.

func (Type) IsA

func (t Type) IsA(isAType Type) bool

IsA is a wrapper around g_type_is_a().

func (Type) IsValue

func (t Type) IsValue() bool

IsValue checks whether the passed in type can be used for g_value_init().

func (Type) Name

func (t Type) Name() string

Name is a wrapper around g_type_name().

func (Type) Parent

func (t Type) Parent() Type

Parent is a wrapper around g_type_parent().

func (Type) String

func (t Type) String() string

String calls t.Name(). It satisfies fmt.Stringer.

type TypeMarshaler

type TypeMarshaler struct {
	T Type
	F GValueMarshaler
}

TypeMarshaler represents an actual type and it's associated marshaler.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value is a representation of GLib's GValue.

func AllocateValue

func AllocateValue() *Value

AllocateValue allocates a Value but does not initialize it. It sets a runtime finalizer to call g_value_unset() on the underlying GValue after leaving scope.

func InitValue

func InitValue(t Type) *Value

InitValue is a wrapper around g_value_init() and allocates and initializes a new Value with the Type t. A runtime finalizer is set to call g_value_unset() on the underlying GValue after leaving scope. ValueInit() returns a non-nil error if the allocation failed.

func NewValue

func NewValue(v interface{}) *Value

NewValue converts a Go type to a comparable GValue. It will panic if the given type is unknown. Most Go primitive types and all Object types are supported.

func ValueFromNative

func ValueFromNative(l unsafe.Pointer) *Value

ValueFromNative returns a type-asserted pointer to the Value. It does not add a finalizer into the Value. This function should only be used for autogenerated bindings.

func (*Value) Boxed

func (v *Value) Boxed() unsafe.Pointer

Boxed is a wrapper around g_value_get_boxed().

func (*Value) Enum

func (v *Value) Enum() int

Enum is a wrapper around g_value_get_enum().

func (*Value) Flags

func (v *Value) Flags() uint

Flags is a wrapper around g_value_get_flags().

func (*Value) GoValue

func (v *Value) GoValue() interface{}

GoValue converts a Value to comparable Go type. GoValue() returns InvalidValue if the conversion was unsuccessful. The returned value must be type asserted to the actual Go type.

Unlike the type getters, although this method is not type-safe, it can get any concrete object type out, as long as there exists a marshaler for it.

func (*Value) GoValueAsType

func (v *Value) GoValueAsType(gtype Type) interface{}

GoValueAsType is like GoValue, except it tries to cast into the given gtype instead of the detected underlying type.

func (*Value) Init

func (v *Value) Init(gtype Type)

Init initializes the Value to the given GType. It does nothing if the Value is already initialized.

func (*Value) InitGoValue

func (v *Value) InitGoValue(goValue any)

InitGoValue sets the Go value of the GValue. The GValue MUST NOT HAVE BEEN INITIALIED ALREADY!

func (*Value) IsValue

func (v *Value) IsValue() bool

IsValue checks if value is a valid and initialized GValue structure.

func (*Value) Native

func (v *Value) Native() uintptr

Native returns a pointer to the underlying GValue.

func (*Value) Object

func (v *Value) Object() *Object

Object is a wrapper around g_value_get_object(). The returned object is taken its own reference.

func (*Value) Pointer

func (v *Value) Pointer() unsafe.Pointer

Pointer is a wrapper around g_value_get_pointer().

func (*Value) SetBool

func (v *Value) SetBool(val bool)

SetBool is a wrapper around g_value_set_boolean().

func (*Value) SetDouble

func (v *Value) SetDouble(val float64)

SetDouble is a wrapper around g_value_set_double().

func (*Value) SetFloat

func (v *Value) SetFloat(val float32)

SetFloat is a wrapper around g_value_set_float().

func (*Value) SetInstance

func (v *Value) SetInstance(instance uintptr)

SetInstance is a wrapper around g_value_set_instance().

func (*Value) SetInt

func (v *Value) SetInt(val int)

SetInt is a wrapper around g_value_set_int().

func (*Value) SetInt64

func (v *Value) SetInt64(val int64)

SetInt64 is a wrapper around g_value_set_int64().

func (*Value) SetLong

func (v *Value) SetLong(long int32)

SetLong is a wrapper around g_value_set_long().

func (*Value) SetObject

func (v *Value) SetObject(obj *Object)

SetObject is a wrapper around g_value_set_object().

func (*Value) SetPointer

func (v *Value) SetPointer(p uintptr)

SetPointer is a wrapper around g_value_set_pointer().

func (*Value) SetSchar

func (v *Value) SetSchar(val int8)

SetSChar is a wrapper around g_value_set_schar().

func (*Value) SetString

func (v *Value) SetString(val string)

SetString is a wrapper around g_value_set_string().

func (*Value) SetUchar

func (v *Value) SetUchar(val uint8)

SetUchar is a wrapper around g_value_set_uchar().

func (*Value) SetUint

func (v *Value) SetUint(val uint)

SetUint is a wrapper around g_value_set_uint().

func (*Value) SetUint64

func (v *Value) SetUint64(val uint64)

SetUint64 is a wrapper around g_value_set_uint64().

func (*Value) SetUlong

func (v *Value) SetUlong(ulong uint32)

SetUlong is a wrapper around g_value_set_ulong().

func (*Value) String

func (v *Value) String() string

String is a wrapper around g_value_get_string(). String() returns a non-nil error if g_value_get_string() returned a NULL pointer to distinguish between returning a NULL pointer and returning an empty string.

func (*Value) Type

func (v *Value) Type() (actual Type)

Type returns the Value's actual type. is a wrapper around the G_VALUE_TYPE() macro. It returns TYPE_INVALID if v does not hold a Type, or otherwise returns the Type of v.

To get the fundamental type, use FundamentalType.

func (*Value) TypeName

func (v *Value) TypeName() string

TypeName gets the type name of value.

func (*Value) WalkGoValue

func (v *Value) WalkGoValue(f func(interface{}) bool) (value interface{})

WalkGoValue is like GoValue, except the user is walked through every single possible type of the value until it's no longer possible or until the callback returns true.

type Variant

type Variant struct {
	GVariant *C.GVariant
}

A Variant is a representation of GLib's GVariant.

func (*Variant) GoValue

func (v *Variant) GoValue() interface{}

GoValue converts the variant's value to the Go value. It only supports the following types for now:

s: string
b: bool
d: float64
n: int16
i: int32
x: int64
y: byte
q: uint16
u: uint32
t: uint64

Variants with unsupported types will cause the function to return nil.

func (*Variant) IsContainer

func (v *Variant) IsContainer() bool

IsContainer returns true if the variant is a container and false otherwise.

func (*Variant) IsFloating

func (v *Variant) IsFloating() bool

IsFloating returns true if the variant has a floating reference count. Reference counting is usually handled in the gotk layer, most applications should not call this.

func (*Variant) IsType

func (v *Variant) IsType(t *VariantType) bool

IsType returns true if the variant's type matches t.

func (*Variant) Native

func (v *Variant) Native() uintptr

Native returns a pointer to the underlying GVariant.

func (*Variant) Print

func (v *Variant) Print(typeAnnotate bool) string

Print wraps g_variant_print(). It returns a string understood by g_variant_parse().

func (*Variant) Ref

func (v *Variant) Ref()

Ref is a wrapper around g_variant_ref. Reference counting is usually handled in the gotk layer, most applications should not need to call this.

func (*Variant) RefSink

func (v *Variant) RefSink()

RefSink is a wrapper around g_variant_ref_sink. Reference counting is usually handled in the gotk layer, most applications should not need to call this.

func (*Variant) String

func (v *Variant) String() string

String is a wrapper around g_variant_get_string. If the Variant type is not a string, then Print is called instead. This is done to satisfy fmt.Stringer; it behaves similarly to reflect.Value.String().

func (*Variant) TakeRef

func (v *Variant) TakeRef()

TakeRef is a wrapper around g_variant_take_ref. Reference counting is usually handled in the gotk layer, most applications should not need to call this.

func (*Variant) Type

func (v *Variant) Type() *VariantType

Type returns the VariantType for this variant.

func (*Variant) TypeString

func (v *Variant) TypeString() string

TypeString returns the g variant type string for this variant.

func (*Variant) Unref

func (v *Variant) Unref()

Unref is a wrapper around g_variant_unref. Reference counting is usually handled in the gotk layer, most applications should not need to call this.

type VariantType

type VariantType struct {
	GVariantType *C.GVariantType
}

A VariantType is a wrapper for the GVariantType, which encodes type information for GVariants.

func NewVariantTypeNew

func NewVariantTypeNew(typeString string) *VariantType

NewVariantType is a wrapper around g_variant_type_new.

func (*VariantType) Equal

func (v *VariantType) Equal(to *VariantType) bool

Equal is a wrapper around g_variant_type_equal.

func (*VariantType) Free

func (v *VariantType) Free()

Free is a wrapper around g_variant_type_free. Reference counting is usually handled in the gotk layer, most applications should not call this.

func (*VariantType) IsSubtypeOf

func (v *VariantType) IsSubtypeOf(supertype *VariantType) bool

IsSubtypeOf is a wrapper around g_variant_type_is_subtype_of.

func (*VariantType) Native

func (v *VariantType) Native() uintptr

func (*VariantType) String

func (v *VariantType) String() string

String returns a copy of this VariantType's type string.

type WeakRef

type WeakRef[T Objector] struct {
	// contains filtered or unexported fields
}

WeakRef wraps GWeakRef. It provides a container that allows the user to obtain a weak reference to a CGo GObject. The weak reference is thread-safe and will be cleared when the object is finalized.

func NewWeakRef

func NewWeakRef[T Objector](obj T) *WeakRef[T]

NewWeakRef creates a new weak reference on the Go heap to the given GObject's C pointer. The fact that the returned WeakRef is in Go-allocated memory does not actually add a reference to the object, which is the default behavior.

func (*WeakRef[T]) Get

func (r *WeakRef[T]) Get() T

Get acquires a strong reference to the object if the weak reference is still valid. If the weak reference is no longer valid, Get returns nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL