class Gtk::PadController

Overview

GtkPadController is an event controller for the pads found in drawing tablets.

Pads are the collection of buttons and tactile sensors often found around the stylus-sensitive area.

These buttons and sensors have no implicit meaning, and by default they perform no action. GtkPadController is provided to map those to Gio#Action objects, thus letting the application give them a more semantic meaning.

Buttons and sensors are not constrained to triggering a single action, some %GDK_SOURCE_TABLET_PAD devices feature multiple "modes". All these input elements have one current mode, which may determine the final action being triggered.

Pad devices often divide buttons and sensors into groups. All elements in a group share the same current mode, but different groups may have different modes. See Gdk::DevicePad#n_groups and Gdk::DevicePad#group_n_modes.

Each of the actions that a given button/strip/ring performs for a given mode is defined by a Gtk#PadActionEntry. It contains an action name that will be looked up in the given Gio#ActionGroup and activated whenever the specified input element and mode are triggered.

A simple example of GtkPadController usage: Assigning button 1 in all modes and pad devices to an "invert-selection" action:

WARNING ⚠️ The following code is in c ⚠️

GtkPadActionEntry *pad_actions[] = {
  { GTK_PAD_ACTION_BUTTON, 1, -1, "Invert selection", "pad-actions.invert-selection" },
  …
};

…
action_group = g_simple_action_group_new ();
action = g_simple_action_new ("pad-actions.invert-selection", NULL);
g_signal_connect (action, "activate", on_invert_selection_activated, NULL);
g_action_map_add_action (G_ACTION_MAP (action_group), action);
…
pad_controller = gtk_pad_controller_new (action_group, NULL);

The actions belonging to rings/strips will be activated with a parameter of type %G_VARIANT_TYPE_DOUBLE bearing the value of the given axis, it is required that those are made stateful and accepting this GVariantType.

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/pad_controller.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Gtk::EventController

current_event : Gdk::Event? current_event, current_event_device : Gdk::Device? current_event_device, current_event_state : Gdk::ModifierType current_event_state, current_event_time : UInt32 current_event_time, name : String? name, name=(value : String) : String
name=(name : String?) : Nil
name=
, propagation_limit : Gtk::PropagationLimit propagation_limit, propagation_limit=(limit : Gtk::PropagationLimit) : Nil propagation_limit=, propagation_phase : Gtk::PropagationPhase propagation_phase, propagation_phase=(phase : Gtk::PropagationPhase) : Nil propagation_phase=, reset : Nil reset, widget : Gtk::Widget widget

Constructor methods inherited from class Gtk::EventController

new
new(*, name : String? = nil, propagation_limit : Gtk::PropagationLimit? = nil, propagation_phase : Gtk::PropagationPhase? = nil, widget : Gtk::Widget? = nil)
new

Class methods inherited from class Gtk::EventController

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new(group : Gio::ActionGroup, pad : Gdk::Device?) : self #

Creates a new GtkPadController that will associate events from @pad to actions.

A %NULL pad may be provided so the controller manages all pad devices generically, it is discouraged to mix GtkPadController objects with %NULL and non-%NULL @pad argument on the same toplevel window, as execution order is not guaranteed.

The GtkPadController is created with no mapped actions. In order to map pad events to actions, use Gtk::PadController#action_entries= or Gtk::PadController#action=.

Be aware that pad events will only be delivered to GtkWindows, so adding a pad controller to any other type of widget will not have an effect.


def self.new #

Initialize a new PadController.


def self.new(*, action_group : Gio::ActionGroup? = nil, name : String? = nil, pad : Gdk::Device? = nil, propagation_limit : Gtk::PropagationLimit? = nil, propagation_phase : Gtk::PropagationPhase? = nil, widget : Gtk::Widget? = nil) #

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def action_entries=(entries : Enumerable(Gtk::PadActionEntry)) : Nil #

A convenience function to add a group of action entries on @controller.

See Gtk#PadActionEntry and Gtk::PadController#action=.


def action_group : Gio::ActionGroup? #

def action_group=(value : Gio::ActionGroup?) : Gio::ActionGroup? #

def pad : Gdk::Device? #

def pad=(value : Gdk::Device?) : Gdk::Device? #

def set_action(type : Gtk::PadActionType, index : Int32, mode : Int32, label : String, action_name : String) : Nil #

Adds an individual action to @controller.

This action will only be activated if the given button/ring/strip number in @index is interacted while the current mode is @mode. -1 may be used for simple cases, so the action is triggered on all modes.

The given @label should be considered user-visible, so internationalization rules apply. Some windowing systems may be able to use those for user feedback.