Marcin Jahn | Dev Notebook
  • Home
  • Programming
  • Technologies
  • Projects
  • About
  • A logo of LinkedIn
  • A logo of GitHub
  • cirro.services
  • Home
  • Programming
  • Technologies
  • Projects
  • About
  • An icon of the .NET section .NET
    • HTTPClient
    • Async
      • How Async Works
      • TAP Tips
    • Equality
    • Comparisons
    • Enumerables
    • Unit Tests
    • Generic Host
    • Logging
    • Configuration
    • Records
    • gRPC
    • Platform Invoke
    • ASP.NET Core
      • Overview
      • Middleware
      • Razor Pages
      • Routing in Razor Pages
      • Web APIs
      • Filters
      • Identity
      • Validation
      • Tips
    • Entity Framework Core
      • Overview
      • Testing
      • Tips
  • An icon of the Angular section Angular
    • Overview
    • Components
    • Directives
    • Services and DI
    • Routing
    • Observables (RxJS)
    • Forms
    • Pipes
    • HTTP
    • Modules
    • NgRx
    • Angular Universal
    • Tips
    • Standalone Components
  • An icon of the JavaScript section JavaScript
    • OOP
    • JavaScript - The Weird Parts
    • JS Functions
    • ES Modules
    • Node.js
    • Axios Tips
    • TypeScript
      • TypeScript Environment Setup
      • TypeScript Tips
    • React
      • React Routing
      • MobX
    • Advanced Vue.js Features
  • An icon of the Rust section Rust
    • Overview
    • Cargo
    • Basics
    • Ownership
    • Structures
    • Enums
    • Organization
    • Collections
    • Error Handling
    • Generics
    • Traits
    • Lifetimes
    • Closures
    • Raw Pointers
    • Smart Pointers
    • Concurrency
    • Testing
    • Tips
  • An icon of the C/C++ section C/C++
    • Structs and Classes
    • Compilation
    • Pointers
    • Strings
    • Dynamic Memory
    • argc and argv Visualization
  • An icon of the GTK section GTK
    • Overview
    • GJS
  • An icon of the CSS section CSS
    • Responsive Design
    • CSS Tips
    • CSS Pixel
  • An icon of the Unity section Unity
    • Unity
  • An icon of the Functional Programming section Functional Programming
    • Fundamentals of Functional Programming
    • .NET Functional Features
    • Signatures
    • Function Composition
    • Error Handling
    • Partial Application
    • Modularity
    • Category Theory
      • Overview
      • Monoid
      • Other Magmas
      • Functors
  • An icon of the Algorithms section Algorithms
    • Big O Notation
    • Array
    • Linked List
    • Queue
    • Hash Table and Set
    • Tree
    • Sorting
    • Searching
  • An icon of the Architecture section Architecture
    • What is architecture?
    • Domain-Driven Design
    • ASP.NET Core Projects
  • An icon of the .NET section .NET
    • HTTPClient
    • Async
      • How Async Works
      • TAP Tips
    • Equality
    • Comparisons
    • Enumerables
    • Unit Tests
    • Generic Host
    • Logging
    • Configuration
    • Records
    • gRPC
    • Platform Invoke
    • ASP.NET Core
      • Overview
      • Middleware
      • Razor Pages
      • Routing in Razor Pages
      • Web APIs
      • Filters
      • Identity
      • Validation
      • Tips
    • Entity Framework Core
      • Overview
      • Testing
      • Tips
  • An icon of the Angular section Angular
    • Overview
    • Components
    • Directives
    • Services and DI
    • Routing
    • Observables (RxJS)
    • Forms
    • Pipes
    • HTTP
    • Modules
    • NgRx
    • Angular Universal
    • Tips
    • Standalone Components
  • An icon of the JavaScript section JavaScript
    • OOP
    • JavaScript - The Weird Parts
    • JS Functions
    • ES Modules
    • Node.js
    • Axios Tips
    • TypeScript
      • TypeScript Environment Setup
      • TypeScript Tips
    • React
      • React Routing
      • MobX
    • Advanced Vue.js Features
  • An icon of the Rust section Rust
    • Overview
    • Cargo
    • Basics
    • Ownership
    • Structures
    • Enums
    • Organization
    • Collections
    • Error Handling
    • Generics
    • Traits
    • Lifetimes
    • Closures
    • Raw Pointers
    • Smart Pointers
    • Concurrency
    • Testing
    • Tips
  • An icon of the C/C++ section C/C++
    • Structs and Classes
    • Compilation
    • Pointers
    • Strings
    • Dynamic Memory
    • argc and argv Visualization
  • An icon of the GTK section GTK
    • Overview
    • GJS
  • An icon of the CSS section CSS
    • Responsive Design
    • CSS Tips
    • CSS Pixel
  • An icon of the Unity section Unity
    • Unity
  • An icon of the Functional Programming section Functional Programming
    • Fundamentals of Functional Programming
    • .NET Functional Features
    • Signatures
    • Function Composition
    • Error Handling
    • Partial Application
    • Modularity
    • Category Theory
      • Overview
      • Monoid
      • Other Magmas
      • Functors
  • An icon of the Algorithms section Algorithms
    • Big O Notation
    • Array
    • Linked List
    • Queue
    • Hash Table and Set
    • Tree
    • Sorting
    • Searching
  • An icon of the Architecture section Architecture
    • What is architecture?
    • Domain-Driven Design
    • ASP.NET Core Projects

