ApplicationRef

public struct ApplicationRef : ApplicationProtocol, GWeakCapturing

GtkApplication is a high-level API for writing applications.

It supports many aspects of writing a GTK application in a convenient fashion, without enforcing a one-size-fits-all 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 [classGtk.Window]s, it is recommended to use it together with [classGtk.ApplicationWindow].

Automatic resources

GtkApplication will automatically load menus from the GtkBuilder resource located at “gtk/menus.ui”, relative to the application’s resource base path (see g_application_set_resource_base_path()). The menu with the ID “menubar” is taken as the application’s menubar. Additional menus (most interesting submenus) can be named and accessed via [methodGtk.Application.get_menu_by_id] which allows for dynamic population of a part of the menu structure.

It is also possible to provide the menubar manually using [methodGtk.Application.set_menubar].

GtkApplication will also automatically setup an icon search path for the default icon theme by appending “icons” to the resource base path. This allows your application to easily store its icons as resources. See [methodGtk.IconTheme.add_resource_path] for more information.

If there is a resource located at “gtk/help-overlay.ui” which defines a [classGtk.ShortcutsWindow] with ID “help_overlay” then GtkApplication associates an instance of this shortcuts window with each [classGtk.ApplicationWindow] and sets up the keyboard accelerator <kbd>Control</kbd>+<kbd>?</kbd> to open it. To create a menu item that displays the shortcuts window, associate the item with the action win.show-help-overlay.

A simple application

A simple example is available in the GTK source code repository

GtkApplication optionally registers with a session manager of the users session (if you set the [propertyGtk.Application: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 [methodGtk.Application.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.

See Also

HowDoI: Using GtkApplication, Getting Started with GTK: Basics

The ApplicationRef type acts as a lightweight Swift reference to an underlying GtkApplication instance. It exposes methods that can operate on this data type through ApplicationProtocol conformance. Use ApplicationRef only as an unowned reference to an existing GtkApplication instance.

  • ptr
    Untyped pointer to the underlying `GtkApplication` instance.
    

    For type-safe access, use the generated, typed pointer application_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

Application Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkApplication>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkApplication>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkApplication>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkApplication>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements ApplicationProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : ApplicationProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> ApplicationRef where T : ApplicationProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ApplicationProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ApplicationProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ApplicationProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ApplicationProtocol.

    Declaration

    Swift

    @inlinable
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ApplicationProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new `GtkApplication` instance.
    

    When using GtkApplication, it is not necessary to call [funcGtk.init] manually. It is called as soon as the application gets registered as the primary instance.

    Concretely, [funcGtk.init] is called in the default handler for the GApplicationstartupsignal. Therefore, `GtkApplication` subclasses should always chain up in their `GApplication`startup handler before using any GTK API.

    Note that commandline arguments are not passed to [funcGtk.init].

    If application_id is not nil, then it must be valid. See g_application_id_is_valid().

    If no application ID is given then some features (most notably application uniqueness) will be disabled.

    Declaration

    Swift

    @inlinable
    init(applicationID: UnsafePointer<CChar>? = nil, flags: GIO.ApplicationFlags)