gendata

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0 Imports: 8 Imported by: 8

Documentation

Overview

Package gendata contains data used to generate GTK4 bindings for Go. It exists primarily to be used externally.

Index

Constants

View Source
const Module = "github.com/diamondburned/gotk4/pkg"

Variables

View Source
var ConversionProcessors = []ConversionProcessor{
	ProcessCallback("Gio-2.AsyncReadyCallback", func(conv *Converter) {

		conv.Results[0].Skip = true
	}),
}
View Source
var DynamicLinkNamespaces = []string{
	"GLib-2",
	"GObject-2",
	"Graphene-1",
	"GdkPixbuf-2",
}

DynamicLinkNamespaces lists namespaces that should be generated directly using Cgo. It includes important core packages as well as packages that are small but performance-sensitive.

View Source
var ExtraGoContents = map[string]string{
	"gtk/v3/gtk.go": `
		// Init binds to the gtk_init() function. Argument parsing is not
		// supported.
		func Init() {
			C.gtk_init(nil, nil)
		}
	`,
}

ExtraGoContents contains the contents of files that are appended into generated outputs. It is used to add custom implementations of missing functions.

View Source
var Filters = []FilterMatcher{
	AbsoluteFilter("C.cairo_image_surface_create"),

	AbsoluteFilter("GLib.VA_COPY_AS_ARRAY"),

	AbsoluteFilter("cairo.ScaledFont"),
	AbsoluteFilter("cairo.FontType"),

	FileFilter("gsk/broadway/gskbroadwayrenderer.h"),

	AbsoluteFilter("GLib.unichar_to_utf8"),

	AbsoluteFilter("GLib.nullify_pointer"),

	AbsoluteFilter("GLib.idle_add_full"),
	AbsoluteFilter("GLib.timeout_add_full"),
	AbsoluteFilter("GLib.timeout_add_seconds_full"),

	AbsoluteFilter("GLib.log_set_writer_func"),
	AbsoluteFilter("GLib.log_set_handler_full"),

	AbsoluteFilter("GLib.unix_error_quark"),
	AbsoluteFilter("Gio.networking_init"),

	AbsoluteFilter("Gio.SimpleProxyResolver.set_ignore_hosts"),

	AbsoluteFilter("C.GdkPixbufModule"),
	AbsoluteFilter("GdkPixbuf.PixbufNonAnim"),
	AbsoluteFilter("GdkPixbuf.PixbufModulePattern"),
	AbsoluteFilter("GdkPixbuf.PixbufFormat.domain"),
	AbsoluteFilter("GdkPixbuf.PixbufFormat.flags"),
	AbsoluteFilter("GdkPixbuf.PixbufFormat.disabled"),

	AbsoluteFilter("GLib.IOChannel.read"),
	AbsoluteFilter("GLib.Bytes.new_take"),
	AbsoluteFilter("GLib.Bytes.new_static"),
	AbsoluteFilter("GLib.Bytes.unref_to_data"),
	AbsoluteFilter("GLib.Bytes.unref_to_array"),

	RegexFilter(`GLib.Source\..*unix.*`),
	RegexFilter(`Gio.Subprocess`),
	RegexFilter(`Gio.SubprocessLauncher`),

	RegexFilter(`Gio..*[Uu]nix.*`),

	AbsoluteFilter("GLib.Pid"),

	AbsoluteFilter("GLib.PollFD"),

	FileFilter("gfiledescriptorbased."),
	FileFilter("gunix"),

	FileFilterNamespace("GLib", "gasyncqueue."),
	FileFilterNamespace("GLib", "gatomic."),
	FileFilterNamespace("GLib", "gbacktrace."),
	FileFilterNamespace("GLib", "gbase64."),
	FileFilterNamespace("GLib", "gbitlock."),
	FileFilterNamespace("GLib", "gdataset."),
	FileFilterNamespace("GLib", "gdate."),
	FileFilterNamespace("GLib", "gerror."),
	FileFilterNamespace("GLib", "ghook."),
	FileFilterNamespace("GLib", "glib-unix."),
	FileFilterNamespace("GLib", "glist."),
	FileFilterNamespace("GLib", "gmacros."),
	FileFilterNamespace("GLib", "gmem."),
	FileFilterNamespace("GLib", "gnetworking."),
	FileFilterNamespace("GLib", "gprintf."),
	FileFilterNamespace("GLib", "grcbox."),
	FileFilterNamespace("GLib", "grefcount."),
	FileFilterNamespace("GLib", "grefstring."),
	FileFilterNamespace("GLib", "gslice."),
	FileFilterNamespace("GLib", "gslist."),
	FileFilterNamespace("GLib", "gstdio."),
	FileFilterNamespace("GLib", "gstrfuncs."),
	FileFilterNamespace("GLib", "gstringchunk."),
	FileFilterNamespace("GLib", "gstring."),
	FileFilterNamespace("GLib", "gstrvbuilder."),
	FileFilterNamespace("GLib", "gtestutils."),
	FileFilterNamespace("GLib", "gthread."),
	FileFilterNamespace("GLib", "gthreadpool."),
	FileFilterNamespace("GLib", "gtrashstack."),
	FileFilterNamespace("Gio", "gsettingsbackend."),

	FileFilter("gskglrenderer."),
	FileFilter("gsknglrenderer."),
	FileFilter("gskvulkanrenderer."),
	FileFilter("gdesktopappinfo."),

	FileFilter("gtkpagesetupunixdialog"),
	FileFilter("gtkprintunixdialog"),
	FileFilter("gtkprinter"),
	FileFilter("gtkprintjob"),
	FileFilter("gdkprivate"),

	AbsoluteFilter("C.g_array_get_type"),
	AbsoluteFilter("C.g_byte_array_get_type"),
	AbsoluteFilter("C.g_bytes_get_type"),
	AbsoluteFilter("C.g_ptr_array_get_type"),
	AbsoluteFilter("C.gtk_header_bar_accessible_get_type"),
	AbsoluteFilter("C.gdk_pixbuf_non_anim_get_type"),
	AbsoluteFilter("C.gdk_window_destroy_notify"),
	AbsoluteFilter("C.gtk_print_capabilities_get_type"),
	AbsoluteFilter("C.GdkPixbufAnimationClass"),
	AbsoluteFilter("C.GdkPixbufAnimationIterClass"),

	AbsoluteFilter("Gtk-3.HeaderBarAccessibleClass"),

	AbsoluteFilter("C.g_source_remove"),
}