GTK

GTK is a tookit for creating GUI apps, mostly targeting Linux systems and the Gnome Platform. It uses the GObject (GLib Object System) base type system.

GLib and GObject

GObject is a library that is a base for many other Gnome libraries (like GTK). It is a common base layer providing OOP paradigm to the C language. It may be seen as an alternative to C++ or ObjectiveC, since it enables developers to create classes, but in this case, directly in C (however, in a rather tedious way, since it’s still “just” C)!

GObject is a part of GLib and uses the same version numbers. GLib contains:

  • GObject - type system
  • GThread - threading
  • GIO - I/O operations
  • others…

QT

A kind of similar thing to GLib in the KDE world is QtCore.

Some features of GObject that are often used in GTK apps are:

  • the GObject root base type
  • signals (like events in .NET)

Bindings

The GObject libraries are written in the C language. However, there are a bunch of bindings for many other programming languages that open the toolkit to a vast group of developers. Examples of supported languages include:

  • C (obviously)
  • JavaScript
  • Python
  • Rust
  • Vala
  • C#
  • and more…

Since there is a lot of GObject-based libraries, there is an established way of generating bindings for them - GObject Introspection. The bindings, under the hood, call the C libraries code via mechanisms similar to PInvoke.

GTK is a base for many other GUI frameworks, often those that taget multiple operating systems (like Avalonia UI or Tauri). These frameworks often rely on GTK 3, since GTK 4 is still relatively new.

Software Stack

Nowadays, the applications developed in GTK use the following tooling/services:

  • GTK as a base for the app and widgets library
  • other GObject-based libs - lots of libraries, like Soup for HTTP
  • language bindings
  • Libadwaita as both the widgets library and design system
  • Gnome Builder as an IDE
  • Flatpak for packaging the apps
  • Flathub for distribution of the apps

Resources

Popularity of GTK apps development would certainly benefit from more materials being available on the topic. These are the resources that I find the most valuable:

  • Gnome Developer Portal - a documentation and guides for developing for the Gnome Platform.
  • GJS Guide - the Guide to GJS with a bunch of information about GObject itself.
  • elementary Developer Docs - Elementary OS encourages the use of Vala and Granite widgets library, which might not be the most popular technologies out there, but the docs are a solid guide to building GTK apps, which will be useful for any developer starting out with GTK.
  • Gtk Inspector - an app that allows for live inspection of GTK apps, similar to dev tools in web browsers.
  • GTK API Documentation - API reference for GTK, GDK, Pango, and many other libs
  • GJS API - all the APIs exposed by GJS
  • Vala API - same as above, but for Vala
GJS →
© 2023 Marcin Jahn | Dev Notebook | All Rights Reserved. | Built with Astro.