19
19
// See window_size_channel.dart for documentation.
20
20
const char kChannelName [] = " flutter/windowsize" ;
21
21
const char kBadArgumentsError [] = " Bad Arguments" ;
22
+ const char kNoScrenError [] = " No Screen" ;
22
23
const char kGetScreenListMethod [] = " getScreenList" ;
23
24
const char kGetWindowInfoMethod [] = " getWindowInfo" ;
24
25
const char kSetWindowFrameMethod [] = " setWindowFrame" ;
@@ -49,12 +50,16 @@ G_DEFINE_TYPE(FlWindowSizePlugin, fl_window_size_plugin, g_object_get_type())
49
50
// Gets the window being controlled.
50
51
GtkWindow* get_window(FlWindowSizePlugin* self) {
51
52
FlView* view = fl_plugin_registrar_get_view (self->registrar );
53
+ if (view == nullptr ) return nullptr ;
54
+
52
55
return GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
53
56
}
54
57
55
58
// Gets the display connection.
56
59
GdkDisplay* get_display (FlWindowSizePlugin* self) {
57
60
FlView* view = fl_plugin_registrar_get_view (self->registrar );
61
+ if (view == nullptr ) return nullptr ;
62
+
58
63
return gtk_widget_get_display (GTK_WIDGET (view));
59
64
}
60
65
@@ -97,6 +102,11 @@ static FlMethodResponse* get_screen_list(FlWindowSizePlugin* self) {
97
102
g_autoptr (FlValue) screens = fl_value_new_list ();
98
103
99
104
GdkDisplay* display = get_display (self);
105
+ if (display == nullptr ) {
106
+ return FL_METHOD_RESPONSE (
107
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
108
+ }
109
+
100
110
gint n_monitors = gdk_display_get_n_monitors (display);
101
111
for (gint i = 0 ; i < n_monitors; i++) {
102
112
GdkMonitor* monitor = gdk_display_get_monitor (display, i);
@@ -109,6 +119,10 @@ static FlMethodResponse* get_screen_list(FlWindowSizePlugin* self) {
109
119
// Gets information about the Flutter window.
110
120
static FlMethodResponse* get_window_info (FlWindowSizePlugin* self) {
111
121
GtkWindow* window = get_window (self);
122
+ if (window == nullptr ) {
123
+ return FL_METHOD_RESPONSE (
124
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
125
+ }
112
126
113
127
g_autoptr (FlValue) window_info = fl_value_new_map ();
114
128
@@ -158,6 +172,11 @@ static FlMethodResponse* set_window_frame(FlWindowSizePlugin* self,
158
172
double height = fl_value_get_float (fl_value_get_list_value (args, 3 ));
159
173
160
174
GtkWindow* window = get_window (self);
175
+ if (window == nullptr ) {
176
+ return FL_METHOD_RESPONSE (
177
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
178
+ }
179
+
161
180
gtk_window_move (window, static_cast <gint>(x), static_cast <gint>(y));
162
181
gtk_window_resize (window, static_cast <gint>(width),
163
182
static_cast <gint>(height));
@@ -183,6 +202,11 @@ static FlMethodResponse* set_window_minimum_size(FlWindowSizePlugin* self,
183
202
double width = fl_value_get_float (fl_value_get_list_value (args, 0 ));
184
203
double height = fl_value_get_float (fl_value_get_list_value (args, 1 ));
185
204
205
+ if (get_window () == nullptr ) {
206
+ return FL_METHOD_RESPONSE (
207
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
208
+ }
209
+
186
210
if (width >= 0 && height >= 0 ) {
187
211
self->window_geometry .min_width = static_cast <gint>(width);
188
212
self->window_geometry .min_height = static_cast <gint>(height);
@@ -204,6 +228,11 @@ static FlMethodResponse* set_window_maximum_size(FlWindowSizePlugin* self,
204
228
double width = fl_value_get_float (fl_value_get_list_value (args, 0 ));
205
229
double height = fl_value_get_float (fl_value_get_list_value (args, 1 ));
206
230
231
+ if (get_window () == nullptr ) {
232
+ return FL_METHOD_RESPONSE (
233
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
234
+ }
235
+
207
236
self->window_geometry .max_width = static_cast <gint>(width);
208
237
self->window_geometry .max_height = static_cast <gint>(height);
209
238
@@ -221,6 +250,10 @@ static FlMethodResponse* set_window_title(FlWindowSizePlugin* self,
221
250
}
222
251
223
252
GtkWindow* window = get_window (self);
253
+ if (window == nullptr ) {
254
+ return FL_METHOD_RESPONSE (
255
+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
256
+ }
224
257
gtk_window_set_title (window, fl_value_get_string (args));
225
258
226
259
return FL_METHOD_RESPONSE (fl_method_success_response_new (nullptr ));
0 commit comments