# HG changeset patch # User ib # Date 1315488650 0 # Node ID 9c2779f2407780b8820978861d6e12adbdf87857 # Parent 8e5680eccf54832cc2565b7a8e15df29184a0423 Move common code to new function wsWindowPosition(). Use the new function in wsCreateWindow() and wsMoveWindow(). diff -r 8e5680eccf54 -r 9c2779f24077 gui/wm/ws.c --- a/gui/wm/ws.c Thu Sep 08 12:34:28 2011 +0000 +++ b/gui/wm/ws.c Thu Sep 08 13:30:50 2011 +0000 @@ -377,6 +377,46 @@ } } +/** + * @brief Calculate and store the x and y position for a window. + * + * @param win pointer to a ws window structure + * @param x x position of the window (real/absolute or mock) + * @param y y position of the window (real/absolute or mock) + * @param width width of the area to place the window in + * @param height height of the area to place the window in + */ +static void wsWindowPosition(wsTWindow *win, int x, int y, int width, int height) +{ + switch (x) { + case -1: + win->X = wsOrgX + (wsMaxX - width) / 2; + break; + + case -2: + win->X = wsOrgX + wsMaxX - width; + break; + + default: + win->X = x; + break; + } + + switch (y) { + case -1: + win->Y = wsOrgY + (wsMaxY - height) / 2; + break; + + case -2: + win->Y = wsOrgY + wsMaxY - height; + break; + + default: + win->Y = y; + break; + } +} + // ---------------------------------------------------------------------------------------------- // Create window. // X,Y : window position @@ -402,34 +442,7 @@ wsHGC = DefaultGC(wsDisplay, wsScreen); -// The window position and size. - switch (X) { - case -1: - win->X = (wsMaxX / 2) - (wX / 2) + wsOrgX; - break; - - case -2: - win->X = wsMaxX - wX - 1 + wsOrgX; - break; - - default: - win->X = X; - break; - } - - switch (Y) { - case -1: - win->Y = (wsMaxY / 2) - (hY / 2) + wsOrgY; - break; - - case -2: - win->Y = wsMaxY - hY - 1 + wsOrgY; - break; - - default: - win->Y = Y; - break; - } + wsWindowPosition(win, X, Y, wX, hY); win->Width = wX; win->Height = hY; @@ -1060,35 +1073,8 @@ if (abs) { win->X = x; win->Y = y; - } else { - switch (x) { - case -1: - win->X = (wsMaxX / 2) - (win->Width / 2) + wsOrgX; - break; - - case -2: - win->X = wsMaxX - win->Width + wsOrgX; - break; - - default: - win->X = x; - break; - } - - switch (y) { - case -1: - win->Y = (wsMaxY / 2) - (win->Height / 2) + wsOrgY; - break; - - case -2: - win->Y = wsMaxY - win->Height + wsOrgY; - break; - - default: - win->Y = y; - break; - } - } + } else + wsWindowPosition(win, x, y, win->Width, win->Height); win->SizeHint.flags = PPosition | PWinGravity; win->SizeHint.x = win->X;