GTK
01 / 02

GTK: GObject, Styling & Application Structure

GTK: GObject, Styling & Application Structure

GObject: The Underlying Object System

Since plain C has no built-in classes or inheritance, GObject provides that object-oriented infrastructure (classes, properties, the signal mechanism itself) as a separate library. GTK's entire widget hierarchy is built using GObject's conventions.

CSS Styling

/* GTK supports CSS-like syntax for customizing widget appearance,
   conceptually similar to web CSS */
button {
  background-color: #3584e4;
  border-radius: 6px;
  color: white;
}

GtkBuilder: Declarative UI Definition

<!-- window.ui -- structure separate from application logic,
     similar to HTML/JavaScript on the web -->
<interface>
  <object class="GtkWindow" id="window">
    <child>
      <object class="GtkButton" id="button">
        <property name="label">Click me</property>
      </object>
    </child>
  </object>
</interface>

Application Structure: GtkApplication

// Handles startup/activation, main window management, and the
// underlying event loop
int main(int argc, char **argv) {
    GtkApplication *app = gtk_application_new(
        "com.example.MyApp",
        G_APPLICATION_DEFAULT_FLAGS
    );
    g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
    return g_application_run(G_APPLICATION(app), argc, argv);
}

GTK vs. Electron & Qt

  • GTK integrates natively with the host desktop (especially Linux/GNOME) and has a smaller runtime footprint than Electron, which bundles a full browser engine.

  • Qt is a similarly-purposed C++ toolkit underlying KDE -- both GTK and Qt solve native cross-platform GUI development with different language/ecosystem choices.

  • GTK follows a retained-mode architecture -- widget objects persist in memory, and GTK decides when to redraw, unlike immediate-mode approaches common in some game UI libraries.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free