| Flutter Linux Embedder |

Classes | Functions | Variables
fl_window_state_monitor.cc File Reference
`#include "flutter/shell/platform/linux/fl_window_state_monitor.h"`
`#include <gtk/gtk.h>`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"`

Go to the source code of this file.

## Classes
struct | _FlWindowStateMonitor

## Functions
| G_DEFINE_TYPE (FlWindowStateMonitor, fl_window_state_monitor, G_TYPE_OBJECT)
static void | send_lifecycle_state (FlWindowStateMonitor *self, const gchar *lifecycle_state)
static gboolean | is_hidden (GdkWindowState state)
static gboolean | window_state_event_cb (FlWindowStateMonitor *self, GdkEvent *event)
static void | fl_window_state_monitor_dispose (GObject *object)
static void | fl_window_state_monitor_class_init (FlWindowStateMonitorClass *klass)
static void | fl_window_state_monitor_init (FlWindowStateMonitor *self)
FlWindowStateMonitor * | fl_window_state_monitor_new (FlBinaryMessenger *messenger, GtkWindow *window)

## Variables
static constexpr const char * | kFlutterLifecycleChannel = "flutter/lifecycle"
static constexpr const char * | kAppLifecycleStateResumed
static constexpr const char * | kAppLifecycleStateInactive
static constexpr const char * | kAppLifecycleStateHidden

## Function Documentation

## ◆ fl_window_state_monitor_class_init()

static void fl_window_state_monitor_class_init | ( | FlWindowStateMonitorClass * | klass | ) |
| static

Definition at line 97 of file fl_window_state_monitor.cc.

98 {
99 G_OBJECT_CLASS(klass)->dispose = fl_window_state_monitor_dispose;
100 }
fl_window_state_monitor_dispose
static void fl_window_state_monitor_dispose(GObject *object)
Definition: fl_window_state_monitor.cc:85

References fl_window_state_monitor_dispose().

## ◆ fl_window_state_monitor_dispose()

static void fl_window_state_monitor_dispose | ( | GObject * | object | ) |
| static

Definition at line 85 of file fl_window_state_monitor.cc.

85 {
86 FlWindowStateMonitor* self = FL_WINDOW_STATE_MONITOR(object);
87
88 g_clear_object(&self->messenger);
89 if (self->window_state_event_cb_id != 0) {
90 g_signal_handler_disconnect(self->window, self->window_state_event_cb_id);
91 self->window_state_event_cb_id = 0;
92 }
93
94 G_OBJECT_CLASS(fl_window_state_monitor_parent_class)->dispose(object);
95 }

Referenced by fl_window_state_monitor_class_init().

## ◆ fl_window_state_monitor_init()

static void fl_window_state_monitor_init | ( | FlWindowStateMonitor * | self | ) |
| static

Definition at line 102 of file fl_window_state_monitor.cc.

102 {}

## ◆ fl_window_state_monitor_new()

FlWindowStateMonitor* fl_window_state_monitor_new | ( | FlBinaryMessenger * | messenger,
|  | GtkWindow * | window
| ) |  |

FlWindowStateMonitor:

Monitors a GtkWindow and reports state change events to the Flutter engine. fl_window_state_monitor_new: @messenger: an #FlBinaryMessenger. @window: a #GtkWindow.

Creates a new window state manager to monitor @window and report events to @messenger.

Returns: a new #FlWindowStateMonitor.

Definition at line 104 of file fl_window_state_monitor.cc.

105 {
106 FlWindowStateMonitor* self = FL_WINDOW_STATE_MONITOR(
107 g_object_new(fl_window_state_monitor_get_type(), nullptr));
108 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
109 self->window = window;
110
111 // Listen to window state changes.
112 self->window_state_event_cb_id =
113 g_signal_connect_swapped(self->window, "window-state-event",
114 G_CALLBACK(window_state_event_cb), self);
115 self->window_state =
116 gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(self->window)));
117
118 return self;
119 }
window
return window
Definition: fl_application.cc:41
window_state_event_cb
static gboolean window_state_event_cb(FlWindowStateMonitor *self, GdkEvent *event)
Definition: fl_window_state_monitor.cc:60

References window, and window_state_event_cb().

Referenced by realize_cb(), and TEST().

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlWindowStateMonitor | ,
|  | fl_window_state_monitor | ,
|  | G_TYPE_OBJECT |
| ) |  |

## ◆ is_hidden()

static gboolean is_hidden | ( | GdkWindowState | state | ) |
| static

Definition at line 54 of file fl_window_state_monitor.cc.

54 {
55 return (state & GDK_WINDOW_STATE_WITHDRAWN) ||
56 (state & GDK_WINDOW_STATE_ICONIFIED);
57 }

Referenced by window_state_event_cb().