Filters defines a list of GIR types to be filtered. The map key is the namespace, and the values are list of names.

View Source
var GenerateExceptions = []string{
	"cairo-1",
}

GenerateExceptions contains the keys of the underneath ImportOverrides map.

View Source
var ImportOverrides = map[string]string{}

ImportOverrides is the list of imports to defer to another library, usually because it's tedious or impossible to generate.

Not included: coreglib (gotk3/gotk3/glib).

View Source
var Main = genmain.Data{
	Module:                Module,
	Packages:              Packages,
	ImportOverrides:       ImportOverrides,
	PkgExceptions:         PkgExceptions,
	GenerateExceptions:    GenerateExceptions,
	PkgGenerated:          PkgGenerated,
	Preprocessors:         Preprocessors,
	Postprocessors:        Postprocessors,
	ExtraGoContents:       ExtraGoContents,
	Filters:               Filters,
	ProcessConverters:     ConversionProcessors,
	DynamicLinkNamespaces: DynamicLinkNamespaces,
	SingleFile:            true,
}

Main contains all of gendata's variables as one big genmain.Data value.

This stays ugly just because it's the main gotk4 package with exposed gendata. Don't actually do this; just make a global genmain.Data instead.

View Source
var Packages = []genmain.Package{
	{Name: "gobject-introspection-1.0", Namespaces: []string{
		"GLib-2",
		"GObject-2",
		"Gio-2",
		"cairo-1",
	}},
	{Name: "gdk-pixbuf-2.0"},
	{Name: "graphene-1.0"},
	{Name: "atk"},
	{Name: "pango", Namespaces: []string{
		"Pango-1",
		"PangoCairo-1",
	}},
	{Name: "gtk4"},
	{Name: "gtk+-3.0"},
}

