summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/bind/core_bind.cpp22
-rw-r--r--core/bind/core_bind.h4
-rw-r--r--core/os/os.h4
-rw-r--r--doc/classes/OS.xml6
-rw-r--r--platform/osx/os_osx.h7
-rw-r--r--platform/osx/os_osx.mm66
-rw-r--r--platform/windows/os_windows.cpp47
-rw-r--r--platform/windows/os_windows.h7
-rw-r--r--platform/x11/os_x11.cpp137
-rw-r--r--platform/x11/os_x11.h7
10 files changed, 291 insertions, 16 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index dbfa04be4d..8a898f3b53 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -308,6 +308,14 @@ void _OS::set_window_position(const Point2 &p_position) {
OS::get_singleton()->set_window_position(p_position);
}
+Size2 _OS::get_max_window_size() const {
+ return OS::get_singleton()->get_max_window_size();
+}
+
+Size2 _OS::get_min_window_size() const {
+ return OS::get_singleton()->get_min_window_size();
+}
+
Size2 _OS::get_window_size() const {
return OS::get_singleton()->get_window_size();
}
@@ -316,6 +324,14 @@ Size2 _OS::get_real_window_size() const {
return OS::get_singleton()->get_real_window_size();
}
+void _OS::set_max_window_size(const Size2 &p_size) {
+ OS::get_singleton()->set_max_window_size(p_size);
+}
+
+void _OS::set_min_window_size(const Size2 &p_size) {
+ OS::get_singleton()->set_min_window_size(p_size);
+}
+
void _OS::set_window_size(const Size2 &p_size) {
OS::get_singleton()->set_window_size(p_size);
}
@@ -1139,6 +1155,10 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position);
ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position);
ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size);
+ ClassDB::bind_method(D_METHOD("get_max_window_size"), &_OS::get_max_window_size);
+ ClassDB::bind_method(D_METHOD("get_min_window_size"), &_OS::get_min_window_size);
+ ClassDB::bind_method(D_METHOD("set_max_window_size", "size"), &_OS::set_max_window_size);
+ ClassDB::bind_method(D_METHOD("set_min_window_size", "size"), &_OS::set_min_window_size);
ClassDB::bind_method(D_METHOD("set_window_size", "size"), &_OS::set_window_size);
ClassDB::bind_method(D_METHOD("get_window_safe_area"), &_OS::get_window_safe_area);
ClassDB::bind_method(D_METHOD("set_window_fullscreen", "enabled"), &_OS::set_window_fullscreen);
@@ -1284,6 +1304,8 @@ void _OS::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_window_size"), "set_min_window_size", "get_min_window_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_window_size"), "set_max_window_size", "get_max_window_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation");
ADD_GROUP("Window", "window_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window");
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 8f74d88be5..2751ff242c 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -175,9 +175,13 @@ public:
virtual int get_screen_dpi(int p_screen = -1) const;
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2 &p_position);
+ virtual Size2 get_max_window_size() const;
+ virtual Size2 get_min_window_size() const;
virtual Size2 get_window_size() const;
virtual Size2 get_real_window_size() const;
virtual Rect2 get_window_safe_area() const;
+ virtual void set_max_window_size(const Size2 &p_size);
+ virtual void set_min_window_size(const Size2 &p_size);
virtual void set_window_size(const Size2 &p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
diff --git a/core/os/os.h b/core/os/os.h
index b128e6424c..514e1e2ad3 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -205,8 +205,12 @@ public:
virtual int get_screen_dpi(int p_screen = -1) const { return 72; }
virtual Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2 &p_position) {}
+ virtual Size2 get_max_window_size() const { return Size2(); };
+ virtual Size2 get_min_window_size() const { return Size2(); };
virtual Size2 get_window_size() const = 0;
virtual Size2 get_real_window_size() const { return get_window_size(); }
+ virtual void set_min_window_size(const Size2 p_size) {}
+ virtual void set_max_window_size(const Size2 p_size) {}
virtual void set_window_size(const Size2 p_size) {}
virtual void set_window_fullscreen(bool p_enabled) {}
virtual bool is_window_fullscreen() const { return true; }
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index e994c24582..2c680e828e 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -811,6 +811,12 @@
<member name="low_processor_usage_mode" type="bool" setter="set_low_processor_usage_mode" getter="is_in_low_processor_usage_mode">
If [code]true[/code], the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.
</member>
+ <member name="min_window_size" type="Vector2" setter="set_min_window_size" getter="get_min_window_size">
+ The minimum size of the window (without counting window manager decorations). Does not affect fullscreen mode. Set to [code](0, 0)[/code] to reset to the system default value.
+ </member>
+ <member name="max_window_size" type="Vector2" setter="set_max_window_size" getter="get_max_window_size">
+ The maximum size of the window (without counting window manager decorations). Does not affect fullscreen mode. Set to [code](0, 0)[/code] to reset to the system default value.
+ </member>
<member name="screen_orientation" type="int" setter="set_screen_orientation" getter="get_screen_orientation" enum="_OS.ScreenOrientation">
The current screen orientation.
</member>
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 09a9c0be4d..0ca94e3a63 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -137,6 +137,9 @@ public:
String im_text;
Point2 im_selection;
+ Size2 min_size;
+ Size2 max_size;
+
PowerOSX *power_manager;
CrashHandler crash_handler;
@@ -235,6 +238,10 @@ public:
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2 &p_position);
+ virtual Size2 get_max_window_size() const;
+ virtual Size2 get_min_window_size() const;
+ virtual void set_min_window_size(const Size2 p_size);
+ virtual void set_max_window_size(const Size2 p_size);
virtual void set_window_size(const Size2 p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 3ee6537180..dade07ffda 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -267,10 +267,23 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
OS_OSX::singleton->zoomed = true;
+
+ [OS_OSX::singleton->window_object setContentMinSize:NSMakeSize(0, 0)];
+ [OS_OSX::singleton->window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
}
- (void)windowDidExitFullScreen:(NSNotification *)notification {
OS_OSX::singleton->zoomed = false;
+
+ if (OS_OSX::singleton->min_size != Size2()) {
+ Size2 size = OS_OSX::singleton->min_size / OS_OSX::singleton->_display_scale();
+ [OS_OSX::singleton->window_object setContentMinSize:NSMakeSize(size.x, size.y)];
+ }
+ if (OS_OSX::singleton->max_size != Size2()) {
+ Size2 size = OS_OSX::singleton->max_size / OS_OSX::singleton->_display_scale();
+ [OS_OSX::singleton->window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
+ }
+
if (!OS_OSX::singleton->resizable)
[OS_OSX::singleton->window_object setStyleMask:[OS_OSX::singleton->window_object styleMask] & ~NSWindowStyleMaskResizable];
}
@@ -2357,6 +2370,46 @@ Size2 OS_OSX::get_real_window_size() const {
return Size2(frame.size.width, frame.size.height) * _display_scale();
}
+Size2 OS_OSX::get_max_window_size() const {
+ return max_size;
+}
+
+Size2 OS_OSX::get_min_window_size() const {
+ return min_size;
+}
+
+void OS_OSX::set_min_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && (max_size != Size2()) && ((p_size.x > max_size.x) || (p_size.y > max_size.y))) {
+ WARN_PRINT("Minimum window size can't be larger than maximum window size!");
+ return;
+ }
+ min_size = p_size;
+
+ if ((min_size != Size2()) && !zoomed) {
+ Size2 size = min_size / _display_scale();
+ [window_object setContentMinSize:NSMakeSize(size.x, size.y)];
+ } else {
+ [window_object setContentMinSize:NSMakeSize(0, 0)];
+ }
+}
+
+void OS_OSX::set_max_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
+ WARN_PRINT("Maximum window size can't be smaller than minimum window size!");
+ return;
+ }
+ max_size = p_size;
+
+ if ((max_size != Size2()) && !zoomed) {
+ Size2 size = max_size / _display_scale();
+ [window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
+ } else {
+ [window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
+ }
+}
+
void OS_OSX::set_window_size(const Size2 p_size) {
Size2 size = p_size / _display_scale();
@@ -2386,6 +2439,19 @@ void OS_OSX::set_window_fullscreen(bool p_enabled) {
set_window_per_pixel_transparency_enabled(false);
if (!resizable)
[window_object setStyleMask:[window_object styleMask] | NSWindowStyleMaskResizable];
+ if (p_enabled) {
+ [window_object setContentMinSize:NSMakeSize(0, 0)];
+ [window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
+ } else {
+ if (min_size != Size2()) {
+ Size2 size = min_size / _display_scale();
+ [window_object setContentMinSize:NSMakeSize(size.x, size.y)];
+ }
+ if (max_size != Size2()) {
+ Size2 size = max_size / _display_scale();
+ [window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
+ }
+ }
[window_object toggleFullScreen:nil];
}
zoomed = p_enabled;
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index db56bf5c7e..6e6df08f02 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -355,7 +355,23 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return 0; // Return To The Message Loop
}
-
+ case WM_GETMINMAXINFO: {
+ if (video_mode.resizable && !video_mode.fullscreen) {
+ Size2 decor = get_real_window_size() - get_window_size(); // Size of window decorations
+ MINMAXINFO *min_max_info = (MINMAXINFO *)lParam;
+ if (min_size != Size2()) {
+ min_max_info->ptMinTrackSize.x = min_size.x + decor.x;
+ min_max_info->ptMinTrackSize.y = min_size.y + decor.y;
+ }
+ if (max_size != Size2()) {
+ min_max_info->ptMaxTrackSize.x = max_size.x + decor.x;
+ min_max_info->ptMaxTrackSize.y = max_size.y + decor.y;
+ }
+ return 0;
+ } else {
+ break;
+ }
+ }
case WM_PAINT:
Main::force_redraw();
@@ -1771,6 +1787,7 @@ void OS_Windows::set_window_position(const Point2 &p_position) {
last_pos = p_position;
update_real_mouse_position();
}
+
Size2 OS_Windows::get_window_size() const {
if (minimized) {
@@ -1783,6 +1800,33 @@ Size2 OS_Windows::get_window_size() const {
}
return Size2();
}
+
+Size2 OS_Windows::get_max_window_size() const {
+ return max_size;
+}
+
+Size2 OS_Windows::get_min_window_size() const {
+ return min_size;
+}
+
+void OS_Windows::set_min_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && (max_size != Size2()) && ((p_size.x > max_size.x) || (p_size.y > max_size.y))) {
+ WARN_PRINT("Minimum window size can't be larger than maximum window size!");
+ return;
+ }
+ min_size = p_size;
+}
+
+void OS_Windows::set_max_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
+ WARN_PRINT("Maximum window size can't be smaller than minimum window size!");
+ return;
+ }
+ max_size = p_size;
+}
+
Size2 OS_Windows::get_real_window_size() const {
RECT r;
@@ -1791,6 +1835,7 @@ Size2 OS_Windows::get_real_window_size() const {
}
return Size2();
}
+
void OS_Windows::set_window_size(const Size2 p_size) {
int w = p_size.width;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index b20d847baa..4660c16b97 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -126,6 +126,9 @@ class OS_Windows : public OS {
HCURSOR hCursor;
+ Size2 min_size;
+ Size2 max_size;
+
Size2 window_rect;
VideoMode video_mode;
bool preserve_window_size = false;
@@ -238,6 +241,10 @@ public:
virtual void set_window_position(const Point2 &p_position);
virtual Size2 get_window_size() const;
virtual Size2 get_real_window_size() const;
+ virtual Size2 get_max_window_size() const;
+ virtual Size2 get_min_window_size() const;
+ virtual void set_min_window_size(const Size2 p_size);
+ virtual void set_max_window_size(const Size2 p_size);
virtual void set_window_size(const Size2 p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 146cd8bb66..6421dc270f 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1006,18 +1006,30 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
XFlush(x11_display);
- if (!p_enabled && !is_window_resizable()) {
+ if (!p_enabled) {
// Reset the non-resizable flags if we un-set these before.
Size2 size = get_window_size();
XSizeHints *xsh;
-
xsh = XAllocSizeHints();
- xsh->flags = PMinSize | PMaxSize;
- xsh->min_width = size.x;
- xsh->max_width = size.x;
- xsh->min_height = size.y;
- xsh->max_height = size.y;
-
+ if (!is_window_resizable()) {
+ xsh->flags = PMinSize | PMaxSize;
+ xsh->min_width = size.x;
+ xsh->max_width = size.x;
+ xsh->min_height = size.y;
+ xsh->max_height = size.y;
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ }
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
}
@@ -1244,6 +1256,72 @@ Size2 OS_X11::get_real_window_size() const {
return Size2(w, h);
}
+Size2 OS_X11::get_max_window_size() const {
+ return max_size;
+}
+
+Size2 OS_X11::get_min_window_size() const {
+ return min_size;
+}
+
+void OS_X11::set_min_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && (max_size != Size2()) && ((p_size.x > max_size.x) || (p_size.y > max_size.y))) {
+ WARN_PRINT("Minimum window size can't be larger than maximum window size!");
+ return;
+ }
+ min_size = p_size;
+
+ if (is_window_resizable()) {
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
+
+ XFlush(x11_display);
+ }
+}
+
+void OS_X11::set_max_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
+ WARN_PRINT("Maximum window size can't be smaller than minimum window size!");
+ return;
+ }
+ max_size = p_size;
+
+ if (is_window_resizable()) {
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
+
+ XFlush(x11_display);
+ }
+}
+
void OS_X11::set_window_size(const Size2 p_size) {
if (current_videomode.width == p_size.width && current_videomode.height == p_size.height)
@@ -1256,17 +1334,29 @@ void OS_X11::set_window_size(const Size2 p_size) {
int old_h = xwa.height;
// If window resizable is disabled we need to update the attributes first
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
if (!is_window_resizable()) {
- XSizeHints *xsh;
- xsh = XAllocSizeHints();
xsh->flags = PMinSize | PMaxSize;
xsh->min_width = p_size.x;
xsh->max_width = p_size.x;
xsh->min_height = p_size.y;
xsh->max_height = p_size.y;
- XSetWMNormalHints(x11_display, x11_window, xsh);
- XFree(xsh);
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
}
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
// Resize the window
XResizeWindow(x11_display, x11_window, p_size.x, p_size.y);
@@ -1312,20 +1402,37 @@ bool OS_X11::is_window_fullscreen() const {
}
void OS_X11::set_window_resizable(bool p_enabled) {
- XSizeHints *xsh;
- Size2 size = get_window_size();
+ XSizeHints *xsh;
xsh = XAllocSizeHints();
- xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
if (!p_enabled) {
+ Size2 size = get_window_size();
+
+ xsh->flags = PMinSize | PMaxSize;
xsh->min_width = size.x;
xsh->max_width = size.x;
xsh->min_height = size.y;
xsh->max_height = size.y;
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
}
+
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
+
current_videomode.resizable = p_enabled;
+
+ XFlush(x11_display);
}
bool OS_X11::is_window_resizable() const {
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index eca617bd90..510487b599 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -120,6 +120,9 @@ class OS_X11 : public OS_Unix {
bool im_active;
Vector2 im_position;
+ Size2 min_size;
+ Size2 max_size;
+
Point2 last_mouse_pos;
bool last_mouse_pos_valid;
Point2i last_click_pos;
@@ -268,6 +271,10 @@ public:
virtual void set_window_position(const Point2 &p_position);
virtual Size2 get_window_size() const;
virtual Size2 get_real_window_size() const;
+ virtual Size2 get_max_window_size() const;
+ virtual Size2 get_min_window_size() const;
+ virtual void set_min_window_size(const Size2 p_size);
+ virtual void set_max_window_size(const Size2 p_size);
virtual void set_window_size(const Size2 p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;