Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ece0b44

Browse files
committed
Add support for setting window size limits for glfw
Add a function to the window which calls the glfw function for fixing the size limits of the window. This can then be called after window creation.
1 parent 89dd067 commit ece0b44

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

shell/platform/glfw/flutter_glfw.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow(
568568
if (window == nullptr) {
569569
return nullptr;
570570
}
571+
571572
GLFWClearCanvas(window);
572573
glfwSetWindowUserPointer(window, state.get());
573574

@@ -736,6 +737,16 @@ void FlutterDesktopWindowSetPixelRatioOverride(
736737
}
737738
}
738739

740+
void FlutterDesktopWindowSetWindowSizeLimits(
741+
FlutterDesktopWindowRef flutter_window,
742+
int minwidth,
743+
int minheight,
744+
int maxwidth,
745+
int maxheight) {
746+
glfwSetWindowSizeLimits(flutter_window->window, minwidth, minheight, maxwidth,
747+
maxheight);
748+
}
749+
739750
bool FlutterDesktopRunWindowEventLoopWithTimeout(
740751
FlutterDesktopWindowControllerRef controller,
741752
uint32_t timeout_milliseconds) {

shell/platform/glfw/public/flutter_glfw.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct {
5252
// Whether or not the user is prevented from resizing the window.
5353
// Reversed so that the default for a cleared struct is to allow resizing.
5454
bool prevent_resize;
55+
// Optional limits for the size of the window.
5556
} FlutterDesktopWindowProperties;
5657

5758
// Sets up the library's graphic context. Must be called before any other
@@ -167,6 +168,17 @@ FLUTTER_EXPORT void FlutterDesktopWindowSetPixelRatioOverride(
167168
FlutterDesktopWindowRef flutter_window,
168169
double pixel_ratio);
169170

171+
// Sets the min/max width/height of |flutter_window| in pixels. Use
172+
// GLFW_DONT_CARE to leave a dimension unconstrained.
173+
//
174+
// This must be called from the main thread.
175+
FLUTTER_EXPORT void FlutterDesktopWindowSetWindowSizeLimits(
176+
FlutterDesktopWindowRef flutter_window,
177+
int minwidth,
178+
int minheight,
179+
int maxwidth,
180+
int maxheight);
181+
170182
// Runs an instance of a headless Flutter engine.
171183
//
172184
// Returns a null pointer in the event of an error.

0 commit comments

Comments
 (0)