Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: add set_default_size method #523

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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