Flutter Linux Embedder
fl_window_monitor.cc File Reference

Go to the source code of this file.

Classes

struct  _FlWindowMonitor
 

Functions

static gboolean configure_event_cb (FlWindowMonitor *self, GdkEventConfigure *event)
 
static gboolean window_state_event_cb (FlWindowMonitor *self, GdkEventWindowState *event)
 
static void is_active_notify_cb (FlWindowMonitor *self)
 
static void title_notify_cb (FlWindowMonitor *self)
 
static void moved_to_rect_cb (FlWindowMonitor *self, GdkRectangle *flipped_rect, GdkRectangle *final_rect, gboolean flipped_x, gboolean flipped_y)
 
static void realize_cb (FlWindowMonitor *self)
 
static gboolean delete_event_cb (FlWindowMonitor *self, GdkEvent *event)
 
static void destroy_cb (FlWindowMonitor *self)
 
static void fl_window_monitor_dispose (GObject *object)
 
static void fl_window_monitor_class_init (FlWindowMonitorClass *klass)
 
static void fl_window_monitor_init (FlWindowMonitor *self)
 
G_MODULE_EXPORT FlWindowMonitor * fl_window_monitor_new (GtkWindow *window, void(*on_configure)(void), void(*on_state_changed)(void), void(*on_is_active_notify)(void), void(*on_title_notify)(void), void(*on_moved_to_rect)(int, int, int, int), void(*on_close)(void), void(*on_destroy)(void))
 

Function Documentation

◆ configure_event_cb()

static gboolean configure_event_cb ( FlWindowMonitor *  self,
GdkEventConfigure *  event 
)
static

Definition at line 31 of file fl_window_monitor.cc.

32  {
33  flutter::IsolateScope scope(self->isolate);
34  self->on_configure();
35 
36  return FALSE;
37 }

Referenced by fl_window_monitor_new().

◆ delete_event_cb()

static gboolean delete_event_cb ( FlWindowMonitor *  self,
GdkEvent *  event 
)
static

Definition at line 86 of file fl_window_monitor.cc.

86  {
87  flutter::IsolateScope scope(self->isolate);
88  self->on_close();
89 
90  // Stop default behaviour of destroying the window.
91  return TRUE;
92 }

References TRUE.

Referenced by fl_window_monitor_new().

◆ destroy_cb()

static void destroy_cb ( FlWindowMonitor *  self)
static

Definition at line 94 of file fl_window_monitor.cc.

94  {
95  flutter::IsolateScope scope(self->isolate);
96  self->on_destroy();
97 }

Referenced by fl_window_monitor_new().

◆ fl_window_monitor_class_init()

static void fl_window_monitor_class_init ( FlWindowMonitorClass *  klass)
static

Definition at line 107 of file fl_window_monitor.cc.

107  {
108  G_OBJECT_CLASS(klass)->dispose = fl_window_monitor_dispose;
109 }
static void fl_window_monitor_dispose(GObject *object)

References fl_window_monitor_dispose().

◆ fl_window_monitor_dispose()

static void fl_window_monitor_dispose ( GObject *  object)
static

Definition at line 99 of file fl_window_monitor.cc.

99  {
100  FlWindowMonitor* self = FL_WINDOW_MONITOR(object);
101 
102  g_clear_object(&self->window);
103 
104  G_OBJECT_CLASS(fl_window_monitor_parent_class)->dispose(object);
105 }

Referenced by fl_window_monitor_class_init().

◆ fl_window_monitor_init()

static void fl_window_monitor_init ( FlWindowMonitor *  self)
static

Definition at line 111 of file fl_window_monitor.cc.

111 {}

◆ fl_window_monitor_new()

G_MODULE_EXPORT FlWindowMonitor* fl_window_monitor_new ( GtkWindow *  window,
void(*)(void)  on_configure,
void(*)(void)  on_state_changed,
void(*)(void)  on_is_active_notify,
void(*)(void)  on_title_notify,
void(*)(int, int, int, int)  on_moved_to_rect,
void(*)(void)  on_close,
void(*)(void)  on_destroy 
)

fl_window_monitor_new: @window: the window being monitored. @on_configure: the function to call when the window changes size, position or stacking. @on_state_changed: the function to call when the window state changes. @on_is_active_notify: the function to call when the is-active property changes. @on_moved_to_rect: the function to call when a popup window is moved to a new position. @on_close: the function to call when the user requests the window to be closed. @on_destroy: the function to call when the window is destroyed.

Helper class to allow the Flutter engine to monitor a GtkWindow using FFI. Callbacks are called in the isolate this class was created with.

Returns: a new #FlWindowMonitor.

Definition at line 113 of file fl_window_monitor.cc.

