Gtk.Application

const Gtk = imports.gi.Gtk;

let application = new Gtk.Application({
    app_menu: value,
    menubar: value,
    register_session: value,
});
  

Gtk.Application is a class that handles many important aspects of a GTK+ application in a convenient fashion, without enforcing a one-size-fits-all application model.

Currently, GtkApplication handles GTK+ initialization, application uniqueness, session management, provides some basic scriptability and desktop shell integration by exporting actions and menus and manages a list of toplevel windows whose life-cycle is automatically tied to the life-cycle of your application.

While GtkApplication works fine with plain #GtkWindows, it is recommended to use it together with Gtk.ApplicationWindow.

When GDK threads are enabled, GtkApplication will acquire the GDK lock when invoking actions that arrive from other processes. The GDK lock is not touched for local action invocations. In order to have actions invoked in a predictable context it is therefore recommended that the GDK lock be held while invoking actions locally with Gio.activate_action. The same applies to actions associated with Gtk.ApplicationWindow and to the 'activate' and 'open' Gio.Application methods.

To set an application menu for a GtkApplication, use Gtk.set_app_menu. The Gio.MenuModel that this function expects is usually constructed using Gtk.Builder, as seen in the following example. To specify a menubar that will be shown by #GtkApplicationWindows, use Gtk.set_menubar. Use the base Gio.ActionMap interface to add actions, to respond to the user selecting these menu items.

GTK+ displays these menus as expected, depending on the platform the application is running on.

<figure label="Menu integration in OS X"> <graphic fileref="bloatpad-osx.png" format="PNG"/> </figure>

<figure label="Menu integration in GNOME"> <graphic fileref="bloatpad-gnome.png" format="PNG"/> </figure>

<figure label="Menu integration in Xfce"> <graphic fileref="bloatpad-xfce.png" format="PNG"/> </figure>

<example id="gtkapplication"><title>A simple application</title> <programlisting> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/bloatpad.c"> <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> </xi:include> </programlisting> </example>

GtkApplication optionally registers with a session manager of the users session (if you set the Gtk.register-session property) and offers various functionality related to the session life-cycle.

An application can block various ways to end the session with the Gtk.inhibit function. Typical use cases for this kind of inhibiting are long-running, uninterruptible operations, such as burning a CD or performing a disk backup. The session manager may not honor the inhibitor, but it can be expected to inform the user about the negative consequences of ending the session while inhibitors are present.

Hierarchy

  • GObject.Object
    • Gio.Application
      • Gtk.Application