Skip to content

Commit

Permalink
linux: add set_default_size method
Browse files Browse the repository at this point in the history
  • Loading branch information
tariq committed Jan 2, 2025
1 parent 3678a0a commit 8445596
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/window_manager/lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@ class WindowManager {
Future<bool> ungrabKeyboard() async {
return await _channel.invokeMethod('ungrabKeyboard');
}

/// Sets the default size of the window at app start
/// @platforms linux
Future<bool> setDefaultSize(Size size) async {
final Map<String, dynamic> arguments = {
'width': size.width,
'height': size.height,
};
return await _channel.invokeMethod('setDefaultSize', arguments);
}
}

final windowManager = WindowManager.instance;
15 changes: 15 additions & 0 deletions packages/window_manager/linux/window_manager_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,19 @@ static FlMethodResponse* set_brightness(WindowManagerPlugin* self,
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* set_default_size(WindowManagerPlugin* self, FlValue* args) {
FlValue* width = fl_value_lookup_string(args, "width");
FlValue* height = fl_value_lookup_string(args, "height");
if (width != nullptr && height != nullptr) {
gtk_window_set_default_size(get_window(self),
static_cast<gint>(fl_value_get_float(width)),
static_cast<gint>(fl_value_get_float(height)));
}

g_autoptr(FlValue) result = fl_value_new_bool(true);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

// Called when a method call is received from Flutter.
static void window_manager_plugin_handle_method_call(
WindowManagerPlugin* self,
Expand Down Expand Up @@ -929,6 +942,8 @@ static void window_manager_plugin_handle_method_call(
response = ungrab_keyboard(self);
} else if (g_strcmp0(method, "setBrightness") == 0) {
response = set_brightness(self, args);
} else if (g_strcmp0(method, "setDefaultSize") == 0) {
response = set_default_size(self, args);
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}
Expand Down

0 comments on commit 8445596

Please sign in to comment.