Packages lists pkg-config packages and optionally the namespaces to be generated. If the list of namespaces is nil, then everything is generated.

View Source
var PkgExceptions = []string{
	"core",
	"cairo",
	"go.mod",
	"go.sum",
	"LICENSE",
}

PkgExceptions contains a list of file names that won't be deleted off of pkg/.

View Source
var PkgGenerated = []string{
	"atk",
	"gdk",
	"gdkpixbuf",
	"gdkpixdata",
	"gdkwayland",
	"gdkx11",
	"gio",
	"glib",
	"gobject",
	"graphene",
	"gsk",
	"gtk",
	"pango",
	"pangocairo",
}

PkgGenerated contains a list of file names that are packages generated using the given Packages list. It is manually updated.

Postprocessors is similar to Append, except the caller can mutate the package in a more flexible manner.

View Source
var Preprocessors = []Preprocessor{

	TypeRenamer("GLib-2.file_test", "test_file"),

	TypeRenamer("Gtk-4.Native", "NativeSurface"),

	TypeRenamer("Gtk-4.Editable", "EditableTextWidget"),

	RenameEnumMembers("Pango-1.AttrType", "ATTR_(.*)", "ATTR_TYPE_$1"),
	RenameEnumMembers("Gsk-4.RenderNodeType", ".*", "${0}_TYPE"),
	RenameEnumMembers("Gdk-3.EventType", ".*", "${0}_TYPE"),

	RemoveCIncludes("Gio-2.0.gir", "gio/gdesktopappinfo.h"),

	RemovePkgconfig("Gio-2.0.gir", "gio-unix-2.0"),
	RemoveCIncludes("Gio-2.0.gir", "gio/gfiledescriptorbased.h", `/gio/gunix.*\.h/`),

	RemoveRecordFields("GLib-2.LogField", "length", "value"),

	ModifyParamDirections("Gio-2.InputStream.read", map[string]string{
		"buffer": "in",
		"count":  "in",
	}),
	ModifyParamDirections("Gio-2.InputStream.read_async", map[string]string{
		"buffer": "in",
		"count":  "in",
	}),
	ModifyParamDirections("Gio-2.InputStream.read_all", map[string]string{
		"buffer": "in",
		"count":  "in",
	}),
	ModifyParamDirections("Gio-2.InputStream.read_all_async", map[string]string{
		"buffer": "in",
		"count":  "in",
	}),
	ModifyParamDirections("Gio-2.Socket.receive", map[string]string{
		"buffer": "in",
		"size":   "in",
	}),
	ModifyParamDirections("Gio-2.Socket.receive_from", map[string]string{
		"buffer": "in",
		"size":   "in",
	}),
	ModifyParamDirections("Gio-2.Socket.receive_with_blocking", map[string]string{
		"buffer": "in",
		"size":   "in",
	}),
	ModifyParamDirections("Gio-2.DBusInterfaceGetPropertyFunc", map[string]string{
		"error": "out",
	}),

	ModifyCallable("Gdk-4.Clipboard.read_async", func(c *gir.CallableAttrs) {

		p := FindParameter(c, "mime_types")
		p.Array = &gir.Array{
			CType: "const char**",
			Type:  &gir.Type{Name: "utf8"},
		}
	}),

	MustIntrospect("Gdk-4.Clipboard.set_text"),
	MustIntrospect("Gdk-4.Clipboard.set_texture"),

	ModifyCallable("GLib-2.Variant.get_string", func(c *gir.CallableAttrs) {
		c.ReturnValue.Array = &gir.Array{
			CType:          "const gchar*",
			Type:           &gir.Type{Name: "gchar"},
			Length:         new(int),
			ZeroTerminated: new(bool),
		}
	}),

	ModifySignal("Gio-2.Application::open", func(sig *gir.Signal) {
		param := FindParameterFromSlice(sig.Parameters.Parameters, "files")
		param.Array.CType = "GFile**"
	}),

	PreprocessorFunc(func(repos gir.Repositories) {
		variant := repos.FindFullType("GLib-2.Variant").Type.(*gir.Record)
		for _, method := range variant.Methods {
			returnsGVariant := true &&
				method.ReturnValue != nil &&
				method.ReturnValue.Type != nil &&
				method.ReturnValue.Type.CType == "GVariant*"

			if returnsGVariant && !method.ReturnValue.Nullable {

				method.ReturnValue.Nullable = true
			}
		}
	}),

	modifyBufferInsert("Gtk-4.TextBuffer.insert"),
	modifyBufferInsert("Gtk-4.TextBuffer.insert_markup"),
	modifyBufferInsert("Gtk-4.TextBuffer.insert_at_cursor"),
	modifyBufferInsert("Gtk-4.TextBuffer.insert_interactive"),
	modifyBufferInsert("Gtk-4.TextBuffer.insert_interactive_at_cursor"),
	modifyBufferInsert("Gtk-4.TextBuffer.set_text"),

	modifyBufferInsert("Gtk-3.TextBuffer.insert"),
	modifyBufferInsert("Gtk-3.TextBuffer.insert_markup"),
	modifyBufferInsert("Gtk-3.TextBuffer.insert_at_cursor"),
	modifyBufferInsert("Gtk-3.TextBuffer.insert_interactive"),
	modifyBufferInsert("Gtk-3.TextBuffer.insert_interactive_at_cursor"),
	modifyBufferInsert("Gtk-3.TextBuffer.set_text"),
}

