| Flutter Linux Embedder |

fl_window_monitor.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 <gtk/gtk.h>
6
7 #include "flutter/shell/platform/common/isolate_scope.h"
8 #include "flutter/shell/platform/linux/fl_window_monitor.h"
9
10 struct _FlWindowMonitor {
11 GObject parent_instance;
12
13 // Window being monitored.
14 GtkWindow* window;
15
16 // Isolate to call callbacks with.
17 flutter::Isolate isolate;
18
19 // Callbacks.
20 void (*on_configure)(void);
21 void (*on_state_changed)(void);
22 void (*on_is_active_notify)(void);
23 void (*on_title_notify)(void);
24 void (*on_close)(void);
25 void (*on_destroy)(void);
26 };
27
28 G_DEFINE_TYPE(FlWindowMonitor, fl_window_monitor, G_TYPE_OBJECT)
29
30 static gboolean configure_event_cb(FlWindowMonitor* self,
31 GdkEventConfigure* event) {
32 flutter::IsolateScope scope(self->isolate);
33 self->on_configure();
34
35 return FALSE;
36 }
37
38 static gboolean window_state_event_cb(FlWindowMonitor* self,
39 GdkEventWindowState* event) {
40 flutter::IsolateScope scope(self->isolate);
41 self->on_state_changed();
42
43 return FALSE;
44 }
45
46 static void is_active_notify_cb(FlWindowMonitor* self) {
47 flutter::IsolateScope scope(self->isolate);
48 self->on_is_active_notify();
49 }
50
51 static void title_notify_cb(FlWindowMonitor* self) {
52 flutter::IsolateScope scope(self->isolate);
53 self->on_title_notify();
54 }
55
56 static gboolean delete_event_cb(FlWindowMonitor* self, GdkEvent* event) {
57 flutter::IsolateScope scope(self->isolate);
58 self->on_close();
59
60 // Stop default behaviour of destroying the window.
61 return TRUE;
62 }
63
64 static void destroy_cb(FlWindowMonitor* self) {
65 flutter::IsolateScope scope(self->isolate);
66 self->on_destroy();
67 }
68
69 static void fl_window_monitor_dispose(GObject* object) {
70 FlWindowMonitor* self = FL_WINDOW_MONITOR(object);
71
72 // Disconnect all handlers using data. If we try and disconnect them
73 // individually they generated warnings after the widget has been destroyed.
74 g_signal_handlers_disconnect_by_data(self->window, self);
75 g_clear_object(&self->window);
76
77 G_OBJECT_CLASS(fl_window_monitor_parent_class)->dispose(object);
78 }
79
80 static void fl_window_monitor_class_init(FlWindowMonitorClass* klass) {
81 G_OBJECT_CLASS(klass)->dispose = fl_window_monitor_dispose;
82 }
83
84 static void fl_window_monitor_init(FlWindowMonitor* self) {}
85
86 G_MODULE_EXPORT FlWindowMonitor* fl_window_monitor_new(
87 GtkWindow* window,
88 void (*on_configure)(void),
89 void (*on_state_changed)(void),
90 void (*on_is_active_notify)(void),
91 void (*on_title_notify)(void),
92 void (*on_close)(void),
93 void (*on_destroy)(void)) {
94 FlWindowMonitor* self =
95 FL_WINDOW_MONITOR(g_object_new(fl_window_monitor_get_type(), nullptr));
96
97 self->window = GTK_WINDOW(g_object_ref(window));
98 self->isolate = flutter::Isolate::Current();
99 self->on_configure = on_configure;
100 self->on_state_changed = on_state_changed;
101 self->on_is_active_notify = on_is_active_notify;
102 self->on_title_notify = on_title_notify;
103 self->on_close = on_close;
104 self->on_destroy = on_destroy;
105 g_signal_connect_swapped(window, "configure-event",
106 G_CALLBACK(configure_event_cb), self);
107 g_signal_connect_swapped(window, "window-state-event",
108 G_CALLBACK(window_state_event_cb), self);
109 g_signal_connect_swapped(window, "notify::is-active",
110 G_CALLBACK(is_active_notify_cb), self);
111 g_signal_connect_swapped(window, "notify::title", G_CALLBACK(title_notify_cb),
112 self);
113 g_signal_connect_swapped(window, "delete-event", G_CALLBACK(delete_event_cb),
114 self);
115 g_signal_connect_swapped(window, "destroy", G_CALLBACK(destroy_cb), self);
116
117 return self;
118 }
flutter::Isolate
Definition: isolate_scope.h:15
flutter::Isolate::Current
static Isolate Current()
Definition: isolate_scope.cc:9
flutter::IsolateScope
Definition: isolate_scope.h:33
window
return window
Definition: fl_application.cc:41
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
destroy_cb
static void destroy_cb(FlWindowMonitor *self)
Definition: fl_window_monitor.cc:64
is_active_notify_cb
static void is_active_notify_cb(FlWindowMonitor *self)
Definition: fl_window_monitor.cc:46
fl_window_monitor_dispose
static void fl_window_monitor_dispose(GObject *object)
Definition: fl_window_monitor.cc:69
fl_window_monitor_class_init
static void fl_window_monitor_class_init(FlWindowMonitorClass *klass)
Definition: fl_window_monitor.cc:80
title_notify_cb
static void title_notify_cb(FlWindowMonitor *self)
Definition: fl_window_monitor.cc:51
configure_event_cb
static gboolean configure_event_cb(FlWindowMonitor *self, GdkEventConfigure *event)
Definition: fl_window_monitor.cc:30
window_state_event_cb
static gboolean window_state_event_cb(FlWindowMonitor *self, GdkEventWindowState *event)
Definition: fl_window_monitor.cc:38
fl_window_monitor_init
static void fl_window_monitor_init(FlWindowMonitor *self)
Definition: fl_window_monitor.cc:84
delete_event_cb
static gboolean delete_event_cb(FlWindowMonitor *self, GdkEvent *event)
Definition: fl_window_monitor.cc:56
fl_window_monitor_new
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_close)(void), void(*on_destroy)(void))
Definition: fl_window_monitor.cc:86
fl_window_monitor.h
isolate_scope.h
_FlWindowMonitor
Definition: fl_window_monitor.cc:10
_FlWindowMonitor::on_title_notify
void(* on_title_notify)(void)
Definition: fl_window_monitor.cc:23
_FlWindowMonitor::on_state_changed
void(* on_state_changed)(void)
Definition: fl_window_monitor.cc:21
_FlWindowMonitor::on_is_active_notify
void(* on_is_active_notify)(void)
Definition: fl_window_monitor.cc:22
_FlWindowMonitor::isolate
flutter::Isolate isolate
Definition: fl_window_monitor.cc:17
_FlWindowMonitor::on_configure
void(* on_configure)(void)
Definition: fl_window_monitor.cc:20
_FlWindowMonitor::on_destroy
void(* on_destroy)(void)
Definition: fl_window_monitor.cc:25
_FlWindowMonitor::on_close
void(* on_close)(void)
Definition: fl_window_monitor.cc:24
_FlWindowMonitor::parent_instance
GObject parent_instance
Definition: fl_window_monitor.cc:11
_FlWindowMonitor::window
GtkWindow * window
Definition: fl_window_monitor.cc:14