121  {
122  FlWindowMonitor* self =
123  FL_WINDOW_MONITOR(g_object_new(fl_window_monitor_get_type(), nullptr));
124 
125  self->window = GTK_WINDOW(g_object_ref(window));
126  // Callbacks are made in the isolate this was created in. There is not always
127  // an isolate, e.g. in unit tests, and the isolate this object is created with
128  // does nothing when entered.
129  if (Dart_CurrentIsolate() != nullptr) {
130  self->isolate = flutter::Isolate::Current();
131  }
132  self->on_configure = on_configure;
133  self->on_state_changed = on_state_changed;
134  self->on_is_active_notify = on_is_active_notify;
135  self->on_title_notify = on_title_notify;
136  self->on_moved_to_rect = on_moved_to_rect;
137  self->on_close = on_close;
138  self->on_destroy = on_destroy;
139  g_signal_connect_object(window, "configure-event",
140  G_CALLBACK(configure_event_cb), self,
141  G_CONNECT_SWAPPED);
142  g_signal_connect_object(window, "window-state-event",
143  G_CALLBACK(window_state_event_cb), self,
144  G_CONNECT_SWAPPED);
145  g_signal_connect_object(window, "notify::is-active",
146  G_CALLBACK(is_active_notify_cb), self,
147  G_CONNECT_SWAPPED);
148  g_signal_connect_object(window, "notify::title", G_CALLBACK(title_notify_cb),
149  self, G_CONNECT_SWAPPED);
150  g_signal_connect_object(window, "realize", G_CALLBACK(realize_cb), self,
151  G_CONNECT_SWAPPED);
152  if (gtk_widget_get_realized(GTK_WIDGET(window))) {
153  realize_cb(self);
154  }
155  g_signal_connect_object(window, "delete-event", G_CALLBACK(delete_event_cb),
156  self, G_CONNECT_SWAPPED);
157  g_signal_connect_object(window, "destroy", G_CALLBACK(destroy_cb), self,
158  G_CONNECT_SWAPPED);
159 
160  return self;
161 }
static Isolate Current()
Definition: isolate_scope.cc:9
static void destroy_cb(FlWindowMonitor *self)
static void is_active_notify_cb(FlWindowMonitor *self)
static void title_notify_cb(FlWindowMonitor *self)
static void realize_cb(FlWindowMonitor *self)
static gboolean configure_event_cb(FlWindowMonitor *self, GdkEventConfigure *event)
static gboolean window_state_event_cb(FlWindowMonitor *self, GdkEventWindowState *event)
static gboolean delete_event_cb(FlWindowMonitor *self, GdkEvent *event)

References configure_event_cb(), flutter::Isolate::Current(), delete_event_cb(), destroy_cb(), is_active_notify_cb(), realize_cb(), title_notify_cb(), and window_state_event_cb().

◆ is_active_notify_cb()

static void is_active_notify_cb ( FlWindowMonitor *  self)
static

Definition at line 47 of file fl_window_monitor.cc.

47  {
48  flutter::IsolateScope scope(self->isolate);
49  self->on_is_active_notify();
50 }

Referenced by fl_window_monitor_new().

◆ moved_to_rect_cb()

static void moved_to_rect_cb ( FlWindowMonitor *  self,
GdkRectangle *  flipped_rect,
GdkRectangle *  final_rect,
gboolean  flipped_x,
gboolean  flipped_y 
)
static

Definition at line 57 of file fl_window_monitor.cc.

61  {
62  // According to the documentation, the final_rect can be null
63  // if the backend can't obtain it.
64  // Reference: https://docs.gtk.org/gdk3/signal.Window.moved-to-rect.html
65  if (final_rect == nullptr) {
66  return;
67  }
68 
69  flutter::IsolateScope scope(self->isolate);
70  self->on_moved_to_rect(final_rect->x, final_rect->y, final_rect->width,
71  final_rect->height);
72 }

Referenced by realize_cb().

◆ realize_cb()

static void realize_cb ( FlWindowMonitor *  self)
static

Definition at line 77 of file fl_window_monitor.cc.

77  {
78  GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(self->window));
79  if (window == nullptr) {
80  return;
81  }
82  g_signal_connect_object(window, "moved-to-rect", G_CALLBACK(moved_to_rect_cb),
83  self, G_CONNECT_SWAPPED);
84 }
static void moved_to_rect_cb(FlWindowMonitor *self, GdkRectangle *flipped_rect, GdkRectangle *final_rect, gboolean flipped_x, gboolean flipped_y)

References moved_to_rect_cb().

Referenced by fl_window_monitor_new().

◆ title_notify_cb()

static void title_notify_cb ( FlWindowMonitor *  self)
static

Definition at line 52 of file fl_window_monitor.cc.

52  {
53  flutter::IsolateScope scope(self->isolate);
54  self->on_title_notify();
55 }

Referenced by fl_window_monitor_new().

◆ window_state_event_cb()

static gboolean window_state_event_cb ( FlWindowMonitor *  self,
GdkEventWindowState *  event 
)
static

Definition at line 39 of file fl_window_monitor.cc.

40  {
41  flutter::IsolateScope scope(self->isolate);
42  self->on_state_changed();
43 
44  return FALSE;
45 }

Referenced by fl_window_monitor_new().