gtk4

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

README

gtk4

Drive GTK4 from pure Go with CGO_ENABLED=0 — windows, the common controls, GObject signals and the GLib main loop — over ebitengine/purego.

It is the Linux sibling of go-macos/objc: the shared native-toolkit bridge a go-widgets host backend embeds real controls through, so a pixel-drawn app can inlay a real GtkEntry, GtkButton or secure field over its own rendering.

ok, err := gtk4.Init()
// win := gtk4.WindowNew(); win.SetTitle("…"); win.SetDefaultSize(360, 200)
// fixed := gtk4.FixedNew()          // the overlay container
// e := gtk4.EntryNew(); e.SetVisibility(false) // a password field
// b := gtk4.ButtonNewWithLabel("OK")
// b.Connect("clicked", func() { … }) // a GObject signal, as a Go closure
// fixed.Put(e, 10, 10); fixed.Put(b, 10, 44); win.SetChild(fixed); win.Present()

No cgo

libgtk-4, libgobject-2.0 and libglib-2.0 are dlopen'd by soname and every entry point is resolved with purego.RegisterLibFunc. A GObject signal reaches Go through a purego.NewCallback, retained for the process life (GTK holds the C pointer). The package links with no cgo and cross-compiles like any other Go code.

What it binds

Init · WindowNew (+ SetTitle/SetDefaultSize/SetChild/Present) · FixedNew (+ Put/Move — absolute overlay positioning) · ButtonNewWithLabel (+ SetLabel) · EntryNew (+ SetVisibility for a secure field) · CheckButtonNewWithLabel (+ Active/SetActive; grouped check buttons are GTK radios) · LabelNew · Text/SetText (GtkEditable) · SetSizeRequest · SetVisible · Unparent · Connect (signals) · MainLoop (Run/Quit) · IdleAdd (marshal onto the GTK thread).

Platform

Linux only — this is the GTK path; a go-widgets host uses AppKit/Win32 on macOS/Windows. Off Linux the package still compiles (a consumer cross-compiles without a build tag) and every constructor's Init returns ErrUnsupported, so nothing is a build-time surprise. It needs only the runtime libgtk-4 (libgtk-4-1 on Debian/Ubuntu) — no -dev package.

Testing

CI builds it on every platform and runs a live test against real GTK4 under a headless X server (Xvfb) — creating a window, entry, secure field, button and check button, round-tripping their values, and proving a changed signal reaches Go through the main loop.

License

BSD-3-Clause. See LICENSE.

Documentation

Index

Constants

View Source
const (
	ModShift   uint = 1 << 0
	ModControl uint = 1 << 2
	ModAlt     uint = 1 << 3
	ModSuper   uint = 1 << 26
)

GDK modifier-state bits, defined here too so consumer code naming them compiles off Linux.

View Source
const MemoryR8G8B8A8 = 5

MemoryR8G8B8A8 is the GdkMemoryFormat for a go-widgets RGBA frame; defined here too so consumer code naming it compiles off Linux.

Variables

View Source
var ErrUnsupported = errors.New("gtk4: only available on Linux")

ErrUnsupported is returned by Init on any platform without GTK4 (everything but Linux). It is defined on every platform so a portable consumer can test for it with errors.Is.

Functions

func IdleAdd

func IdleAdd(func())

func Init

func Init() (bool, error)

Init reports ErrUnsupported off Linux.

func KeyvalToUnicode added in v0.3.0

func KeyvalToUnicode(uint) rune

The input event controllers do nothing off Linux; a host there uses the platform's own toolkit for input.

func TextureFromRGBA added in v0.2.0

func TextureFromRGBA([]byte, int, int) uintptr

Types

type MainLoop

type MainLoop uintptr

MainLoop is a GLib main loop. Off Linux it does nothing.

func MainLoopNew

func MainLoopNew() MainLoop

func (MainLoop) Quit

func (l MainLoop) Quit()

func (MainLoop) Run

func (l MainLoop) Run()

type Picture added in v0.2.0

type Picture uintptr

Picture is a GtkPicture showing an RGBA frame. Off Linux it does nothing.

func PictureNew added in v0.2.0

func PictureNew() Picture

func (Picture) SetRGBA added in v0.2.0

func (p Picture) SetRGBA([]byte, int, int)

func (Picture) Widget added in v0.2.0

func (p Picture) Widget() Widget

type Widget

type Widget uintptr

Widget is a GTK widget. Off Linux no real one is ever created.

func BoxNew added in v0.5.0

func BoxNew(bool) Widget

func ButtonNewWithLabel

func ButtonNewWithLabel(string) Widget

func CheckButtonNewWithLabel

func CheckButtonNewWithLabel(string) Widget

func ColorNew added in v0.5.0

func ColorNew() Widget

func ComboNew added in v0.5.0

func ComboNew([]string) Widget

func DateNew added in v0.5.0

func DateNew() Widget

func DrawingAreaNew added in v0.2.0

func DrawingAreaNew() Widget

func EntryNew

func EntryNew() Widget

func FixedNew

func FixedNew() Widget

func LabelNew

func LabelNew(string) Widget

func LinkNew added in v0.5.0

