1.175 <GtkShortcutController>

Class: <GtkShortcutController>

It derives from <GtkEventController>.

Manages keyboard shortcuts and their activation.

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 Gtk.WidgetClass.add_binding, or by adding accelerators to global actions using 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 GtkBuildable

<GtkShortcutController>s can be created in <GtkBuilder> 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'>&lt;Control&gt;k</property>
            <property name='action'>activate</property>
          </object>
        </child>
      </object>
    </child>
  </object>

This example creates a <GtkActivateAction> for triggering the activate signal of the <GtkButton>. See shortcut-action:parse-string for the syntax for other kinds of <GtkShortcutAction>. See shortcut-trigger:parse-string to learn more about the syntax for triggers.

Properties

Property: shortcut-controller:item-type self

The type of items. See list-model:get-item-type.

Its value is a class, or a GType number.

It is read only.

Property: shortcut-controller:mnemonic-modifiers self

The modifiers that need to be pressed to allow mnemonics activation.

Its value is a <GdkModifierType> (or, to set it, a list of its symbols, or one of them).

Set it with (set! (shortcut-controller:mnemonic-modifiers self) value).

Property: shortcut-controller:model self

A list model to take shortcuts from.

Its value is a <GListModel>, or #f.

It can only be set when the object is made, with #:model. It cannot be read.

Property: shortcut-controller:n-items self

The number of items. See list-model:get-n-items.

Its value is an unsigned 32-bit integer.

It is read only.

Property: shortcut-controller:scope self

What scope the shortcuts will be handled in.

Its value is a <GtkShortcutScope> (or, to set it, one of its symbols).

Set it with (set! (shortcut-controller:scope self) value).

Procedures

Method: shortcut-controller:add-shortcut self shortcut
Method: add-shortcut self shortcut

Adds shortcut to the list of shortcuts handled by self.

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

self

Passed: a <GtkShortcutController>.

the controller

shortcut

Passed: a <GtkShortcut>.

a <GtkShortcut>

Method: shortcut-controller:get-mnemonics-modifiers self ⇒ %return
Method: get-mnemonics-modifiers self ⇒ %return

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

self

Passed: a <GtkShortcutController>.

a <GtkShortcutController>

%return

Returned: a <GdkModifierType>.

the controller’s mnemonics modifiers

Method: shortcut-controller:get-scope self ⇒ %return
Method: get-scope self ⇒ %return

Gets the scope for when this controller activates its shortcuts.

See shortcut-controller:set-scope for details.

self

Passed: a <GtkShortcutController>.

a <GtkShortcutController>

%return

Returned: a <GtkShortcutScope>.

the controller’s scope

Procedure: shortcut-controller:new ⇒ %return

Creates a new shortcut controller.

%return

Returned: a <GtkEventController>.

a newly created shortcut controller

Procedure: shortcut-controller:new-for-model model ⇒ %return

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.

model

Passed: a <GListModel>.

a <GListModel> containing shortcuts

%return

Returned: a <GtkEventController>.

a newly created shortcut controller

Method: shortcut-controller:remove-shortcut self shortcut
Method: remove-shortcut self 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.

self

Passed: a <GtkShortcutController>.

the controller

shortcut

Passed: a <GtkShortcut>.

a <GtkShortcut>

Method: shortcut-controller:set-mnemonics-modifiers self modifiers
Method: set-mnemonics-modifiers self 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.

self

Passed: a <GtkShortcutController>.

a <GtkShortcutController>

modifiers

Passed: a <GdkModifierType>, or a list of its symbols, or one of them.

the new mnemonics_modifiers to use

Method: shortcut-controller:set-scope self scope
Method: set-scope self 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 local, shortcuts will only be activated when the widget has focus.

self

Passed: a <GtkShortcutController>.

a <GtkShortcutController>

scope

Passed: a <GtkShortcutScope>, or one of its symbols.

the new scope to use