internal void SetWindowMinMax (IntPtr handle, Rectangle maximized, Size min, Size max, CreateParams cp)
{
Hwnd hwnd;
XSizeHints hints;
IntPtr dummy;
hwnd = Hwnd.ObjectFromHandle(handle);
if (hwnd == null) {
return;
}
min.Width = Math.Max (min.Width, SystemInformation.MinimumWindowSize.Width);
min.Height = Math.Max (min.Height, SystemInformation.MinimumWindowSize.Height);
hints = new XSizeHints();
XGetWMNormalHints(DisplayHandle, hwnd.whole_window, ref hints, out dummy);
if ((min != Size.Empty) && (min.Width > 0) && (min.Height > 0)) {
if (cp != null)
min = TranslateWindowSizeToXWindowSize (cp, min);
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMinSize);
hints.min_width = min.Width;
hints.min_height = min.Height;
}
if ((max != Size.Empty) && (max.Width > 0) && (max.Height > 0)) {
if (cp != null)
max = TranslateWindowSizeToXWindowSize (cp, max);
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMaxSize);
hints.max_width = max.Width;
hints.max_height = max.Height;
}
if (hints.flags != IntPtr.Zero) {
// The Metacity team has decided that they won't care about this when clicking the maximize icon,
// they will maximize the window to fill the screen/parent no matter what.
// http://bugzilla.ximian.com/show_bug.cgi?id=80021
XSetWMNormalHints(DisplayHandle, hwnd.whole_window, ref hints);
}
if ((maximized != Rectangle.Empty) && (maximized.Width > 0) && (maximized.Height > 0)) {
if (cp != null)
maximized.Size = TranslateWindowSizeToXWindowSize (cp);
hints.flags = (IntPtr)XSizeHintsFlags.PPosition;
hints.x = maximized.X;
hints.y = maximized.Y;
hints.width = maximized.Width;
hints.height = maximized.Height;
// Metacity does not seem to follow this constraint for maximized (zoomed) windows
XSetZoomHints(DisplayHandle, hwnd.whole_window, ref hints);
}
}