func LinkNew(string) Widget

func ListBoxNew added in v0.6.0

func ListBoxNew() Widget

func PopUpNew added in v0.4.0

func PopUpNew([]string) Widget

func ProgressNew added in v0.5.0

func ProgressNew() Widget

Widgets added for the go-widgets host backend; null/no-op/zero off Linux.

func SearchNew added in v0.5.0

func SearchNew() Widget

func SliderNew added in v0.4.0

func SliderNew(float64, float64, float64) Widget

func SpinnerNew added in v0.5.0

func SpinnerNew() Widget

func StepperNew added in v0.5.0

func StepperNew(float64, float64, float64) Widget

func TextViewNew added in v0.5.0

func TextViewNew() Widget

func ToggleButtonNewWithLabel added in v0.5.0

func ToggleButtonNewWithLabel(string) Widget

func WindowNew

func WindowNew() Widget

The constructors return the null widget off Linux; the methods are no-ops or zero, so consumer code that names them still compiles.

func (Widget) Active

func (w Widget) Active() bool

func (Widget) AddTickCallback added in v0.2.4

func (w Widget) AddTickCallback(func() bool) uint64

func (Widget) Append added in v0.5.0

func (w Widget) Append(Widget)

func (Widget) Buffer added in v0.5.0

func (w Widget) Buffer() Widget

func (Widget) ColorHex added in v0.5.0

func (w Widget) ColorHex() string

func (Widget) ComboText added in v0.5.0

func (w Widget) ComboText() string

func (Widget) Connect

func (w Widget) Connect(string, func()) uint64

func (Widget) ConnectBufferChanged added in v0.5.0

func (w Widget) ConnectBufferChanged(func()) uint64

func (Widget) DateISO added in v0.5.0

func (w Widget) DateISO() string

func (Widget) ListBoxAppendText added in v0.6.0

func (w Widget) ListBoxAppendText(string)

func (Widget) Move

func (f Widget) Move(Widget, float64, float64)
func (w Widget) OnActivateLink(func()) uint64

func (Widget) OnKey added in v0.3.0

func (w Widget) OnKey(func(uint, uint, uint, bool))

func (Widget) OnMotion added in v0.3.0

func (w Widget) OnMotion(func(uint, float64, float64))

func (Widget) OnMouseDown added in v0.3.0

func (w Widget) OnMouseDown(func(int, uint, float64, float64))

func (Widget) OnMouseUp added in v0.3.0

func (w Widget) OnMouseUp(func(int, uint, float64, float64))

func (Widget) OnScroll added in v0.3.0

func (w Widget) OnScroll(func(float64, float64, uint))

func (Widget) Present

func (w Widget) Present()

func (Widget) Put

func (f Widget) Put(Widget, float64, float64)

func (Widget) QueueDraw added in v0.2.0

func (w Widget) QueueDraw()

func (Widget) SelectRow added in v0.6.0

func (w Widget) SelectRow(int)

func (Widget) Selected added in v0.4.0

func (w Widget) Selected() int

func (Widget) SelectedRow added in v0.6.0

func (w Widget) SelectedRow() int

func (Widget) SetActive

func (w Widget) SetActive(bool)

func (Widget) SetChild

func (w Widget) SetChild(Widget)

func (Widget) SetColorHex added in v0.5.0

func (w Widget) SetColorHex(string)

func (Widget) SetComboText added in v0.5.0

func (w Widget) SetComboText(string)

func (Widget) SetDateISO added in v0.5.0

func (w Widget) SetDateISO(string)

func (Widget) SetDefaultSize

func (w Widget) SetDefaultSize(int, int)

func (Widget) SetFraction added in v0.5.0

func (w Widget) SetFraction(float64)

func (Widget) SetGroup added in v0.5.0

func (w Widget) SetGroup(Widget)

func (Widget) SetLabel

func (w Widget) SetLabel(string)

func (Widget) SetSelected added in v0.4.0

func (w Widget) SetSelected(int)

func (Widget) SetSizeRequest

func (w Widget) SetSizeRequest(int, int)

func (Widget) SetSpinValue added in v0.5.0

func (w Widget) SetSpinValue(float64)

func (Widget) SetText

func (w Widget) SetText(string)

func (Widget) SetTextViewText added in v0.5.0

func (w Widget) SetTextViewText(string)

func (Widget) SetTitle

func (w Widget) SetTitle(string)

func (Widget) SetValue added in v0.4.0

func (w Widget) SetValue(float64)

func (Widget) SetVisibility

func (w Widget) SetVisibility(bool)

func (Widget) SetVisible

func (w Widget) SetVisible(bool)

func (Widget) SpinValue added in v0.5.0

func (w Widget) SpinValue() float64

func (Widget) Start added in v0.5.0

func (w Widget) Start()

func (Widget) Stop added in v0.5.0

func (w Widget) Stop()

func (Widget) Text

func (w Widget) Text() string

func (Widget) TextViewText added in v0.5.0

func (w Widget) TextViewText() string

func (Widget) Unparent

func (w Widget) Unparent()

func (Widget) Value added in v0.4.0

func (w Widget) Value() float64

Jump to

Keyboard shortcuts

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