Commit 43d3b655 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Screen.c: improve readability of size calculations

... by using some short named variables and the min() macro. No change in behaviour.
parent 8dea3075
...@@ -885,8 +885,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -885,8 +885,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
#endif #endif
/* /*
* Forced geometry parameter * Forced geometry parameter to user geometry.
* to user geometry.
*/ */
if (nxagentResizeDesktopAtStartup) if (nxagentResizeDesktopAtStartup)
...@@ -903,32 +902,26 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -903,32 +902,26 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
if (nxagentUserGeometry.flag & WidthValue) if (nxagentUserGeometry.flag & WidthValue)
{ {
nxagentChangeOption(Width, nxagentUserGeometry.Width); int uw = nxagentUserGeometry.Width;
nxagentChangeOption(RootWidth, nxagentUserGeometry.Width);
if (nxagentOption(SavedWidth) > nxagentUserGeometry.Width) nxagentChangeOption(Width, uw);
{ nxagentChangeOption(RootWidth, uw);
nxagentChangeOption(SavedWidth, nxagentUserGeometry.Width); nxagentChangeOption(SavedWidth, min(nxagentOption(SavedWidth), uw));
}
} }
if (nxagentUserGeometry.flag & HeightValue) if (nxagentUserGeometry.flag & HeightValue)
{ {
nxagentChangeOption(Height, nxagentUserGeometry.Height); int uh = nxagentUserGeometry.Height;
nxagentChangeOption(RootHeight, nxagentUserGeometry.Height);
if (nxagentOption(SavedHeight) > nxagentUserGeometry.Height) nxagentChangeOption(Height, uh);
{ nxagentChangeOption(RootHeight, uh);
nxagentChangeOption(SavedHeight, nxagentUserGeometry.Height); nxagentChangeOption(SavedHeight, min(nxagentOption(SavedHeight), uh));
}
} }
} }
/* /*
* This is first time the * This is first time the screen is initialized.
* screen is initialized. * Filling the geometry parameter from user geometry.
* Filling the geometry parameter
* from user geometry.
*/ */
if (nxagentReconnectTrap == False) if (nxagentReconnectTrap == False)
...@@ -971,10 +964,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -971,10 +964,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
} }
/* /*
* Determine the size of the root window. * Determine the size of the root window. It is the maximum size of
* It is the maximum size of the screen * the screen if we are either in rootless or in fullscreen mode.
* if we are either in rootless or in
* fullscreen mode.
*/ */
if (nxagentOption(Rootless) == False && !nxagentWMIsRunning) if (nxagentOption(Rootless) == False && !nxagentWMIsRunning)
...@@ -1013,46 +1004,58 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1013,46 +1004,58 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
nxagentChangeOption(BorderWidth, 0); nxagentChangeOption(BorderWidth, 0);
/* get the screen size of the real X server once */
int w = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
int h = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
if (nxagentOption(Fullscreen)) if (nxagentOption(Fullscreen))
{ {
nxagentChangeOption(X, 0); nxagentChangeOption(X, 0);
nxagentChangeOption(Y, 0); nxagentChangeOption(Y, 0);
nxagentChangeOption(Width, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(Width, w);
nxagentChangeOption(Height, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(Height, h);
/* first time screen initialization or resize during reconnect */
if (nxagentReconnectTrap == False || nxagentResizeDesktopAtStartup) if (nxagentReconnectTrap == False || nxagentResizeDesktopAtStartup)
{ {
nxagentChangeOption(RootWidth, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(RootWidth, w);
nxagentChangeOption(RootHeight, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(RootHeight, h);
if (nxagentOption(RootWidth) > WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) if (nxagentOption(RootWidth) > w)
{ {
nxagentChangeOption(SavedWidth, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) * 3 / 4); nxagentChangeOption(SavedWidth, w * 3 / 4);
} }
else else
{ {
nxagentChangeOption(SavedWidth, nxagentOption(RootWidth)); nxagentChangeOption(SavedWidth, nxagentOption(RootWidth));
} }
if (nxagentOption(RootHeight) > HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) if (nxagentOption(RootHeight) > h)
{ {
nxagentChangeOption(SavedHeight, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) * 3 / 4); nxagentChangeOption(SavedHeight, h * 3 / 4);
} }
else else
{ {
nxagentChangeOption(SavedHeight, nxagentOption(RootHeight)); nxagentChangeOption(SavedHeight, nxagentOption(RootHeight));
} }
}
nxagentChangeOption(RootX, ((WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) - nxagentChangeOption(RootX, 0);
nxagentOption(RootWidth)) / 2)); nxagentChangeOption(RootY, 0);
nxagentChangeOption(RootY, ((HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) - }
nxagentOption(RootHeight)) / 2)); else
{
/* center */
nxagentChangeOption(RootX, (w - nxagentOption(RootWidth)) / 2);
nxagentChangeOption(RootY, (h - nxagentOption(RootHeight)) / 2);
}
} }
else else
{ {
/*
* screen is initialized for the first time
*/
if (nxagentReconnectTrap == False) if (nxagentReconnectTrap == False)
{ {
nxagentChangeOption(RootX, 0); nxagentChangeOption(RootX, 0);
...@@ -1063,53 +1066,44 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1063,53 +1066,44 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
} }
/* /*
* Be sure that the agent window won't be bigger * Ensure that the agent window won't be bigger
* than the root window. * than the root window.
*/ */
if (nxagentOption(Width) > nxagentOption(RootWidth)) nxagentChangeOption(Width, min(nxagentOption(Width), nxagentOption(RootWidth)));
{ nxagentChangeOption(Height, min(nxagentOption(Height), nxagentOption(RootHeight)));
nxagentChangeOption(Width, nxagentOption(RootWidth));
}
if (nxagentOption(Height) > nxagentOption(RootHeight))
{
nxagentChangeOption(Height, nxagentOption(RootHeight));
}
/* /*
* Be sure that the agent window won't be bigger * Be sure that the agent window won't be bigger
* than the X server root window. * than the X server root window.
*/ */
if (nxagentOption(Width) > WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) if (nxagentOption(Width) > w)
{ {
nxagentChangeOption(Width, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) * 3 / 4); nxagentChangeOption(Width, w * 3 / 4);
} }
if (nxagentOption(Height) > HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) if (nxagentOption(Height) > h)
{ {
nxagentChangeOption(Height, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) * 3 / 4); nxagentChangeOption(Height, h * 3 / 4);
} }
/* /*
* Forcing the agent window geometry to be equal to * Forcing the agent window geometry to be equal to the root
* the root window geometry the first time the * window geometry the first time the screen is initialized if the
* screen is initialized if the geometry hasn't been * geometry hasn't been explicitly set in the option file and if
* esplicitly set in the option file and if * the root window isn't bigger than the X server root window..
* the root window isn't bigger than the X server
* root window..
*/ */
if (nxagentReconnectTrap == False) if (nxagentReconnectTrap == False)
{ {
if ((nxagentOption(RootWidth) < WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) && if ((nxagentOption(RootWidth) < w) &&
!(nxagentUserGeometry.flag & WidthValue)) !(nxagentUserGeometry.flag & WidthValue))
{ {
nxagentChangeOption(Width, nxagentOption(RootWidth)); nxagentChangeOption(Width, nxagentOption(RootWidth));
} }
if ((nxagentOption(RootHeight) < HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))) && if ((nxagentOption(RootHeight) < h) &&
!(nxagentUserGeometry.flag & HeightValue)) !(nxagentUserGeometry.flag & HeightValue))
{ {
nxagentChangeOption(Height, nxagentOption(RootHeight)); nxagentChangeOption(Height, nxagentOption(RootHeight));
...@@ -1118,11 +1112,9 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1118,11 +1112,9 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
if (resetAgentPosition) if (resetAgentPosition)
{ {
nxagentChangeOption(X, ((WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) - /* center */
nxagentOption(Width)) / 2)); nxagentChangeOption(X, (w - nxagentOption(Width)) / 2);
nxagentChangeOption(Y, (h - nxagentOption(Height)) / 2);
nxagentChangeOption(Y, ((HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)) -
nxagentOption(Height)) / 2));
} }
nxagentChangeOption(SavedWidth, nxagentOption(RootWidth)); nxagentChangeOption(SavedWidth, nxagentOption(RootWidth));
...@@ -1131,8 +1123,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1131,8 +1123,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
if (nxagentOption(Rootless)) if (nxagentOption(Rootless))
{ {
nxagentChangeOption(RootWidth, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(RootWidth, w);
nxagentChangeOption(RootHeight, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); nxagentChangeOption(RootHeight, h);
} }
nxagentChangeOption(SavedRootWidth, nxagentOption(RootWidth)); nxagentChangeOption(SavedRootWidth, nxagentOption(RootWidth));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment