[PATCH 07/13] Cygwin/X: Correctly allow for the native window frame width in ValidateSizing()

Jon TURNEY jon.turney at dronecode.org.uk
Thu Feb 12 05:22:21 PST 2009


Colin Harrison wrote:
> Hi,
> 
> Jon wrote
>> XXX: Needs to allow for different border thickness when window is
> uncaptioned?
> 
> I found this works for me...
> --- ./save_winmultiwindowwndproc.c	2009-01-19 18:42:49.000000000 +0000
> +++ ./winmultiwindowwndproc.c	2009-01-19 18:43:30.000000000 +0000
> @@ -207,6 +209,7 @@

> -  /* Now remove size of any borders */
> -  iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME);
> -  iHeight -= (GetSystemMetrics(SM_CYCAPTION)
> -	      + 2 * GetSystemMetrics(SM_CYSIZEFRAME));
> -	      
> +  /* Now remove size of any borders and title bar */
> +  gwlStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
> +  if (gwlStyle & WS_CAPTION)
> +      iHeight -= GetSystemMetrics(SM_CYCAPTION);
> +  else 
> +    {
> +      iWidth += 2;  /* Small fiddle factors as sizebox appears to be */
> +      iHeight += 2; /* not the same thickness with and without a caption */
> +    }
> +  if (gwlStyle & WS_SIZEBOX)
> +    {
> +      iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME);
> +      iHeight -= 2 * GetSystemMetrics(SM_CYSIZEFRAME);
> +    }

Hmm... perhaps it would be better (less brittle) if it used the difference 
between GetClientRect() and GetWindowRect() to find the size of the native 
window frame and decorations, rather than trying to understand all the WS_ 
style bits?  So something like the following? (This appears to disagree with
the initial window sizing, though...)

diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index b5e789c..0dd8885 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -207,6 +207,8 @@ ValidateSizing (HWND hwnd, WindowPtr pWin,
    WinXSizeHints sizeHints;
    RECT *rect;
    int iWidth, iHeight;
+  RECT rcClient, rcWindow;
+  int iBorderWidthX, iBorderWidthY;

    /* Invalid input checking */
    if (pWin==NULL || lParam==0)
@@ -228,19 +230,20 @@ ValidateSizing (HWND hwnd, WindowPtr pWin,
    iWidth = rect->right - rect->left;
    iHeight = rect->bottom - rect->top;

-  /* Now remove size of any borders */
-  iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME);
-  iHeight -= (GetSystemMetrics(SM_CYCAPTION)
-             + 2 * GetSystemMetrics(SM_CYSIZEFRAME));
-
+  /* Now remove size of any borders and title bar */
+  GetClientRect(hwnd, &rcClient);
+  GetWindowRect(hwnd, &rcWindow);
+  iBorderWidthX = (rcWindow.right - rcWindow.left) - (rcClient.right - 
rcClient.left);
+  iBorderWidthY = (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - 
rcClient.top);
+  iWidth -= iBorderWidthX;
+  iHeight -= iBorderWidthY;

    /* Constrain the size to legal values */
    ConstrainSize (sizeHints, &iWidth, &iHeight);

-  /* Add back the borders */
-  iWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME);
-  iHeight += (GetSystemMetrics(SM_CYCAPTION)
-             + 2 * GetSystemMetrics(SM_CYSIZEFRAME));
+  /* Add back the size of borders and title bar */
+  iWidth += iBorderWidthX;
+  iHeight += iBorderWidthY;

    /* Adjust size according to where we're dragging from */
    switch(wParam) {




More information about the xorg mailing list