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,7 @@ void fl_remove_pending_event(FlKeyEventPlugin* self, uint64_t id) {
104106 id);
105107 return ;
106108 }
109+ gdk_event_free (reinterpret_cast <GdkEvent*>(self->pendingEvents .front ().second ));
107110 self->pendingEvents .pop_front ();
108111}
109112
@@ -134,12 +137,15 @@ void fl_handle_response(GObject* object,
134137 gpointer user_data) {
135138 _KeyEventResponseData* data =
136139 reinterpret_cast <_KeyEventResponseData*>(user_data);
137- if (data->self == nullptr ) {
138- // Weak pointer to the plugin has been destroyed.
139- return ;
140- }
140+
141+ // Will also return if the weak pointer has been destroyed.
141142 g_return_if_fail (FL_IS_KEY_EVENT_PLUGIN (data->self ));
142143
144+ FlKeyEventPlugin* self = data->self ;
145+ // Don't need to weak pointer anymore.
146+ g_object_remove_weak_pointer (G_OBJECT (self),
147+ reinterpret_cast <gpointer*>(&(data->self )));
148+
143149 g_autoptr (GError) error = nullptr ;
144150 FlBasicMessageChannel* messageChannel = FL_BASIC_MESSAGE_CHANNEL (object);
145151 FlValue* message =
@@ -152,7 +158,7 @@ void fl_handle_response(GObject* object,
152158 g_autoptr (FlValue) handled_value = fl_value_lookup_string (message, " handled" );
153159 bool handled = false ;
154160 if (handled_value != nullptr ) {
155- GdkEventKey* event = fl_find_pending_event (data-> self , data->id );
161+ GdkEventKey* event = fl_find_pending_event (self, data->id );
156162 if (event == nullptr ) {
157163 g_warning (
158164 " Event response for event id %ld received, but event was received "
@@ -161,16 +167,16 @@ void fl_handle_response(GObject* object,
161167 } else {
162168 handled = fl_value_get_bool (handled_value);
163169 if (!handled) {
164- if (data-> self ->text_input_plugin != nullptr ) {
170+ if (self->text_input_plugin != nullptr ) {
165171 // Propagate the event to the text input plugin.
166172 handled = fl_text_input_plugin_filter_keypress (
167- data-> self ->text_input_plugin , event);
173+ self->text_input_plugin , event);
168174 }
169175 // Dispatch the event to other GTK windows if the text input plugin
170176 // didn't handle it. We keep track of the event id so we can recognize
171177 // the event when our window receives it again and not respond to it. If
172178 // the response callback is set, then use that instead.
173- if (!handled && data-> self ->response_callback == nullptr ) {
179+ if (!handled && self->response_callback == nullptr ) {
174180 gdk_event_put (reinterpret_cast <GdkEvent*>(event));
175181 }
176182 }
@@ -180,11 +186,11 @@ void fl_handle_response(GObject* object,
180186 if (handled) {
181187 // Because the event was handled, we no longer need to track it. Unhandled
182188 // events will be removed when the event is re-dispatched to the window.
183- fl_remove_pending_event (data-> self , data->id );
189+ fl_remove_pending_event (self, data->id );
184190 }
185191
186- if (data-> self ->response_callback != nullptr ) {
187- data-> self ->response_callback (object, message, handled, data->user_data );
192+ if (self->response_callback != nullptr ) {
193+ self->response_callback (object, message, handled, data->user_data );
188194 }
189195}
190196
0 commit comments