From 7860401b02f3d8cfc2dadb1364aa4f653cb22285 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 22 Oct 2019 23:42:44 +0200 Subject: Display.c: shorten code scope improvements, designated initializers --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 90 ++++++++++------------------ 1 file changed, 32 insertions(+), 58 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 6d62a978f..27e5aee79 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -371,13 +371,12 @@ static void nxagentSigchldHandler(int signal) { int pid = 0; int status; - int options; #ifdef TEST fprintf(stderr, "nxagentSigchldHandler: Going to check the children processes.\n"); #endif - options = WNOHANG | WUNTRACED; + int options = WNOHANG | WUNTRACED; /* * Try with the pid of the dialog process. @@ -732,8 +731,6 @@ int nxagentGetDataRate(void) static void nxagentDisplayFlushHandler(Display *display, int length) { - CARD32 time; - if (nxagentDisplay != NULL) { #ifdef TEST @@ -752,9 +749,7 @@ static void nxagentDisplayFlushHandler(Display *display, int length) { nxagentFlush = GetTimeInMillis(); - time = nxagentFlush; - - time = time - nxagentLastTime; + CARD32 time = nxagentFlush - nxagentLastTime; if (time < nxagentRateTime) { @@ -1126,9 +1121,8 @@ void nxagentResetSignalHandlers(void) void nxagentOpenDisplay(int argc, char *argv[]) { - int i; - - if (!nxagentDoFullGeneration) return; + if (!nxagentDoFullGeneration) + return; #ifdef NXAGENT_TIMESTAMP @@ -1230,7 +1224,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio nxagentDefaultColormaps = (Colormap *)malloc(nxagentNumDefaultColormaps * sizeof(Colormap)); - for (i = 0; i < nxagentNumDefaultColormaps; i++) + for (int i = 0; i < nxagentNumDefaultColormaps; i++) { nxagentDefaultColormaps[i] = XCreateColormap(nxagentDisplay, DefaultRootWindow(nxagentDisplay), @@ -1491,20 +1485,17 @@ void nxagentSetDefaultVisual(void) void nxagentInitVisuals(void) { - XVisualInfo vi; - XVisualInfo *viList = NULL; - - long mask; - int i, viNumList; - - mask = VisualScreenMask; - vi.screen = DefaultScreen(nxagentDisplay); - vi.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); - viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList); + long mask = VisualScreenMask; + XVisualInfo vi = { + .screen = DefaultScreen(nxagentDisplay), + .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)) + }; + int viNumList; + XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList); nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo)); nxagentNumVisuals = 0; - for (i = 0; i < viNumList; i++) + for (int i = 0; i < viNumList; i++) { if (viList[i].depth == vi.depth) { @@ -1547,10 +1538,6 @@ void nxagentInitVisuals(void) void nxagentInitDepths(void) { - #ifdef TEST - int i; - #endif - nxagentDepths = XListDepths(nxagentDisplay, DefaultScreen(nxagentDisplay), &nxagentNumDepths); @@ -1568,7 +1555,7 @@ void nxagentInitDepths(void) fprintf(stderr, "nxagentInitDepths: Got [%d] available depths:\n", nxagentNumDepths); - for (i = 0; i < nxagentNumDepths; i++) + for (int i = 0; i < nxagentNumDepths; i++) { fprintf(stderr, " [%d]", nxagentDepths[i]); } @@ -1580,9 +1567,6 @@ void nxagentInitDepths(void) void nxagentInitPixmapFormats(void) { - int i, j; - int depth; - /* * Formats are created with no care of which are supported * on the real display. Creating only formats supported @@ -1598,9 +1582,9 @@ XXX: Some X server doesn't list 1 among available depths... 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) { @@ -1608,7 +1592,7 @@ XXX: Some X server doesn't list 1 among available depths... } else { - for (j = 0; j < nxagentNumDepths; j++) + for (int j = 0; j < nxagentNumDepths; j++) { if (nxagentDepths[j] == i) { @@ -1667,14 +1651,12 @@ XXX: Some X server doesn't list 1 among available depths... void nxagentSetDefaultDrawables(void) { - int i, j; - - for (i = 0; i <= MAXDEPTH; i++) + for (int i = 0; i <= MAXDEPTH; i++) { nxagentDefaultDrawables[i] = None; } - for (i = 0; i < nxagentNumPixmapFormats; i++) + for (int i = 0; i < nxagentNumPixmapFormats; i++) { #ifdef TEST fprintf(stderr, "nxagentSetDefaultDrawables: Checking remote pixmap format [%d] with depth [%d] " @@ -1695,7 +1677,7 @@ void nxagentSetDefaultDrawables(void) } } - for (j = 0; j < nxagentNumDepths; j++) + for (int j = 0; j < nxagentNumDepths; j++) { #ifdef TEST fprintf(stderr, "nxagentSetDefaultDrawables: Checking depth at index [%d] with pixmap depth [%d] " @@ -1778,7 +1760,6 @@ FIXME: Is this needed? if (nxagentDisplay != NULL) { NXFreeCache(nxagentDisplay); - NXResetDisplay(nxagentDisplay); } @@ -1982,9 +1963,7 @@ static int nxagentCheckForDefaultDepthCompatibility(void) * deactivated. This is probably a very bad idea. */ - int dDepth; - - dDepth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); + int dDepth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); const unsigned int tolerance = nxagentOption(ReconnectTolerance); @@ -2327,28 +2306,24 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) static int nxagentInitAndCheckVisuals(int flexibility) { /* FIXME: does this also need work? */ - XVisualInfo viTemplate; - XVisualInfo *viList; - XVisualInfo *newVisuals; - - long viMask; - int i, n; bool matched; bool compatible = true; - int viNumList; - viMask = VisualScreenMask; - viTemplate.screen = DefaultScreen(nxagentDisplay); - viTemplate.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); - viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList); + long viMask = VisualScreenMask; + XVisualInfo viTemplate = { + .screen = DefaultScreen(nxagentDisplay), + .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; - for (n = 0; n < viNumList; n++) + for (int n = 0; n < viNumList; n++) { if (nxagentCompareVisuals(nxagentVisuals[i], viList[n]) == 1) { @@ -2458,7 +2433,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) Bool nxagentReconnectDisplay(void *p0) { - int i; int flexibility = *(int*)p0; #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_DISPLAY_DEBUG) @@ -2569,7 +2543,7 @@ Bool nxagentReconnectDisplay(void *p0) reconnectDisplayState = ALLOC_DEF_COLORMAP; - for (i = 0; i < nxagentNumDefaultColormaps; i++) + for (int i = 0; i < nxagentNumDefaultColormaps; i++) { if (nxagentVisualHasBeenIgnored[i]) { -- cgit v1.2.3 From b1d156888a3a75f1ec394702b1d4d8b10ef3e91f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 22 Oct 2019 23:42:13 +0200 Subject: Display.c: reformat comments --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 267 ++++++++++++--------------- 1 file changed, 113 insertions(+), 154 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 27e5aee79..50f85b257 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -212,20 +212,18 @@ int nxagentServerOrder(void) } /* - * FIXME: This error handler is not printing anything - * in the session log. This is OK once the session is - * started, because the error is handled by the other - * layers, but not before that point, as the agent - * would die without giving any feedback to the user - * (or, worse, to the NX server). We should check how - * many requests have been handled for this display - * and print a message if the display dies before the - * session is up and running. + * FIXME: This error handler is not printing anything in the session + * log. This is OK once the session is started, because the error is + * handled by the other layers, but not before that point, as the + * agent would die without giving any feedback to the user (or, worse, + * to the NX server). We should check how many requests have been + * handled for this display and print a message if the display dies + * before the session is up and running. */ /* - * FIXME: This should be moved to Error.c, The other - * handlers should be probably moved to Handlers.c. + * FIXME: This should be moved to Error.c, The other handlers should + * be probably moved to Handlers.c. */ int nxagentIOErrorHandler(Display *display) @@ -246,11 +244,9 @@ int nxagentIOErrorHandler(Display *display) } /* - * Force a shutdown of any connection attempt - * while connecting to the remote display. - * This is needed to avoid a hang up in case - * of loopback connections to our own listen- - * ing sockets. + * Force a shutdown of any connection attempt while connecting to the + * remote display. This is needed to avoid a hang up in case of + * loopback connections to our own listening sockets. */ static void nxagentRejectConnection(int signal) @@ -266,16 +262,15 @@ static void nxagentRejectConnection(int signal) #endif /* - * A further timeout is unlikely to happen - * in the case of loopback connections. + * A further timeout is unlikely to happen in the case of loopback + * connections. */ alarm(5); } /* - * Ignore the signal if the NX transport is - * not running. + * Ignore the signal if the NX transport is not running. */ static void nxagentSigusrHandler(int signal) @@ -379,8 +374,8 @@ static void nxagentSigchldHandler(int signal) int options = WNOHANG | WUNTRACED; /* - * Try with the pid of the dialog process. - * Leave the other children unaffected. + * Try with the pid of the dialog process. Leave the other children + * unaffected. */ if (nxagentRootlessDialogPid) @@ -574,22 +569,19 @@ Display *nxagentInternalOpenDisplay(char *display) int result; /* - * Stop the smart schedule timer since - * it uses SIGALRM as we do. + * Stop the smart schedule timer since it uses SIGALRM as we do. */ nxagentStopTimer(); /* - * Install the handler rejecting a possible - * loopback connection. + * Install the handler rejecting a possible loopback connection. */ /* -FIXME: Should print a warning if the user tries to let - the agent impersonate the same display as the - display where the agent is supposed to connect. - We actually handle this by means of RejectWell- - KnownSockets() but without giving a friendly +FIXME: Should print a warning if the user tries to let the agent + impersonate the same display as the display where the agent is + supposed to connect. We actually handle this by means of + RejectWellKnownSockets() but without giving a friendly explanation for the error to the user. */ @@ -645,9 +637,8 @@ static void nxagentDisplayBlockHandler(Display *display, int reason) if (nxagentDisplay != NULL) { /* - * Don't allow the smart schedule to - * interrupt the agent while waiting - * for the remote display. + * Don't allow the smart schedule to interrupt the agent while + * waiting for the remote display. */ #ifdef DEBUG @@ -674,8 +665,7 @@ static void nxagentDisplayBlockHandler(Display *display, int reason) { /* - * Let the dispatch attend the next - * client. + * Let the dispatch attend the next client. */ #ifdef DEBUG @@ -799,18 +789,17 @@ static int nxagentDisplayErrorPredicate(Display *display, int error) void nxagentInstallDisplayHandlers(void) { /* - * If the display was already opened, be sure - * all structures are freed. + * If the display was already opened, be sure all structures are + * freed. */ nxagentResetDisplayHandlers(); /* - * We want the Xlib I/O error handler to return, - * instead of quitting the application. Using - * setjmp()/longjmp() leaves the door open to - * unexpected bugs when dealing with interaction - * with the other X server layers. + * We want the Xlib I/O error handler to return, instead of quitting + * the application. Using setjmp()/longjmp() leaves the door open to + * unexpected bugs when dealing with interaction with the other X + * server layers. */ NXHandleDisplayError(1); @@ -828,14 +817,12 @@ void nxagentInstallDisplayHandlers(void) XSetIOErrorHandler(nxagentIOErrorHandler); /* - * Let Xlib become aware of our interrupts. In theory - * we don't need to have the error handler installed - * during the normal operations and could simply let - * the dispatcher handle the interrupts. In practice - * it's better to have Xlib invalidating the display - * as soon as possible rather than incurring in the - * risk of entering a loop that doesn't care checking - * the display errors explicitly. + * Let Xlib become aware of our interrupts. In theory we don't need + * to have the error handler installed during the normal operations + * and could simply let the dispatcher handle the interrupts. In + * practice it's better to have Xlib invalidating the display as + * soon as possible rather than incurring in the risk of entering a + * loop that doesn't care checking the display errors explicitly. */ #ifdef TEST @@ -848,8 +835,8 @@ void nxagentInstallDisplayHandlers(void) void nxagentPostInstallDisplayHandlers(void) { /* - * This is executed after having opened the - * display, once we know the display address. + * This is executed after having opened the display, once we know + * the display address. */ if (nxagentDisplay != NULL) @@ -881,15 +868,13 @@ void nxagentResetDisplayHandlers(void) if (nxagentDisplay != NULL) { /* - * Free the internal nxcompext - * structures. + * Free the internal nxcompext structures. */ NXResetDisplay(nxagentDisplay); /* - * Remove the display descriptor - * from the listened sockets. + * Remove the display descriptor from the listened sockets. */ nxagentRemoveXConnection(); @@ -912,8 +897,7 @@ void nxagentResetDisplayHandlers(void) nxagentCongestion = 0; /* - * Reset the counter of synchronization - * requests pending. + * Reset the counter of synchronization requests pending. */ nxagentTokens.soft = 0; @@ -937,9 +921,8 @@ void nxagentInstallSignalHandlers(void) #endif /* - * Keep the default X server's handlers for - * SIGINT and SIGTERM and restore the other - * signals of interest to our defaults. + * Keep the default X server's handlers for SIGINT and SIGTERM and + * restore the other signals of interest to our defaults. */ struct sigaction newAction; @@ -947,9 +930,9 @@ void nxagentInstallSignalHandlers(void) int result; /* - * By default nxcomp installs its signal handlers. - * We need to ensure that SIGUSR1 and SIGUSR2 are - * ignored if the NX transport is not running. + * By default nxcomp installs its signal handlers. We need to + * ensure that SIGUSR1 and SIGUSR2 are ignored if the NX transport + * is not running. */ newAction.sa_handler = nxagentSigusrHandler; @@ -993,8 +976,7 @@ void nxagentInstallSignalHandlers(void) } /* - * Let the smart schedule set the SIGALRM - * handler again. + * Let the smart schedule set the SIGALRM handler again. */ nxagentInitTimer(); @@ -1043,13 +1025,12 @@ void nxagentPostInstallSignalHandlers(void) #endif /* - * Reconfigure our signal handlers to work well - * with the NX transport. + * Reconfigure our signal handlers to work well with the NX + * transport. * - * Let our handlers manage the SIGINT and SIGTERM. - * The following calls will tell the NX transport - * to restore the old handlers (those originally - * installed by us or the X server). + * Let our handlers manage the SIGINT and SIGTERM. The following + * calls will tell the NX transport to restore the old handlers + * (those originally installed by us or the X server). */ NXTransSignal(SIGINT, NX_SIGNAL_DISABLE); @@ -1062,16 +1043,14 @@ void nxagentPostInstallSignalHandlers(void) NXTransSignal(SIGHUP, NX_SIGNAL_DISABLE); /* - * Both the proxy and the agent need to catch - * their children, so we'll have to send the - * signal to transport. + * Both the proxy and the agent need to catch their children, so + * we'll have to send the signal to transport. */ NXTransSignal(SIGCHLD, NX_SIGNAL_DISABLE); /* - * Let the NX transport take care of SIGUSR1 - * and SIGUSR2. + * Let the NX transport take care of SIGUSR1 and SIGUSR2. */ } @@ -1084,8 +1063,7 @@ void nxagentResetSignalHandlers(void) memset(&newAction, 0, sizeof(newAction)); /* - * Reset the signal handlers - * to a well known state. + * Reset the signal handlers to a well known state. */ #ifdef TEST @@ -1111,8 +1089,7 @@ void nxagentResetSignalHandlers(void) } /* - * Let the smart schedule set the SIGALRM - * handler again. + * Let the smart schedule set the SIGALRM handler again. */ nxagentInitTimer(); @@ -1134,8 +1111,8 @@ void nxagentOpenDisplay(int argc, char *argv[]) #endif /* - * Initialize the reconnector only in the case - * of persistent sessions. + * Initialize the reconnector only in the case of persistent + * sessions. */ if (nxagentOption(Persistent)) @@ -1163,8 +1140,8 @@ void nxagentOpenDisplay(int argc, char *argv[]) if (nxagentDisplay == NULL) { /* -FIXME: The agent should never exit the program with a FatalError() - but rather use a specific function that may eventually call +FIXME: The agent should never exit the program with a FatalError() but + rather use a specific function that may eventually call FatalError() on its turn. */ FatalError("Unable to open display '%s'.\n", nxagentDisplayName); @@ -1264,18 +1241,17 @@ N/A #endif /* - * Initialize the agent's event mask that will be requested - * for the root and all the top level windows. If the nested - * window is a child of an existing window, we will need to - * receive StructureNotify events. If we are going to manage - * the changes in root window's visibility we'll also need - * VisibilityChange events. + * Initialize the agent's event mask that will be requested for the + * root and all the top level windows. If the nested window is a + * child of an existing window, we will need to receive + * StructureNotify events. If we are going to manage the changes in + * root window's visibility we'll also need VisibilityChange events. */ /* -FIXME: Use of nxagentParentWindow is strongly deprecated. - We need also to clarify which events are selected - in the different operating modes. +FIXME: Use of nxagentParentWindow is strongly deprecated. We need + also to clarify which events are selected in the different + operating modes. */ nxagentInitDefaultEventMask(); @@ -1290,9 +1266,8 @@ FIXME: Use of nxagentParentWindow is strongly deprecated. (void) nxagentCheckForPixmapFormatsCompatibility(); /* - * Create a pixmap for each depth matching the - * local supported formats with format available - * on the remote display. + * Create a pixmap for each depth matching the local supported + * formats with format available on the remote display. */ nxagentSetDefaultDrawables(); @@ -1305,16 +1280,15 @@ FIXME: Use of nxagentParentWindow is strongly deprecated. #endif /* - * This GC is referenced in Cursor.c. It can be - * probably removed. + * This GC is referenced in Cursor.c. It can be probably removed. */ nxagentBitmapGC = XCreateGC(nxagentDisplay, nxagentDefaultDrawables[1], 0L, NULL); /* - * Note that this "confine window" is useless at the - * moment as we reimplement nxagentConstrainCursor() - * to skip the "constrain" stuff. + * Note that this "confine windoqw" is useless at the moment as we + * reimplement nxagentConstrainCursor() to skip the "constrain" + * stuff. */ #ifdef TEST @@ -1568,10 +1542,10 @@ void nxagentInitDepths(void) void nxagentInitPixmapFormats(void) { /* - * Formats are created with no care of which are supported - * on the real display. Creating only formats supported - * by the remote end makes troublesome handling migration - * of session from a display to another. + * Formats are created with no care of which are supported on the + * real display. Creating only formats supported by the remote end + * makes troublesome handling migration of session from a display to + * another. */ nxagentNumPixmapFormats = 0; @@ -1732,11 +1706,9 @@ void nxagentCloseDisplay(void) } /* - * If nxagentDoFullGeneration is true, all - * the X resources will be destroyed upon - * closing the display connection, so there - * is no real need to generate additional - * traffic + * If nxagentDoFullGeneration is true, all the X resources will be + * destroyed upon closing the display connection, so there is no + * real need to generate additional traffic */ SAFE_free(nxagentDefaultColormaps); @@ -1753,8 +1725,7 @@ FIXME: Is this needed? */ /* - * Free the image cache. This is useful - * for detecting memory leaks. + * Free the image cache. This is useful for detecting memory leaks. */ if (nxagentDisplay != NULL) @@ -1836,14 +1807,11 @@ void nxagentBackupDisplayInfo(void) } /* - * Since we need the display structure - * in order to behave correctly when no X - * connection is available, we must always - * have a good display record. - * It can be discarded only when a new X - * connection is available, so we store it - * in order to destroy whenever the recon- - * nection succed. + * Since we need the display structure in order to behave correctly + * when no X connection is available, we must always have a good + * display record. It can be discarded only when a new X connection + * is available, so we store it in order to destroy whenever the + * reconnection succeeds. */ nxagentDisplayBackup = nxagentDisplay; @@ -1925,9 +1893,8 @@ void nxagentDisconnectDisplay(void) case GOT_VISUAL_INFO: case OPENED: /* - * Actually we need the nxagentDisplay - * structure in order to let the agent - * go when no X connection is available. + * Actually we need the nxagentDisplay structure in order to let + * the agent go when no X connection is available. */ if (nxagentDisplay && @@ -2328,10 +2295,9 @@ static int nxagentInitAndCheckVisuals(int flexibility) if (nxagentCompareVisuals(nxagentVisuals[i], viList[n]) == 1) { /* -FIXME: Should the visual be ignored in this case? - We can flag the visuals with inverted masks, - and use this information to switch the masks - when contacting the remote X server. +FIXME: Should the visual be ignored in this case? We can flag the + visuals with inverted masks, and use this information to switch + the masks when contacting the remote X server. */ if (nxagentVisuals[i].red_mask == viList[n].blue_mask && nxagentVisuals[i].blue_mask == viList[n].red_mask) @@ -2502,9 +2468,8 @@ Bool nxagentReconnectDisplay(void *p0) DefaultScreenOfDisplay(nxagentDisplay)); /* - * After processing the arguments all the - * timeout values have been set. Now we - * have to change the screen-saver timeout. + * After processing the arguments all the timeout values have been + * set. Now we have to change the screen-saver timeout. */ nxagentSetScreenSaverTime(); @@ -2585,8 +2550,7 @@ Bool nxagentReconnectDisplay(void *p0) SAFE_XFree(nxagentRemotePixmapFormats); /* - * Check if all the required pixmap - * formats are supported. + * Check if all the required pixmap formats are supported. */ nxagentInitPixmapFormats(); @@ -2602,9 +2566,8 @@ Bool nxagentReconnectDisplay(void *p0) reconnectDisplayState = GOT_PIXMAP_FORMAT_LIST; /* - * Create a pixmap for each depth matching the - * local supported formats with format available - * on the remote display. + * Create a pixmap for each depth matching the local supported + * formats with format available on the remote display. */ nxagentSetDefaultDrawables(); @@ -2632,12 +2595,11 @@ Bool nxagentReconnectDisplay(void *p0) nxagentWhitePixel = WhitePixel(nxagentDisplay, DefaultScreen(nxagentDisplay)); /* - * Initialize the agent's event mask that will be requested - * for the root or all the top level windows. If the nested - * window is a child of an existing window we will need to - * receive StructureNotify events. If we are going to manage - * the changes in root window's visibility we'll also need - * VisibilityChange events. + * Initialize the agent's event mask that will be requested for the + * root or all the top level windows. If the nested window is a + * child of an existing window we will need to receive + * StructureNotify events. If we are going to manage the changes in + * root window's visibility we'll also need VisibilityChange events. */ nxagentInitDefaultEventMask(); @@ -2667,8 +2629,7 @@ Bool nxagentReconnectDisplay(void *p0) useXpmIcon = nxagentMakeIcon(nxagentDisplay, &nxagentIconPixmap, &nxagentIconShape); /* - * All went fine. We can continue - * handling our clients. + * All went fine. We can continue handling our clients. */ reconnectDisplayState = EVERYTHING_DONE; @@ -2701,10 +2662,9 @@ void nxagentRemoveXConnection(void) } /* - * Force an I/O error and wait until the NX trans- - * port is gone. It must be called before suspend- - * ing or terminating a session to ensure that the - * NX transport is terminated first. + * Force an I/O error and wait until the NX transport is gone. It must + * be called before suspending or terminating a session to ensure that + * the NX transport is terminated first. */ void nxagentWaitDisplay(void) @@ -2742,8 +2702,7 @@ void nxagentWaitDisplay(void) #endif /* - * Be sure the signal handlers are - * in a known state. + * Be sure the signal handlers are in a known state. */ nxagentResetSignalHandlers(); @@ -2760,9 +2719,9 @@ void nxagentWaitDisplay(void) void nxagentAbortDisplay(void) { /* - * Be sure the X server socket in .X11-unix is - * deleted otherwise other users may to become - * unable to run a session on the same display. + * Be sure the X server socket in .X11-unix is deleted otherwise + * other users may to become unable to run a session on the same + * display. */ #ifdef TEST -- cgit v1.2.3 From 88e3a37ad7abfa6e7172d7f84cae05c36b7c3d26 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 6 Sep 2019 00:28:14 +0200 Subject: Display.c: reformat comments --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 79 +++++++++++++--------------- 1 file changed, 36 insertions(+), 43 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 50f85b257..2fb8d4960 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -152,8 +152,8 @@ Drawable nxagentDefaultDrawables[MAXDEPTH + 1]; Pixmap nxagentScreenSaverPixmap; /* - * Also used in Cursor.c. There are huge problems - * using GC definition. This is to be reworked. + * Also used in Cursor.c. There are huge problems using GC + * definition. This is to be reworked. */ XlibGC nxagentBitmapGC; @@ -1188,9 +1188,8 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio DefaultScreenOfDisplay(nxagentDisplay)); /* - * Processing the arguments all the timeouts - * have been set. Now we have to change the - * screen-saver timeout. + * Processing the arguments all the timeouts have been set. Now we + * have to change the screen-saver timeout. */ nxagentSetScreenSaverTime(); @@ -1286,7 +1285,7 @@ FIXME: Use of nxagentParentWindow is strongly deprecated. We need nxagentBitmapGC = XCreateGC(nxagentDisplay, nxagentDefaultDrawables[1], 0L, NULL); /* - * Note that this "confine windoqw" is useless at the moment as we + * Note that this "confine window" is useless at the moment as we * reimplement nxagentConstrainCursor() to skip the "constrain" * stuff. */ @@ -1918,14 +1917,13 @@ static int nxagentCheckForDefaultDepthCompatibility(void) /* * Depending on the (reconnect) tolerance checks value, this * function checks stricter or looser: - * - Strict means that the old and new default depth values - * must match exactly. - * - Safe or Risky means that the default depth values might differ, - * but the new default depth value must be at least as - * high as the former default depth value. This is - * recommended, because it allows clients with a - * higher default depth value to still connect, but - * not lose functionality. + * - Strict means that the old and new default depth values must + * match exactly. + * - Safe or Risky means that the default depth values might + * differ, but the new default depth value must be at least as + * high as the former default depth value. This is recommended, + * because it allows clients with a higher default depth value + * to still connect, but not lose functionality. * - Bypass means that all of these checks are essentially * deactivated. This is probably a very bad idea. */ @@ -1982,18 +1980,16 @@ static int nxagentCheckForDepthsCompatibility(void) /* * Depending on the (reconnect) tolerance checks value, this * function checks stricter or looser: - * - Strict means that the number of old and new depths must - * match exactly and every old depth value must be - * available in the new depth array. - * - Safe means that the number of depths might diverge, - * but all former depth must also be included in the - * new depth array. This is recommended, because - * it allows clients with more depths to still - * connect, but not lose functionality. + * - Strict means that the number of old and new depths must match + * exactly and every old depth value must be available in the + * new depth array. + * - Safe means that the number of depths might diverge, but all + * former depth must also be included in the new depth + * array. This is recommended, because it allows clients with + * more depths to still connect, but not lose functionality. * - Risky means that the new depths array is allowed to be - * smaller than the old depths array, but at least - * one depth value must be included in both. - * This is potentially unsafe. + * smaller than the old depths array, but at least one depth + * value must be included in both. This is potentially unsafe. * - Bypass or higher means that all of these checks are * essentially deactivated. This is a very bad idea. */ @@ -2140,20 +2136,18 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) /* * Depending on the (reconnect) tolerance checks value, this * function checks stricter or looser: - * - Strict means that the number of internal and external - * pixmap formats must match exactly and every - * internal pixmap format must be available in the - * external pixmap format array. - * - Safe means that the number of pixmap formats might - * diverge, but all internal pixmap formats must - * also be included in the external pixmap formats - * array. This is recommended, because it allows - * clients with more pixmap formats to still connect, + * - Strict means that the number of internal and external pixmap + * formats must match exactly and every internal pixmap format + * must be available in the external pixmap format array. + * - Safe means that the number of pixmap formats might diverge, + * but all internal pixmap formats must also be included in the + * external pixmap formats array. This is recommended, because + * it allows clients with more pixmap formats to still connect, * but not lose functionality. - * - Risky means that the internal pixmap formats array is - * allowed to be smaller than the external pixmap - * formats array, but at least one pixmap format must - * be included in both. This is potentially unsafe. + * - Risky means that the internal pixmap formats array is allowed + * to be smaller than the external pixmap formats array, but at + * least one pixmap format must be included in both. This is + * potentially unsafe. * - Bypass or higher means that all of these checks are * essentially deactivated. This is a very bad idea. */ @@ -2709,11 +2703,10 @@ void nxagentWaitDisplay(void) } /* - * This has not to do with the remote display but - * with the X server that the agent is impersonating. - * We have it here to be consistent with the other - * cleanup procedures which have mainly to do with - * the Xlib display connection. + * This has not to do with the remote display but with the X server + * that the agent is impersonating. We have it here to be consistent + * with the other cleanup procedures which have mainly to do with the + * Xlib display connection. */ void nxagentAbortDisplay(void) -- cgit v1.2.3 From 462ad036e5d0414150f36f074be4ecb7f0ae7339 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 6 Sep 2019 00:29:14 +0200 Subject: Display.c: code simplification, scope improvements --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 45 +++++++++++----------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 2fb8d4960..51d75fefb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -561,8 +561,6 @@ static void nxagentSigchldHandler(int signal) Display *nxagentInternalOpenDisplay(char *display) { - Display *newDisplay; - struct sigaction oldAction; struct sigaction newAction; @@ -606,7 +604,7 @@ FIXME: Should print a warning if the user tries to let the agent display); #endif - newDisplay = XOpenDisplay(display); + Display *newDisplay = XOpenDisplay(display); alarm(0); @@ -1413,15 +1411,11 @@ N/A void nxagentSetDefaultVisual(void) { - XVisualInfo vi; - - int i; - if (nxagentUserDefaultClass || nxagentUserDefaultDepth) { nxagentDefaultVisualIndex = UNDEFINED; - for (i = 0; i < nxagentNumVisuals; i++) + for (int i = 0; i < nxagentNumVisuals; i++) { if ((!nxagentUserDefaultClass || nxagentVisuals[i].class == nxagentDefaultClass) @@ -1430,7 +1424,6 @@ void nxagentSetDefaultVisual(void) nxagentVisuals[i].depth == nxagentDefaultDepth)) { nxagentDefaultVisualIndex = i; - break; } } @@ -1442,11 +1435,13 @@ void nxagentSetDefaultVisual(void) } else { + XVisualInfo vi = {0}; + vi.visualid = XVisualIDFromVisual(DefaultVisual(nxagentDisplay, DefaultScreen(nxagentDisplay))); nxagentDefaultVisualIndex = 0; - for (i = 0; i < nxagentNumVisuals; i++) + for (int i = 0; i < nxagentNumVisuals; i++) { if (vi.visualid == nxagentVisuals[i].visualid) { @@ -1458,13 +1453,14 @@ void nxagentSetDefaultVisual(void) void nxagentInitVisuals(void) { - long mask = VisualScreenMask; XVisualInfo vi = { .screen = DefaultScreen(nxagentDisplay), - .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)) + .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)), }; + long mask = VisualScreenMask; int viNumList; XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList); + nxagentVisuals = (XVisualInfo *) malloc(viNumList * sizeof(XVisualInfo)); nxagentNumVisuals = 0; @@ -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", nxagentRemoteNumPixmapFormats); - for (i = 0; i < nxagentRemoteNumPixmapFormats; i++) + for (int i = 0; i < nxagentRemoteNumPixmapFormats; i++) { fprintf(stderr, "nxagentInitPixmapFormats: Remote pixmap format [%d]: depth [%d] " "bits_per_pixel [%d] scanline_pad [%d].\n", i, nxagentRemotePixmapFormats[i].depth, @@ -1882,9 +1878,7 @@ void nxagentDisconnectDisplay(void) case ALLOC_DEF_COLORMAP: if (nxagentDefaultColormaps) { - int i; - - for (i = 0; i < nxagentNumDefaultColormaps; i++) + for (int i = 0; i < nxagentNumDefaultColormaps; i++) { nxagentDefaultColormaps[i] = None; } @@ -2044,7 +2038,6 @@ static int nxagentCheckForDepthsCompatibility(void) bool compatible = true; bool one_match = false; - bool matched = false; int total_matches = 0; /* @@ -2066,7 +2059,7 @@ static int nxagentCheckForDepthsCompatibility(void) */ for (int i = 0; i < nxagentNumDepths; ++i) { - matched = false; + bool matched = false; for (int j = 0; j < nxagentNumDepthsRecBackup; ++j) { @@ -2200,12 +2193,11 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) */ bool compatible = true; - bool matched = false; int total_matches = 0; for (int i = 0; i < nxagentNumPixmapFormats; ++i) { - matched = false; + bool matched = false; for (int j = 0; j < nxagentRemoteNumPixmapFormats; ++j) { @@ -2267,22 +2259,22 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) static int nxagentInitAndCheckVisuals(int flexibility) { /* FIXME: does this also need work? */ - bool matched; - bool compatible = true; long viMask = VisualScreenMask; XVisualInfo viTemplate = { .screen = DefaultScreen(nxagentDisplay), - .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)) + .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)), }; int viNumList; XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList); XVisualInfo *newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals); + bool compatible = true; + for (int i = 0; i < nxagentNumVisuals; i++) { - matched = false; + bool matched = false; for (int n = 0; n < viNumList; n++) { @@ -2386,7 +2378,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) "doesn't match with old colormaps [%d].\n", nxagentNumDefaultColormaps, nxagentNumDefaultColormapsRecBackup); #endif - return 0; } } @@ -2633,9 +2624,7 @@ Bool nxagentReconnectDisplay(void *p0) void nxagentAddXConnection(void) { - int fd = XConnectionNumber(nxagentDisplay); - - nxagentXConnectionNumber = fd; + nxagentXConnectionNumber = XConnectionNumber(nxagentDisplay); #ifdef TEST fprintf(stderr, "nxagentAddXConnection: Adding the X connection [%d] " -- cgit v1.2.3 From 827defa14148cd8429f5863612aa9bf935d77cec Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 6 Sep 2019 00:30:05 +0200 Subject: Display.c: remove blank lines --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 51d75fefb..a93fd2418 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -1934,7 +1934,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) "is [%d], former default depth value is [%d].\n", tolerance, ToleranceChecksBypass, dDepth, nxagentDefaultDepthRecBackup); #endif - return 1; } @@ -1944,7 +1943,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) fprintf(stderr, "nxagentCheckForDefaultDepthCompatibility: New default depth [%d] " "matches with old default depth.\n", dDepth); #endif - return 1; } else if ((ToleranceChecksSafe <= tolerance) && (nxagentDefaultDepthRecBackup < dDepth)) @@ -1954,7 +1952,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) "higher than the old default depth [%d] at tolerance [%u].\n", dDepth, nxagentDefaultDepthRecBackup, tolerance); #endif - return 1; } else @@ -1964,7 +1961,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) "doesn't match with old default depth [%d] at tolerance [%u].\n", dDepth, nxagentDefaultDepthRecBackup, tolerance); #endif - return 0; } } @@ -1998,7 +1994,6 @@ static int nxagentCheckForDepthsCompatibility(void) "is [%d], number of old depths is [%d].\n", tolerance, ToleranceChecksBypass, nxagentNumDepths, nxagentNumDepthsRecBackup); #endif - return 1; } @@ -2010,7 +2005,6 @@ static int nxagentCheckForDepthsCompatibility(void) "depths [%d].\n", nxagentNumDepths, nxagentNumDepthsRecBackup); #endif - return 0; } @@ -2022,7 +2016,6 @@ static int nxagentCheckForDepthsCompatibility(void) "lower than number of old depths [%d].\n", tolerance, nxagentNumDepths, nxagentNumDepthsRecBackup); #endif - return 0; } @@ -2155,7 +2148,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) "pixmap formats is [%d], number of externally available pixmap formats is [%d].\n", tolerance, ToleranceChecksBypass, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); #endif - return 1; } @@ -2166,7 +2158,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) "of internal pixmap formats [%d] doesn't match with number of remote formats [%d].\n", nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); #endif - return 0; } @@ -2177,7 +2168,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) "and number of internal pixmap formats [%d] higher than number of external formats [%d].\n", tolerance, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); #endif - return 0; } @@ -2368,7 +2358,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) fprintf(stderr, "nxagentCheckForColormapsCompatibility: Number of new colormaps [%d] " "matches with old colormaps.\n", nxagentNumDefaultColormaps); #endif - return 1; } else -- cgit v1.2.3