Skip to content

chris-armstrong/ocgtk

Repository files navigation

ocgtk - OCaml Bindings for GTK

This repository contains OCaml bindings for the GTK toolkit version 4

Repository Structure

<repo root>/
├── gir/               # Bundled GIR data files (9 namespaces)
├── gir_gen/           # GIR code generator (standalone dune project, OCaml >= 5.3)
├── ocgtk/             # GTK 4 bindings (dune project, OCaml >= 5.0)
├── ci/                # Docker-based multi-distro CI scripts
└── scripts/           # Helper scripts (e.g. generate-bindings.sh)
  • gir_gen/ — reads GIR XML files and generates OCaml/C FFI bindings. Only needed when regenerating bindings; not a runtime dependency of ocgtk.
  • ocgtk/ — the GTK 4 binding library itself. Depends only on GTK system libraries.

Status

The bindings are under active development and rapidly approaching a stable release.

Features currently supported:

  • Bindings for GTK and its dependencies (GLib, GObject, Pango, Gdk, GdkPixbuf, GIO)
  • Classes, interfaces, records, enumerations and bitfields
  • Constructors, methods, properties and signals^[1]
  • GObject interface implementation in the type hierarchy (:> coercions work)

Currently unsupported:

  • Signals with multiple parameters
  • Standalone namespace-level functions (e.g. gtk_show_uri)
  • Accessing fields of non-opaque record types
  • Callbacks

^[1]: Only signals with no parameters are currently supported.

Quick Start

Install system dependencies (Ubuntu/Debian):

sudo apt-get install libgtk-4-dev libcairo2-dev

Install OCaml dependencies and build:

# To use the bindings only (OCaml >= 5.0):
opam install ./ocgtk --deps-only --with-test

# Also install the code generator (OCaml >= 5.3):
opam install ./ocgtk ./gir_gen --deps-only --with-test

dune build

Comparison and relation to lablgtk

lablgtk is a GTK 3 bindings library for OCaml which served as the inspiration and some of the basis for this project. The main difference is that ocgtk uses generated bindings instead of manually written bindings. Although efforts have been made to generate code in a similar style, the APIs are different and not compatible.

Requirements

  • OCaml >= 5.0 (ocgtk); >= 5.3 (gir_gen code generator)
  • GTK 4 >= 4.0 (bindings are generated up to 4.14.5 — older versions will throw runtime errors on unavailable APIs)
  • Dune >= 3.13

License

Copyright (C) 2025 Chris Armstrong, with some parts derived from lablgtk3 (see LICENSE).

This library is distributed under the terms of the GNU Library General Public License v2, with the special exception on linking described in the LICENSE file.

Documentation

📚 Architecture - architecture and design documentation (mix of LLM and manually written)

Key Documents

Resources

About

GTK4 bindings for OCaml

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors