Class ShortcutController

All Implemented Interfaces:
PointerInterface

public class ShortcutController extends EventController
`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 [method@Gtk.WidgetClass.add_binding], or by adding accelerators
to global actions using [method@Gtk.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`:
```xml
<object class='GtkButton'>
<child>
<object class='GtkShortcutController'>
<property name='scope'>managed</property>
<child>
<object class='GtkShortcut'>
<property name='trigger'>&lt;Control&gt;k</property>
<property name='action'>activate</property>
</object>
</child>
</object>
</child>
</object>
```

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

https://docs.gtk.org/gtk4/class.ShortcutController.html

  • Constructor Details

    • ShortcutController

      public ShortcutController(PointerContainer pointer)
    • ShortcutController

      public ShortcutController()
      Creates a new shortcut controller.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newForModelShortcutController

      public static ShortcutController newForModelShortcutController(@Nonnull ListModel model)
      Creates a new shortcut controller that takes its shortcuts from
      the given list model.

      A controller created by this function does not let you add or
      remove individual shortcuts using the shortcut controller api,
      but you can change the contents of the model.
      Parameters:
      model - a `GListModel` containing shortcuts
      Returns:
      a newly created shortcut controller
    • addShortcut

      public void addShortcut(@Nonnull Shortcut shortcut)
      Adds @shortcut to the list of shortcuts handled by @self.

      If this controller uses an external shortcut list, this
      function does nothing.
      Parameters:
      shortcut - a `GtkShortcut`
    • getMnemonicsModifiers

      public int getMnemonicsModifiers()
      Gets the mnemonics modifiers for when this controller activates its shortcuts.
      Returns:
      the controller's mnemonics modifiers
    • getScope

      public int getScope()
      Gets the scope for when this controller activates its shortcuts.

      See [method@Gtk.ShortcutController.set_scope] for details.
      Returns:
      the controller's scope
    • removeShortcut

      public void removeShortcut(@Nonnull Shortcut shortcut)
      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.
      Parameters:
      shortcut - a `GtkShortcut`
    • setMnemonicsModifiers

      public void setMnemonicsModifiers(int modifiers)
      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 `GtkPopoverMenu`s,
      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.
      Parameters:
      modifiers - the new mnemonics_modifiers to use
    • setScope

      public void setScope(int scope)
      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.
      Parameters:
      scope - the new scope to use
    • asListModel

      public ListModel asListModel()
      Implements interface ListModel. Call this to get access to interface functions.
      Returns:
      ListModel
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Returns:
      Buildable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()