Skip to content

About

Pascal bindings for GLib/GObject and GTK4, generated from GObject Introspection (GIR)

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

pasgobject

CI License: LGPL v3+

About

pasgobject provides Free Pascal bindings for GLib/GObject, Gio, GTK 4, libadwaita, GtkSourceView, VTE, libsoup, json-glib, libsecret, polkit, WebKitGTK, libportal, libshumate, libnotify, librsvg and gtk4-layer-shell. The GObject core is written by hand. All other bindings are generated at build time from the GObject Introspection data installed on the system. The project is intended for Free Pascal developers who write GTK 4 applications or use GObject-based libraries.

pasgobject replaces pasgtk4, which is no longer maintained.

Dependencies

Dependency Version
Free Pascal 3.2.2 or later
Meson 1.4 or later
Ninja any
GLib, GObject, Gio 2.66 or later
GTK 4.10 or later (optional)
libadwaita 1.4 or later (optional)
GtkSourceView 5.4 or later (optional)
VTE for GTK 4 0.70 or later (optional)
libsoup 3 (optional)
json-glib 1.6 or later (optional)
libsecret 1 (optional)
polkit 1 (optional)
WebKitGTK 6.0 (optional)
libportal, libportal-gtk4 0.7 or later (optional)
libshumate 1 (optional)
libnotify 0.7 (optional)
librsvg 2 (optional)
gtk4-layer-shell 1 (optional)
GIR files for every generated namespace

Arch Linux:

sudo pacman -S fpc meson ninja glib2 gtk4 libadwaita gtksourceview5 vte4 libsoup3 json-glib \
  libsecret polkit webkitgtk-6.0 libportal libportal-gtk4 libshumate libnotify librsvg gtk4-layer-shell gobject-introspection

Debian and Ubuntu:

sudo apt install fpc meson ninja-build libglib2.0-dev libgtk-4-dev libadwaita-1-dev \
  libgtksourceview-5-dev libvte-2.91-gtk4-dev libsoup-3.0-dev libjson-glib-dev libsecret-1-dev libpolkit-gobject-1-dev libwebkitgtk-6.0-dev libportal-dev libportal-gtk4-dev libshumate-dev libnotify-dev librsvg2-dev \
  libgirepository1.0-dev

Fedora:

sudo dnf install fpc meson ninja-build glib2-devel gtk4-devel libadwaita-devel \
  gtksourceview5-devel vte291-gtk4-devel libsoup3-devel json-glib-devel libsecret-devel polkit-devel webkitgtk6.0-devel libportal-devel libportal-gtk4-devel libshumate-devel libnotify-devel librsvg2-devel \
  gobject-introspection-devel

gtk4-layer-shell is packaged under different names on Debian, Ubuntu and Fedora. Install it from your distribution or build it from source if needed.

Build

meson setup build
meson compile -C build
meson test -C build

Options:

Option Default Description
gtk auto Generate the GTK 4 stack. Without it only Gio is generated.
adwaita auto Generate libadwaita. Requires the GTK 4 stack.
gtksourceview auto Generate GtkSourceView 5. Requires the GTK 4 stack.
vte auto Generate VTE for GTK 4. Requires the GTK 4 stack.
soup auto Generate libsoup 3
json auto Generate json-glib
secret auto Generate libsecret
polkit auto Generate polkit
webkit auto Generate WebKitGTK 6 and JavaScriptCore. Requires the GTK 4 stack and libsoup.
portal auto Generate libportal. XdpGtk4 is added when GTK 4 and libportal-gtk4 are available.
shumate auto Generate libshumate. Requires the GTK 4 stack.
notify auto Generate libnotify. Requires the GTK 4 stack.
rsvg auto Generate librsvg. Requires the GTK 4 stack.
layershell auto Generate gtk4-layer-shell. Requires the GTK 4 stack.
gir_dir girdir of gobject-introspection-1.0 Directory with .gir files
fpc_args [] Extra arguments for every fpc call
tests true Build and register the tests
examples true Build the examples

The compiled units end up in build/bindings/units. Programs outside the tree are compiled with:

fpc -Fubuild/bindings/units program.pas

meson install copies the units to <libdir>/pasgobject/units. The .ppu files only work with the same Free Pascal version that built them.

If the linker reports that crtbeginS.o is missing, the fpc.cfg of the system points to an old GCC directory. Pass the current one:

meson setup build -Dfpc_args=-Fl$(dirname $(gcc -print-file-name=crtbeginS.o))

Example

program hello;

{$mode objfpc}{$H+}

uses
  cthreads, GObjects, Gio, Gtk;

type
  THello = class
    procedure Activate(ASender: TGApplication);
  end;

procedure THello.Activate(ASender: TGApplication);
var
  Window: TGtkApplicationWindow;
begin
  Window := TGtkApplicationWindow.New(TGtkApplication(ASender));
  Window.SetTitle('Hello');
  Window.SetChild(TGtkLabel.New('Hello from Pascal'));
  Window.Present;
end;

var
  App: TGtkApplication;
  Handler: THello;
begin
  Handler := THello.Create;
  App := TGtkApplication.New('org.example.Hello', G_APPLICATION_DEFAULT_FLAGS);
  App.ConnectActivate(@Handler.Activate);
  ExitCode := App.Run(argc, argv);
  App.Free;
  Handler.Free;
end.

More programs are in examples.

Lazarus

meson setup writes a Lazarus package to build/lazarus/pasgobject.lpk. Build the project first, then open the package in Lazarus or compile it with lazbuild. See docs/lazarus.md.

Acknowledgments

The bindings are generated from the introspection data maintained by the GLib, GTK and GObject Introspection projects.

Documentation and contributing

License

GNU Lesser General Public License, version 3 or later. See LICENSE.

About

Pascal bindings for GLib/GObject and GTK4, generated from GObject Introspection (GIR)

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages