Commit 7860401b authored by Ulrich Sibiller's avatar Ulrich Sibiller

Display.c: shorten code

scope improvements, designated initializers
parent 44138137
...@@ -371,13 +371,12 @@ static void nxagentSigchldHandler(int signal) ...@@ -371,13 +371,12 @@ static void nxagentSigchldHandler(int signal)
{ {
int pid = 0; int pid = 0;
int status; int status;
int options;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSigchldHandler: Going to check the children processes.\n"); fprintf(stderr, "nxagentSigchldHandler: Going to check the children processes.\n");
#endif #endif
options = WNOHANG | WUNTRACED; int options = WNOHANG | WUNTRACED;
/* /*
* Try with the pid of the dialog process. * Try with the pid of the dialog process.
...@@ -732,8 +731,6 @@ int nxagentGetDataRate(void) ...@@ -732,8 +731,6 @@ int nxagentGetDataRate(void)
static void nxagentDisplayFlushHandler(Display *display, int length) static void nxagentDisplayFlushHandler(Display *display, int length)
{ {
CARD32 time;
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
{ {
#ifdef TEST #ifdef TEST
...@@ -752,9 +749,7 @@ static void nxagentDisplayFlushHandler(Display *display, int length) ...@@ -752,9 +749,7 @@ static void nxagentDisplayFlushHandler(Display *display, int length)
{ {
nxagentFlush = GetTimeInMillis(); nxagentFlush = GetTimeInMillis();
time = nxagentFlush; CARD32 time = nxagentFlush - nxagentLastTime;
time = time - nxagentLastTime;
if (time < nxagentRateTime) if (time < nxagentRateTime)
{ {
...@@ -1126,9 +1121,8 @@ void nxagentResetSignalHandlers(void) ...@@ -1126,9 +1121,8 @@ void nxagentResetSignalHandlers(void)
void nxagentOpenDisplay(int argc, char *argv[]) void nxagentOpenDisplay(int argc, char *argv[])
{ {
int i; if (!nxagentDoFullGeneration)
return;
if (!nxagentDoFullGeneration) return;
#ifdef NXAGENT_TIMESTAMP #ifdef NXAGENT_TIMESTAMP
...@@ -1230,7 +1224,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -1230,7 +1224,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
nxagentDefaultColormaps = (Colormap *)malloc(nxagentNumDefaultColormaps * nxagentDefaultColormaps = (Colormap *)malloc(nxagentNumDefaultColormaps *
sizeof(Colormap)); sizeof(Colormap));
for (i = 0; i < nxagentNumDefaultColormaps; i++) for (int i = 0; i < nxagentNumDefaultColormaps; i++)
{ {
nxagentDefaultColormaps[i] = XCreateColormap(nxagentDisplay, nxagentDefaultColormaps[i] = XCreateColormap(nxagentDisplay,
DefaultRootWindow(nxagentDisplay), DefaultRootWindow(nxagentDisplay),
...@@ -1491,20 +1485,17 @@ void nxagentSetDefaultVisual(void) ...@@ -1491,20 +1485,17 @@ void nxagentSetDefaultVisual(void)
void nxagentInitVisuals(void) void nxagentInitVisuals(void)
{ {
XVisualInfo vi; long mask = VisualScreenMask;
XVisualInfo *viList = NULL; XVisualInfo vi = {
.screen = DefaultScreen(nxagentDisplay),
long mask; .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay))
int i, viNumList; };
int viNumList;
mask = VisualScreenMask; XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList);
vi.screen = DefaultScreen(nxagentDisplay);
vi.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay));
viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList);
nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo)); nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo));
nxagentNumVisuals = 0; nxagentNumVisuals = 0;
for (i = 0; i < viNumList; i++) for (int i = 0; i < viNumList; i++)
{ {
if (viList[i].depth == vi.depth) if (viList[i].depth == vi.depth)
{ {
...@@ -1547,10 +1538,6 @@ void nxagentInitVisuals(void) ...@@ -1547,10 +1538,6 @@ void nxagentInitVisuals(void)
void nxagentInitDepths(void) void nxagentInitDepths(void)
{ {
#ifdef TEST
int i;
#endif
nxagentDepths = XListDepths(nxagentDisplay, DefaultScreen(nxagentDisplay), nxagentDepths = XListDepths(nxagentDisplay, DefaultScreen(nxagentDisplay),
&nxagentNumDepths); &nxagentNumDepths);
...@@ -1568,7 +1555,7 @@ void nxagentInitDepths(void) ...@@ -1568,7 +1555,7 @@ void nxagentInitDepths(void)
fprintf(stderr, "nxagentInitDepths: Got [%d] available depths:\n", fprintf(stderr, "nxagentInitDepths: Got [%d] available depths:\n",
nxagentNumDepths); nxagentNumDepths);
for (i = 0; i < nxagentNumDepths; i++) for (int i = 0; i < nxagentNumDepths; i++)
{ {
fprintf(stderr, " [%d]", nxagentDepths[i]); fprintf(stderr, " [%d]", nxagentDepths[i]);
} }
...@@ -1580,9 +1567,6 @@ void nxagentInitDepths(void) ...@@ -1580,9 +1567,6 @@ void nxagentInitDepths(void)
void nxagentInitPixmapFormats(void) void nxagentInitPixmapFormats(void)
{ {
int i, j;
int depth;
/* /*
* Formats are created with no care of which are supported * Formats are created with no care of which are supported
* on the real display. Creating only formats supported * on the real display. Creating only formats supported
...@@ -1598,9 +1582,9 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1598,9 +1582,9 @@ XXX: Some X server doesn't list 1 among available depths...
nxagentPixmapFormats = malloc((nxagentNumDepths + 1) * sizeof(XPixmapFormatValues)); nxagentPixmapFormats = malloc((nxagentNumDepths + 1) * sizeof(XPixmapFormatValues));
for (i = 1; i <= MAXDEPTH; i++) for (int i = 1; i <= MAXDEPTH; i++)
{ {
depth = 0; int depth = 0;
if (i == 1) if (i == 1)
{ {
...@@ -1608,7 +1592,7 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1608,7 +1592,7 @@ XXX: Some X server doesn't list 1 among available depths...
} }
else else
{ {
for (j = 0; j < nxagentNumDepths; j++) for (int j = 0; j < nxagentNumDepths; j++)
{ {
if (nxagentDepths[j] == i) if (nxagentDepths[j] == i)
{ {
...@@ -1667,14 +1651,12 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1667,14 +1651,12 @@ XXX: Some X server doesn't list 1 among available depths...
void nxagentSetDefaultDrawables(void) void nxagentSetDefaultDrawables(void)
{ {
int i, j; for (int i = 0; i <= MAXDEPTH; i++)
for (i = 0; i <= MAXDEPTH; i++)
{ {
nxagentDefaultDrawables[i] = None; nxagentDefaultDrawables[i] = None;
} }
for (i = 0; i < nxagentNumPixmapFormats; i++) for (int i = 0; i < nxagentNumPixmapFormats; i++)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSetDefaultDrawables: Checking remote pixmap format [%d] with depth [%d] " fprintf(stderr, "nxagentSetDefaultDrawables: Checking remote pixmap format [%d] with depth [%d] "
...@@ -1695,7 +1677,7 @@ void nxagentSetDefaultDrawables(void) ...@@ -1695,7 +1677,7 @@ void nxagentSetDefaultDrawables(void)
} }
} }
for (j = 0; j < nxagentNumDepths; j++) for (int j = 0; j < nxagentNumDepths; j++)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSetDefaultDrawables: Checking depth at index [%d] with pixmap depth [%d] " fprintf(stderr, "nxagentSetDefaultDrawables: Checking depth at index [%d] with pixmap depth [%d] "
...@@ -1778,7 +1760,6 @@ FIXME: Is this needed? ...@@ -1778,7 +1760,6 @@ FIXME: Is this needed?
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
{ {
NXFreeCache(nxagentDisplay); NXFreeCache(nxagentDisplay);
NXResetDisplay(nxagentDisplay); NXResetDisplay(nxagentDisplay);
} }
...@@ -1982,9 +1963,7 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -1982,9 +1963,7 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
* deactivated. This is probably a very bad idea. * deactivated. This is probably a very bad idea.
*/ */
int dDepth; int dDepth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay));
dDepth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay));
const unsigned int tolerance = nxagentOption(ReconnectTolerance); const unsigned int tolerance = nxagentOption(ReconnectTolerance);
...@@ -2327,28 +2306,24 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2327,28 +2306,24 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
static int nxagentInitAndCheckVisuals(int flexibility) static int nxagentInitAndCheckVisuals(int flexibility)
{ {
/* FIXME: does this also need work? */ /* FIXME: does this also need work? */
XVisualInfo viTemplate;
XVisualInfo *viList;
XVisualInfo *newVisuals;
long viMask;
int i, n;
bool matched; bool matched;
bool compatible = true; bool compatible = true;
int viNumList;
viMask = VisualScreenMask; long viMask = VisualScreenMask;
viTemplate.screen = DefaultScreen(nxagentDisplay); XVisualInfo viTemplate = {
viTemplate.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); .screen = DefaultScreen(nxagentDisplay),
viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList); .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay))
};
int viNumList;
XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList);
newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals); XVisualInfo *newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals);
for (i = 0; i < nxagentNumVisuals; i++) for (int i = 0; i < nxagentNumVisuals; i++)
{ {
matched = false; matched = false;
for (n = 0; n < viNumList; n++) for (int n = 0; n < viNumList; n++)
{ {
if (nxagentCompareVisuals(nxagentVisuals[i], viList[n]) == 1) if (nxagentCompareVisuals(nxagentVisuals[i], viList[n]) == 1)
{ {
...@@ -2458,7 +2433,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) ...@@ -2458,7 +2433,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility)
Bool nxagentReconnectDisplay(void *p0) Bool nxagentReconnectDisplay(void *p0)
{ {
int i;
int flexibility = *(int*)p0; int flexibility = *(int*)p0;
#if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_DISPLAY_DEBUG) #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_DISPLAY_DEBUG)
...@@ -2569,7 +2543,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2569,7 +2543,7 @@ Bool nxagentReconnectDisplay(void *p0)
reconnectDisplayState = ALLOC_DEF_COLORMAP; reconnectDisplayState = ALLOC_DEF_COLORMAP;
for (i = 0; i < nxagentNumDefaultColormaps; i++) for (int i = 0; i < nxagentNumDefaultColormaps; i++)
{ {
if (nxagentVisualHasBeenIgnored[i]) if (nxagentVisualHasBeenIgnored[i])
{ {
......
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