[gtk/readonly-events-1: 139/149] Bring back im context focus-in/out
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/readonly-events-1: 139/149] Bring back im context focus-in/out
- Date: Fri, 21 Feb 2020 06:00:55 +0000 (UTC)
commit 0c96b2d8f749eada0391a0315c7235841e3300da
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Feb 20 07:30:15 2020 -0500
Bring back im context focus-in/out
The key controller still needs to track focus,
in order to emit these signals when required.
gtk/gtkeventcontrollerkey.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkeventcontrollerkey.c b/gtk/gtkeventcontrollerkey.c
index 79103f407c..ea2b4c994d 100644
--- a/gtk/gtkeventcontrollerkey.c
+++ b/gtk/gtkeventcontrollerkey.c
@@ -52,8 +52,7 @@ struct _GtkEventControllerKey
GdkEvent *current_event;
- guint is_focus : 1;
- guint contains_focus : 1;
+ gboolean is_focus;
};
struct _GtkEventControllerKeyClass
@@ -145,6 +144,44 @@ gtk_event_controller_key_handle_event (GtkEventController *controller,
return handled;
}
+static void
+gtk_event_controller_key_handle_crossing (GtkEventController *controller,
+ const GtkCrossingData *crossing,
+ double x,
+ double y)
+{
+ GtkEventControllerKey *key = GTK_EVENT_CONTROLLER_KEY (controller);
+ GtkWidget *widget = gtk_event_controller_get_widget (controller);
+ gboolean start_crossing, end_crossing;
+ gboolean is_focus;
+
+ if (crossing->type != GTK_CROSSING_FOCUS)
+ return;
+
+ start_crossing = crossing->direction == GTK_CROSSING_OUT &&
+ widget == crossing->old_target;
+ end_crossing = crossing->direction == GTK_CROSSING_IN &&
+ widget == crossing->new_target;
+
+ if (!start_crossing && !end_crossing)
+ return;
+
+ is_focus = end_crossing;
+
+ if (key->is_focus != is_focus)
+ {
+ key->is_focus = is_focus;
+
+ if (key->im_context)
+ {
+ if (is_focus)
+ gtk_im_context_focus_in (key->im_context);
+ else
+ gtk_im_context_focus_out (key->im_context);
+ }
+ }
+}
+
static void
gtk_event_controller_key_class_init (GtkEventControllerKeyClass *klass)
{
@@ -153,6 +190,7 @@ gtk_event_controller_key_class_init (GtkEventControllerKeyClass *klass)
object_class->finalize = gtk_event_controller_key_finalize;
controller_class->handle_event = gtk_event_controller_key_handle_event;
+ controller_class->handle_crossing = gtk_event_controller_key_handle_crossing;
/**
* GtkEventControllerKey::key-pressed:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]