Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_window_state_monitor.cc File Reference

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 90 of file fl_window_state_monitor.cc.

91 {
92 G_OBJECT_CLASS(klass)->dispose = fl_window_state_monitor_dispose;
93}
static void fl_window_state_monitor_dispose(GObject *object)

References fl_window_state_monitor_dispose().

◆ fl_window_state_monitor_dispose()

static void fl_window_state_monitor_dispose ( GObject *  object)
static

Definition at line 82 of file fl_window_state_monitor.cc.

82 {
83 FlWindowStateMonitor* self = FL_WINDOW_STATE_MONITOR(object);
84
85 g_clear_object(&self->messenger);
86
87 G_OBJECT_CLASS(fl_window_state_monitor_parent_class)->dispose(object);
88}

References self.

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 95 of file fl_window_state_monitor.cc.

95{}

◆ 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 97 of file fl_window_state_monitor.cc.

98 {
99 FlWindowStateMonitor* self = FL_WINDOW_STATE_MONITOR(
100 g_object_new(fl_window_state_monitor_get_type(), nullptr));
101 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
102 self->window = window;
103
104 // Listen to window state changes.
105 g_signal_connect_object(self->window, "window-state-event",
106 G_CALLBACK(window_state_event_cb), self,
107 G_CONNECT_SWAPPED);
108 self->window_state =
109 gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(self->window)));
110
111 return self;
112}
GLFWwindow * window
Definition main.cc:60
static gboolean window_state_event_cb(FlWindowStateMonitor *self, GdkEvent *event)
GdkWindow * gtk_widget_get_window(GtkWidget *widget)
Definition mock_gtk.cc:309
GdkWindowState gdk_window_get_state(GdkWindow *window)
Definition mock_gtk.cc:100

References gdk_window_get_state(), gtk_widget_get_window(), self, window, and window_state_event_cb().

Referenced by realize_cb(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ 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 51 of file fl_window_state_monitor.cc.

51 {
52 return (state & GDK_WINDOW_STATE_WITHDRAWN) ||
53 (state & GDK_WINDOW_STATE_ICONIFIED);
54}

Referenced by window_state_event_cb().

◆ send_lifecycle_state()

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

Definition at line 35 of file fl_window_state_monitor.cc.

36 {
37 g_autoptr(FlValue) value = fl_value_new_string(lifecycle_state);
38 g_autoptr(FlStringCodec) codec = fl_string_codec_new();
39 g_autoptr(GError) error = nullptr;
40 g_autoptr(GBytes) message =
41 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
42 if (message == nullptr) {
43 g_warning("Failed to encoding lifecycle state message: %s", error->message);
44 return;
45 }
46
48 message, nullptr, nullptr, nullptr);
49}
int32_t value
const char * message
g_autoptr(FlEngine) engine
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition fl_value.cc:276
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
static constexpr const char * kFlutterLifecycleChannel

References error, fl_binary_messenger_send_on_channel(), fl_message_codec_encode_message(), fl_string_codec_new(), fl_value_new_string(), g_autoptr(), kFlutterLifecycleChannel, message, self, 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 57 of file fl_window_state_monitor.cc.

58 {
59 GdkWindowState state = event->window_state.new_window_state;
60 GdkWindowState previous_state = self->window_state;
61 self->window_state = state;
62 bool was_visible = !is_hidden(previous_state);
63 bool is_visible = !is_hidden(state);
64 bool was_focused = (previous_state & GDK_WINDOW_STATE_FOCUSED);
65 bool is_focused = (state & GDK_WINDOW_STATE_FOCUSED);
66
67 if (was_visible != is_visible || was_focused != is_focused) {
68 const gchar* lifecycle_state;
69 if (is_visible) {
70 lifecycle_state =
72 } else {
73 lifecycle_state = kAppLifecycleStateHidden;
74 }
75
76 send_lifecycle_state(self, lifecycle_state);
77 }
78
79 return FALSE;
80}
static gboolean is_focused(FlutterSemanticsFlags flags)
static constexpr const char * kAppLifecycleStateHidden
static gboolean is_hidden(GdkWindowState state)
static constexpr const char * kAppLifecycleStateResumed
static void send_lifecycle_state(FlWindowStateMonitor *self, const gchar *lifecycle_state)
static constexpr const char * kAppLifecycleStateInactive

References is_focused(), is_hidden(), kAppLifecycleStateHidden, kAppLifecycleStateInactive, kAppLifecycleStateResumed, self, 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().