2017-12-11 18:21:38 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2017, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*/
|
|
|
|
|
2018-06-26 16:19:00 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkeventcontrollerkey
|
|
|
|
* @Short_description: Event controller for key events
|
|
|
|
* @Title: GtkEventControllerKey
|
|
|
|
* @See_also: #GtkEventController
|
|
|
|
*
|
|
|
|
* #GtkEventControllerKey is an event controller meant for situations
|
|
|
|
* where you need access to key events.
|
|
|
|
**/
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
2019-06-02 21:07:27 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2017-12-11 18:21:38 +00:00
|
|
|
#include "gtkprivate.h"
|
2018-03-11 12:38:19 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2017-12-11 18:21:38 +00:00
|
|
|
#include "gtkeventcontrollerprivate.h"
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
|
|
|
#include "gtkbindings.h"
|
2019-02-20 11:48:08 +00:00
|
|
|
#include "gtkenums.h"
|
2019-03-08 15:16:27 +00:00
|
|
|
#include "gtkmain.h"
|
2017-12-11 18:21:38 +00:00
|
|
|
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
|
|
|
|
struct _GtkEventControllerKey
|
|
|
|
{
|
|
|
|
GtkEventController parent_instance;
|
|
|
|
GtkIMContext *im_context;
|
|
|
|
GHashTable *pressed_keys;
|
|
|
|
|
2019-05-13 17:01:51 +00:00
|
|
|
GdkModifierType state;
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
const GdkEvent *current_event;
|
2019-03-08 14:55:27 +00:00
|
|
|
|
|
|
|
guint is_focus : 1;
|
|
|
|
guint contains_focus : 1;
|
2017-12-11 18:21:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkEventControllerKeyClass
|
|
|
|
{
|
|
|
|
GtkEventControllerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
KEY_PRESSED,
|
|
|
|
KEY_RELEASED,
|
|
|
|
MODIFIERS,
|
|
|
|
IM_UPDATE,
|
2018-03-22 17:32:19 +00:00
|
|
|
FOCUS_IN,
|
|
|
|
FOCUS_OUT,
|
2017-12-11 18:21:38 +00:00
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
enum {
|
|
|
|
PROP_IS_FOCUS = 1,
|
|
|
|
PROP_CONTAINS_FOCUS,
|
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
G_DEFINE_TYPE (GtkEventControllerKey, gtk_event_controller_key,
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER)
|
|
|
|
|
|
|
|
static void
|
2019-03-08 14:20:06 +00:00
|
|
|
gtk_event_controller_key_finalize (GObject *object)
|
2017-12-11 18:21:38 +00:00
|
|
|
{
|
|
|
|
GtkEventControllerKey *key = GTK_EVENT_CONTROLLER_KEY (object);
|
|
|
|
|
|
|
|
g_hash_table_destroy (key->pressed_keys);
|
|
|
|
g_clear_object (&key->im_context);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_event_controller_key_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
static void
|
|
|
|
update_focus (GtkEventControllerKey *key,
|
|
|
|
gboolean focus_in,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
gboolean is_focus;
|
|
|
|
gboolean contains_focus;
|
|
|
|
|
|
|
|
switch (detail)
|
|
|
|
{
|
|
|
|
case GDK_NOTIFY_VIRTUAL:
|
|
|
|
case GDK_NOTIFY_NONLINEAR_VIRTUAL:
|
|
|
|
is_focus = FALSE;
|
|
|
|
contains_focus = focus_in;
|
|
|
|
break;
|
|
|
|
case GDK_NOTIFY_ANCESTOR:
|
|
|
|
case GDK_NOTIFY_NONLINEAR:
|
|
|
|
is_focus = focus_in;
|
|
|
|
contains_focus = FALSE;
|
|
|
|
break;
|
|
|
|
case GDK_NOTIFY_INFERIOR:
|
|
|
|
is_focus = focus_in;
|
|
|
|
contains_focus = !focus_in;
|
|
|
|
break;
|
|
|
|
case GDK_NOTIFY_UNKNOWN:
|
|
|
|
default:
|
|
|
|
g_warning ("Unknown focus change detail");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (key));
|
|
|
|
if (key->is_focus != is_focus)
|
|
|
|
{
|
|
|
|
key->is_focus = is_focus;
|
|
|
|
g_object_notify (G_OBJECT (key), "is-focus");
|
|
|
|
}
|
|
|
|
if (key->contains_focus != contains_focus)
|
|
|
|
{
|
|
|
|
key->contains_focus = contains_focus;
|
|
|
|
g_object_notify (G_OBJECT (key), "contains-focus");
|
|
|
|
}
|
|
|
|
g_object_thaw_notify (G_OBJECT (key));
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_key_handle_event (GtkEventController *controller,
|
|
|
|
const GdkEvent *event)
|
|
|
|
{
|
|
|
|
GtkEventControllerKey *key = GTK_EVENT_CONTROLLER_KEY (controller);
|
|
|
|
GdkEventType event_type = gdk_event_get_event_type (event);
|
|
|
|
GdkModifierType state;
|
|
|
|
guint16 keycode;
|
|
|
|
guint keyval;
|
2019-05-13 17:01:51 +00:00
|
|
|
gboolean handled = FALSE;
|
2017-12-11 18:21:38 +00:00
|
|
|
|
2018-03-22 17:32:19 +00:00
|
|
|
if (event_type == GDK_FOCUS_CHANGE)
|
|
|
|
{
|
|
|
|
gboolean focus_in;
|
2019-03-07 05:14:26 +00:00
|
|
|
GdkCrossingMode mode;
|
|
|
|
GdkNotifyType detail;
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
gdk_event_get_focus_in (event, &focus_in);
|
2019-03-07 05:14:26 +00:00
|
|
|
gdk_event_get_crossing_mode (event, &mode);
|
|
|
|
gdk_event_get_crossing_detail (event, &detail);
|
2018-03-22 17:32:19 +00:00
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
update_focus (key, focus_in, detail);
|
|
|
|
|
2019-03-08 15:16:27 +00:00
|
|
|
key->current_event = event;
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
if (focus_in)
|
2019-03-07 05:14:26 +00:00
|
|
|
g_signal_emit (controller, signals[FOCUS_IN], 0, mode, detail);
|
2018-03-22 17:32:19 +00:00
|
|
|
else
|
2019-03-07 05:14:26 +00:00
|
|
|
g_signal_emit (controller, signals[FOCUS_OUT], 0, mode, detail);
|
2018-03-22 17:32:19 +00:00
|
|
|
|
2019-03-08 15:16:27 +00:00
|
|
|
key->current_event = NULL;
|
|
|
|
|
2018-03-22 17:32:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
if (event_type != GDK_KEY_PRESS && event_type != GDK_KEY_RELEASE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (key->im_context &&
|
|
|
|
gtk_im_context_filter_keypress (key->im_context, (GdkEventKey *) event))
|
|
|
|
{
|
|
|
|
g_signal_emit (controller, signals[IM_UPDATE], 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
key->current_event = event;
|
|
|
|
|
2019-05-13 17:01:51 +00:00
|
|
|
gdk_event_get_state (event, &state);
|
|
|
|
if (key->state != state)
|
2017-12-11 18:21:38 +00:00
|
|
|
{
|
2019-05-13 17:01:51 +00:00
|
|
|
gboolean unused;
|
2017-12-11 18:21:38 +00:00
|
|
|
|
2019-05-13 17:01:51 +00:00
|
|
|
key->state = state;
|
|
|
|
g_signal_emit (controller, signals[MODIFIERS], 0, state, &unused);
|
2017-12-11 18:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gdk_event_get_keycode (event, &keycode);
|
|
|
|
gdk_event_get_keyval (event, &keyval);
|
|
|
|
|
|
|
|
if (event_type == GDK_KEY_PRESS)
|
|
|
|
{
|
|
|
|
g_signal_emit (controller, signals[KEY_PRESSED], 0,
|
|
|
|
keyval, keycode, state, &handled);
|
|
|
|
if (handled)
|
|
|
|
g_hash_table_add (key->pressed_keys, GUINT_TO_POINTER (keyval));
|
|
|
|
}
|
|
|
|
else if (event_type == GDK_KEY_RELEASE)
|
|
|
|
{
|
|
|
|
g_signal_emit (controller, signals[KEY_RELEASED], 0,
|
|
|
|
keyval, keycode, state);
|
|
|
|
|
|
|
|
handled = g_hash_table_lookup (key->pressed_keys, GUINT_TO_POINTER (keyval)) != NULL;
|
|
|
|
g_hash_table_remove (key->pressed_keys, GUINT_TO_POINTER (keyval));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
handled = FALSE;
|
|
|
|
|
|
|
|
key->current_event = NULL;
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_key_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEventControllerKey *controller = GTK_EVENT_CONTROLLER_KEY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_IS_FOCUS:
|
|
|
|
g_value_set_boolean (value, controller->is_focus);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_CONTAINS_FOCUS:
|
|
|
|
g_value_set_boolean (value, controller->contains_focus);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:21:38 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_key_class_init (GtkEventControllerKeyClass *klass)
|
|
|
|
{
|
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2019-03-08 14:20:06 +00:00
|
|
|
object_class->finalize = gtk_event_controller_key_finalize;
|
2019-03-08 14:55:27 +00:00
|
|
|
object_class->get_property = gtk_event_controller_key_get_property;
|
2017-12-11 18:21:38 +00:00
|
|
|
controller_class->handle_event = gtk_event_controller_key_handle_event;
|
|
|
|
|
2019-03-08 14:55:27 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerKey:is-focus:
|
|
|
|
*
|
|
|
|
* Whether focus is in the controllers widget itself,
|
|
|
|
* as opposed to in a descendent widget. See
|
|
|
|
* #GtkEventControllerKey:contains-focus.
|
|
|
|
*
|
|
|
|
* When handling focus events, this property is updated
|
|
|
|
* before #GtkEventControllerKey::focus-in or
|
|
|
|
* #GtkEventControllerKey::focus-out are emitted.
|
|
|
|
*/
|
|
|
|
props[PROP_IS_FOCUS] =
|
|
|
|
g_param_spec_boolean ("is-focus",
|
|
|
|
P_("Is Focus"),
|
|
|
|
P_("Whether the focus is in the controllers widget"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerKey:contains-focus:
|
|
|
|
*
|
|
|
|
* Whether focus is in a descendant of the controllers widget.
|
|
|
|
* See #GtkEventControllerKey:is-focus.
|
|
|
|
*
|
|
|
|
* When handling focus events, this property is updated
|
|
|
|
* before #GtkEventControllerKey::focus-in or
|
|
|
|
* #GtkEventControllerKey::focus-out are emitted.
|
|
|
|
*/
|
|
|
|
props[PROP_CONTAINS_FOCUS] =
|
|
|
|
g_param_spec_boolean ("contains-focus",
|
|
|
|
P_("Contains Focus"),
|
|
|
|
P_("Whether the focus is in a descendant of the controllers widget"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
|
|
|
|
|
2018-07-02 09:18:26 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::key-pressed:
|
|
|
|
* @controller: the object which received the signal.
|
|
|
|
* @keyval: the pressed key.
|
|
|
|
* @keycode: the raw code of the pressed key.
|
|
|
|
* @state: the bitmask, representing the state of modifier keys and pointer buttons. See #GdkModifierType.
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever a key is pressed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the key press was handled, %FALSE otherwise.
|
|
|
|
*/
|
2017-12-11 18:21:38 +00:00
|
|
|
signals[KEY_PRESSED] =
|
|
|
|
g_signal_new (I_("key-pressed"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2019-06-02 21:07:27 +00:00
|
|
|
0, _gtk_boolean_handled_accumulator, NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__UINT_UINT_FLAGS,
|
2017-12-11 18:21:38 +00:00
|
|
|
G_TYPE_BOOLEAN, 3, G_TYPE_UINT, G_TYPE_UINT, GDK_TYPE_MODIFIER_TYPE);
|
2019-06-02 21:07:27 +00:00
|
|
|
g_signal_set_va_marshaller (signals[KEY_PRESSED],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_BOOLEAN__UINT_UINT_FLAGSv);
|
2018-12-14 23:28:54 +00:00
|
|
|
|
2018-07-02 09:18:26 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::key-released:
|
|
|
|
* @controller: the object which received the signal.
|
|
|
|
* @keyval: the released key.
|
|
|
|
* @keycode: the raw code of the released key.
|
|
|
|
* @state: the bitmask, representing the state of modifier keys and pointer buttons. See #GdkModifierType.
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever a key is released.
|
|
|
|
*/
|
2017-12-11 18:21:38 +00:00
|
|
|
signals[KEY_RELEASED] =
|
|
|
|
g_signal_new (I_("key-released"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2019-06-02 21:07:27 +00:00
|
|
|
0, NULL, NULL,
|
|
|
|
_gtk_marshal_VOID__UINT_UINT_FLAGS,
|
2017-12-11 18:21:38 +00:00
|
|
|
G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, GDK_TYPE_MODIFIER_TYPE);
|
2019-06-02 21:07:27 +00:00
|
|
|
g_signal_set_va_marshaller (signals[KEY_RELEASED],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_VOID__UINT_UINT_FLAGSv);
|
2018-12-14 23:28:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::modifiers:
|
|
|
|
* @controller: the object which received the signal.
|
|
|
|
* @keyval: the released key.
|
|
|
|
* @state: the bitmask, representing the new state of modifier keys and
|
|
|
|
* pointer buttons. See #GdkModifierType.
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever the state of modifier keys and pointer
|
|
|
|
* buttons change.
|
|
|
|
*/
|
2017-12-11 18:21:38 +00:00
|
|
|
signals[MODIFIERS] =
|
|
|
|
g_signal_new (I_("modifiers"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2019-06-02 21:07:27 +00:00
|
|
|
0, NULL,
|
|
|
|
NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__FLAGS,
|
2017-12-11 18:21:38 +00:00
|
|
|
G_TYPE_BOOLEAN, 1, GDK_TYPE_MODIFIER_TYPE);
|
2019-06-02 21:07:27 +00:00
|
|
|
g_signal_set_va_marshaller (signals[MODIFIERS],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_BOOLEAN__FLAGSv);
|
2018-12-14 23:28:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::im-update:
|
|
|
|
* @controller: the object which received the signal.
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever the input method context filters away a
|
|
|
|
* keypress and prevents the @controller receiving it. See
|
|
|
|
* gtk_event_controller_key_set_im_context() and
|
|
|
|
* gtk_im_context_filter_keypress().
|
|
|
|
*/
|
2017-12-11 18:21:38 +00:00
|
|
|
signals[IM_UPDATE] =
|
|
|
|
g_signal_new (I_("im-update"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL,
|
2019-03-07 05:14:26 +00:00
|
|
|
NULL,
|
2017-12-11 18:21:38 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2018-12-14 23:28:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::focus-in:
|
|
|
|
* @controller: the object which received the signal.
|
2019-03-07 05:14:26 +00:00
|
|
|
* @mode: crossing mode indicating what caused this change
|
|
|
|
* @detail: detail indication where the focus is coming from
|
2018-12-14 23:28:54 +00:00
|
|
|
*
|
2019-03-08 14:55:27 +00:00
|
|
|
* This signal is emitted whenever the widget controlled
|
|
|
|
* by the @controller or one of its descendants) is given
|
|
|
|
* the keyboard focus.
|
2018-12-14 23:28:54 +00:00
|
|
|
*/
|
2018-03-22 17:32:19 +00:00
|
|
|
signals[FOCUS_IN] =
|
|
|
|
g_signal_new (I_("focus-in"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL,
|
2019-03-07 05:14:26 +00:00
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
2,
|
|
|
|
GDK_TYPE_CROSSING_MODE,
|
|
|
|
GDK_TYPE_NOTIFY_TYPE);
|
2018-12-14 23:28:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerKey::focus-out:
|
|
|
|
* @controller: the object which received the signal.
|
2019-03-07 05:14:26 +00:00
|
|
|
* @mode: crossing mode indicating what caused this change
|
|
|
|
* @detail: detail indication where the focus is going
|
2018-12-14 23:28:54 +00:00
|
|
|
*
|
2019-03-08 14:55:27 +00:00
|
|
|
* This signal is emitted whenever the widget controlled
|
|
|
|
* by the @controller (or one of its descendants) loses
|
|
|
|
* the keyboard focus.
|
2018-12-14 23:28:54 +00:00
|
|
|
*/
|
2018-03-22 17:32:19 +00:00
|
|
|
signals[FOCUS_OUT] =
|
|
|
|
g_signal_new (I_("focus-out"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_KEY,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL,
|
2019-03-07 05:14:26 +00:00
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
2,
|
|
|
|
GDK_TYPE_CROSSING_MODE,
|
|
|
|
GDK_TYPE_NOTIFY_TYPE);
|
2017-12-11 18:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_key_init (GtkEventControllerKey *controller)
|
|
|
|
{
|
|
|
|
controller->pressed_keys = g_hash_table_new (NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2018-12-14 23:28:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_new:
|
|
|
|
*
|
|
|
|
* Creates a new event controller that will handle key events.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkEventControllerKey
|
|
|
|
**/
|
2017-12-11 18:21:38 +00:00
|
|
|
GtkEventController *
|
2018-04-20 17:58:06 +00:00
|
|
|
gtk_event_controller_key_new (void)
|
2017-12-11 18:21:38 +00:00
|
|
|
{
|
2019-03-07 05:14:26 +00:00
|
|
|
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_KEY, NULL);
|
2017-12-11 18:21:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 23:28:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_set_im_context:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
* @im_context: a #GtkIMContext
|
|
|
|
*
|
|
|
|
* Sets the input method context of the key @controller.
|
|
|
|
**/
|
2017-12-11 18:21:38 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_key_set_im_context (GtkEventControllerKey *controller,
|
|
|
|
GtkIMContext *im_context)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller));
|
|
|
|
g_return_if_fail (!im_context || GTK_IS_IM_CONTEXT (im_context));
|
|
|
|
|
|
|
|
if (controller->im_context)
|
|
|
|
gtk_im_context_reset (controller->im_context);
|
|
|
|
|
|
|
|
g_set_object (&controller->im_context, im_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_get_im_context:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
*
|
2018-12-14 23:28:54 +00:00
|
|
|
* Gets the input method context of the key @controller.
|
2017-12-11 18:21:38 +00:00
|
|
|
*
|
2018-12-14 23:28:54 +00:00
|
|
|
* Returns: (transfer none): the #GtkIMContext
|
2017-12-11 18:21:38 +00:00
|
|
|
**/
|
|
|
|
GtkIMContext *
|
|
|
|
gtk_event_controller_key_get_im_context (GtkEventControllerKey *controller)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller), NULL);
|
|
|
|
|
|
|
|
return controller->im_context;
|
|
|
|
}
|
2018-03-11 12:38:19 +00:00
|
|
|
|
2018-12-14 23:28:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_forward:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
*
|
|
|
|
* Forwards the current event of this @controller to a @widget.
|
|
|
|
*
|
2019-03-08 15:19:12 +00:00
|
|
|
* This function can only be used in handlers for the
|
|
|
|
* #GtkEventControllerKey::key-pressed,
|
|
|
|
* #GtkEventControllerKey::key-released
|
|
|
|
* or
|
|
|
|
* #GtkEventControllerKey::modifiers
|
|
|
|
* signals.
|
|
|
|
*
|
2018-12-14 23:28:54 +00:00
|
|
|
* Returns: whether the @widget handled the event
|
|
|
|
**/
|
2018-03-11 12:38:19 +00:00
|
|
|
gboolean
|
|
|
|
gtk_event_controller_key_forward (GtkEventControllerKey *controller,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
g_return_val_if_fail (controller->current_event != NULL, FALSE);
|
2019-03-08 15:21:02 +00:00
|
|
|
g_return_val_if_fail (gdk_event_get_event_type (controller->current_event) == GDK_KEY_PRESS ||
|
|
|
|
gdk_event_get_event_type (controller->current_event) == GDK_KEY_RELEASE, FALSE);
|
2018-03-11 12:38:19 +00:00
|
|
|
|
|
|
|
if (!gtk_widget_get_realized (widget))
|
|
|
|
gtk_widget_realize (widget);
|
|
|
|
|
2019-02-20 11:48:08 +00:00
|
|
|
if (gtk_widget_run_controllers (widget, controller->current_event,
|
|
|
|
GTK_PHASE_CAPTURE))
|
2018-03-11 12:38:19 +00:00
|
|
|
return TRUE;
|
2019-02-20 11:48:08 +00:00
|
|
|
if (gtk_widget_run_controllers (widget, controller->current_event,
|
|
|
|
GTK_PHASE_TARGET))
|
|
|
|
return TRUE;
|
|
|
|
if (gtk_widget_run_controllers (widget, controller->current_event,
|
|
|
|
GTK_PHASE_BUBBLE))
|
2018-03-11 12:38:19 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2019-03-31 18:04:35 +00:00
|
|
|
if (gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *)controller->current_event))
|
|
|
|
return TRUE;
|
|
|
|
|
2018-03-11 12:38:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-03-22 16:54:52 +00:00
|
|
|
|
2018-12-14 23:28:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_get_group:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
*
|
|
|
|
* Gets the key group of the current event of this @controller.
|
|
|
|
* See gdk_event_get_key_group().
|
|
|
|
*
|
|
|
|
* Returns: the key group
|
|
|
|
**/
|
2018-03-22 16:54:52 +00:00
|
|
|
guint
|
|
|
|
gtk_event_controller_key_get_group (GtkEventControllerKey *controller)
|
|
|
|
{
|
|
|
|
guint group;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller), FALSE);
|
|
|
|
g_return_val_if_fail (controller->current_event != NULL, FALSE);
|
|
|
|
|
|
|
|
gdk_event_get_key_group (controller->current_event, &group);
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
2019-03-08 15:16:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_get_focus_origin:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
*
|
|
|
|
* Returns the widget that was holding focus before.
|
|
|
|
*
|
|
|
|
* This function can only be used in handlers for the
|
|
|
|
* #GtkEventControllerKey::focus-in and
|
|
|
|
* #GtkEventControllerKey::focus-out signals.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the previous focus
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_event_controller_key_get_focus_origin (GtkEventControllerKey *controller)
|
|
|
|
{
|
|
|
|
gboolean focus_in;
|
|
|
|
GtkWidget *origin;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller), NULL);
|
|
|
|
g_return_val_if_fail (controller->current_event != NULL, NULL);
|
|
|
|
g_return_val_if_fail (gdk_event_get_event_type (controller->current_event) == GDK_FOCUS_CHANGE, NULL);
|
|
|
|
|
|
|
|
gdk_event_get_focus_in (controller->current_event, &focus_in);
|
|
|
|
|
|
|
|
if (focus_in)
|
|
|
|
origin = (GtkWidget *)gdk_event_get_related_target (controller->current_event);
|
|
|
|
else
|
|
|
|
origin = (GtkWidget *)gdk_event_get_target (controller->current_event);
|
|
|
|
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_key_get_focus_target:
|
|
|
|
* @controller: a #GtkEventControllerKey
|
|
|
|
*
|
|
|
|
* Returns the widget that will be holding focus afterwards.
|
|
|
|
*
|
|
|
|
* This function can only be used in handlers for the
|
|
|
|
* #GtkEventControllerKey::focus-in and
|
|
|
|
* #GtkEventControllerKey::focus-out signals.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the next focus
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_event_controller_key_get_focus_target (GtkEventControllerKey *controller)
|
|
|
|
{
|
|
|
|
gboolean focus_in;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (controller), NULL);
|
|
|
|
g_return_val_if_fail (controller->current_event != NULL, NULL);
|
|
|
|
g_return_val_if_fail (gdk_event_get_event_type (controller->current_event) == GDK_FOCUS_CHANGE, NULL);
|
|
|
|
|
|
|
|
gdk_event_get_focus_in (controller->current_event, &focus_in);
|
|
|
|
|
|
|
|
if (focus_in)
|
|
|
|
return (GtkWidget *)gdk_event_get_target (controller->current_event);
|
|
|
|
else
|
|
|
|
return (GtkWidget *)gdk_event_get_related_target (controller->current_event);
|
|
|
|
}
|