Skip to content

Commit deab7e8

Browse files
authored
Merge pull request #156 from jpnurmi/bounds
[Linux] update get/setBounds
2 parents 75ae9d1 + 089ce9c commit deab7e8

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

linux/window_manager_plugin.cc

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -222,46 +222,35 @@ static FlMethodResponse* set_background_color(WindowManagerPlugin* self,
222222
fl_method_success_response_new(fl_value_new_bool(true)));
223223
}
224224

225-
static FlMethodResponse* get_position(WindowManagerPlugin* self) {
226-
gint x, y;
225+
static FlMethodResponse* get_bounds(WindowManagerPlugin* self) {
226+
gint x, y, width, height;
227227
gtk_window_get_position(get_window(self), &x, &y);
228+
gtk_window_get_size(get_window(self), &width, &height);
228229

229230
g_autoptr(FlValue) result_data = fl_value_new_map();
230231
fl_value_set_string_take(result_data, "x", fl_value_new_float(x));
231232
fl_value_set_string_take(result_data, "y", fl_value_new_float(y));
232-
233-
return FL_METHOD_RESPONSE(fl_method_success_response_new(result_data));
234-
}
235-
236-
static FlMethodResponse* set_position(WindowManagerPlugin* self,
237-
FlValue* args) {
238-
const float x = fl_value_get_float(fl_value_lookup_string(args, "x"));
239-
const float y = fl_value_get_float(fl_value_lookup_string(args, "y"));
240-
241-
gtk_window_move(get_window(self), static_cast<gint>(x), static_cast<gint>(y));
242-
243-
return FL_METHOD_RESPONSE(
244-
fl_method_success_response_new(fl_value_new_bool(true)));
245-
}
246-
247-
static FlMethodResponse* get_size(WindowManagerPlugin* self) {
248-
gint width, height;
249-
gtk_window_get_size(get_window(self), &width, &height);
250-
251-
g_autoptr(FlValue) result_data = fl_value_new_map();
252233
fl_value_set_string_take(result_data, "width", fl_value_new_float(width));
253234
fl_value_set_string_take(result_data, "height", fl_value_new_float(height));
254235

255236
return FL_METHOD_RESPONSE(fl_method_success_response_new(result_data));
256237
}
257238

258-
static FlMethodResponse* set_size(WindowManagerPlugin* self, FlValue* args) {
259-
const float width = fl_value_get_float(fl_value_lookup_string(args, "width"));
260-
const float height =
261-
fl_value_get_float(fl_value_lookup_string(args, "height"));
239+
static FlMethodResponse* set_bounds(WindowManagerPlugin* self, FlValue* args) {
240+
FlValue* x = fl_value_lookup_string(args, "x");
241+
FlValue* y = fl_value_lookup_string(args, "y");
242+
if (x != nullptr && y != nullptr) {
243+
gtk_window_move(get_window(self), static_cast<gint>(fl_value_get_float(x)),
244+
static_cast<gint>(fl_value_get_float(y)));
245+
}
262246

263-
gtk_window_resize(get_window(self), static_cast<gint>(width),
264-
static_cast<gint>(height));
247+
FlValue* width = fl_value_lookup_string(args, "width");
248+
FlValue* height = fl_value_lookup_string(args, "height");
249+
if (width != nullptr && height != nullptr) {
250+
gtk_window_resize(get_window(self),
251+
static_cast<gint>(fl_value_get_float(width)),
252+
static_cast<gint>(fl_value_get_float(height)));
253+
}
265254

266255
return FL_METHOD_RESPONSE(
267256
fl_method_success_response_new(fl_value_new_bool(true)));
@@ -592,14 +581,10 @@ static void window_manager_plugin_handle_method_call(
592581
response = set_aspect_ratio(self, args);
593582
} else if (strcmp(method, "setBackgroundColor") == 0) {
594583
response = set_background_color(self, args);
595-
} else if (strcmp(method, "getPosition") == 0) {
596-
response = get_position(self);
597-
} else if (strcmp(method, "setPosition") == 0) {
598-
response = set_position(self, args);
599-
} else if (strcmp(method, "getSize") == 0) {
600-
response = get_size(self);
601-
} else if (strcmp(method, "setSize") == 0) {
602-
response = set_size(self, args);
584+
} else if (strcmp(method, "getBounds") == 0) {
585+
response = get_bounds(self);
586+
} else if (strcmp(method, "setBounds") == 0) {
587+
response = set_bounds(self, args);
603588
} else if (strcmp(method, "setMinimumSize") == 0) {
604589
response = set_minimum_size(self, args);
605590
} else if (strcmp(method, "setMaximumSize") == 0) {

0 commit comments

Comments
 (0)