glib

GLib/GObject main loop and signal foundation for Kit GUI packages

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
examples/main-loop.kitMinimal GLib main-loop example
kit.tomlPackage manifest with metadata and native requirements
src/glib.kitPublic Kit API for GLib, GObject, and Gio bindings
tests/main-loop.test.kitPackage tests
zig/glib.zigZig FFI implementation
zig/kit_ffi.zigShared Zig FFI helpers

Dependencies

No Kit package dependencies.

System packages:

  • macOS: brew install glib pkg-config
  • Ubuntu: apt install libglib2.0-dev pkg-config
  • Fedora: dnf install glib2-devel pkgconf-pkg-config

Installation

kit add gitlab.com/kit-lang/packages/kit-glib.git

Usage

import GLib

unwrap-or-panic = fn(result) =>
  match result
    | Ok value -> value
    | Err err -> panic (show err)

main = fn =>
  loop = unwrap-or-panic (GLib.MainLoop.new no-op)

  GLib.MainLoop.timeout-add 50 (fn(_) =>
    println "tick"
    unwrap-or-panic (GLib.MainLoop.quit loop)
    false
  ) |> Result.unwrap

  GLib.MainLoop.run loop |> Result.unwrap
  GLib.MainLoop.unref loop |> Result.unwrap

main

The current API surface includes:

  • GLib.MainLoop and GLib.MainContext
  • GLib.Object reference helpers
  • GLib.Signal connection helpers
  • GLib.Application and GLib.Action
  • GLib.File, GLib.Settings, GLib.Bytes, and GLib.Variant

Development

Running Examples

Run the example with the interpreter:

kit run examples/main-loop.kit --allow=ffi,file

Compile the example to a native binary:

kit build examples/main-loop.kit -o main-loop --allow=ffi,file && ./main-loop

Running Tests

Run the test suite:

kit test tests/

Running kit dev

Run the standard development workflow:

kit dev

This will:

  1. Format and check Kit source files
  2. Run package tests
  3. Run Zig tests when applicable

Cleaning Build Artifacts

Remove generated files, caches, and native build outputs:

kit task clean

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/glib/, making it available for import as GLib in other projects.

License

This package is released under the MIT License. See LICENSE for details.

Exported Functions & Types

GLibError

GLib main-loop bindings for Kit.

Phase 1 focuses on the event loop and source scheduling primitives that higher-level GTK bindings will need.

Variants

GLibError {message}

MainLoopRef

Opaque reference to a native GMainLoop.

Variants

MainLoopRef {handle}

MainContextRef

Opaque reference to a native GMainContext.

Variants

MainContextRef {handle}

ApplicationRef

Opaque reference to a native GApplication.

Variants

ApplicationRef {handle}

ActionRef

Opaque reference to a native GSimpleAction.

Variants

ActionRef {handle}

ActionGroupRef

Opaque reference to a native GSimpleActionGroup.

Variants

ActionGroupRef {handle}

Opaque reference to a native GMenuModel.

Variants

MenuModelRef {handle}

Opaque reference to a native GMenu.

Variants

MenuRef {handle}

Opaque reference to a native GMenuItem.

Variants

MenuItemRef {handle}

AppInfoRef

Opaque reference to a native GAppInfo.

Variants

AppInfoRef {handle}

FileRef

Opaque reference to a native GFile.

Variants

FileRef {handle}

SettingsRef

Opaque reference to a native GSettings.

Variants

SettingsRef {handle}

BytesRef

Opaque reference to a native GBytes.

Variants

BytesRef {handle}

VariantRef

Opaque reference to a native GVariant.

Variants

VariantRef {handle}

SourceId

Opaque identifier for a registered GLib source.

Variants

SourceId {handle}

SignalHandlerId

Opaque identifier for a connected GLib signal handler.

Variants

SignalHandlerId {handle}

SignalProbeRef

Opaque reference to an internal probe object used for signal marshaling tests.

Variants

SignalProbeRef {handle}

MainLoop

Main-loop API used by GUI packages and GLib-based background tasks.

MainContext

Main-context helpers for driving queued work without a full loop run.

Priority

Common GLib main-loop priority constants.

Object

Generic helpers for supported GObject-backed refs.

Bytes

Byte-buffer helpers for the first GLib data transport slice.

Variant

Narrow GVariant helpers for strings, bools, and ints.

Signal

Generic no-extra-arg signal helpers for supported GObject-backed refs.

Application

Gio application helpers for the current GTK app lifecycle slice.

Action

Simple Gio action helpers for action-map and shortcut plumbing.

ActionGroup

Simple Gio action-group helpers for namespaced menu routing.

Minimal Gio menu-model helpers for menu-backed widgets.

Minimal Gio menu-item helpers for namespaced menu sections.

AppInfo

Narrow Gio application-info helpers for desktop integration queries.

File

Narrow Gio file helpers built around local path access and byte loading.

Settings

Narrow Gio settings helpers for desktop-app configuration reads.

SignalProbe

Internal probe helpers for verifying signal callback marshaling.

Source

Source lifecycle helpers for timers and idle callbacks.