Skip to content

Commit 3cf24aa

Browse files
authored
[linux] implement minimizable & maximizable (#270)
These are implemented in terms of the current window state and type to make them match with the native window popup menu (e.g. a dialog always has minimize and mazimize items dimmed in the menu).
1 parent f1b1462 commit 3cf24aa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

linux/window_manager_plugin.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,45 @@ static FlMethodResponse* set_resizable(WindowManagerPlugin* self,
341341
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
342342
}
343343

344+
static FlMethodResponse* is_minimizable(WindowManagerPlugin* self) {
345+
GdkWindowState state = gdk_window_get_state(get_gdk_window(self));
346+
GdkWindowTypeHint type_hint = gtk_window_get_type_hint(get_window(self));
347+
g_autoptr(FlValue) result =
348+
fl_value_new_bool(!(state & GDK_WINDOW_STATE_ICONIFIED) &&
349+
type_hint == GDK_WINDOW_TYPE_HINT_NORMAL);
350+
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
351+
}
352+
353+
static FlMethodResponse* set_minimizable(WindowManagerPlugin* self,
354+
FlValue* args) {
355+
gboolean minimizable =
356+
fl_value_get_bool(fl_value_lookup_string(args, "isMinimizable"));
357+
GdkWindowTypeHint type_hint =
358+
minimizable ? GDK_WINDOW_TYPE_HINT_NORMAL : GDK_WINDOW_TYPE_HINT_DIALOG;
359+
gtk_window_set_type_hint(get_window(self), type_hint);
360+
return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
361+
}
362+
363+
static FlMethodResponse* is_maximizable(WindowManagerPlugin* self) {
364+
gboolean resizable = gtk_window_get_resizable(get_window(self));
365+
GdkWindowState state = gdk_window_get_state(get_gdk_window(self));
366+
GdkWindowTypeHint type_hint = gtk_window_get_type_hint(get_window(self));
367+
g_autoptr(FlValue) result =
368+
fl_value_new_bool(resizable && !(state & GDK_WINDOW_STATE_MAXIMIZED) &&
369+
type_hint == GDK_WINDOW_TYPE_HINT_NORMAL);
370+
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
371+
}
372+
373+
static FlMethodResponse* set_maximizable(WindowManagerPlugin* self,
374+
FlValue* args) {
375+
gboolean maximizable =
376+
fl_value_get_bool(fl_value_lookup_string(args, "isMaximizable"));
377+
GdkWindowTypeHint type_hint =
378+
maximizable ? GDK_WINDOW_TYPE_HINT_NORMAL : GDK_WINDOW_TYPE_HINT_DIALOG;
379+
gtk_window_set_type_hint(get_window(self), type_hint);
380+
return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
381+
}
382+
344383
static FlMethodResponse* is_closable(WindowManagerPlugin* self) {
345384
bool is_closable = gtk_window_get_deletable(get_window(self));
346385
g_autoptr(FlValue) result = fl_value_new_bool(is_closable);
@@ -804,6 +843,14 @@ static void window_manager_plugin_handle_method_call(
804843
response = is_resizable(self);
805844
} else if (g_strcmp0(method, "setResizable") == 0) {
806845
response = set_resizable(self, args);
846+
} else if (g_strcmp0(method, "isMinimizable") == 0) {
847+
response = is_minimizable(self);
848+
} else if (g_strcmp0(method, "setMinimizable") == 0) {
849+
response = set_minimizable(self, args);
850+
} else if (g_strcmp0(method, "isMaximizable") == 0) {
851+
response = is_maximizable(self);
852+
} else if (g_strcmp0(method, "setMaximizable") == 0) {
853+
response = set_maximizable(self, args);
807854
} else if (g_strcmp0(method, "isClosable") == 0) {
808855
response = is_closable(self);
809856
} else if (g_strcmp0(method, "setClosable") == 0) {

0 commit comments

Comments
 (0)