Commit 462ad036 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Display.c: code simplification, scope improvements

parent 88e3a37a
...@@ -561,8 +561,6 @@ static void nxagentSigchldHandler(int signal) ...@@ -561,8 +561,6 @@ static void nxagentSigchldHandler(int signal)
Display *nxagentInternalOpenDisplay(char *display) Display *nxagentInternalOpenDisplay(char *display)
{ {
Display *newDisplay;
struct sigaction oldAction; struct sigaction oldAction;
struct sigaction newAction; struct sigaction newAction;
...@@ -606,7 +604,7 @@ FIXME: Should print a warning if the user tries to let the agent ...@@ -606,7 +604,7 @@ FIXME: Should print a warning if the user tries to let the agent
display); display);
#endif #endif
newDisplay = XOpenDisplay(display); Display *newDisplay = XOpenDisplay(display);
alarm(0); alarm(0);
...@@ -1413,15 +1411,11 @@ N/A ...@@ -1413,15 +1411,11 @@ N/A
void nxagentSetDefaultVisual(void) void nxagentSetDefaultVisual(void)
{ {
XVisualInfo vi;
int i;
if (nxagentUserDefaultClass || nxagentUserDefaultDepth) if (nxagentUserDefaultClass || nxagentUserDefaultDepth)
{ {
nxagentDefaultVisualIndex = UNDEFINED; nxagentDefaultVisualIndex = UNDEFINED;
for (i = 0; i < nxagentNumVisuals; i++) for (int i = 0; i < nxagentNumVisuals; i++)
{ {
if ((!nxagentUserDefaultClass || if ((!nxagentUserDefaultClass ||
nxagentVisuals[i].class == nxagentDefaultClass) nxagentVisuals[i].class == nxagentDefaultClass)
...@@ -1430,7 +1424,6 @@ void nxagentSetDefaultVisual(void) ...@@ -1430,7 +1424,6 @@ void nxagentSetDefaultVisual(void)
nxagentVisuals[i].depth == nxagentDefaultDepth)) nxagentVisuals[i].depth == nxagentDefaultDepth))
{ {
nxagentDefaultVisualIndex = i; nxagentDefaultVisualIndex = i;
break; break;
} }
} }
...@@ -1442,11 +1435,13 @@ void nxagentSetDefaultVisual(void) ...@@ -1442,11 +1435,13 @@ void nxagentSetDefaultVisual(void)
} }
else else
{ {
XVisualInfo vi = {0};
vi.visualid = XVisualIDFromVisual(DefaultVisual(nxagentDisplay, vi.visualid = XVisualIDFromVisual(DefaultVisual(nxagentDisplay,
DefaultScreen(nxagentDisplay))); DefaultScreen(nxagentDisplay)));
nxagentDefaultVisualIndex = 0; nxagentDefaultVisualIndex = 0;
for (i = 0; i < nxagentNumVisuals; i++) for (int i = 0; i < nxagentNumVisuals; i++)
{ {
if (vi.visualid == nxagentVisuals[i].visualid) if (vi.visualid == nxagentVisuals[i].visualid)
{ {
...@@ -1458,13 +1453,14 @@ void nxagentSetDefaultVisual(void) ...@@ -1458,13 +1453,14 @@ void nxagentSetDefaultVisual(void)
void nxagentInitVisuals(void) void nxagentInitVisuals(void)
{ {
long mask = VisualScreenMask;
XVisualInfo vi = { XVisualInfo vi = {
.screen = DefaultScreen(nxagentDisplay), .screen = DefaultScreen(nxagentDisplay),
.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)) .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)),
}; };
long mask = VisualScreenMask;
int viNumList; int viNumList;
XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList); XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList);
nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo)); nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo));
nxagentNumVisuals = 0; nxagentNumVisuals = 0;
...@@ -1612,7 +1608,7 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1612,7 +1608,7 @@ XXX: Some X server doesn't list 1 among available depths...
fprintf(stderr, "nxagentInitPixmapFormats: Got [%d] available remote pixmap formats:\n", fprintf(stderr, "nxagentInitPixmapFormats: Got [%d] available remote pixmap formats:\n",
nxagentRemoteNumPixmapFormats); nxagentRemoteNumPixmapFormats);
for (i = 0; i < nxagentRemoteNumPixmapFormats; i++) for (int i = 0; i < nxagentRemoteNumPixmapFormats; i++)
{ {
fprintf(stderr, "nxagentInitPixmapFormats: Remote pixmap format [%d]: depth [%d] " fprintf(stderr, "nxagentInitPixmapFormats: Remote pixmap format [%d]: depth [%d] "
"bits_per_pixel [%d] scanline_pad [%d].\n", i, nxagentRemotePixmapFormats[i].depth, "bits_per_pixel [%d] scanline_pad [%d].\n", i, nxagentRemotePixmapFormats[i].depth,
...@@ -1882,9 +1878,7 @@ void nxagentDisconnectDisplay(void) ...@@ -1882,9 +1878,7 @@ void nxagentDisconnectDisplay(void)
case ALLOC_DEF_COLORMAP: case ALLOC_DEF_COLORMAP:
if (nxagentDefaultColormaps) if (nxagentDefaultColormaps)
{ {
int i; for (int i = 0; i < nxagentNumDefaultColormaps; i++)
for (i = 0; i < nxagentNumDefaultColormaps; i++)
{ {
nxagentDefaultColormaps[i] = None; nxagentDefaultColormaps[i] = None;
} }
...@@ -2044,7 +2038,6 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2044,7 +2038,6 @@ static int nxagentCheckForDepthsCompatibility(void)
bool compatible = true; bool compatible = true;
bool one_match = false; bool one_match = false;
bool matched = false;
int total_matches = 0; int total_matches = 0;
/* /*
...@@ -2066,7 +2059,7 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2066,7 +2059,7 @@ static int nxagentCheckForDepthsCompatibility(void)
*/ */
for (int i = 0; i < nxagentNumDepths; ++i) for (int i = 0; i < nxagentNumDepths; ++i)
{ {
matched = false; bool matched = false;
for (int j = 0; j < nxagentNumDepthsRecBackup; ++j) for (int j = 0; j < nxagentNumDepthsRecBackup; ++j)
{ {
...@@ -2200,12 +2193,11 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2200,12 +2193,11 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
*/ */
bool compatible = true; bool compatible = true;
bool matched = false;
int total_matches = 0; int total_matches = 0;
for (int i = 0; i < nxagentNumPixmapFormats; ++i) for (int i = 0; i < nxagentNumPixmapFormats; ++i)
{ {
matched = false; bool matched = false;
for (int j = 0; j < nxagentRemoteNumPixmapFormats; ++j) for (int j = 0; j < nxagentRemoteNumPixmapFormats; ++j)
{ {
...@@ -2267,22 +2259,22 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2267,22 +2259,22 @@ 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? */
bool matched;
bool compatible = true;
long viMask = VisualScreenMask; long viMask = VisualScreenMask;
XVisualInfo viTemplate = { XVisualInfo viTemplate = {
.screen = DefaultScreen(nxagentDisplay), .screen = DefaultScreen(nxagentDisplay),
.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)) .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)),
}; };
int viNumList; int viNumList;
XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList); XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList);
XVisualInfo *newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals); XVisualInfo *newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals);
bool compatible = true;
for (int i = 0; i < nxagentNumVisuals; i++) for (int i = 0; i < nxagentNumVisuals; i++)
{ {
matched = false; bool matched = false;
for (int n = 0; n < viNumList; n++) for (int n = 0; n < viNumList; n++)
{ {
...@@ -2386,7 +2378,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) ...@@ -2386,7 +2378,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility)
"doesn't match with old colormaps [%d].\n", nxagentNumDefaultColormaps, "doesn't match with old colormaps [%d].\n", nxagentNumDefaultColormaps,
nxagentNumDefaultColormapsRecBackup); nxagentNumDefaultColormapsRecBackup);
#endif #endif
return 0; return 0;
} }
} }
...@@ -2633,9 +2624,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2633,9 +2624,7 @@ Bool nxagentReconnectDisplay(void *p0)
void nxagentAddXConnection(void) void nxagentAddXConnection(void)
{ {
int fd = XConnectionNumber(nxagentDisplay); nxagentXConnectionNumber = XConnectionNumber(nxagentDisplay);
nxagentXConnectionNumber = fd;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentAddXConnection: Adding the X connection [%d] " fprintf(stderr, "nxagentAddXConnection: Adding the X connection [%d] "
......
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