44
55#include " flutter/shell/platform/linux/fl_key_event_plugin.h"
66
7+ #include < gtk/gtk.h>
78#include < deque>
89
910#include " flutter/shell/platform/linux/fl_text_input_plugin.h"
@@ -42,6 +43,9 @@ static void fl_key_event_plugin_dispose(GObject* object) {
4243 FlKeyEventPlugin* self = FL_KEY_EVENT_PLUGIN (object);
4344
4445 g_clear_object (&self->channel );
46+ g_object_remove_weak_pointer (
47+ G_OBJECT (self->text_input_plugin ),
48+ reinterpret_cast <gpointer*>(&(self->text_input_plugin )));
4549
4650 G_OBJECT_CLASS (fl_key_event_plugin_parent_class)->dispose (object);
4751}
@@ -50,9 +54,7 @@ static void fl_key_event_plugin_class_init(FlKeyEventPluginClass* klass) {
5054 G_OBJECT_CLASS (klass)->dispose = fl_key_event_plugin_dispose;
5155}
5256
53- static void fl_key_event_plugin_init (FlKeyEventPlugin* self) {
54- self->pendingEvents .clear ();
55- }
57+ static void fl_key_event_plugin_init (FlKeyEventPlugin* self) {}
5658
5759FlKeyEventPlugin* fl_key_event_plugin_new (
5860 FlBinaryMessenger* messenger,
@@ -104,6 +106,8 @@ void fl_remove_pending_event(FlKeyEventPlugin* self, uint64_t id) {
104106 id);
105107 return ;
106108 }
109+ gdk_event_free (
110+ reinterpret_cast <GdkEvent*>(self->pendingEvents .front ().second ));
107111 self->pendingEvents .pop_front ();
108112}
109113
@@ -134,12 +138,15 @@ void fl_handle_response(GObject* object,
134138 gpointer user_data) {
135139 _KeyEventResponseData* data =
136140 reinterpret_cast <_KeyEventResponseData*>(user_data);
137- if (data->self == nullptr ) {
138- // Weak pointer to the plugin has been destroyed.
139- return ;
140- }
141+
142+ // Will also return if the weak pointer has been destroyed.
141143 g_return_if_fail (FL_IS_KEY_EVENT_PLUGIN (data->self ));
142144
145+ FlKeyEventPlugin* self = data->self ;
146+ // Don't need to weak pointer anymore.
147+ g_object_remove_weak_pointer (G_OBJECT (self),
148+ reinterpret_cast <gpointer*>(&(data->self )));
149+
143150 g_autoptr (GError) error = nullptr ;
144151 FlBasicMessageChannel* messageChannel = FL_BASIC_MESSAGE_CHANNEL (object);
145152 FlValue* message =
@@ -152,7 +159,7 @@ void fl_handle_response(GObject* object,
152159 g_autoptr (FlValue) handled_value = fl_value_lookup_string (message, " handled" );
153160 bool handled = false ;
154161 if (handled_value != nullptr ) {
155- GdkEventKey* event = fl_find_pending_event (data-> self , data->id );
162+ GdkEventKey* event = fl_find_pending_event (self, data->id );
156163 if (event == nullptr ) {
157164 g_warning (
158165 " Event response for event id %ld received, but event was received "
@@ -161,16 +168,16 @@ void fl_handle_response(GObject* object,
161168 } else {
162169 handled = fl_value_get_bool (handled_value);
163170 if (!handled) {
164- if (data-> self ->text_input_plugin != nullptr ) {
171+ if (self->text_input_plugin != nullptr ) {
165172 // Propagate the event to the text input plugin.
166173 handled = fl_text_input_plugin_filter_keypress (
167- data-> self ->text_input_plugin , event);
174+ self->text_input_plugin , event);
168175 }
169176 // Dispatch the event to other GTK windows if the text input plugin
170177 // didn't handle it. We keep track of the event id so we can recognize
171178 // the event when our window receives it again and not respond to it. If
172179 // the response callback is set, then use that instead.
173- if (!handled && data-> self ->response_callback == nullptr ) {
180+ if (!handled && self->response_callback == nullptr ) {
174181 gdk_event_put (reinterpret_cast <GdkEvent*>(event));
175182 }
176183 }
@@ -180,11 +187,11 @@ void fl_handle_response(GObject* object,
180187 if (handled) {
181188 // Because the event was handled, we no longer need to track it. Unhandled
182189 // events will be removed when the event is re-dispatched to the window.
183- fl_remove_pending_event (data-> self , data->id );
190+ fl_remove_pending_event (self, data->id );
184191 }
185192
186- if (data-> self ->response_callback != nullptr ) {
187- data-> self ->response_callback (object, message, handled, data->user_data );
193+ if (self->response_callback != nullptr ) {
194+ self->response_callback (object, message, handled, data->user_data );
188195 }
189196}
190197
0 commit comments