## ◆ send_lifecycle_state()

static void send_lifecycle_state | ( | FlWindowStateMonitor * | self,
|  | const gchar * | lifecycle_state
| ) |  |
| static

Definition at line 38 of file fl_window_state_monitor.cc.

39 {
40 g_autoptr(FlValue) value = fl_value_new_string(lifecycle_state);
41 g_autoptr(FlStringCodec) codec = fl_string_codec_new();
42 g_autoptr(GError) error = nullptr;
43 g_autoptr(GBytes) message =
44 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
45 if (message == nullptr) {
46 g_warning("Failed to encoding lifecycle state message: %s", error->message);
47 return;
48 }
49
50 fl_binary_messenger_send_on_channel(self->messenger, kFlutterLifecycleChannel,
51 message, nullptr, nullptr, nullptr);
52 }
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:435
g_autoptr
g_autoptr(GMutexLocker) locker
fl_message_codec_encode_message
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
Definition: fl_message_codec.cc:17
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_string_codec_new
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
Definition: fl_string_codec.cc:53
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
kFlutterLifecycleChannel
static constexpr const char * kFlutterLifecycleChannel
Definition: fl_window_state_monitor.cc:11

References error, fl_binary_messenger_send_on_channel(), fl_message_codec_encode_message(), fl_string_codec_new(), fl_value_new_string(), g_autoptr(), kFlutterLifecycleChannel, and value.

Referenced by window_state_event_cb().

## ◆ window_state_event_cb()

static gboolean window_state_event_cb | ( | FlWindowStateMonitor * | self,
|  | GdkEvent * | event
| ) |  |
| static

Definition at line 60 of file fl_window_state_monitor.cc.

61 {
62 GdkWindowState state = event->window_state.new_window_state;
63 GdkWindowState previous_state = self->window_state;
64 self->window_state = state;
65 bool was_visible = !is_hidden(previous_state);
66 bool is_visible = !is_hidden(state);
67 bool was_focused = (previous_state & GDK_WINDOW_STATE_FOCUSED);
68 bool is_focused = (state & GDK_WINDOW_STATE_FOCUSED);
69
70 if (was_visible != is_visible || was_focused != is_focused) {
71 const gchar* lifecycle_state;
72 if (is_visible) {
73 lifecycle_state =
74 is_focused ? kAppLifecycleStateResumed : kAppLifecycleStateInactive;
75 } else {
76 lifecycle_state = kAppLifecycleStateHidden;
77 }
78
79 send_lifecycle_state(self, lifecycle_state);
80 }
81
82 return FALSE;
83 }
is_focused
static gboolean is_focused(FlutterSemanticsFlags flags)
Definition: fl_accessible_node.cc:104
kAppLifecycleStateHidden
static constexpr const char * kAppLifecycleStateHidden
Definition: fl_window_state_monitor.cc:17
is_hidden
static gboolean is_hidden(GdkWindowState state)
Definition: fl_window_state_monitor.cc:54
kAppLifecycleStateResumed
static constexpr const char * kAppLifecycleStateResumed
Definition: fl_window_state_monitor.cc:13
send_lifecycle_state
static void send_lifecycle_state(FlWindowStateMonitor *self, const gchar *lifecycle_state)
Definition: fl_window_state_monitor.cc:38
kAppLifecycleStateInactive
static constexpr const char * kAppLifecycleStateInactive
Definition: fl_window_state_monitor.cc:15

References is_focused(), is_hidden(), kAppLifecycleStateHidden, kAppLifecycleStateInactive, kAppLifecycleStateResumed, and send_lifecycle_state().

Referenced by fl_window_state_monitor_new().

## Variable Documentation

## ◆ kAppLifecycleStateHidden

constexpr const char* kAppLifecycleStateHidden
| staticconstexpr

Initial value:
=
"AppLifecycleState.hidden"

Definition at line 17 of file fl_window_state_monitor.cc.

Referenced by window_state_event_cb().

## ◆ kAppLifecycleStateInactive

constexpr const char* kAppLifecycleStateInactive
| staticconstexpr

Initial value:
=
"AppLifecycleState.inactive"

Definition at line 15 of file fl_window_state_monitor.cc.

Referenced by window_state_event_cb().

## ◆ kAppLifecycleStateResumed

constexpr const char* kAppLifecycleStateResumed
| staticconstexpr

Initial value:
=
"AppLifecycleState.resumed"

Definition at line 13 of file fl_window_state_monitor.cc.

Referenced by window_state_event_cb().

## ◆ kFlutterLifecycleChannel

constexpr const char* kFlutterLifecycleChannel = "flutter/lifecycle"
| staticconstexpr

Definition at line 11 of file fl_window_state_monitor.cc.

Referenced by send_lifecycle_state().