Preprocessors defines a list of preprocessors that the main generator will use. It's mostly used for renaming colliding types/identifiers.

Functions

func GLibAliases

func GLibAliases(nsgen *girgen.NamespaceGenerator) error

GLibAliases generates aliases in the glib/v2 package to the core/glib package. It is generated so that users don't have to import both glib packages.

func GLibDateTime

func GLibDateTime(nsgen *girgen.NamespaceGenerator) error

GLibDateTime generates NewTimeZoneFromGo and NewDateTimeFromGo.

func GLibLogs

func GLibLogs(nsgen *girgen.NamespaceGenerator) error

GLibLogs adds the following g_log_* functions:

  • g_log_set_handler
  • g_log_set_handler_full

func GLibVariantIter

func GLibVariantIter(nsgen *girgen.NamespaceGenerator) error

func GdkPixbufFromImage

func GdkPixbufFromImage(nsgen *girgen.NamespaceGenerator) error

func GioArrayUseBytes

func GioArrayUseBytes(nsgen *girgen.NamespaceGenerator) error

GioArrayUseBytes is the postprocessor that adds gio/v2.UseBytes.

func GtkLockOSThread

func GtkLockOSThread(nsgen *girgen.NamespaceGenerator) error

func GtkNewDialog

func GtkNewDialog(nsgen *girgen.NamespaceGenerator) error

func GtkNewMessageDialog

func GtkNewMessageDialog(nsgen *girgen.NamespaceGenerator) error

func ImportGError

func ImportGError(nsgen *girgen.NamespaceGenerator) error

ImportGError ensures that gerror is imported.

Types

type Package

type Package struct {
	PkgName    string   // pkg-config name
	Namespaces []string // refer to ./cmd/gir_namespaces
}

func (*Package) HasNamespace

func (pkg *Package) HasNamespace(n *gir.Namespace) bool

HasNamespace returns true if the package allows all namespaces or has the given namespace in the list.

Jump to

Keyboard shortcuts

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