ShortcutControllerProtocol

public protocol ShortcutControllerProtocol : ListModelProtocol, BuildableProtocol, EventControllerProtocol

GtkShortcutController is an event controller that manages shortcuts.

Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a GtkLabel, or by installing a key binding using [methodGtk.WidgetClass.add_binding], or by adding accelerators to global actions using [methodGtk.Application.set_accels_for_action].

But it is possible to create your own shortcut controller, and add shortcuts to it.

GtkShortcutController implements GListModel for querying the shortcuts that have been added to it.

GtkShortcutController as a GtkBuildable

GtkShortcutControllers can be creates in ui files to set up shortcuts in the same place as the widgets.

An example of a UI definition fragment with GtkShortcutController:

  <object class='GtkButton'>
    <child>
      <object class='GtkShortcutController'>
        <property name='scope'>managed</property>
        <child>
          <object class='GtkShortcut'>
            <property name='trigger'><Control>k</property>
            <property name='action'>activate</property>
          </object>
        </child>
      </object>
    </child>
  </object>

This example creates a [classGtk.ActivateAction] for triggering the activate signal of the GtkButton. See [ctorGtk.ShortcutAction.parse_string] for the syntax for other kinds of GtkShortcutAction. See [ctorGtk.ShortcutTrigger.parse_string] to learn more about the syntax for triggers.

The ShortcutControllerProtocol protocol exposes the methods and properties of an underlying GtkShortcutController instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see ShortcutController. Alternatively, use ShortcutControllerRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkShortcutController instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • shortcut_controller_ptr Default implementation

    Typed pointer to the underlying GtkShortcutController instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkShortcutController instance.

    Declaration

    Swift

    var shortcut_controller_ptr: UnsafeMutablePointer<GtkShortcutController>! { get }
  • Required Initialiser for types conforming to ShortcutControllerProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

ShortcutController Class

  • Bind a ShortcutControllerPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: ShortcutControllerPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a ShortcutController property

    Declaration

    Swift

    @inlinable
    func get(property: ShortcutControllerPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a ShortcutController property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: ShortcutControllerPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

ShortcutController Class: ShortcutControllerProtocol extension (methods and fields)

  • add(shortcut:) Extension method

    Adds shortcut to the list of shortcuts handled by self.

    If this controller uses an external shortcut list, this function does nothing.

    Declaration

    Swift

    @inlinable
    func add<ShortcutT>(shortcut: ShortcutT) where ShortcutT : ShortcutProtocol
  • getMnemonicsModifiers() Extension method

    Gets the mnemonics modifiers for when this controller activates its shortcuts.

    Declaration

    Swift

    @inlinable
    func getMnemonicsModifiers() -> Gdk.ModifierType
  • getScope() Extension method

    Gets the scope for when this controller activates its shortcuts.

    See [methodGtk.ShortcutController.set_scope] for details.

    Declaration

    Swift

    @inlinable
    func getScope() -> GtkShortcutScope
  • remove(shortcut:) Extension method

    Removes shortcut from the list of shortcuts handled by self.

    If shortcut had not been added to controller or this controller uses an external shortcut list, this function does nothing.

    Declaration

    Swift

    @inlinable
    func remove<ShortcutT>(shortcut: ShortcutT) where ShortcutT : ShortcutProtocol
  • setMnemonics(modifiers:) Extension method

    Sets the controller to use the given modifier for mnemonics.

    The mnemonics modifiers determines which modifiers need to be pressed to allow activation of shortcuts with mnemonics triggers.

    GTK normally uses the Alt modifier for mnemonics, except in GtkPopoverMenus, where mnemonics can be triggered without any modifiers. It should be very rarely necessary to change this, and doing so is likely to interfere with other shortcuts.

    This value is only relevant for local shortcut controllers. Global and managed shortcut controllers will have their shortcuts activated from other places which have their own modifiers for activating mnemonics.

    Declaration

    Swift

    @inlinable
    func setMnemonics(modifiers: Gdk.ModifierType)
  • set(scope:) Extension method

    Sets the controller to have the given scope.

    The scope allows shortcuts to be activated outside of the normal event propagation. In particular, it allows installing global keyboard shortcuts that can be activated even when a widget does not have focus.

    With GTK_SHORTCUT_SCOPE_LOCAL, shortcuts will only be activated when the widget has focus.

    Declaration

    Swift

    @inlinable
    func set(scope: GtkShortcutScope)
  • mnemonicsModifiers Extension method

    Gets the mnemonics modifiers for when this controller activates its shortcuts.

    Declaration

    Swift

    @inlinable
    var mnemonicsModifiers: Gdk.ModifierType { get nonmutating set }
  • scope Extension method

    What scope the shortcuts will be handled in.

    Declaration

    Swift

    @inlinable
    var scope: GtkShortcutScope { get nonmutating set }