| Flutter Linux Embedder |

fl_key_event.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/fl_key_event.h"
6
7 static void dispose_origin_from_gdk_event(gpointer origin) {
8 g_return_if_fail(origin != nullptr);
9 gdk_event_free(reinterpret_cast<GdkEvent*>(origin));
10 }
11
12 FlKeyEvent* fl_key_event_new_from_gdk_event(GdkEvent* raw_event) {
13 g_return_val_if_fail(raw_event != nullptr, nullptr);
14 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(raw_event);
15 GdkEventType type = event->type;
16 g_return_val_if_fail(type == GDK_KEY_PRESS || type == GDK_KEY_RELEASE,
17 nullptr);
18 FlKeyEvent* result = g_new(FlKeyEvent, 1);
19
20 result->time = event->time;
21 result->is_press = type == GDK_KEY_PRESS;
22 result->keycode = event->hardware_keycode;
23 result->keyval = event->keyval;
24 result->state = event->state;
25 result->string = g_strdup(event->string);
26 result->group = event->group;
27 result->origin = event;
28 result->dispose_origin = dispose_origin_from_gdk_event;
29
30 return result;
31 }
32
33 void fl_key_event_dispose(FlKeyEvent* event) {
34 if (event->string != nullptr) {
35 g_free(const_cast<char*>(event->string));
36 }
37 if (event->dispose_origin != nullptr) {
38 event->dispose_origin(event->origin);
39 }
40 g_free(event);
41 }
42
43 FlKeyEvent* fl_key_event_clone(const FlKeyEvent* event) {
44 FlKeyEvent* new_event = g_new(FlKeyEvent, 1);
45 *new_event = *event;
46 new_event->string = g_strdup(event->string);
47 return new_event;
48 }
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
fl_key_event_new_from_gdk_event
FlKeyEvent * fl_key_event_new_from_gdk_event(GdkEvent *raw_event)
Definition: fl_key_event.cc:12
_FlKeyEvent::origin
gpointer origin
Definition: fl_key_event.h:52
_FlKeyEvent
Definition: fl_key_event.h:31
_FlKeyEvent::dispose_origin
FlKeyEventDisposeOrigin dispose_origin
Definition: fl_key_event.h:56
fl_key_event_clone
FlKeyEvent * fl_key_event_clone(const FlKeyEvent *event)
Definition: fl_key_event.cc:43
fl_key_event_dispose
void fl_key_event_dispose(FlKeyEvent *event)
Definition: fl_key_event.cc:33
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
dispose_origin_from_gdk_event
static void dispose_origin_from_gdk_event(gpointer origin)
Definition: fl_key_event.cc:7
fl_key_event.h
_FlKeyEvent::string
const char * string
Definition: fl_key_event.h:47