Unverified Commit a261b724 authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/code_cleanup' into 3.6.x

parents 0e2b7479 adca0cc9
...@@ -46,19 +46,13 @@ int nxagentCheckBinder(int argc, char *argv[], int i) ...@@ -46,19 +46,13 @@ int nxagentCheckBinder(int argc, char *argv[], int i)
{ {
if (++i < argc) if (++i < argc)
{ {
char *display; char *display = argv[i];
char *found;
int port;
display = argv[i];
/* /*
* Check if a display specification follows * Check if a display specification follows the -B switch.
* the -B switch.
*/ */
found = rindex(display, ':'); char *found = rindex(display, ':');
if (found == NULL || *(found + 1) == '\0' || if (found == NULL || *(found + 1) == '\0' ||
isdigit(*(found + 1)) == 0) isdigit(*(found + 1)) == 0)
...@@ -69,7 +63,7 @@ int nxagentCheckBinder(int argc, char *argv[], int i) ...@@ -69,7 +63,7 @@ int nxagentCheckBinder(int argc, char *argv[], int i)
return 0; return 0;
} }
port = atoi(found + 1); int port = atoi(found + 1);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCheckBinder: Identified agent display port [%d].\n", fprintf(stderr, "nxagentCheckBinder: Identified agent display port [%d].\n",
...@@ -78,8 +72,8 @@ int nxagentCheckBinder(int argc, char *argv[], int i) ...@@ -78,8 +72,8 @@ int nxagentCheckBinder(int argc, char *argv[], int i)
/* /*
* The NX options must be specified in the DISPLAY * The NX options must be specified in the DISPLAY
* environment. Check if the display specified on * environment. Check if the display specified on the command line
* the command line matches the NX virtual display. * matches the NX virtual display.
*/ */
display = getenv("DISPLAY"); display = getenv("DISPLAY");
...@@ -108,8 +102,8 @@ int nxagentCheckBinder(int argc, char *argv[], int i) ...@@ -108,8 +102,8 @@ int nxagentCheckBinder(int argc, char *argv[], int i)
#endif #endif
/* /*
* Save the proxy options. They will be later * Save the proxy options. They will be later used to create the
* used to create the transport. * transport.
*/ */
nxagentChangeOption(Rootless, False); nxagentChangeOption(Rootless, False);
...@@ -117,10 +111,9 @@ int nxagentCheckBinder(int argc, char *argv[], int i) ...@@ -117,10 +111,9 @@ int nxagentCheckBinder(int argc, char *argv[], int i)
nxagentChangeOption(Binder, True); nxagentChangeOption(Binder, True);
/* /*
* FIXME: This now points to the buffer that was * FIXME: This now points to the buffer that was returned by
* returned by getenv(). It is to be decided how * getenv(). It is to be decided how to handle the values of type
* to handle the values of type string in the * string in the Options repository.
* Options repository.
*/ */
nxagentChangeOption(BinderOptions, display); nxagentChangeOption(BinderOptions, display);
......
...@@ -115,4 +115,3 @@ nxagentFourByteSwap(unsigned char *buf, int nbytes) ...@@ -115,4 +115,3 @@ nxagentFourByteSwap(unsigned char *buf, int nbytes)
buf[2] = c; buf[2] = c;
} }
} }
...@@ -54,8 +54,7 @@ ...@@ -54,8 +54,7 @@
#include "Utils.h" #include "Utils.h"
/* /*
* Need to include this after the stub * Need to include this after the stub definition of GC in Agent.h.
* definition of GC in Agent.h.
*/ */
#include "compext/Compext.h" #include "compext/Compext.h"
...@@ -70,22 +69,20 @@ ...@@ -70,22 +69,20 @@
#undef DEBUG #undef DEBUG
/* /*
* Returns the last signal delivered * Returns the last signal delivered to the process.
* to the process.
*/ */
extern int _X11TransSocketCheckSignal(void); extern int _X11TransSocketCheckSignal(void);
/* /*
* Time in milliseconds of first iteration * Time in milliseconds of first iteration through the dispatcher.
* through the dispatcher.
*/ */
unsigned long nxagentStartTime = -1; unsigned long nxagentStartTime = -1;
/* /*
* If defined, add a function checking if we * If defined, add a function checking if we need a null timeout after
* need a null timeout after a client wakeup. * a client wakeup.
*/ */
#undef CHECK_RESTARTED_CLIENTS #undef CHECK_RESTARTED_CLIENTS
...@@ -103,8 +100,8 @@ void nxagentCheckRestartedClients(struct timeval **timeout); ...@@ -103,8 +100,8 @@ void nxagentCheckRestartedClients(struct timeval **timeout);
int nxagentClientPrivateIndex; int nxagentClientPrivateIndex;
/* /*
* The master nxagent holds in nxagentShadowCounter * The master nxagent holds in nxagentShadowCounter the number of
* the number of shadow nxagents connected to itself. * shadow nxagents connected to itself.
*/ */
int nxagentShadowCounter = 0; int nxagentShadowCounter = 0;
...@@ -120,8 +117,8 @@ void nxagentInitClientPrivates(ClientPtr client) ...@@ -120,8 +117,8 @@ void nxagentInitClientPrivates(ClientPtr client)
} }
/* /*
* Guess the running application based on the * Guess the running application based on the properties attached to
* properties attached to its main window. * its main window.
*/ */
void nxagentGuessClientHint(ClientPtr client, Atom property, char *data) void nxagentGuessClientHint(ClientPtr client, Atom property, char *data)
...@@ -199,8 +196,8 @@ void nxagentGuessShadowHint(ClientPtr client, Atom property) ...@@ -199,8 +196,8 @@ void nxagentGuessShadowHint(ClientPtr client, Atom property)
#endif #endif
/* /*
* From this moment on we ignore the visibility * From this moment on we ignore the visibility checks to keep
* checks to keep the windows updated. * the windows updated.
*/ */
nxagentChangeOption(IgnoreVisibility, 1); nxagentChangeOption(IgnoreVisibility, 1);
...@@ -210,7 +207,6 @@ void nxagentGuessShadowHint(ClientPtr client, Atom property) ...@@ -210,7 +207,6 @@ void nxagentGuessShadowHint(ClientPtr client, Atom property)
void nxagentCheckIfShadowAgent(ClientPtr client) void nxagentCheckIfShadowAgent(ClientPtr client)
{ {
if (nxagentClientPriv(client) -> clientHint == NXAGENT_SHADOW) if (nxagentClientPriv(client) -> clientHint == NXAGENT_SHADOW)
{ {
#ifdef TEST #ifdef TEST
...@@ -234,14 +230,11 @@ void nxagentCheckIfShadowAgent(ClientPtr client) ...@@ -234,14 +230,11 @@ void nxagentCheckIfShadowAgent(ClientPtr client)
nxagentShadowCounter); nxagentShadowCounter);
#endif #endif
if (nxagentShadowCounter == 0) if (nxagentShadowCounter == 0)
{ {
/* /*
* The last shadow nxagent has been detached * The last shadow nxagent has been detached from master
* from master nxagent. * nxagent. The master nxagent could do some action here.
* The master nxagent could do some action
* here.
*/ */
#ifdef TEST #ifdef TEST
...@@ -255,13 +248,11 @@ void nxagentCheckIfShadowAgent(ClientPtr client) ...@@ -255,13 +248,11 @@ void nxagentCheckIfShadowAgent(ClientPtr client)
void nxagentWakeupByReconnect(void) void nxagentWakeupByReconnect(void)
{ {
int i;
#ifdef TEST #ifdef TEST
fprintf(stderr, "++++++nxagentWakeupByReconnect: Going to wakeup all clients.\n"); fprintf(stderr, "++++++nxagentWakeupByReconnect: Going to wakeup all clients.\n");
#endif #endif
for (i = 1; i < currentMaxClients; i++) for (int i = 1; i < currentMaxClients; i++)
{ {
if (clients[i] != NULL) if (clients[i] != NULL)
{ {
...@@ -343,8 +334,7 @@ void nxagentWaitWakeupBySplit(ClientPtr client) ...@@ -343,8 +334,7 @@ void nxagentWaitWakeupBySplit(ClientPtr client)
#endif #endif
/* /*
* Be sure we intercept an I/O error * Be sure we intercept an I/O error as well as an interrupt.
* as well as an interrupt.
*/ */
#ifdef USE_FINISH_SPLIT #ifdef USE_FINISH_SPLIT
...@@ -358,11 +348,9 @@ void nxagentWaitWakeupBySplit(ClientPtr client) ...@@ -358,11 +348,9 @@ void nxagentWaitWakeupBySplit(ClientPtr client)
for (;;) for (;;)
{ {
/* /*
* Can we handle all the possible events here * Can we handle all the possible events here or we need to select
* or we need to select only the split events? * only the split events? Handling all the possible events would
* Handling all the possible events would pre- * preempt the queue and make a better use of the link.
* empt the queue and make a better use of the
* link.
*/ */
#ifdef WAIT_ALL_EVENTS #ifdef WAIT_ALL_EVENTS
...@@ -407,9 +395,9 @@ void nxagentWaitWakeupBySplit(ClientPtr client) ...@@ -407,9 +395,9 @@ void nxagentWaitWakeupBySplit(ClientPtr client)
int nxagentSuspendBySplit(ClientPtr client) int nxagentSuspendBySplit(ClientPtr client)
{ {
/* /*
FIXME: Should record a serial number for the client, so that FIXME: Should record a serial number for the client, so that the
the client is not restarted because of an end of split client is not restarted because of an end of split of a
of a previous client with the same index. previous client with the same index.
*/ */
if (client -> index < MAX_CONNECTIONS) if (client -> index < MAX_CONNECTIONS)
{ {
...@@ -453,9 +441,9 @@ FIXME: Should record a serial number for the client, so that ...@@ -453,9 +441,9 @@ FIXME: Should record a serial number for the client, so that
int nxagentWakeupBySplit(ClientPtr client) int nxagentWakeupBySplit(ClientPtr client)
{ {
/* /*
FIXME: Should record a serial number for the client, so that FIXME: Should record a serial number for the client, so that the
the client is not restarted because of the end of the client is not restarted because of the end of the split for a
split for a previous client with the same index. previous client with the same index.
*/ */
if (client -> index < MAX_CONNECTIONS) if (client -> index < MAX_CONNECTIONS)
{ {
...@@ -498,16 +486,13 @@ void nxagentCheckRestartedClients(struct timeval **timeout) ...@@ -498,16 +486,13 @@ void nxagentCheckRestartedClients(struct timeval **timeout)
{ {
static struct timeval zero; static struct timeval zero;
int i;
/* /*
* If any of the restarted clients had requests * If any of the restarted clients had requests in input we'll need
* in input we'll need to enter the select with * to enter the select with a null timeout, or we will block until
* a null timeout, or we will block until any * any other client becomes available.
* other client becomes available.
*/ */
for (i = 1; i < currentMaxClients; i++) for (int i = 1; i < currentMaxClients; i++)
{ {
if (clients[i] != NULL && clients[i] -> osPrivate != NULL && if (clients[i] != NULL && clients[i] -> osPrivate != NULL &&
nxagentNeedWakeup(clients[i]) == 0) nxagentNeedWakeup(clients[i]) == 0)
...@@ -542,5 +527,4 @@ void nxagentCheckRestartedClients(struct timeval **timeout) ...@@ -542,5 +527,4 @@ void nxagentCheckRestartedClients(struct timeval **timeout)
} }
} }
} }
#endif #endif
...@@ -296,12 +296,10 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen) ...@@ -296,12 +296,10 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
*/ */
if (icws.numWindows) if (icws.numWindows)
{ {
WindowPtr pWin;
Visual *visual;
ColormapPtr pCmap; ColormapPtr pCmap;
pWin = nxagentWindowPtr(icws.windows[0]); WindowPtr pWin = nxagentWindowPtr(icws.windows[0]);
visual = nxagentVisualFromID(pScreen, wVisual(pWin)); Visual *visual = nxagentVisualFromID(pScreen, wVisual(pWin));
if (visual == nxagentDefaultVisual(pScreen)) if (visual == nxagentDefaultVisual(pScreen))
pCmap = (ColormapPtr)LookupIDByType(wColormap(pWin), pCmap = (ColormapPtr)LookupIDByType(wColormap(pWin),
...@@ -380,9 +378,7 @@ void nxagentDirectUninstallColormaps(ScreenPtr pScreen) ...@@ -380,9 +378,7 @@ void nxagentDirectUninstallColormaps(ScreenPtr pScreen)
int n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs); int n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
ColormapPtr pCmap; ColormapPtr pCmap = (ColormapPtr)LookupIDByType(pCmapIDs[i], RT_COLORMAP);
pCmap = (ColormapPtr)LookupIDByType(pCmapIDs[i], RT_COLORMAP);
if (pCmap) if (pCmap)
XUninstallColormap(nxagentDisplay, nxagentColormap(pCmap)); XUninstallColormap(nxagentDisplay, nxagentColormap(pCmap));
} }
......
...@@ -44,8 +44,7 @@ ...@@ -44,8 +44,7 @@
#undef DEBUG #undef DEBUG
/* /*
* Set if the composite extension is supported * Set if the composite extension is supported by the remote display.
* by the remote display.
*/ */
int nxagentCompositeEnable = UNDEFINED; int nxagentCompositeEnable = UNDEFINED;
...@@ -53,8 +52,7 @@ int nxagentCompositeEnable = UNDEFINED; ...@@ -53,8 +52,7 @@ int nxagentCompositeEnable = UNDEFINED;
void nxagentCompositeExtensionInit(void) void nxagentCompositeExtensionInit(void)
{ {
/* /*
* Set the flag only if the initialization * Set the flag only if the initialization completes.
* completes.
*/ */
nxagentCompositeEnable = 0; nxagentCompositeEnable = 0;
...@@ -70,8 +68,8 @@ void nxagentCompositeExtensionInit(void) ...@@ -70,8 +68,8 @@ void nxagentCompositeExtensionInit(void)
if (XCompositeQueryExtension(nxagentDisplay, &eventBase, &errorBase) == 1) if (XCompositeQueryExtension(nxagentDisplay, &eventBase, &errorBase) == 1)
{ {
/* /*
* At the moment we don't need to care * At the moment we don't need to care the version of the
* the version of the extension. * extension.
*/ */
#ifdef TEST #ifdef TEST
...@@ -117,8 +115,6 @@ void nxagentCompositeExtensionInit(void) ...@@ -117,8 +115,6 @@ void nxagentCompositeExtensionInit(void)
void nxagentRedirectDefaultWindows(void) void nxagentRedirectDefaultWindows(void)
{ {
int i;
if (nxagentOption(Rootless) == 1 || if (nxagentOption(Rootless) == 1 ||
nxagentCompositeEnable == 0) nxagentCompositeEnable == 0)
{ {
...@@ -131,7 +127,7 @@ void nxagentRedirectDefaultWindows(void) ...@@ -131,7 +127,7 @@ void nxagentRedirectDefaultWindows(void)
return; return;
} }
for (i = 0; i < screenInfo.numScreens; i++) for (int i = 0; i < screenInfo.numScreens; i++)
{ {
WindowPtr pWin = screenInfo.screens[i]->root; WindowPtr pWin = screenInfo.screens[i]->root;
...@@ -143,13 +139,12 @@ void nxagentRedirectDefaultWindows(void) ...@@ -143,13 +139,12 @@ void nxagentRedirectDefaultWindows(void)
#endif #endif
/* /*
* When trying to redirect only the top level window, * When trying to redirect only the top level window, and not the
* and not the subwindows, we incur in a strange be- * subwindows, we incur in a strange be- haviour. The top level is
* haviour. The top level is unmapped, mapped, unmap- * unmapped, mapped, unmap- ped and then reparented. This at first
* ped and then reparented. This at first makes the * makes the agent think that the window manager is gone, then the
* agent think that the window manager is gone, then * agent window disappears. To make thinks even more weird, this
* the agent window disappears. To make thinks even * happens only at reconnection.
* more weird, this happens only at reconnection.
*/ */
XCompositeRedirectSubwindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], XCompositeRedirectSubwindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
......
...@@ -78,10 +78,8 @@ is" without express or implied warranty. ...@@ -78,10 +78,8 @@ is" without express or implied warranty.
#undef DEBUG #undef DEBUG
/* /*
* Defined in Display.c. There are huge * Defined in Display.c. There are huge problems mixing the GC
* problems mixing the GC definition in * definition in Xlib with the server code. This must be reworked.
* Xlib with the server code. This must
* be reworked.
*/ */
extern XlibGC nxagentBitmapGC; extern XlibGC nxagentBitmapGC;
...@@ -95,24 +93,20 @@ extern CursorPtr GetSpriteCursor(void); ...@@ -95,24 +93,20 @@ extern CursorPtr GetSpriteCursor(void);
void nxagentConstrainCursor(ScreenPtr pScreen, BoxPtr pBox) void nxagentConstrainCursor(ScreenPtr pScreen, BoxPtr pBox)
{ {
#ifdef TEST #ifdef TEST
int width = nxagentOption(RootWidth);
int width, height; int height = nxagentOption(RootHeight);
width = nxagentOption(RootWidth);
height = nxagentOption(RootHeight);
if (pBox->x1 <= 0 && pBox->y1 <= 0 && if (pBox->x1 <= 0 && pBox->y1 <= 0 &&
pBox->x2 >= width && pBox->y2 >= height) pBox->x2 >= width && pBox->y2 >= height)
{ {
fprintf(stderr, "nxagentConstrainCursor: Called with box [%d,%d,%d,%d]. " fprintf(stderr, "%s: Called with box [%d,%d,%d,%d]. Skipping the operation.\n",
"Skipping the operation.\n", pBox->x1, pBox->y1, pBox->x2, pBox->y2); __func__, pBox->x1, pBox->y1, pBox->x2, pBox->y2);
} }
else else
{ {
fprintf(stderr, "nxagentConstrainCursor: WARNING! Called with box [%d,%d,%d,%d].\n", fprintf(stderr, "%s: WARNING! Called with box [%d,%d,%d,%d].\n", __func__,
pBox->x1, pBox->y1, pBox->x2, pBox->y2); pBox->x1, pBox->y1, pBox->x2, pBox->y2);
} }
#endif #endif
} }
...@@ -124,16 +118,12 @@ void nxagentCursorLimits(ScreenPtr pScreen, CursorPtr pCursor, ...@@ -124,16 +118,12 @@ void nxagentCursorLimits(ScreenPtr pScreen, CursorPtr pCursor,
Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor) Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor)
{ {
/* /*
* Don't define the root cursor * Don't define the root cursor so that nxagent root window inherits
* so that nxagent root window * the parent's cursor.
* inherits the parent's cursor.
*/ */
Cursor cursor; Cursor cursor = (pCursor != rootCursor) ? nxagentCursor(pCursor, pScreen): None;
cursor = (pCursor != rootCursor) ? nxagentCursor(pCursor, pScreen): None;
if (nxagentOption(Rootless) == False) if (nxagentOption(Rootless) == False)
{ {
...@@ -142,7 +132,7 @@ Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -142,7 +132,7 @@ Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor)
cursor); cursor);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisplayCursor: Called for cursor at [%p] with private [%p].\n", fprintf(stderr, "%s: Called for cursor at [%p] with private [%p].\n", __func__,
(void *) pCursor, pCursor->devPriv[pScreen->myNum]); (void *) pCursor, pCursor->devPriv[pScreen->myNum]);
#endif #endif
} }
...@@ -152,43 +142,35 @@ Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -152,43 +142,35 @@ Bool nxagentDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor)
Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
{ {
XImage *image;
Pixmap source, mask;
XColor fg_color, bg_color;
unsigned long valuemask;
XGCValues values;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentRealizeCursor: Called for cursor at [%p].\n", (void *) pCursor); fprintf(stderr, "%s: Called for cursor at [%p].\n", __func__, (void *) pCursor);
#endif #endif
valuemask = GCFunction | unsigned long valuemask = GCFunction | GCPlaneMask | GCForeground | GCBackground | GCClipMask;
GCPlaneMask |
GCForeground |
GCBackground |
GCClipMask;
values.function = GXcopy; XGCValues values = {
values.plane_mask = AllPlanes; .function = GXcopy,
values.foreground = 1L; .plane_mask = AllPlanes,
values.background = 0L; .foreground = 1L,
values.clip_mask = None; .background = 0L,
.clip_mask = None,
};
XChangeGC(nxagentDisplay, nxagentBitmapGC, valuemask, &values); XChangeGC(nxagentDisplay, nxagentBitmapGC, valuemask, &values);
source = XCreatePixmap(nxagentDisplay, Pixmap source = XCreatePixmap(nxagentDisplay,
nxagentDefaultWindows[pScreen->myNum], nxagentDefaultWindows[pScreen->myNum],
pCursor->bits->width, pCursor->bits->width,
pCursor->bits->height, pCursor->bits->height,
1); 1);
mask = XCreatePixmap(nxagentDisplay, Pixmap mask = XCreatePixmap(nxagentDisplay,
nxagentDefaultWindows[pScreen->myNum], nxagentDefaultWindows[pScreen->myNum],
pCursor->bits->width, pCursor->bits->width,
pCursor->bits->height, pCursor->bits->height,
1); 1);
image = XCreateImage(nxagentDisplay, XImage *image = XCreateImage(nxagentDisplay,
nxagentDefaultVisual(pScreen), nxagentDefaultVisual(pScreen),
1, XYBitmap, 0, 1, XYBitmap, 0,
(char *)pCursor->bits->source, (char *)pCursor->bits->source,
...@@ -197,11 +179,9 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -197,11 +179,9 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
BitmapPad(nxagentDisplay), 0); BitmapPad(nxagentDisplay), 0);
/* /*
* If we used nxagentImageNormalize() here, * If we used nxagentImageNormalize() here, we'd swap our own cursor
* we'd swap our own cursor data in place. * data in place. Change byte_order and bitmap_bit_order in the
* Change byte_order and bitmap_bit_order * image struct to let Xlib do the swap for us.
* in the image struct to let Xlib do the
* swap for us.
*/ */
image -> byte_order = IMAGE_BYTE_ORDER; image -> byte_order = IMAGE_BYTE_ORDER;
...@@ -232,13 +212,17 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -232,13 +212,17 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
SAFE_XFree(image); SAFE_XFree(image);
fg_color.red = pCursor->foreRed; XColor fg_color = {
fg_color.green = pCursor->foreGreen; .red = pCursor->foreRed,
fg_color.blue = pCursor->foreBlue; .green = pCursor->foreGreen,
.blue = pCursor->foreBlue,
};
bg_color.red = pCursor->backRed; XColor bg_color = {
bg_color.green = pCursor->backGreen; .red = pCursor->backRed,
bg_color.blue = pCursor->backBlue; .green = pCursor->backGreen,
.blue = pCursor->backBlue,
};
pCursor->devPriv[pScreen->myNum] = (void *) malloc(sizeof(nxagentPrivCursor)); pCursor->devPriv[pScreen->myNum] = (void *) malloc(sizeof(nxagentPrivCursor));
...@@ -249,7 +233,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -249,7 +233,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
nxagentCursorUsesRender(pCursor, pScreen) = 0; nxagentCursorUsesRender(pCursor, pScreen) = 0;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentRealizeCursor: Set cursor private at [%p] cursor is [%ld].\n", fprintf(stderr, "%s: Set cursor private at [%p] cursor is [%ld].\n", __func__,
(void *) nxagentCursorPriv(pCursor, pScreen), (void *) nxagentCursorPriv(pCursor, pScreen),
nxagentCursorPriv(pCursor, pScreen) -> cursor); nxagentCursorPriv(pCursor, pScreen) -> cursor);
#endif #endif
...@@ -282,15 +266,17 @@ Bool nxagentUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -282,15 +266,17 @@ Bool nxagentUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
void nxagentRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, void nxagentRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor,
Bool displayed) Bool displayed)
{ {
XColor fg_color, bg_color; XColor fg_color = {
.red = pCursor->foreRed,
fg_color.red = pCursor->foreRed; .green = pCursor->foreGreen,
fg_color.green = pCursor->foreGreen; .blue = pCursor->foreBlue,
fg_color.blue = pCursor->foreBlue; };
bg_color.red = pCursor->backRed; XColor bg_color = {
bg_color.green = pCursor->backGreen; .red = pCursor->backRed,
bg_color.blue = pCursor->backBlue; .green = pCursor->backGreen,
.blue = pCursor->backBlue,
};
XRecolorCursor(nxagentDisplay, XRecolorCursor(nxagentDisplay,
nxagentCursor(pCursor, pScreen), nxagentCursor(pCursor, pScreen),
...@@ -310,10 +296,9 @@ Bool nxagentSetCursorPosition(ScreenPtr pScreen, int x, int y, ...@@ -310,10 +296,9 @@ Bool nxagentSetCursorPosition(ScreenPtr pScreen, int x, int y,
else else
{ {
/* /*
* Calling miSetCursorPosition with generateEvent == 0 * Calling miSetCursorPosition with generateEvent == 0 causes a
* causes a crash in miPoiterUpdate(). * crash in miPoiterUpdate().
*/ */
return 1; return 1;
} }
} }
...@@ -323,15 +308,8 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2) ...@@ -323,15 +308,8 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2)
Bool* pBool = (Bool*)p2; Bool* pBool = (Bool*)p2;
CursorPtr pCursor = (CursorPtr) p0; CursorPtr pCursor = (CursorPtr) p0;
AnimCurPtr ac; #if defined( TEST) || defined(NXAGENT_RECONNECT_CURSOR_DEBUG)
int j; fprintf(stderr, "%s: pCursor at [%p]\n", __func__, pCursor);
#ifdef TEST
fprintf(stderr, "nxagentReconnectCursor: pCursor at [%p]\n", pCursor);
#endif
#ifdef NXAGENT_RECONNECT_CURSOR_DEBUG
fprintf(stderr, "nxagentReconnectCursor: pCursor at [%p]\n", pCursor);
#endif #endif
if (!*pBool || !pCursor) if (!*pBool || !pCursor)
...@@ -344,22 +322,21 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2) ...@@ -344,22 +322,21 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2)
if (nxagentIsAnimCursor(pCursor)) if (nxagentIsAnimCursor(pCursor))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentReconnectCursor: nxagentIsAnimCursor pCursor at [%p]\n", pCursor); fprintf(stderr, "%s: nxagentIsAnimCursor pCursor at [%p]\n", __func__, pCursor);
#endif #endif
ac = nxagentGetAnimCursor(pCursor); AnimCurPtr ac = nxagentGetAnimCursor(pCursor);
for (j = 0; j < ac->nelt; j++) for (int j = 0; j < ac->nelt; j++)
{ {
nxagentReconnectCursor (ac->elts[j].pCursor, x1, p2); nxagentReconnectCursor (ac->elts[j].pCursor, x1, p2);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentReconnectCursor: Iteration [%d] pCursor at [%p]\n", j, ac->elts[j].pCursor); fprintf(stderr, "%s: Iteration [%d] pCursor at [%p]\n", __func__, j, ac->elts[j].pCursor);
#endif #endif
} }
} }
} }
else else
{ {
if (nxagentCursorUsesRender(pCursor, nxagentDefaultScreen)) if (nxagentCursorUsesRender(pCursor, nxagentDefaultScreen))
...@@ -376,14 +353,14 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2) ...@@ -376,14 +353,14 @@ void nxagentReconnectCursor(void * p0, XID x1, void * p2)
free(nxagentCursorPriv(pCursor, nxagentDefaultScreen)); free(nxagentCursorPriv(pCursor, nxagentDefaultScreen));
if (!nxagentRealizeCursor(nxagentDefaultScreen, pCursor)) if (!nxagentRealizeCursor(nxagentDefaultScreen, pCursor))
{ {
fprintf(stderr, "nxagentReconnectCursor: nxagentRealizeCursor failed\n"); fprintf(stderr, "%s: nxagentRealizeCursor failed\n", __func__);
*pBool = False; *pBool = False;
} }
} }
} }
#ifdef NXAGENT_RECONNECT_CURSOR_DEBUG #ifdef NXAGENT_RECONNECT_CURSOR_DEBUG
fprintf(stderr, "nxagentReconnectCursor: %p - ID %lx\n", pCursor, nxagentCursor(pCursor, nxagentDefaultScreen)); fprintf(stderr, "%s: %p - ID %lx\n", __func__, pCursor, nxagentCursor(pCursor, nxagentDefaultScreen));
#endif #endif
} }
...@@ -405,29 +382,26 @@ void nxagentReDisplayCurrentCursor(void) ...@@ -405,29 +382,26 @@ void nxagentReDisplayCurrentCursor(void)
Bool nxagentReconnectAllCursor(void *p0) Bool nxagentReconnectAllCursor(void *p0)
{ {
int i;
Bool r = True; Bool r = True;
GrabPtr grab = inputInfo.pointer -> grab; GrabPtr grab = inputInfo.pointer -> grab;
#if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_CURSOR_DEBUG) #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_CURSOR_DEBUG)
fprintf(stderr, "nxagentReconnectAllCursor\n"); fprintf(stderr, "%s\n", __func__);
#endif #endif
for (i = 0, r = 1; i < MAXCLIENTS; r = 1, i++) for (int i = 0; i < MAXCLIENTS; r = 1, i++)
{ {
if (clients[i]) if (clients[i])
{ {
FindClientResourcesByType(clients[i], RT_CURSOR, nxagentReconnectCursor, &r); FindClientResourcesByType(clients[i], RT_CURSOR, nxagentReconnectCursor, &r);
#ifdef WARNING #ifdef WARNING
if (r == False) if (r == False)
{ {
fprintf(stderr, "nxagentReconnectAllCursor: WARNING! Failed to recreate " fprintf(stderr, "%s: WARNING! Failed to recreate "
"cursor for client [%d].\n", i); "cursor for client [%d].\n", __func__, i);
} }
#endif #endif
} }
} }
...@@ -445,9 +419,6 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2) ...@@ -445,9 +419,6 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2)
Bool* pBool = (Bool *) p2; Bool* pBool = (Bool *) p2;
CursorPtr pCursor = (CursorPtr) p0; CursorPtr pCursor = (CursorPtr) p0;
AnimCurPtr ac;
int j;
if (!*pBool || !pCursor) if (!*pBool || !pCursor)
{ {
return; return;
...@@ -458,17 +429,17 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2) ...@@ -458,17 +429,17 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2)
if (nxagentIsAnimCursor(pCursor)) if (nxagentIsAnimCursor(pCursor))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisconnectCursor: nxagentIsAnimCursor pCursor at [%p]\n", pCursor); fprintf(stderr, "%s: nxagentIsAnimCursor pCursor at [%p]\n", __func__, pCursor);
#endif #endif
ac = nxagentGetAnimCursor(pCursor); AnimCurPtr ac = nxagentGetAnimCursor(pCursor);
for (j = 0; j < ac->nelt; j++) for (int j = 0; j < ac->nelt; j++)
{ {
nxagentDisconnectCursor (ac->elts[j].pCursor, x1, p2); nxagentDisconnectCursor (ac->elts[j].pCursor, x1, p2);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisconnectCursor: Iteration [%d] pCursor at [%p]\n", j, ac->elts[j].pCursor); fprintf(stderr, "%s: Iteration [%d] pCursor at [%p]\n", __func__, j, ac->elts[j].pCursor);
#endif #endif
} }
} }
...@@ -476,29 +447,28 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2) ...@@ -476,29 +447,28 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2)
} }
#ifdef NXAGENT_RECONNECT_CURSOR_DEBUG #ifdef NXAGENT_RECONNECT_CURSOR_DEBUG
fprintf(stderr, "nxagentDisconnectCursor: %p - ID %lx\n", fprintf(stderr, "%s: %p - ID %lx\n", __func__, pCursor,
pCursor,
nxagentCursor(pCursor, nxagentDefaultScreen)); nxagentCursor(pCursor, nxagentDefaultScreen));
#endif #endif
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisconnectCursor: Called with bool [%d].\n", *pBool); fprintf(stderr, "%s: Called with bool [%d].\n", __func__, *pBool);
fprintf(stderr, "nxagentDisconnectCursor: Pointer to cursor is [%p] with counter [%d].\n", fprintf(stderr, "%s: Pointer to cursor is [%p] with counter [%d].\n", __func__,
(void *) pCursor, pCursor -> refcnt); (void *) pCursor, pCursor -> refcnt);
fprintf(stderr, "nxagentDisconnectCursor: Dummy screen is at [%p].\n", fprintf(stderr, "%s: Dummy screen is at [%p].\n", __func__,
(void *) nxagentDefaultScreen); (void *) nxagentDefaultScreen);
fprintf(stderr, "nxagentDisconnectCursor: Cursor private is at [%p].\n", fprintf(stderr, "%s: Cursor private is at [%p].\n", __func__,
(void *) nxagentCursorPriv(pCursor, nxagentDefaultScreen)); (void *) nxagentCursorPriv(pCursor, nxagentDefaultScreen));
#endif #endif
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisconnectCursor: Dummy screen number is [%d].\n", fprintf(stderr, "%s: Dummy screen number is [%d].\n", __func__,
nxagentDefaultScreen -> myNum); nxagentDefaultScreen -> myNum);
fprintf(stderr, "nxagentDisconnectCursor: Cursor is [%ld].\n", fprintf(stderr, "%s: Cursor is [%ld].\n", __func__,
nxagentCursor(pCursor, nxagentDefaultScreen)); nxagentCursor(pCursor, nxagentDefaultScreen));
#endif #endif
...@@ -510,7 +480,7 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2) ...@@ -510,7 +480,7 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2)
int ret = 1; int ret = 1;
#if defined(NXAGENT_RECONNECT_CURSOR_DEBUG) || defined(NXAGENT_RECONNECT_PICTURE_DEBUG) #if defined(NXAGENT_RECONNECT_CURSOR_DEBUG) || defined(NXAGENT_RECONNECT_PICTURE_DEBUG)
fprintf(stderr, "nxagentDisconnectCursor: disconnecting attached picture %p\n", pPicture); fprintf(stderr, "%s: disconnecting attached picture %p\n", __func__, pPicture);
#endif #endif
nxagentDisconnectPicture(pPicture, 0, &ret); nxagentDisconnectPicture(pPicture, 0, &ret);
...@@ -519,29 +489,26 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2) ...@@ -519,29 +489,26 @@ void nxagentDisconnectCursor(void * p0, XID x1, void * p2)
Bool nxagentDisconnectAllCursor(void) Bool nxagentDisconnectAllCursor(void)
{ {
int i;
Bool r = True; Bool r = True;
GrabPtr grab = inputInfo.pointer -> grab; GrabPtr grab = inputInfo.pointer -> grab;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDisconnectAllCursor: Going to iterate through cursor resources.\n"); fprintf(stderr, "%s: Going to iterate through cursor resources.\n", __func__);
#endif #endif
for (i = 0, r = 1; i < MAXCLIENTS; r = 1, i++) for (int i = 0; i < MAXCLIENTS; r = 1, i++)
{ {
if (clients[i]) if (clients[i])
{ {
FindClientResourcesByType(clients[i], RT_CURSOR, nxagentDisconnectCursor, &r); FindClientResourcesByType(clients[i], RT_CURSOR, nxagentDisconnectCursor, &r);
#ifdef WARNING #ifdef WARNING
if (r == False) if (r == False)
{ {
fprintf(stderr, "nxagentDisconnectAllCursor: WARNING! Failed to disconnect " fprintf(stderr, "%s: WARNING! Failed to disconnect "
"cursor for client [%d].\n", i); "cursor for client [%d].\n", __func__, i);
} }
#endif #endif
} }
} }
...@@ -572,23 +539,19 @@ void nxagentListCursor(void *p0, void *p1, void *p2) ...@@ -572,23 +539,19 @@ void nxagentListCursor(void *p0, void *p1, void *p2)
void nxagentListCursors(void) void nxagentListCursors(void)
{ {
int i; Bool r = True;
Bool r;
for (i = 0, r = 1; i < MAXCLIENTS; r = 1, i++) for (int i = 0; i < MAXCLIENTS; r = 1, i++)
{ {
if (clients[i]) if (clients[i])
{ {
FindClientResourcesByType(clients[i], RT_CURSOR, nxagentListCursor, &r); FindClientResourcesByType(clients[i], RT_CURSOR, nxagentListCursor, &r);
#ifdef WARNING #ifdef WARNING
if (r == False) if (r == False)
{ {
fprintf(stderr, "nxagentListCursors: WARNING! Failed to list " fprintf(stderr, "%s: WARNING! Failed to list cursor for client [%d].\n", __func__, i);
"cursor for client [%d].\n", i);
} }
#endif #endif
} }
} }
......
...@@ -198,7 +198,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -198,7 +198,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_KILL_SESSION_TYPE; type = DIALOG_KILL_SESSION_TYPE;
local = DIALOG_KILL_SESSION_LOCAL; local = DIALOG_KILL_SESSION_LOCAL;
pid = &nxagentKillDialogPid; pid = &nxagentKillDialogPid;
break; break;
} }
case DIALOG_SUSPEND_SESSION: case DIALOG_SUSPEND_SESSION:
...@@ -207,7 +206,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -207,7 +206,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_SUSPEND_SESSION_TYPE; type = DIALOG_SUSPEND_SESSION_TYPE;
local = DIALOG_SUSPEND_SESSION_LOCAL; local = DIALOG_SUSPEND_SESSION_LOCAL;
pid = &nxagentSuspendDialogPid; pid = &nxagentSuspendDialogPid;
break; break;
} }
case DIALOG_ROOTLESS: case DIALOG_ROOTLESS:
...@@ -216,7 +214,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -216,7 +214,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_ROOTLESS_TYPE; type = DIALOG_ROOTLESS_TYPE;
local = DIALOG_ROOTLESS_LOCAL; local = DIALOG_ROOTLESS_LOCAL;
pid = &nxagentRootlessDialogPid; pid = &nxagentRootlessDialogPid;
break; break;
} }
case DIALOG_PULLDOWN: case DIALOG_PULLDOWN:
...@@ -226,7 +223,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -226,7 +223,6 @@ void nxagentLaunchDialog(DialogType dialogType)
local = DIALOG_PULLDOWN_LOCAL; local = DIALOG_PULLDOWN_LOCAL;
pid = &nxagentPulldownDialogPid; pid = &nxagentPulldownDialogPid;
window = nxagentPulldownWindow; window = nxagentPulldownWindow;
break; break;
} }
case DIALOG_FONT_REPLACEMENT: case DIALOG_FONT_REPLACEMENT:
...@@ -235,7 +231,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -235,7 +231,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_FONT_REPLACEMENT_TYPE; type = DIALOG_FONT_REPLACEMENT_TYPE;
local = DIALOG_FONT_REPLACEMENT_LOCAL; local = DIALOG_FONT_REPLACEMENT_LOCAL;
pid = &nxagentFontsReplacementDialogPid; pid = &nxagentFontsReplacementDialogPid;
break; break;
} }
case DIALOG_FAILED_RECONNECTION: case DIALOG_FAILED_RECONNECTION:
...@@ -244,7 +239,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -244,7 +239,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_FAILED_RECONNECTION_TYPE; type = DIALOG_FAILED_RECONNECTION_TYPE;
local = DIALOG_FAILED_RECONNECTION_LOCAL; local = DIALOG_FAILED_RECONNECTION_LOCAL;
pid = &nxagentFailedReconnectionDialogPid; pid = &nxagentFailedReconnectionDialogPid;
break; break;
} }
case DIALOG_ENABLE_DESKTOP_RESIZE_MODE: case DIALOG_ENABLE_DESKTOP_RESIZE_MODE:
...@@ -253,7 +247,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -253,7 +247,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_ENABLE_DESKTOP_RESIZE_MODE_TYPE; type = DIALOG_ENABLE_DESKTOP_RESIZE_MODE_TYPE;
local = DIALOG_ENABLE_DESKTOP_RESIZE_MODE_LOCAL; local = DIALOG_ENABLE_DESKTOP_RESIZE_MODE_LOCAL;
pid = &nxagentEnableRandRModeDialogPid; pid = &nxagentEnableRandRModeDialogPid;
break; break;
} }
case DIALOG_DISABLE_DESKTOP_RESIZE_MODE: case DIALOG_DISABLE_DESKTOP_RESIZE_MODE:
...@@ -262,7 +255,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -262,7 +255,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_DISABLE_DESKTOP_RESIZE_MODE_TYPE; type = DIALOG_DISABLE_DESKTOP_RESIZE_MODE_TYPE;
local = DIALOG_DISABLE_DESKTOP_RESIZE_MODE_LOCAL; local = DIALOG_DISABLE_DESKTOP_RESIZE_MODE_LOCAL;
pid = &nxagentDisableRandRModeDialogPid; pid = &nxagentDisableRandRModeDialogPid;
break; break;
} }
case DIALOG_ENABLE_DEFER_MODE: case DIALOG_ENABLE_DEFER_MODE:
...@@ -271,7 +263,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -271,7 +263,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_ENABLE_DEFER_MODE_TYPE; type = DIALOG_ENABLE_DEFER_MODE_TYPE;
local = DIALOG_ENABLE_DEFER_MODE_LOCAL; local = DIALOG_ENABLE_DEFER_MODE_LOCAL;
pid = &nxagentEnableDeferModePid; pid = &nxagentEnableDeferModePid;
break; break;
} }
case DIALOG_DISABLE_DEFER_MODE: case DIALOG_DISABLE_DEFER_MODE:
...@@ -280,7 +271,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -280,7 +271,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_DISABLE_DEFER_MODE_TYPE; type = DIALOG_DISABLE_DEFER_MODE_TYPE;
local = DIALOG_DISABLE_DEFER_MODE_LOCAL; local = DIALOG_DISABLE_DEFER_MODE_LOCAL;
pid = &nxagentDisableDeferModePid; pid = &nxagentDisableDeferModePid;
break; break;
} }
case DIALOG_ENABLE_AUTOGRAB_MODE: case DIALOG_ENABLE_AUTOGRAB_MODE:
...@@ -289,7 +279,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -289,7 +279,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_ENABLE_AUTOGRAB_MODE_TYPE; type = DIALOG_ENABLE_AUTOGRAB_MODE_TYPE;
local = DIALOG_ENABLE_AUTOGRAB_MODE_LOCAL; local = DIALOG_ENABLE_AUTOGRAB_MODE_LOCAL;
pid = &nxagentEnableAutograbModePid; pid = &nxagentEnableAutograbModePid;
break; break;
} }
case DIALOG_DISABLE_AUTOGRAB_MODE: case DIALOG_DISABLE_AUTOGRAB_MODE:
...@@ -298,7 +287,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -298,7 +287,6 @@ void nxagentLaunchDialog(DialogType dialogType)
type = DIALOG_DISABLE_AUTOGRAB_MODE_TYPE; type = DIALOG_DISABLE_AUTOGRAB_MODE_TYPE;
local = DIALOG_DISABLE_AUTOGRAB_MODE_LOCAL; local = DIALOG_DISABLE_AUTOGRAB_MODE_LOCAL;
pid = &nxagentDisableAutograbModePid; pid = &nxagentDisableAutograbModePid;
break; break;
} }
default: default:
...@@ -306,7 +294,6 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -306,7 +294,6 @@ void nxagentLaunchDialog(DialogType dialogType)
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentLaunchDialog: Unknown Dialog type [%d].\n", dialogType); fprintf(stderr, "nxagentLaunchDialog: Unknown Dialog type [%d].\n", dialogType);
#endif #endif
return; return;
} }
} }
...@@ -325,8 +312,7 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -325,8 +312,7 @@ void nxagentLaunchDialog(DialogType dialogType)
} }
/* /*
* We don't want to receive SIGCHLD * We don't want to receive SIGCHLD before we store the child pid.
* before we store the child pid.
*/ */
sigemptyset(&set); sigemptyset(&set);
...@@ -346,8 +332,7 @@ void nxagentLaunchDialog(DialogType dialogType) ...@@ -346,8 +332,7 @@ void nxagentLaunchDialog(DialogType dialogType)
dialogDisplay[0] = '\0'; dialogDisplay[0] = '\0';
/* /*
* Restore the previous set of * Restore the previous set of blocked signal.
* blocked signal.
*/ */
sigprocmask(SIG_SETMASK, &oldSet, NULL); sigprocmask(SIG_SETMASK, &oldSet, NULL);
...@@ -385,17 +370,16 @@ void nxagentFailedReconnectionDialog(int alert, char *error) ...@@ -385,17 +370,16 @@ void nxagentFailedReconnectionDialog(int alert, char *error)
NXTransAlert(alert, NX_ALERT_REMOTE); NXTransAlert(alert, NX_ALERT_REMOTE);
/* /*
* Make it possible to interrupt the * Make it possible to interrupt the loop with a signal.
* loop with a signal.
*/ */
while (NXDisplayError(nxagentDisplay) == 0 && while (NXDisplayError(nxagentDisplay) == 0 &&
NXTransRunning(NX_FD_ANY) == 1) NXTransRunning(NX_FD_ANY) == 1)
{ {
struct timeval timeout; struct timeval timeout = {
.tv_sec = 30,
timeout.tv_sec = 30; .tv_usec = 0,
timeout.tv_usec = 0; };
NXTransContinue(&timeout); NXTransContinue(&timeout);
} }
...@@ -477,73 +461,61 @@ void nxagentTerminateDialog(DialogType type) ...@@ -477,73 +461,61 @@ void nxagentTerminateDialog(DialogType type)
case DIALOG_KILL_SESSION: case DIALOG_KILL_SESSION:
{ {
pid = nxagentKillDialogPid; pid = nxagentKillDialogPid;
break; break;
} }
case DIALOG_SUSPEND_SESSION: case DIALOG_SUSPEND_SESSION:
{ {
pid = nxagentSuspendDialogPid; pid = nxagentSuspendDialogPid;
break; break;
} }
case DIALOG_ROOTLESS: case DIALOG_ROOTLESS:
{ {
pid = nxagentRootlessDialogPid; pid = nxagentRootlessDialogPid;
break; break;
} }
case DIALOG_PULLDOWN: case DIALOG_PULLDOWN:
{ {
pid = nxagentPulldownDialogPid; pid = nxagentPulldownDialogPid;
break; break;
} }
case DIALOG_FONT_REPLACEMENT: case DIALOG_FONT_REPLACEMENT:
{ {
pid = nxagentFontsReplacementDialogPid; pid = nxagentFontsReplacementDialogPid;
break; break;
} }
case DIALOG_FAILED_RECONNECTION: case DIALOG_FAILED_RECONNECTION:
{ {
pid = nxagentFailedReconnectionDialogPid; pid = nxagentFailedReconnectionDialogPid;
break; break;
} }
case DIALOG_ENABLE_DESKTOP_RESIZE_MODE: case DIALOG_ENABLE_DESKTOP_RESIZE_MODE:
{ {
pid = nxagentEnableRandRModeDialogPid; pid = nxagentEnableRandRModeDialogPid;
break; break;
} }
case DIALOG_DISABLE_DESKTOP_RESIZE_MODE: case DIALOG_DISABLE_DESKTOP_RESIZE_MODE:
{ {
pid = nxagentDisableRandRModeDialogPid; pid = nxagentDisableRandRModeDialogPid;
break; break;
} }
case DIALOG_ENABLE_DEFER_MODE: case DIALOG_ENABLE_DEFER_MODE:
{ {
pid = nxagentEnableDeferModePid; pid = nxagentEnableDeferModePid;
break; break;
} }
case DIALOG_DISABLE_DEFER_MODE: case DIALOG_DISABLE_DEFER_MODE:
{ {
pid = nxagentDisableDeferModePid; pid = nxagentDisableDeferModePid;
break; break;
} }
case DIALOG_ENABLE_AUTOGRAB_MODE: case DIALOG_ENABLE_AUTOGRAB_MODE:
{ {
pid = nxagentEnableAutograbModePid; pid = nxagentEnableAutograbModePid;
break; break;
} }
case DIALOG_DISABLE_AUTOGRAB_MODE: case DIALOG_DISABLE_AUTOGRAB_MODE:
{ {
pid = nxagentDisableAutograbModePid; pid = nxagentDisableAutograbModePid;
break; break;
} }
default: default:
...@@ -551,7 +523,6 @@ void nxagentTerminateDialog(DialogType type) ...@@ -551,7 +523,6 @@ void nxagentTerminateDialog(DialogType type)
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentTerminateDialog: Unknown dialog type [%d].\n", type); fprintf(stderr, "nxagentTerminateDialog: Unknown dialog type [%d].\n", type);
#endif #endif
return; return;
} }
} }
...@@ -577,13 +548,11 @@ void nxagentTerminateDialog(DialogType type) ...@@ -577,13 +548,11 @@ void nxagentTerminateDialog(DialogType type)
void nxagentTerminateDialogs(void) void nxagentTerminateDialogs(void)
{ {
DialogType type;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentTerminateDialogs: Terminating all the running dialogs.\n"); fprintf(stderr, "nxagentTerminateDialogs: Terminating all the running dialogs.\n");
#endif #endif
for (type = DIALOG_FIRST_TAG; type < DIALOG_LAST_TAG; type++) for (DialogType type = DIALOG_FIRST_TAG; type < DIALOG_LAST_TAG; type++)
{ {
nxagentTerminateDialog(type); nxagentTerminateDialog(type);
} }
......
...@@ -152,8 +152,8 @@ Drawable nxagentDefaultDrawables[MAXDEPTH + 1]; ...@@ -152,8 +152,8 @@ Drawable nxagentDefaultDrawables[MAXDEPTH + 1];
Pixmap nxagentScreenSaverPixmap; Pixmap nxagentScreenSaverPixmap;
/* /*
* Also used in Cursor.c. There are huge problems * Also used in Cursor.c. There are huge problems using GC
* using GC definition. This is to be reworked. * definition. This is to be reworked.
*/ */
XlibGC nxagentBitmapGC; XlibGC nxagentBitmapGC;
...@@ -212,20 +212,18 @@ int nxagentServerOrder(void) ...@@ -212,20 +212,18 @@ int nxagentServerOrder(void)
} }
/* /*
* FIXME: This error handler is not printing anything * FIXME: This error handler is not printing anything in the session
* in the session log. This is OK once the session is * log. This is OK once the session is started, because the error is
* started, because the error is handled by the other * handled by the other layers, but not before that point, as the
* layers, but not before that point, as the agent * agent would die without giving any feedback to the user (or, worse,
* would die without giving any feedback to the user * to the NX server). We should check how many requests have been
* (or, worse, to the NX server). We should check how * handled for this display and print a message if the display dies
* many requests have been handled for this display * before the session is up and running.
* 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 * FIXME: This should be moved to Error.c, The other handlers should
* handlers should be probably moved to Handlers.c. * be probably moved to Handlers.c.
*/ */
int nxagentIOErrorHandler(Display *display) int nxagentIOErrorHandler(Display *display)
...@@ -246,11 +244,9 @@ int nxagentIOErrorHandler(Display *display) ...@@ -246,11 +244,9 @@ int nxagentIOErrorHandler(Display *display)
} }
/* /*
* Force a shutdown of any connection attempt * Force a shutdown of any connection attempt while connecting to the
* while connecting to the remote display. * remote display. This is needed to avoid a hang up in case of
* This is needed to avoid a hang up in case * loopback connections to our own listening sockets.
* of loopback connections to our own listen-
* ing sockets.
*/ */
static void nxagentRejectConnection(int signal) static void nxagentRejectConnection(int signal)
...@@ -266,16 +262,15 @@ static void nxagentRejectConnection(int signal) ...@@ -266,16 +262,15 @@ static void nxagentRejectConnection(int signal)
#endif #endif
/* /*
* A further timeout is unlikely to happen * A further timeout is unlikely to happen in the case of loopback
* in the case of loopback connections. * connections.
*/ */
alarm(5); alarm(5);
} }
/* /*
* Ignore the signal if the NX transport is * Ignore the signal if the NX transport is not running.
* not running.
*/ */
static void nxagentSigusrHandler(int signal) static void nxagentSigusrHandler(int signal)
...@@ -371,17 +366,16 @@ static void nxagentSigchldHandler(int signal) ...@@ -371,17 +366,16 @@ 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. Leave the other children
* Leave the other children unaffected. * unaffected.
*/ */
if (nxagentRootlessDialogPid) if (nxagentRootlessDialogPid)
...@@ -567,30 +561,25 @@ static void nxagentSigchldHandler(int signal) ...@@ -567,30 +561,25 @@ 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;
int result; int result;
/* /*
* Stop the smart schedule timer since * Stop the smart schedule timer since it uses SIGALRM as we do.
* it uses SIGALRM as we do.
*/ */
nxagentStopTimer(); nxagentStopTimer();
/* /*
* Install the handler rejecting a possible * Install the handler rejecting a possible loopback connection.
* loopback connection.
*/ */
/* /*
FIXME: Should print a warning if the user tries to let FIXME: Should print a warning if the user tries to let the agent
the agent impersonate the same display as the impersonate the same display as the display where the agent is
display where the agent is supposed to connect. supposed to connect. We actually handle this by means of
We actually handle this by means of RejectWell- RejectWellKnownSockets() but without giving a friendly
KnownSockets() but without giving a friendly
explanation for the error to the user. explanation for the error to the user.
*/ */
...@@ -615,7 +604,7 @@ FIXME: Should print a warning if the user tries to let ...@@ -615,7 +604,7 @@ FIXME: Should print a warning if the user tries to let
display); display);
#endif #endif
newDisplay = XOpenDisplay(display); Display *newDisplay = XOpenDisplay(display);
alarm(0); alarm(0);
...@@ -646,9 +635,8 @@ static void nxagentDisplayBlockHandler(Display *display, int reason) ...@@ -646,9 +635,8 @@ static void nxagentDisplayBlockHandler(Display *display, int reason)
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
{ {
/* /*
* Don't allow the smart schedule to * Don't allow the smart schedule to interrupt the agent while
* interrupt the agent while waiting * waiting for the remote display.
* for the remote display.
*/ */
#ifdef DEBUG #ifdef DEBUG
...@@ -675,8 +663,7 @@ static void nxagentDisplayBlockHandler(Display *display, int reason) ...@@ -675,8 +663,7 @@ static void nxagentDisplayBlockHandler(Display *display, int reason)
{ {
/* /*
* Let the dispatch attend the next * Let the dispatch attend the next client.
* client.
*/ */
#ifdef DEBUG #ifdef DEBUG
...@@ -732,8 +719,6 @@ int nxagentGetDataRate(void) ...@@ -732,8 +719,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 +737,7 @@ static void nxagentDisplayFlushHandler(Display *display, int length) ...@@ -752,9 +737,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)
{ {
...@@ -804,18 +787,17 @@ static int nxagentDisplayErrorPredicate(Display *display, int error) ...@@ -804,18 +787,17 @@ static int nxagentDisplayErrorPredicate(Display *display, int error)
void nxagentInstallDisplayHandlers(void) void nxagentInstallDisplayHandlers(void)
{ {
/* /*
* If the display was already opened, be sure * If the display was already opened, be sure all structures are
* all structures are freed. * freed.
*/ */
nxagentResetDisplayHandlers(); nxagentResetDisplayHandlers();
/* /*
* We want the Xlib I/O error handler to return, * We want the Xlib I/O error handler to return, instead of quitting
* instead of quitting the application. Using * the application. Using setjmp()/longjmp() leaves the door open to
* setjmp()/longjmp() leaves the door open to * unexpected bugs when dealing with interaction with the other X
* unexpected bugs when dealing with interaction * server layers.
* with the other X server layers.
*/ */
NXHandleDisplayError(1); NXHandleDisplayError(1);
...@@ -833,14 +815,12 @@ void nxagentInstallDisplayHandlers(void) ...@@ -833,14 +815,12 @@ void nxagentInstallDisplayHandlers(void)
XSetIOErrorHandler(nxagentIOErrorHandler); XSetIOErrorHandler(nxagentIOErrorHandler);
/* /*
* Let Xlib become aware of our interrupts. In theory * Let Xlib become aware of our interrupts. In theory we don't need
* we don't need to have the error handler installed * to have the error handler installed during the normal operations
* during the normal operations and could simply let * and could simply let the dispatcher handle the interrupts. In
* the dispatcher handle the interrupts. In practice * practice it's better to have Xlib invalidating the display as
* it's better to have Xlib invalidating the display * soon as possible rather than incurring in the risk of entering a
* as soon as possible rather than incurring in the * loop that doesn't care checking the display errors explicitly.
* risk of entering a loop that doesn't care checking
* the display errors explicitly.
*/ */
#ifdef TEST #ifdef TEST
...@@ -853,8 +833,8 @@ void nxagentInstallDisplayHandlers(void) ...@@ -853,8 +833,8 @@ void nxagentInstallDisplayHandlers(void)
void nxagentPostInstallDisplayHandlers(void) void nxagentPostInstallDisplayHandlers(void)
{ {
/* /*
* This is executed after having opened the * This is executed after having opened the display, once we know
* display, once we know the display address. * the display address.
*/ */
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
...@@ -886,15 +866,13 @@ void nxagentResetDisplayHandlers(void) ...@@ -886,15 +866,13 @@ void nxagentResetDisplayHandlers(void)
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
{ {
/* /*
* Free the internal nxcompext * Free the internal nxcompext structures.
* structures.
*/ */
NXResetDisplay(nxagentDisplay); NXResetDisplay(nxagentDisplay);
/* /*
* Remove the display descriptor * Remove the display descriptor from the listened sockets.
* from the listened sockets.
*/ */
nxagentRemoveXConnection(); nxagentRemoveXConnection();
...@@ -917,8 +895,7 @@ void nxagentResetDisplayHandlers(void) ...@@ -917,8 +895,7 @@ void nxagentResetDisplayHandlers(void)
nxagentCongestion = 0; nxagentCongestion = 0;
/* /*
* Reset the counter of synchronization * Reset the counter of synchronization requests pending.
* requests pending.
*/ */
nxagentTokens.soft = 0; nxagentTokens.soft = 0;
...@@ -942,9 +919,8 @@ void nxagentInstallSignalHandlers(void) ...@@ -942,9 +919,8 @@ void nxagentInstallSignalHandlers(void)
#endif #endif
/* /*
* Keep the default X server's handlers for * Keep the default X server's handlers for SIGINT and SIGTERM and
* SIGINT and SIGTERM and restore the other * restore the other signals of interest to our defaults.
* signals of interest to our defaults.
*/ */
struct sigaction newAction; struct sigaction newAction;
...@@ -952,9 +928,9 @@ void nxagentInstallSignalHandlers(void) ...@@ -952,9 +928,9 @@ void nxagentInstallSignalHandlers(void)
int result; int result;
/* /*
* By default nxcomp installs its signal handlers. * By default nxcomp installs its signal handlers. We need to
* We need to ensure that SIGUSR1 and SIGUSR2 are * ensure that SIGUSR1 and SIGUSR2 are ignored if the NX transport
* ignored if the NX transport is not running. * is not running.
*/ */
newAction.sa_handler = nxagentSigusrHandler; newAction.sa_handler = nxagentSigusrHandler;
...@@ -998,8 +974,7 @@ void nxagentInstallSignalHandlers(void) ...@@ -998,8 +974,7 @@ void nxagentInstallSignalHandlers(void)
} }
/* /*
* Let the smart schedule set the SIGALRM * Let the smart schedule set the SIGALRM handler again.
* handler again.
*/ */
nxagentInitTimer(); nxagentInitTimer();
...@@ -1048,13 +1023,12 @@ void nxagentPostInstallSignalHandlers(void) ...@@ -1048,13 +1023,12 @@ void nxagentPostInstallSignalHandlers(void)
#endif #endif
/* /*
* Reconfigure our signal handlers to work well * Reconfigure our signal handlers to work well with the NX
* with the NX transport. * transport.
* *
* Let our handlers manage the SIGINT and SIGTERM. * Let our handlers manage the SIGINT and SIGTERM. The following
* The following calls will tell the NX transport * calls will tell the NX transport to restore the old handlers
* to restore the old handlers (those originally * (those originally installed by us or the X server).
* installed by us or the X server).
*/ */
NXTransSignal(SIGINT, NX_SIGNAL_DISABLE); NXTransSignal(SIGINT, NX_SIGNAL_DISABLE);
...@@ -1067,16 +1041,14 @@ void nxagentPostInstallSignalHandlers(void) ...@@ -1067,16 +1041,14 @@ void nxagentPostInstallSignalHandlers(void)
NXTransSignal(SIGHUP, NX_SIGNAL_DISABLE); NXTransSignal(SIGHUP, NX_SIGNAL_DISABLE);
/* /*
* Both the proxy and the agent need to catch * Both the proxy and the agent need to catch their children, so
* their children, so we'll have to send the * we'll have to send the signal to transport.
* signal to transport.
*/ */
NXTransSignal(SIGCHLD, NX_SIGNAL_DISABLE); NXTransSignal(SIGCHLD, NX_SIGNAL_DISABLE);
/* /*
* Let the NX transport take care of SIGUSR1 * Let the NX transport take care of SIGUSR1 and SIGUSR2.
* and SIGUSR2.
*/ */
} }
...@@ -1089,8 +1061,7 @@ void nxagentResetSignalHandlers(void) ...@@ -1089,8 +1061,7 @@ void nxagentResetSignalHandlers(void)
memset(&newAction, 0, sizeof(newAction)); memset(&newAction, 0, sizeof(newAction));
/* /*
* Reset the signal handlers * Reset the signal handlers to a well known state.
* to a well known state.
*/ */
#ifdef TEST #ifdef TEST
...@@ -1116,8 +1087,7 @@ void nxagentResetSignalHandlers(void) ...@@ -1116,8 +1087,7 @@ void nxagentResetSignalHandlers(void)
} }
/* /*
* Let the smart schedule set the SIGALRM * Let the smart schedule set the SIGALRM handler again.
* handler again.
*/ */
nxagentInitTimer(); nxagentInitTimer();
...@@ -1126,9 +1096,8 @@ void nxagentResetSignalHandlers(void) ...@@ -1126,9 +1096,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
...@@ -1140,8 +1109,8 @@ void nxagentOpenDisplay(int argc, char *argv[]) ...@@ -1140,8 +1109,8 @@ void nxagentOpenDisplay(int argc, char *argv[])
#endif #endif
/* /*
* Initialize the reconnector only in the case * Initialize the reconnector only in the case of persistent
* of persistent sessions. * sessions.
*/ */
if (nxagentOption(Persistent)) if (nxagentOption(Persistent))
...@@ -1169,8 +1138,8 @@ void nxagentOpenDisplay(int argc, char *argv[]) ...@@ -1169,8 +1138,8 @@ void nxagentOpenDisplay(int argc, char *argv[])
if (nxagentDisplay == NULL) if (nxagentDisplay == NULL)
{ {
/* /*
FIXME: The agent should never exit the program with a FatalError() FIXME: The agent should never exit the program with a FatalError() but
but rather use a specific function that may eventually call rather use a specific function that may eventually call
FatalError() on its turn. FatalError() on its turn.
*/ */
FatalError("Unable to open display '%s'.\n", nxagentDisplayName); FatalError("Unable to open display '%s'.\n", nxagentDisplayName);
...@@ -1217,9 +1186,8 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -1217,9 +1186,8 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
DefaultScreenOfDisplay(nxagentDisplay)); DefaultScreenOfDisplay(nxagentDisplay));
/* /*
* Processing the arguments all the timeouts * Processing the arguments all the timeouts have been set. Now we
* have been set. Now we have to change the * have to change the screen-saver timeout.
* screen-saver timeout.
*/ */
nxagentSetScreenSaverTime(); nxagentSetScreenSaverTime();
...@@ -1230,7 +1198,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -1230,7 +1198,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),
...@@ -1270,18 +1238,17 @@ N/A ...@@ -1270,18 +1238,17 @@ N/A
#endif #endif
/* /*
* Initialize the agent's event mask that will be requested * Initialize the agent's event mask that will be requested for the
* for the root and all the top level windows. If the nested * root and all the top level windows. If the nested window is a
* window is a child of an existing window, we will need to * child of an existing window, we will need to receive
* receive StructureNotify events. If we are going to manage * StructureNotify events. If we are going to manage the changes in
* the changes in root window's visibility we'll also need * root window's visibility we'll also need VisibilityChange events.
* VisibilityChange events.
*/ */
/* /*
FIXME: Use of nxagentParentWindow is strongly deprecated. FIXME: Use of nxagentParentWindow is strongly deprecated. We need
We need also to clarify which events are selected also to clarify which events are selected in the different
in the different operating modes. operating modes.
*/ */
nxagentInitDefaultEventMask(); nxagentInitDefaultEventMask();
...@@ -1296,9 +1263,8 @@ FIXME: Use of nxagentParentWindow is strongly deprecated. ...@@ -1296,9 +1263,8 @@ FIXME: Use of nxagentParentWindow is strongly deprecated.
(void) nxagentCheckForPixmapFormatsCompatibility(); (void) nxagentCheckForPixmapFormatsCompatibility();
/* /*
* Create a pixmap for each depth matching the * Create a pixmap for each depth matching the local supported
* local supported formats with format available * formats with format available on the remote display.
* on the remote display.
*/ */
nxagentSetDefaultDrawables(); nxagentSetDefaultDrawables();
...@@ -1311,16 +1277,15 @@ FIXME: Use of nxagentParentWindow is strongly deprecated. ...@@ -1311,16 +1277,15 @@ FIXME: Use of nxagentParentWindow is strongly deprecated.
#endif #endif
/* /*
* This GC is referenced in Cursor.c. It can be * This GC is referenced in Cursor.c. It can be probably removed.
* probably removed.
*/ */
nxagentBitmapGC = XCreateGC(nxagentDisplay, nxagentDefaultDrawables[1], 0L, NULL); nxagentBitmapGC = XCreateGC(nxagentDisplay, nxagentDefaultDrawables[1], 0L, NULL);
/* /*
* Note that this "confine window" is useless at the * Note that this "confine window" is useless at the moment as we
* moment as we reimplement nxagentConstrainCursor() * reimplement nxagentConstrainCursor() to skip the "constrain"
* to skip the "constrain" stuff. * stuff.
*/ */
#ifdef TEST #ifdef TEST
...@@ -1446,15 +1411,11 @@ N/A ...@@ -1446,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)
...@@ -1463,7 +1424,6 @@ void nxagentSetDefaultVisual(void) ...@@ -1463,7 +1424,6 @@ void nxagentSetDefaultVisual(void)
nxagentVisuals[i].depth == nxagentDefaultDepth)) nxagentVisuals[i].depth == nxagentDefaultDepth))
{ {
nxagentDefaultVisualIndex = i; nxagentDefaultVisualIndex = i;
break; break;
} }
} }
...@@ -1475,11 +1435,13 @@ void nxagentSetDefaultVisual(void) ...@@ -1475,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)
{ {
...@@ -1491,20 +1453,18 @@ void nxagentSetDefaultVisual(void) ...@@ -1491,20 +1453,18 @@ void nxagentSetDefaultVisual(void)
void nxagentInitVisuals(void) void nxagentInitVisuals(void)
{ {
XVisualInfo vi; XVisualInfo vi = {
XVisualInfo *viList = NULL; .screen = DefaultScreen(nxagentDisplay),
.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)),
long mask; };
int i, viNumList; long mask = VisualScreenMask;
int viNumList;
XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, mask, &vi, &viNumList);
mask = VisualScreenMask;
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 +1507,6 @@ void nxagentInitVisuals(void) ...@@ -1547,10 +1507,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 +1524,7 @@ void nxagentInitDepths(void) ...@@ -1568,7 +1524,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,14 +1536,11 @@ void nxagentInitDepths(void) ...@@ -1580,14 +1536,11 @@ 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
* on the real display. Creating only formats supported * real display. Creating only formats supported by the remote end
* by the remote end makes troublesome handling migration * makes troublesome handling migration of session from a display to
* of session from a display to another. * another.
*/ */
nxagentNumPixmapFormats = 0; nxagentNumPixmapFormats = 0;
...@@ -1598,9 +1551,9 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1598,9 +1551,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 +1561,7 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1608,7 +1561,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)
{ {
...@@ -1655,7 +1608,7 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1655,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,
...@@ -1667,14 +1620,12 @@ XXX: Some X server doesn't list 1 among available depths... ...@@ -1667,14 +1620,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 +1646,7 @@ void nxagentSetDefaultDrawables(void) ...@@ -1695,7 +1646,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] "
...@@ -1750,11 +1701,9 @@ void nxagentCloseDisplay(void) ...@@ -1750,11 +1701,9 @@ void nxagentCloseDisplay(void)
} }
/* /*
* If nxagentDoFullGeneration is true, all * If nxagentDoFullGeneration is true, all the X resources will be
* the X resources will be destroyed upon * destroyed upon closing the display connection, so there is no
* closing the display connection, so there * real need to generate additional traffic
* is no real need to generate additional
* traffic
*/ */
SAFE_free(nxagentDefaultColormaps); SAFE_free(nxagentDefaultColormaps);
...@@ -1771,14 +1720,12 @@ FIXME: Is this needed? ...@@ -1771,14 +1720,12 @@ FIXME: Is this needed?
*/ */
/* /*
* Free the image cache. This is useful * Free the image cache. This is useful for detecting memory leaks.
* for detecting memory leaks.
*/ */
if (nxagentDisplay != NULL) if (nxagentDisplay != NULL)
{ {
NXFreeCache(nxagentDisplay); NXFreeCache(nxagentDisplay);
NXResetDisplay(nxagentDisplay); NXResetDisplay(nxagentDisplay);
} }
...@@ -1855,14 +1802,11 @@ void nxagentBackupDisplayInfo(void) ...@@ -1855,14 +1802,11 @@ void nxagentBackupDisplayInfo(void)
} }
/* /*
* Since we need the display structure * Since we need the display structure in order to behave correctly
* in order to behave correctly when no X * when no X connection is available, we must always have a good
* connection is available, we must always * display record. It can be discarded only when a new X connection
* have a good display record. * is available, so we store it in order to destroy whenever the
* It can be discarded only when a new X * reconnection succeeds.
* connection is available, so we store it
* in order to destroy whenever the recon-
* nection succed.
*/ */
nxagentDisplayBackup = nxagentDisplay; nxagentDisplayBackup = nxagentDisplay;
...@@ -1934,9 +1878,7 @@ void nxagentDisconnectDisplay(void) ...@@ -1934,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;
} }
...@@ -1944,9 +1886,8 @@ void nxagentDisconnectDisplay(void) ...@@ -1944,9 +1886,8 @@ void nxagentDisconnectDisplay(void)
case GOT_VISUAL_INFO: case GOT_VISUAL_INFO:
case OPENED: case OPENED:
/* /*
* Actually we need the nxagentDisplay * Actually we need the nxagentDisplay structure in order to let
* structure in order to let the agent * the agent go when no X connection is available.
* go when no X connection is available.
*/ */
if (nxagentDisplay && if (nxagentDisplay &&
...@@ -1970,21 +1911,18 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -1970,21 +1911,18 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
/* /*
* Depending on the (reconnect) tolerance checks value, this * Depending on the (reconnect) tolerance checks value, this
* function checks stricter or looser: * function checks stricter or looser:
* - Strict means that the old and new default depth values * - Strict means that the old and new default depth values must
* must match exactly. * match exactly.
* - Safe or Risky means that the default depth values might differ, * - Safe or Risky means that the default depth values might
* but the new default depth value must be at least as * differ, but the new default depth value must be at least as
* high as the former default depth value. This is * high as the former default depth value. This is recommended,
* recommended, because it allows clients with a * because it allows clients with a higher default depth value
* higher default depth value to still connect, but * to still connect, but not lose functionality.
* not lose functionality.
* - Bypass means that all of these checks are essentially * - Bypass means that all of these checks are essentially
* 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);
...@@ -1996,7 +1934,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -1996,7 +1934,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
"is [%d], former default depth value is [%d].\n", tolerance, "is [%d], former default depth value is [%d].\n", tolerance,
ToleranceChecksBypass, dDepth, nxagentDefaultDepthRecBackup); ToleranceChecksBypass, dDepth, nxagentDefaultDepthRecBackup);
#endif #endif
return 1; return 1;
} }
...@@ -2006,7 +1943,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -2006,7 +1943,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
fprintf(stderr, "nxagentCheckForDefaultDepthCompatibility: New default depth [%d] " fprintf(stderr, "nxagentCheckForDefaultDepthCompatibility: New default depth [%d] "
"matches with old default depth.\n", dDepth); "matches with old default depth.\n", dDepth);
#endif #endif
return 1; return 1;
} }
else if ((ToleranceChecksSafe <= tolerance) && (nxagentDefaultDepthRecBackup < dDepth)) else if ((ToleranceChecksSafe <= tolerance) && (nxagentDefaultDepthRecBackup < dDepth))
...@@ -2016,7 +1952,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -2016,7 +1952,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
"higher than the old default depth [%d] at tolerance [%u].\n", dDepth, "higher than the old default depth [%d] at tolerance [%u].\n", dDepth,
nxagentDefaultDepthRecBackup, tolerance); nxagentDefaultDepthRecBackup, tolerance);
#endif #endif
return 1; return 1;
} }
else else
...@@ -2026,7 +1961,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void) ...@@ -2026,7 +1961,6 @@ static int nxagentCheckForDefaultDepthCompatibility(void)
"doesn't match with old default depth [%d] at tolerance [%u].\n", dDepth, "doesn't match with old default depth [%d] at tolerance [%u].\n", dDepth,
nxagentDefaultDepthRecBackup, tolerance); nxagentDefaultDepthRecBackup, tolerance);
#endif #endif
return 0; return 0;
} }
} }
...@@ -2036,18 +1970,16 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2036,18 +1970,16 @@ static int nxagentCheckForDepthsCompatibility(void)
/* /*
* Depending on the (reconnect) tolerance checks value, this * Depending on the (reconnect) tolerance checks value, this
* function checks stricter or looser: * function checks stricter or looser:
* - Strict means that the number of old and new depths must * - Strict means that the number of old and new depths must match
* match exactly and every old depth value must be * exactly and every old depth value must be available in the
* available in the new depth array. * new depth array.
* - Safe means that the number of depths might diverge, * - Safe means that the number of depths might diverge, but all
* but all former depth must also be included in the * former depth must also be included in the new depth
* new depth array. This is recommended, because * array. This is recommended, because it allows clients with
* it allows clients with more depths to still * more depths to still connect, but not lose functionality.
* connect, but not lose functionality.
* - Risky means that the new depths array is allowed to be * - Risky means that the new depths array is allowed to be
* smaller than the old depths array, but at least * smaller than the old depths array, but at least one depth
* one depth value must be included in both. * value must be included in both. This is potentially unsafe.
* This is potentially unsafe.
* - Bypass or higher means that all of these checks are * - Bypass or higher means that all of these checks are
* essentially deactivated. This is a very bad idea. * essentially deactivated. This is a very bad idea.
*/ */
...@@ -2062,7 +1994,6 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2062,7 +1994,6 @@ static int nxagentCheckForDepthsCompatibility(void)
"is [%d], number of old depths is [%d].\n", tolerance, ToleranceChecksBypass, "is [%d], number of old depths is [%d].\n", tolerance, ToleranceChecksBypass,
nxagentNumDepths, nxagentNumDepthsRecBackup); nxagentNumDepths, nxagentNumDepthsRecBackup);
#endif #endif
return 1; return 1;
} }
...@@ -2074,7 +2005,6 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2074,7 +2005,6 @@ static int nxagentCheckForDepthsCompatibility(void)
"depths [%d].\n", nxagentNumDepths, "depths [%d].\n", nxagentNumDepths,
nxagentNumDepthsRecBackup); nxagentNumDepthsRecBackup);
#endif #endif
return 0; return 0;
} }
...@@ -2086,7 +2016,6 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2086,7 +2016,6 @@ static int nxagentCheckForDepthsCompatibility(void)
"lower than number of old depths [%d].\n", tolerance, "lower than number of old depths [%d].\n", tolerance,
nxagentNumDepths, nxagentNumDepthsRecBackup); nxagentNumDepths, nxagentNumDepthsRecBackup);
#endif #endif
return 0; return 0;
} }
...@@ -2102,7 +2031,6 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2102,7 +2031,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;
/* /*
...@@ -2124,7 +2052,7 @@ static int nxagentCheckForDepthsCompatibility(void) ...@@ -2124,7 +2052,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)
{ {
...@@ -2194,20 +2122,18 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2194,20 +2122,18 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
/* /*
* Depending on the (reconnect) tolerance checks value, this * Depending on the (reconnect) tolerance checks value, this
* function checks stricter or looser: * function checks stricter or looser:
* - Strict means that the number of internal and external * - Strict means that the number of internal and external pixmap
* pixmap formats must match exactly and every * formats must match exactly and every internal pixmap format
* internal pixmap format must be available in the * must be available in the external pixmap format array.
* external pixmap format array. * - Safe means that the number of pixmap formats might diverge,
* - Safe means that the number of pixmap formats might * but all internal pixmap formats must also be included in the
* diverge, but all internal pixmap formats must * external pixmap formats array. This is recommended, because
* also be included in the external pixmap formats * it allows clients with more pixmap formats to still connect,
* array. This is recommended, because it allows
* clients with more pixmap formats to still connect,
* but not lose functionality. * but not lose functionality.
* - Risky means that the internal pixmap formats array is * - Risky means that the internal pixmap formats array is allowed
* allowed to be smaller than the external pixmap * to be smaller than the external pixmap formats array, but at
* formats array, but at least one pixmap format must * least one pixmap format must be included in both. This is
* be included in both. This is potentially unsafe. * potentially unsafe.
* - Bypass or higher means that all of these checks are * - Bypass or higher means that all of these checks are
* essentially deactivated. This is a very bad idea. * essentially deactivated. This is a very bad idea.
*/ */
...@@ -2222,7 +2148,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2222,7 +2148,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
"pixmap formats is [%d], number of externally available pixmap formats is [%d].\n", "pixmap formats is [%d], number of externally available pixmap formats is [%d].\n",
tolerance, ToleranceChecksBypass, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); tolerance, ToleranceChecksBypass, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats);
#endif #endif
return 1; return 1;
} }
...@@ -2233,7 +2158,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2233,7 +2158,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
"of internal pixmap formats [%d] doesn't match with number of remote formats [%d].\n", "of internal pixmap formats [%d] doesn't match with number of remote formats [%d].\n",
nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats);
#endif #endif
return 0; return 0;
} }
...@@ -2244,7 +2168,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2244,7 +2168,6 @@ static int nxagentCheckForPixmapFormatsCompatibility(void)
"and number of internal pixmap formats [%d] higher than number of external formats [%d].\n", "and number of internal pixmap formats [%d] higher than number of external formats [%d].\n",
tolerance, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats); tolerance, nxagentNumPixmapFormats, nxagentRemoteNumPixmapFormats);
#endif #endif
return 0; return 0;
} }
...@@ -2260,12 +2183,11 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2260,12 +2183,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)
{ {
...@@ -2327,36 +2249,31 @@ static int nxagentCheckForPixmapFormatsCompatibility(void) ...@@ -2327,36 +2249,31 @@ 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; long viMask = VisualScreenMask;
int i, n; XVisualInfo viTemplate = {
bool matched; .screen = DefaultScreen(nxagentDisplay),
bool compatible = true; .depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)),
};
int viNumList; int viNumList;
XVisualInfo *viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList);
viMask = VisualScreenMask; XVisualInfo *newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals);
viTemplate.screen = DefaultScreen(nxagentDisplay);
viTemplate.depth = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay));
viList = XGetVisualInfo(nxagentDisplay, viMask, &viTemplate, &viNumList);
newVisuals = malloc(sizeof(XVisualInfo) * nxagentNumVisuals); bool compatible = true;
for (i = 0; i < nxagentNumVisuals; i++) for (int i = 0; i < nxagentNumVisuals; i++)
{ {
matched = false; bool 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)
{ {
/* /*
FIXME: Should the visual be ignored in this case? FIXME: Should the visual be ignored in this case? We can flag the
We can flag the visuals with inverted masks, visuals with inverted masks, and use this information to switch
and use this information to switch the masks the masks when contacting the remote X server.
when contacting the remote X server.
*/ */
if (nxagentVisuals[i].red_mask == viList[n].blue_mask && if (nxagentVisuals[i].red_mask == viList[n].blue_mask &&
nxagentVisuals[i].blue_mask == viList[n].red_mask) nxagentVisuals[i].blue_mask == viList[n].red_mask)
...@@ -2441,7 +2358,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) ...@@ -2441,7 +2358,6 @@ static int nxagentCheckForColormapsCompatibility(int flexibility)
fprintf(stderr, "nxagentCheckForColormapsCompatibility: Number of new colormaps [%d] " fprintf(stderr, "nxagentCheckForColormapsCompatibility: Number of new colormaps [%d] "
"matches with old colormaps.\n", nxagentNumDefaultColormaps); "matches with old colormaps.\n", nxagentNumDefaultColormaps);
#endif #endif
return 1; return 1;
} }
else else
...@@ -2451,14 +2367,12 @@ static int nxagentCheckForColormapsCompatibility(int flexibility) ...@@ -2451,14 +2367,12 @@ 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;
} }
} }
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)
...@@ -2528,9 +2442,8 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2528,9 +2442,8 @@ Bool nxagentReconnectDisplay(void *p0)
DefaultScreenOfDisplay(nxagentDisplay)); DefaultScreenOfDisplay(nxagentDisplay));
/* /*
* After processing the arguments all the * After processing the arguments all the timeout values have been
* timeout values have been set. Now we * set. Now we have to change the screen-saver timeout.
* have to change the screen-saver timeout.
*/ */
nxagentSetScreenSaverTime(); nxagentSetScreenSaverTime();
...@@ -2569,7 +2482,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2569,7 +2482,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])
{ {
...@@ -2611,8 +2524,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2611,8 +2524,7 @@ Bool nxagentReconnectDisplay(void *p0)
SAFE_XFree(nxagentRemotePixmapFormats); SAFE_XFree(nxagentRemotePixmapFormats);
/* /*
* Check if all the required pixmap * Check if all the required pixmap formats are supported.
* formats are supported.
*/ */
nxagentInitPixmapFormats(); nxagentInitPixmapFormats();
...@@ -2628,9 +2540,8 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2628,9 +2540,8 @@ Bool nxagentReconnectDisplay(void *p0)
reconnectDisplayState = GOT_PIXMAP_FORMAT_LIST; reconnectDisplayState = GOT_PIXMAP_FORMAT_LIST;
/* /*
* Create a pixmap for each depth matching the * Create a pixmap for each depth matching the local supported
* local supported formats with format available * formats with format available on the remote display.
* on the remote display.
*/ */
nxagentSetDefaultDrawables(); nxagentSetDefaultDrawables();
...@@ -2658,12 +2569,11 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2658,12 +2569,11 @@ Bool nxagentReconnectDisplay(void *p0)
nxagentWhitePixel = WhitePixel(nxagentDisplay, DefaultScreen(nxagentDisplay)); nxagentWhitePixel = WhitePixel(nxagentDisplay, DefaultScreen(nxagentDisplay));
/* /*
* Initialize the agent's event mask that will be requested * Initialize the agent's event mask that will be requested for the
* for the root or all the top level windows. If the nested * root or all the top level windows. If the nested window is a
* window is a child of an existing window we will need to * child of an existing window we will need to receive
* receive StructureNotify events. If we are going to manage * StructureNotify events. If we are going to manage the changes in
* the changes in root window's visibility we'll also need * root window's visibility we'll also need VisibilityChange events.
* VisibilityChange events.
*/ */
nxagentInitDefaultEventMask(); nxagentInitDefaultEventMask();
...@@ -2693,8 +2603,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2693,8 +2603,7 @@ Bool nxagentReconnectDisplay(void *p0)
useXpmIcon = nxagentMakeIcon(nxagentDisplay, &nxagentIconPixmap, &nxagentIconShape); useXpmIcon = nxagentMakeIcon(nxagentDisplay, &nxagentIconPixmap, &nxagentIconShape);
/* /*
* All went fine. We can continue * All went fine. We can continue handling our clients.
* handling our clients.
*/ */
reconnectDisplayState = EVERYTHING_DONE; reconnectDisplayState = EVERYTHING_DONE;
...@@ -2704,9 +2613,7 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2704,9 +2613,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] "
...@@ -2727,10 +2634,9 @@ void nxagentRemoveXConnection(void) ...@@ -2727,10 +2634,9 @@ void nxagentRemoveXConnection(void)
} }
/* /*
* Force an I/O error and wait until the NX trans- * Force an I/O error and wait until the NX transport is gone. It must
* port is gone. It must be called before suspend- * be called before suspending or terminating a session to ensure that
* ing or terminating a session to ensure that the * the NX transport is terminated first.
* NX transport is terminated first.
*/ */
void nxagentWaitDisplay(void) void nxagentWaitDisplay(void)
...@@ -2768,27 +2674,25 @@ void nxagentWaitDisplay(void) ...@@ -2768,27 +2674,25 @@ void nxagentWaitDisplay(void)
#endif #endif
/* /*
* Be sure the signal handlers are * Be sure the signal handlers are in a known state.
* in a known state.
*/ */
nxagentResetSignalHandlers(); nxagentResetSignalHandlers();
} }
/* /*
* This has not to do with the remote display but * This has not to do with the remote display but with the X server
* with the X server that the agent is impersonating. * that the agent is impersonating. We have it here to be consistent
* We have it here to be consistent with the other * with the other cleanup procedures which have mainly to do with the
* cleanup procedures which have mainly to do with * Xlib display connection.
* the Xlib display connection.
*/ */
void nxagentAbortDisplay(void) void nxagentAbortDisplay(void)
{ {
/* /*
* Be sure the X server socket in .X11-unix is * Be sure the X server socket in .X11-unix is deleted otherwise
* deleted otherwise other users may to become * other users may to become unable to run a session on the same
* unable to run a session on the same display. * display.
*/ */
#ifdef TEST #ifdef TEST
......
...@@ -55,26 +55,23 @@ ...@@ -55,26 +55,23 @@
#undef DUMP #undef DUMP
/* /*
* The list of rectangles composing a region * The list of rectangles composing a region s returned by
* s returned by nxagentGetOptimizedRegion- * nxagentGetOptimizedRegion- Boxes() instead of RegionRects().
* Boxes() instead of RegionRects().
*/ */
#define USE_OPTIMIZED_BOXES #define USE_OPTIMIZED_BOXES
/* /*
* The rectangles composing a region are de- * The rectangles composing a region are de- fragmented to reduce the
* fragmented to reduce the number of synch- * number of synch- ronizing PutImage's.
* ronizing PutImage's.
*/ */
#define ADVANCED_BOXES_DEFRAG #define ADVANCED_BOXES_DEFRAG
/* /*
* If defined, send the XClearArea at the end * If defined, send the XClearArea at the end of the loop
* of the loop synchronizing the shadow pixmap. * synchronizing the shadow pixmap. In this way, large images can be
* In this way, large images can be split but * split but the user will see more updates together.
* the user will see more updates together.
*/ */
#undef COLLECTED_UPDATES #undef COLLECTED_UPDATES
...@@ -104,9 +101,8 @@ _nxagentSynchronizationRec nxagentSynchronization = { (DrawablePtr) NULL, 0, 0, ...@@ -104,9 +101,8 @@ _nxagentSynchronizationRec nxagentSynchronization = { (DrawablePtr) NULL, 0, 0,
RegionPtr nxagentDeferredBackgroundExposures = NullRegion; RegionPtr nxagentDeferredBackgroundExposures = NullRegion;
/* /*
* Predicate functions used to synchronize the * Predicate functions used to synchronize the content of the remote
* content of the remote drawable with the data * drawable with the data stored in the virtual frame-buffer.
* stored in the virtual frame-buffer.
*/ */
void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2); void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2);
...@@ -126,12 +122,8 @@ int nxagentSkipImage = 0; ...@@ -126,12 +122,8 @@ int nxagentSkipImage = 0;
static int nxagentTooManyImageData(void) static int nxagentTooManyImageData(void)
{ {
unsigned int r; unsigned int limit = nxagentOption(ImageRateLimit);
unsigned int limit; unsigned int r = nxagentGetDataRate() / 1000;
limit = nxagentOption(ImageRateLimit);
r = nxagentGetDataRate() / 1000;
#ifdef TEST #ifdef TEST
if (r > limit) if (r > limit)
...@@ -145,8 +137,6 @@ static int nxagentTooManyImageData(void) ...@@ -145,8 +137,6 @@ static int nxagentTooManyImageData(void)
int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int breakMask, WindowPtr owner) int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int breakMask, WindowPtr owner)
{ {
int result;
pDrawable = nxagentSplitDrawable(pDrawable); pDrawable = nxagentSplitDrawable(pDrawable);
if (nxagentLosslessTrap == 0) if (nxagentLosslessTrap == 0)
...@@ -164,19 +154,17 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre ...@@ -164,19 +154,17 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre
} }
/* /*
* What we want here is to avoid drawing on the * What we want here is to avoid drawing on the framebuffer and just
* framebuffer and just perform the operation * perform the operation on the real X server. This is the purpose
* on the real X server. This is the purpose of * of the FB trap. At the same time we also want to avoid a split,
* the FB trap. At the same time we also want * so that the image will be transferred in a single operation.
* to avoid a split, so that the image will be
* transferred in a single operation.
*/ */
nxagentFBTrap = 1; nxagentFBTrap = 1;
nxagentSplitTrap = 1; nxagentSplitTrap = 1;
result = nxagentSynchronizeDrawableData(pDrawable, breakMask, owner); int result = nxagentSynchronizeDrawableData(pDrawable, breakMask, owner);
nxagentSplitTrap = 0; nxagentSplitTrap = 0;
...@@ -188,7 +176,6 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre ...@@ -188,7 +176,6 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre
} }
#ifdef TEST #ifdef TEST
if (nxagentDrawableStatus(pDrawable) == Synchronized) if (nxagentDrawableStatus(pDrawable) == Synchronized)
{ {
fprintf(stderr, "nxagentSynchronizeDrawable: Drawable %s [%p] with id [%ld] now synchronized.\n", fprintf(stderr, "nxagentSynchronizeDrawable: Drawable %s [%p] with id [%ld] now synchronized.\n",
...@@ -199,7 +186,6 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre ...@@ -199,7 +186,6 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre
fprintf(stderr, "nxagentSynchronizeDrawable: Drawable %s [%p] with id [%ld] not fully synchronized.\n", fprintf(stderr, "nxagentSynchronizeDrawable: Drawable %s [%p] with id [%ld] not fully synchronized.\n",
nxagentDrawableType(pDrawable), (void *) pDrawable, pDrawable -> id); nxagentDrawableType(pDrawable), (void *) pDrawable, pDrawable -> id);
} }
#endif #endif
return result; return result;
...@@ -207,31 +193,27 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre ...@@ -207,31 +193,27 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre
int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner) int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner)
{ {
int width, height, depth, length;
unsigned int leftPad, format;
char *data = NULL; char *data = NULL;
DrawablePtr pSrcDrawable;
GCPtr pGC;
int success; int success;
if (pDrawable -> type == DRAWABLE_PIXMAP) if (pDrawable -> type == DRAWABLE_PIXMAP)
{ {
leftPad = 0; GCPtr pGC;
unsigned int leftPad = 0;
width = pDrawable -> width; int width = pDrawable -> width;
height = pDrawable -> height; int height = pDrawable -> height;
depth = pDrawable -> depth; int depth = pDrawable -> depth;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSynchronizeDrawableData: Synchronizing drawable (%s) with geometry [%d][%d][%d].\n", fprintf(stderr, "nxagentSynchronizeDrawableData: Synchronizing drawable (%s) with geometry [%d][%d][%d].\n",
nxagentDrawableType(pDrawable), width, height, depth); nxagentDrawableType(pDrawable), width, height, depth);
#endif #endif
format = (depth == 1) ? XYPixmap : ZPixmap; unsigned int format = (depth == 1) ? XYPixmap : ZPixmap;
length = nxagentImageLength(width, height, format, leftPad, depth); int length = nxagentImageLength(width, height, format, leftPad, depth);
if ((data = malloc(length)) == NULL) if ((data = malloc(length)) == NULL)
{ {
...@@ -244,14 +226,13 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -244,14 +226,13 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
goto nxagentSynchronizeDrawableDataEnd; goto nxagentSynchronizeDrawableDataEnd;
} }
pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ? DrawablePtr pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ?
((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) : ((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) :
pDrawable); pDrawable);
/* /*
* Synchronize the whole pixmap if we need * Synchronize the whole pixmap if we need to download a fresh
* to download a fresh copy with lossless * copy with lossless compression turned off.
* compression turned off.
*/ */
if (nxagentLosslessTrap == 1) if (nxagentLosslessTrap == 1)
...@@ -289,10 +270,9 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -289,10 +270,9 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
else if (nxagentReconnectTrap == 1) else if (nxagentReconnectTrap == 1)
{ {
/* /*
* The pixmap data is not synchronized unless * The pixmap data is not synchronized unless we need it. We
* we need it. We noticed we have to reconnect * noticed we have to reconnect the pixmaps used by the GC's
* the pixmaps used by the GC's clip mask. * clip mask. The other data will be synchronized on demand.
* The other data will be synchronized on demand.
*/ */
if (pDrawable -> depth == 1) if (pDrawable -> depth == 1)
...@@ -357,9 +337,8 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -357,9 +337,8 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
} }
/* /*
* By calling this function with the NullRegion * By calling this function with the NullRegion as parameter we are
* as parameter we are requesting to synchro- * requesting to synchronize the full visible corrupted region of
* nize the full visible corrupted region of
* the drawable. * the drawable.
*/ */
...@@ -372,53 +351,26 @@ nxagentSynchronizeDrawableDataEnd: ...@@ -372,53 +351,26 @@ nxagentSynchronizeDrawableDataEnd:
} }
/* /*
* If pRegion is NullRegion, all the viewable * If pRegion is NullRegion, all the viewable corrupted region will be
* corrupted region will be synchronized. * synchronized.
*/ */
int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned int breakMask, WindowPtr owner) int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned int breakMask, WindowPtr owner)
{ {
GCPtr pGC;
DrawablePtr pSrcDrawable; DrawablePtr pSrcDrawable;
BoxPtr pBox;
RegionPtr clipRegion;
RegionRec tileRegion; int leftPad = 0;
RegionRec exposeRegion; int success = 0;
BoxRec box; char *data = NULL;
BoxRec tileBox; GCPtr pGC = NULL;
RegionPtr clipRegion = NullRegion;
#ifdef COLLECTED_UPDATES #ifdef COLLECTED_UPDATES
RegionRec collectedUpdates; RegionRec collectedUpdates;
#endif
char *data;
int nBox;
int x, y;
int w, h;
int extentWidth, extentHeight;
int tileWidth, tileHeight;
int length, format, leftPad;
int i;
int saveTrap;
int success;
int useStoredBitmap;
unsigned long now;
unsigned long elapsedTime;
leftPad = 0;
success = 0;
data = NULL;
pGC = NULL;
clipRegion = NullRegion;
#ifdef COLLECTED_UPDATES
RegionInit(&collectedUpdates, NullBox, 1); RegionInit(&collectedUpdates, NullBox, 1);
#endif #endif
RegionRec exposeRegion;
RegionInit(&exposeRegion, NullBox, 1); RegionInit(&exposeRegion, NullBox, 1);
if (nxagentDrawableBitmap(pDrawable) != NullPixmap && if (nxagentDrawableBitmap(pDrawable) != NullPixmap &&
...@@ -434,12 +386,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -434,12 +386,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
} }
/* /*
* The stored bitmap may be used if we * The stored bitmap may be used if we are going to synchronize the
* are going to synchronize the full * full drawable.
* drawable.
*/ */
useStoredBitmap = (nxagentDrawableBitmap(pDrawable) != NullPixmap && pRegion == NullRegion); int useStoredBitmap = (nxagentDrawableBitmap(pDrawable) != NullPixmap && pRegion == NullRegion);
if (useStoredBitmap != 0) if (useStoredBitmap != 0)
{ {
...@@ -454,24 +405,21 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -454,24 +405,21 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
RegionNumRects(nxagentCorruptedRegion((DrawablePtr) nxagentDrawableBitmap(pDrawable)))); RegionNumRects(nxagentCorruptedRegion((DrawablePtr) nxagentDrawableBitmap(pDrawable))));
#endif #endif
clipRegion = nxagentCreateRegion(pDrawable, NULL, 0, 0, pDrawable -> width, pDrawable -> height); RegionPtr clipRegion = nxagentCreateRegion(pDrawable, NULL, 0, 0, pDrawable -> width, pDrawable -> height);
/* /*
* Intersecting the viewable region of the * Intersecting the viewable region of the drawable with the
* drawable with the region remaining from * region remaining from a previous loop.
* a previous loop.
*/ */
RegionIntersect(clipRegion, clipRegion, RegionIntersect(clipRegion, clipRegion,
nxagentCorruptedRegion((DrawablePtr) nxagentDrawableBitmap(pDrawable))); nxagentCorruptedRegion((DrawablePtr) nxagentDrawableBitmap(pDrawable)));
/* /*
* The bitmap regions used in the synchro- * The bitmap regions used in the synchronizations are only those
* nizations are only those corrupted also * corrupted also on the drawable. In this way, if we put a tile
* on the drawable. In this way, if we put * in a bad position (e.g. if the corrupted region moves), the
* a tile in a bad position (e.g. if the * next synchronization will fix the error.
* corrupted region moves), the next synch-
* ronization will fix the error.
*/ */
RegionIntersect(clipRegion, clipRegion, RegionIntersect(clipRegion, clipRegion,
...@@ -495,8 +443,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -495,8 +443,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
} }
/* /*
* Using the saved bitmap as source, instead * Using the saved bitmap as source, instead of the drawable
* of the drawable itself. * itself.
*/ */
pSrcDrawable = ((DrawablePtr) nxagentVirtualPixmap(nxagentDrawableBitmap(pDrawable))); pSrcDrawable = ((DrawablePtr) nxagentVirtualPixmap(nxagentDrawableBitmap(pDrawable)));
...@@ -524,15 +472,14 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -524,15 +472,14 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
} }
/* /*
* Creating a region containing the viewable * Creating a region containing the viewable area of drawable.
* area of drawable.
*/ */
clipRegion = nxagentCreateRegion(pDrawable, NULL, 0, 0, pDrawable -> width, pDrawable -> height); clipRegion = nxagentCreateRegion(pDrawable, NULL, 0, 0, pDrawable -> width, pDrawable -> height);
/* /*
* If the corrupted region is not viewable, we * If the corrupted region is not viewable, we can skip the
* can skip the synchronization. * synchronization.
*/ */
RegionIntersect(clipRegion, clipRegion, nxagentCorruptedRegion(pDrawable)); RegionIntersect(clipRegion, clipRegion, nxagentCorruptedRegion(pDrawable));
...@@ -550,10 +497,9 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -550,10 +497,9 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
} }
/* /*
* We can skip the synchronization if the re- * We can skip the synchronization if the requested region is not
* quested region is not corrupted. Specifying * corrupted. Specifying a NullRegion as parameter, all the
* a NullRegion as parameter, all the viewable * viewable corrupted region will be synchronized.
* corrupted region will be synchronized.
*/ */
if (pRegion != NullRegion) if (pRegion != NullRegion)
...@@ -585,7 +531,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -585,7 +531,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
nxagentDrawableType(pDrawable), (void *) pDrawable); nxagentDrawableType(pDrawable), (void *) pDrawable);
#endif #endif
saveTrap = nxagentGCTrap; int saveTrap = nxagentGCTrap;
nxagentGCTrap = 0; nxagentGCTrap = 0;
...@@ -618,14 +564,13 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -618,14 +564,13 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
#endif #endif
/* /*
* We are going to synchronize the corrupted * We are going to synchronize the corrupted area, so we use the
* area, so we use the corrupted extents as * corrupted extents as maximum size of the image data. It's
* maximum size of the image data. It's im- * important to avoid using the drawable size, because in case of a
* portant to avoid using the drawable size, * huge window it had to result in a failed data memory allocation.
* because in case of a huge window it had to
* result in a failed data memory allocation.
*/ */
int w, h, extentWidth, extentHeight, tileWidth, tileHeight;
extentWidth = clipRegion -> extents.x2 - clipRegion -> extents.x1; extentWidth = clipRegion -> extents.x2 - clipRegion -> extents.x1;
extentHeight = clipRegion -> extents.y2 - clipRegion -> extents.y1; extentHeight = clipRegion -> extents.y2 - clipRegion -> extents.y1;
...@@ -636,6 +581,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -636,6 +581,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
fprintf(stderr, "nxagentSynchronizeRegion: Using tiles of size [%dx%d].\n", tileWidth, tileHeight); fprintf(stderr, "nxagentSynchronizeRegion: Using tiles of size [%dx%d].\n", tileWidth, tileHeight);
#endif #endif
int length, format;
data = nxagentAllocateImageData(w, h, pDrawable -> depth, &length, &format); data = nxagentAllocateImageData(w, h, pDrawable -> depth, &length, &format);
if (data == NULL) if (data == NULL)
...@@ -645,8 +591,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -645,8 +591,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
fprintf(stderr, "nxagentSynchronizeRegion: WARNING! Failed to allocate memory for synchronization.\n"); fprintf(stderr, "nxagentSynchronizeRegion: WARNING! Failed to allocate memory for synchronization.\n");
/* /*
* Print detailed information if the * Print detailed information if the image length is zero.
* image length is zero.
*/ */
if (length == 0) if (length == 0)
...@@ -664,17 +609,17 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -664,17 +609,17 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
#ifndef USE_OPTIMIZED_BOXES #ifndef USE_OPTIMIZED_BOXES
pBox = RegionRects(clipRegion); BoxPtr pBox = RegionRects(clipRegion);
#else #else
pBox = nxagentGetOptimizedRegionBoxes(clipRegion); BoxPtr pBox = nxagentGetOptimizedRegionBoxes(clipRegion);
#endif /* USE_OPTIMIZED_BOXES */ #endif /* USE_OPTIMIZED_BOXES */
nBox = RegionNumRects(clipRegion); int nBox = RegionNumRects(clipRegion);
now = GetTimeInMillis(); unsigned long now = GetTimeInMillis();
nxagentSynchronization.abort = 0; nxagentSynchronization.abort = 0;
...@@ -682,7 +627,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -682,7 +627,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
* Going to split the updated region into small blocks. * Going to split the updated region into small blocks.
*/ */
for (i = 0; i < nBox; i++) for (int i = 0; i < nBox; i++)
{ {
#ifdef USE_OPTIMIZED_BOXES #ifdef USE_OPTIMIZED_BOXES
...@@ -694,13 +639,13 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -694,13 +639,13 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
#endif #endif
box = pBox[i]; BoxRec box = pBox[i];
for (y = box.y1; y < box.y2; y += h) for (int y = box.y1; y < box.y2; y += h)
{ {
h = min(box.y2 - y, tileHeight); h = min(box.y2 - y, tileHeight);
for (x = box.x1; x < box.x2; x += w) for (int x = box.x1; x < box.x2; x += w)
{ {
w = min(box.x2 - x, tileWidth); w = min(box.x2 - x, tileWidth);
...@@ -727,12 +672,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -727,12 +672,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
if (canBreakOnTimeout(breakMask)) if (canBreakOnTimeout(breakMask))
{ {
/* /*
* Abort the synchronization loop if it * Abort the synchronization loop if it lasts for more than
* lasts for more than DeferTimeout * DeferTimeout milliseconds.
* milliseconds.
*/ */
elapsedTime = GetTimeInMillis() - now; unsigned long elapsedTime = GetTimeInMillis() - now;
if (elapsedTime > nxagentOption(DeferTimeout)) if (elapsedTime > nxagentOption(DeferTimeout))
{ {
...@@ -781,10 +725,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -781,10 +725,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
goto nxagentSynchronizeRegionStop; goto nxagentSynchronizeRegionStop;
} }
tileBox.x1 = x; BoxRec tileBox = {.x1 = x, .y1 = y, .x2 = x + w, .y2 = y + h};
tileBox.y1 = y;
tileBox.x2 = x + w;
tileBox.y2 = y + h;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSynchronizeRegion: Going to synchronize tile [%d,%d,%d,%d].\n", fprintf(stderr, "nxagentSynchronizeRegion: Going to synchronize tile [%d,%d,%d,%d].\n",
...@@ -794,10 +735,10 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -794,10 +735,10 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
nxagentGetImage(pSrcDrawable, x, y, w, h, format, AllPlanes, data); nxagentGetImage(pSrcDrawable, x, y, w, h, format, AllPlanes, data);
/* /*
* Going to unmark the synchronized * Going to unmark the synchronized region.
* region.
*/ */
RegionRec tileRegion;
RegionInit(&tileRegion, &tileBox, 1); RegionInit(&tileRegion, &tileBox, 1);
RegionUnion(&exposeRegion, &exposeRegion, &tileRegion); RegionUnion(&exposeRegion, &exposeRegion, &tileRegion);
...@@ -809,30 +750,26 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -809,30 +750,26 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
if (useStoredBitmap != 0) if (useStoredBitmap != 0)
{ {
/* /*
* When a bitmap's tile is synchronized, * When a bitmap's tile is synchronized, we can clear the
* we can clear the corresponding region. * corresponding region. We can't use the
* We can't use the nxagentUnmarkCorrupted- * nxagentUnmarkCorruptedRegion because we have not a
* Region because we have not a resource * resource associated to this pixmap.
* associated to this pixmap.
*/ */
RegionSubtract(nxagentPixmapCorruptedRegion(nxagentDrawableBitmap(pDrawable)), RegionSubtract(nxagentPixmapCorruptedRegion(nxagentDrawableBitmap(pDrawable)),
nxagentPixmapCorruptedRegion(nxagentDrawableBitmap(pDrawable)), &tileRegion); nxagentPixmapCorruptedRegion(nxagentDrawableBitmap(pDrawable)), &tileRegion);
/* /*
* The drawable's corrupted region can * The drawable's corrupted region can be cleared if the
* be cleared if the bitmap's tile data * bitmap's tile data matches the drawable's content at the
* matches the drawable's content at the
* same position. * same position.
*/ */
if (nxagentDrawableStatus(pDrawable) == NotSynchronized) if (nxagentDrawableStatus(pDrawable) == NotSynchronized)
{ {
char *cmpData;
int cmpLength, cmpFormat; int cmpLength, cmpFormat;
cmpData = nxagentAllocateImageData(w, h, pDrawable -> depth, &cmpLength, &cmpFormat); char *cmpData = nxagentAllocateImageData(w, h, pDrawable -> depth, &cmpLength, &cmpFormat);
if (cmpData != NULL) if (cmpData != NULL)
{ {
...@@ -882,8 +819,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -882,8 +819,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
} }
/* /*
* Realize the image after comparing the * Realize the image after comparing the source data with the
* source data with the bitmap data. * bitmap data.
*/ */
nxagentRealizeImage(pDrawable, pGC, pDrawable -> depth, nxagentRealizeImage(pDrawable, pGC, pDrawable -> depth,
...@@ -899,16 +836,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -899,16 +836,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
(nxagentOption(XRatio) != DONT_SCALE || (nxagentOption(XRatio) != DONT_SCALE ||
nxagentOption(YRatio) != DONT_SCALE)) nxagentOption(YRatio) != DONT_SCALE))
{ {
int scaledx; int scaledx = nxagentScale(x, nxagentOption(XRatio));
int scaledy; int scaledy = nxagentScale(y, nxagentOption(YRatio));
int scaledw;
int scaledh;
scaledx = nxagentScale(x, nxagentOption(XRatio));
scaledy = nxagentScale(y, nxagentOption(YRatio));
scaledw = nxagentScale(x + w, nxagentOption(XRatio)) - scaledx; int scaledw = nxagentScale(x + w, nxagentOption(XRatio)) - scaledx;
scaledh = nxagentScale(y + h, nxagentOption(YRatio)) - scaledy; int scaledh = nxagentScale(y + h, nxagentOption(YRatio)) - scaledy;
XClearArea(nxagentDisplay, nxagentWindow(owner), scaledx, scaledy, scaledw, scaledh, 0); XClearArea(nxagentDisplay, nxagentWindow(owner), scaledx, scaledy, scaledw, scaledh, 0);
} }
...@@ -921,9 +853,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -921,9 +853,8 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
#endif /* #if !defined(COLLECTED_UPDATES) */ #endif /* #if !defined(COLLECTED_UPDATES) */
/* /*
* Abort the loop on the user's input. * Abort the loop on the user's input. This is done here to
* This is done here to check for events * check for events read after the flush caused by the
* read after the flush caused by the
* PutImage. * PutImage.
*/ */
...@@ -959,10 +890,9 @@ nxagentSynchronizeRegionStop: ...@@ -959,10 +890,9 @@ nxagentSynchronizeRegionStop:
if (nxagentSynchronization.abort == 1) if (nxagentSynchronization.abort == 1)
{ {
/* /*
* Storing the pointer to the drawable we * Storing the pointer to the drawable we were synchronizing
* were synchronizing when the loop aborted. * when the loop aborted. It is used in
* It is used in nxagentSynchronizeDrawable- * nxagentSynchronizeDrawablePredicate.
* Predicate.
*/ */
nxagentSynchronization.pDrawable = pDrawable; nxagentSynchronization.pDrawable = pDrawable;
...@@ -993,14 +923,12 @@ nxagentSynchronizeRegionStop: ...@@ -993,14 +923,12 @@ nxagentSynchronizeRegionStop:
nxagentIsCorruptedBackground((PixmapPtr) pDrawable) == 1 && nxagentIsCorruptedBackground((PixmapPtr) pDrawable) == 1 &&
RegionNil(&exposeRegion) == 0) RegionNil(&exposeRegion) == 0)
{ {
struct nxagentExposeBackground eb; struct nxagentExposeBackground eb = {
.pBackground = (PixmapPtr) pDrawable,
int i; .pExpose = &exposeRegion,
};
eb.pBackground = (PixmapPtr) pDrawable;
eb.pExpose = &exposeRegion;
for (i = 0; i < MAXCLIENTS; i++) for (int i = 0; i < MAXCLIENTS; i++)
{ {
if (clients[i] != NULL) if (clients[i] != NULL)
{ {
...@@ -1019,27 +947,22 @@ nxagentSynchronizeRegionStop: ...@@ -1019,27 +947,22 @@ nxagentSynchronizeRegionStop:
RegionValidate(&collectedUpdates, &overlap); RegionValidate(&collectedUpdates, &overlap);
for (i = 0; i < RegionNumRects(&collectedUpdates); i++) for (int i = 0; i < RegionNumRects(&collectedUpdates); i++)
{ {
x = RegionRects(&collectedUpdates)[i].x1; int x = RegionRects(&collectedUpdates)[i].x1;
y = RegionRects(&collectedUpdates)[i].y1; int y = RegionRects(&collectedUpdates)[i].y1;
w = RegionRects(&collectedUpdates)[i].x2 - RegionRects(&collectedUpdates)[i].x1; int w = RegionRects(&collectedUpdates)[i].x2 - RegionRects(&collectedUpdates)[i].x1;
h = RegionRects(&collectedUpdates)[i].y2 - RegionRects(&collectedUpdates)[i].y1; int h = RegionRects(&collectedUpdates)[i].y2 - RegionRects(&collectedUpdates)[i].y1;
if (nxagentOption(Shadow) == 1 && if (nxagentOption(Shadow) == 1 &&
(nxagentOption(XRatio) != DONT_SCALE || (nxagentOption(XRatio) != DONT_SCALE ||
nxagentOption(YRatio) != DONT_SCALE)) nxagentOption(YRatio) != DONT_SCALE))
{ {
int scaledx; int scaledx = nxagentScale(x, nxagentOption(XRatio));
int scaledy; int scaledy = nxagentScale(y, nxagentOption(YRatio));
int scaledw;
int scaledh;
scaledx = nxagentScale(x, nxagentOption(XRatio));
scaledy = nxagentScale(y, nxagentOption(YRatio));
scaledw = nxagentScale(x + w, nxagentOption(XRatio)) - scaledx; int scaledw = nxagentScale(x + w, nxagentOption(XRatio)) - scaledx;
scaledh = nxagentScale(y + h, nxagentOption(YRatio)) - scaledy; int scaledh = nxagentScale(y + h, nxagentOption(YRatio)) - scaledy;
XClearArea(nxagentDisplay, nxagentWindow(owner), scaledx, scaledy, scaledw, scaledh, 0); XClearArea(nxagentDisplay, nxagentWindow(owner), scaledx, scaledy, scaledw, scaledh, 0);
} }
...@@ -1074,8 +997,6 @@ nxagentSynchronizeRegionFree: ...@@ -1074,8 +997,6 @@ nxagentSynchronizeRegionFree:
void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int breakMask) void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int breakMask)
{ {
RegionPtr pRegion;
if (nxagentDrawableStatus(pDrawable) == Synchronized) if (nxagentDrawableStatus(pDrawable) == Synchronized)
{ {
#ifdef TEST #ifdef TEST
...@@ -1102,7 +1023,7 @@ void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int brea ...@@ -1102,7 +1023,7 @@ void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int brea
pBox -> x1, pBox -> y1, pBox -> x2, pBox -> y2); pBox -> x1, pBox -> y1, pBox -> x2, pBox -> y2);
#endif #endif
pRegion = nxagentCreateRegion(pDrawable, NULL, pBox -> x1, pBox -> y1, RegionPtr pRegion = nxagentCreateRegion(pDrawable, NULL, pBox -> x1, pBox -> y1,
pBox -> x2 - pBox -> x1, pBox -> y2 - pBox -> y1); pBox -> x2 - pBox -> x1, pBox -> y2 - pBox -> y1);
...@@ -1138,10 +1059,9 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2) ...@@ -1138,10 +1059,9 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2)
int shouldClearHiddenRegion = 1; int shouldClearHiddenRegion = 1;
/* /*
* The nxagentSynchronization.abort propa- * The nxagentSynchronization.abort propagates a break condition
* gates a break condition across the resour- * across the resources loop, in order to block also the subsequent
* ces loop, in order to block also the sub- * synchronizations.
* sequent synchronizations.
*/ */
if (nxagentSynchronization.abort == 1 || if (nxagentSynchronization.abort == 1 ||
...@@ -1151,10 +1071,9 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2) ...@@ -1151,10 +1071,9 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2)
} }
/* /*
* In order to implement a kind of round-robin * In order to implement a kind of round-robin synchronization, the
* synchronization, the previous incomplete * previous incomplete drawable synchronization is saved to jump to
* drawable synchronization is saved to jump * the next resource available of same type.
* to the next resource available of same type.
*/ */
if (nxagentSynchronization.pDrawable != NULL && if (nxagentSynchronization.pDrawable != NULL &&
...@@ -1186,10 +1105,8 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2) ...@@ -1186,10 +1105,8 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2)
if (pDrawable -> type == DRAWABLE_PIXMAP) if (pDrawable -> type == DRAWABLE_PIXMAP)
{ {
/* /*
* The pixmaps to be synchronized are those * The pixmaps to be synchronized are those used as background or
* used as background or used as source of * used as source of any deferred operations for at least 2 times.
* any deferred operations for at least 2
* times.
*/ */
if (NXAGENT_SHOULD_SYNCHRONIZE_PIXMAP(pDrawable) == 0) if (NXAGENT_SHOULD_SYNCHRONIZE_PIXMAP(pDrawable) == 0)
...@@ -1234,17 +1151,15 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2) ...@@ -1234,17 +1151,15 @@ void nxagentSynchronizeDrawablePredicate(void *p0, XID x1, void *p2)
} }
/* /*
* Postpone the synchronization if we went * Postpone the synchronization if we went out of bandwidth or if
* out of bandwidth or if the display blocks. * the display blocks. The pixmap synchronization is more careful
* The pixmap synchronization is more careful
* with bandwidth usage. * with bandwidth usage.
*/ */
/* /*
FIXME: This condition sounds only as a FIXME: This condition sounds only as a complication, as the break
complication, as the break parameters parameters are already checked while synchronizing the
are already checked while synchroni- drawable.
zing the drawable.
if (breakOnCongestion(*breakMask) == 1 || if (breakOnCongestion(*breakMask) == 1 ||
(pDrawable -> type == DRAWABLE_PIXMAP && (pDrawable -> type == DRAWABLE_PIXMAP &&
...@@ -1275,10 +1190,9 @@ FIXME: This condition sounds only as a ...@@ -1275,10 +1190,9 @@ FIXME: This condition sounds only as a
#endif #endif
/* /*
* The stored bitmap is destroyed inside * The stored bitmap is destroyed inside the synchronization loop,
* the synchronization loop, so we have * so we have to check here its presence to know if we can clear the
* to check here its presence to know if * dirty windows.
* we can clear the dirty windows.
*/ */
shouldClearHiddenRegion = (nxagentDrawableBitmap(pDrawable) == NullPixmap); shouldClearHiddenRegion = (nxagentDrawableBitmap(pDrawable) == NullPixmap);
...@@ -1293,10 +1207,9 @@ FIXME: This condition sounds only as a ...@@ -1293,10 +1207,9 @@ FIXME: This condition sounds only as a
#endif #endif
/* /*
* If the remaining corrupted region is on * If the remaining corrupted region is on an hidden section (not
* an hidden section (not viewable or outside * viewable or outside of the pixmap's area) of a drawable, we can
* of the pixmap's area) of a drawable, * clear it.
* we can clear it.
*/ */
if (nxagentSynchronization.abort == 0 && if (nxagentSynchronization.abort == 0 &&
...@@ -1314,14 +1227,9 @@ FIXME: This condition sounds only as a ...@@ -1314,14 +1227,9 @@ FIXME: This condition sounds only as a
void nxagentSynchronizationLoop(unsigned int mask) void nxagentSynchronizationLoop(unsigned int mask)
{ {
unsigned int breakMask;
int doRoundRobin;
/* /*
FIXME: All drawables should be set as synchronized and FIXME: All drawables should be set as synchronized and never marked as
never marked as corrupted while the display is corrupted while the display is down.
down.
*/ */
nxagentSkipImage = nxagentTooManyImageData(); nxagentSkipImage = nxagentTooManyImageData();
...@@ -1358,17 +1266,15 @@ FIXME: All drawables should be set as synchronized and ...@@ -1358,17 +1266,15 @@ FIXME: All drawables should be set as synchronized and
"blocking [%d].\n", nxagentCongestion, nxagentBlocking); "blocking [%d].\n", nxagentCongestion, nxagentBlocking);
#endif #endif
breakMask = mask; unsigned int breakMask = mask;
/* /*
* The resource counter can be reset if we * The resource counter can be reset if we have not aborted the
* have not aborted the synchronization loop, * synchronization loop, if we are not skipping resources to do
* if we are not skipping resources to do * round-robin and if the bitmaps are all synchronized.
* round-robin and if the bitmaps are all
* synchronized.
*/ */
doRoundRobin = (nxagentSynchronization.pDrawable != NULL); int doRoundRobin = (nxagentSynchronization.pDrawable != NULL);
nxagentSynchronization.abort = 0; nxagentSynchronization.abort = 0;
...@@ -1436,11 +1342,10 @@ FIXME: All drawables should be set as synchronized and ...@@ -1436,11 +1342,10 @@ FIXME: All drawables should be set as synchronized and
} }
/* /*
* If there is bandwidth remaining, synchronize * If there is bandwidth remaining, synchronize the
* the pixmaps. Synchronizing a pixmap doesn't * pixmaps. Synchronizing a pixmap doesn't produce any visible
* produce any visible results. Better is to * results. Better is to synchronize them on demand, before using
* synchronize them on demand, before using the * the pixmap in a copy or in a composite operation.
* pixmap in a copy or in a composite operation.
*/ */
if (nxagentSynchronization.abort == 0 && if (nxagentSynchronization.abort == 0 &&
...@@ -1474,9 +1379,8 @@ FIXME: All drawables should be set as synchronized and ...@@ -1474,9 +1379,8 @@ FIXME: All drawables should be set as synchronized and
} }
/* /*
* If the last synchronized drawable has been * If the last synchronized drawable has been removed, we have to
* removed, we have to reset the variable sto- * reset the variable sto- ring its pointer.
* ring its pointer.
*/ */
if (nxagentSynchronization.pDrawable != NULL && if (nxagentSynchronization.pDrawable != NULL &&
...@@ -1508,15 +1412,8 @@ FIXME: All drawables should be set as synchronized and ...@@ -1508,15 +1412,8 @@ FIXME: All drawables should be set as synchronized and
RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
int width, int height) int width, int height)
{ {
RegionPtr pRegion; BoxRec box = {.x1 = x, .y1 = y, .x2 = x + width, .y2 = y + height};
BoxRec box; RegionPtr pRegion = RegionCreate(&box, 1);
box.x1 = x;
box.y1 = y;
box.x2 = x + width;
box.y2 = y + height;
pRegion = RegionCreate(&box, 1);
/* /*
* Clipping the region. * Clipping the region.
...@@ -1524,22 +1421,17 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, ...@@ -1524,22 +1421,17 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
if (pDrawable -> type == DRAWABLE_PIXMAP) if (pDrawable -> type == DRAWABLE_PIXMAP)
{ {
BoxRec tmpBox;
RegionRec tmpRegion;
/* /*
* The region created doesn't need to be clipped * The region created doesn't need to be clipped if it has the
* if it has the pixmap dimensions. * pixmap dimensions.
*/ */
if (x != 0 || y != 0 || if (x != 0 || y != 0 ||
width != pDrawable -> width || width != pDrawable -> width ||
height != pDrawable -> height) height != pDrawable -> height)
{ {
tmpBox.x1 = 0; BoxRec tmpBox = {.x1 = 0, .y1 = 0, .x2 = pDrawable -> width, .y2 = pDrawable -> height};
tmpBox.y1 = 0; RegionRec tmpRegion;
tmpBox.x2 = pDrawable -> width;
tmpBox.y2 = pDrawable -> height;
RegionInit(&tmpRegion, &tmpBox, 1); RegionInit(&tmpRegion, &tmpBox, 1);
...@@ -1551,9 +1443,8 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, ...@@ -1551,9 +1443,8 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
else else
{ {
/* /*
* We use the clipList because the borderClip * We use the clipList because the borderClip contains also parts
* contains also parts of the window covered * of the window covered by its children.
* by its children.
*/ */
RegionTranslate(pRegion, RegionTranslate(pRegion,
...@@ -1579,8 +1470,8 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, ...@@ -1579,8 +1470,8 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
#endif #endif
/* /*
* If the pRegion is NIL we don't need * If the pRegion is NIL we don't need to intersect it with the GC's
* to intersect it with the GC's clipmask. * clipmask.
*/ */
if (RegionNil(pRegion) == 0 && if (RegionNil(pRegion) == 0 &&
...@@ -1594,9 +1485,9 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, ...@@ -1594,9 +1485,9 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
RegionCopy(&clipRegion, (RegionPtr) pGC -> clientClip); RegionCopy(&clipRegion, (RegionPtr) pGC -> clientClip);
/* /*
* The clip origin is relative to the origin of * The clip origin is relative to the origin of the destination
* the destination drawable. The clip mask coor- * drawable. The clip mask coor- dinates are relative to the clip
* dinates are relative to the clip origin. * origin.
*/ */
if (pGC -> clipOrg.x != 0 || pGC -> clipOrg.y != 0) if (pGC -> clipOrg.x != 0 || pGC -> clipOrg.y != 0)
...@@ -1620,11 +1511,6 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y, ...@@ -1620,11 +1511,6 @@ RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
int x;
int y;
int width;
int height;
if (pRegion != NullRegion && RegionNil(pRegion) == 1) if (pRegion != NullRegion && RegionNil(pRegion) == 1)
{ {
#ifdef TEST #ifdef TEST
...@@ -1636,10 +1522,9 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1636,10 +1522,9 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
} }
/* /*
* If the drawable was synchronized, the counter * If the drawable was synchronized, the counter reporting the
* reporting the number of corrupted drawables * number of corrupted drawables must be increased. Moreover the
* must be increased. Moreover the corrupted ti- * corrupted ti- mestamp must be set.
* mestamp must be set.
*/ */
if (nxagentDrawableStatus(pDrawable) == Synchronized) if (nxagentDrawableStatus(pDrawable) == Synchronized)
...@@ -1654,11 +1539,11 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1654,11 +1539,11 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
if (pRegion == NullRegion) if (pRegion == NullRegion)
{ {
x = 0; int x = 0;
y = 0; int y = 0;
width = pDrawable -> width; int width = pDrawable -> width;
height = pDrawable -> height; int height = pDrawable -> height;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentMarkCorruptedRegion: Fully invalidating %s [%p] with " fprintf(stderr, "nxagentMarkCorruptedRegion: Fully invalidating %s [%p] with "
...@@ -1700,8 +1585,6 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1700,8 +1585,6 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
int oldStatus;
if (pRegion != NullRegion && RegionNil(pRegion) == 1) if (pRegion != NullRegion && RegionNil(pRegion) == 1)
{ {
#ifdef TEST #ifdef TEST
...@@ -1712,7 +1595,7 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1712,7 +1595,7 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
return; return;
} }
oldStatus = nxagentDrawableStatus(pDrawable); int oldStatus = nxagentDrawableStatus(pDrawable);
if (oldStatus == Synchronized) if (oldStatus == Synchronized)
{ {
...@@ -1752,9 +1635,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1752,9 +1635,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
} }
/* /*
* If the drawable becomes synchronized, the * If the drawable becomes synchronized, the counter reporting the
* counter reporting the number of corrupted * number of corrupted drawables must be decreased. Moreover the
* drawables must be decreased. Moreover the
* corrupted timestamp must be reset. * corrupted timestamp must be reset.
*/ */
...@@ -1777,8 +1659,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1777,8 +1659,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
nxagentResetCorruptedTimestamp(pDrawable); nxagentResetCorruptedTimestamp(pDrawable);
/* /*
* If the resource is no longer dirty, * If the resource is no longer dirty, the associated bitmap is
* the associated bitmap is destroyed. * destroyed.
*/ */
if (nxagentDrawableBitmap(pDrawable) != NullPixmap) if (nxagentDrawableBitmap(pDrawable) != NullPixmap)
...@@ -1791,9 +1673,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1791,9 +1673,8 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask) void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask)
{ {
/* /*
* If a window is resized, its corrupted * If a window is resized, its corrupted region is moved according
* region is moved according to the bit * to the bit gravity.
* gravity.
*/ */
if (nxagentDrawableStatus((DrawablePtr) pWin) == NotSynchronized) if (nxagentDrawableStatus((DrawablePtr) pWin) == NotSynchronized)
...@@ -1819,18 +1700,17 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask) ...@@ -1819,18 +1700,17 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask)
nx, ny); nx, ny);
/* /*
* Having moved the corrupted region, we * Having moved the corrupted region, we need to invalidate the
* need to invalidate the pending commits * pending commits or otherwise the image will fall in the wrong
* or otherwise the image will fall in * area.
* the wrong area.
*/ */
nxagentValidateSplit((DrawablePtr) pWin, NULL); nxagentValidateSplit((DrawablePtr) pWin, NULL);
/* /*
* The window reconfiguration invalidates * The window reconfiguration invalidates the synchronization
* the synchronization bitmap. * bitmap.
*/ */
nxagentDestroyDrawableBitmap((DrawablePtr) pWin); nxagentDestroyDrawableBitmap((DrawablePtr) pWin);
...@@ -1839,13 +1719,12 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask) ...@@ -1839,13 +1719,12 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask)
} }
/* /*
* The DDX layer uses an 'Y-X banding' representation of * The DDX layer uses an 'Y-X banding' representation of regions: it
* regions: it sorts all rectangles composing a region * sorts all rectangles composing a region using first the
* using first the y-dimension, than the x-dimension; mo- * y-dimension, than the x-dimension; moreover it organizes the
* reover it organizes the rectangles in 'bands' sharing * rectangles in 'bands' sharing the same y-dimension. This
* the same y-dimension. This representation does not mi- * representation does not minimize the number of rectangles. For
* nimize the number of rectangles. For example, the fol- * example, the following region has 4 rectangles:
* lowing region has 4 rectangles:
* *
* +-----------+ * +-----------+
* | | +---+ * | | +---+
...@@ -1853,40 +1732,30 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask) ...@@ -1853,40 +1732,30 @@ void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask)
* | | +---+ * | | +---+
* +-----------+ * +-----------+
* *
* The rectangle 'B' creates a band which splits the rec- * The rectangle 'B' creates a band which splits the rectangle A in 3
* tangle A in 3 parts, for a total of 3 bands. The num- * parts, for a total of 3 bands. The number of rectangles composing
* ber of rectangles composing the region is 4. * the region is 4.
* *
* This kind of representation is not advisable for the * This kind of representation is not advisable for the lazy
* lazy synchronization because, in the example above, * synchronization because, in the example above, the nxagent had to
* the nxagent had to send 4 put images instead of 2. * send 4 put images instead of 2.
* *
* To minimize the problem we use the following function: * To minimize the problem we use the following function: by
* by traversing the list of rectangles we merge all bo- * traversing the list of rectangles we merge all boxes with same x
* xes with same x coordinates and coincident y, in order * coordinates and coincident y, in order to create an X-Y banding.
* to create an X-Y banding.
* *
* Be careful: all the coordinates of boxes merged are * Be careful: all the coordinates of boxes merged are set to 0, so
* set to 0, so take care of this when looping through * take care of this when looping through the box list returned by
* the box list returned by this function. * this function.
*/ */
BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
{ {
BoxPtr pBox;
BoxRec boxExtents; BoxRec boxExtents;
int nBox; BoxPtr pBox = RegionRects(pRegion);
int i, j;
#ifdef DEBUG
int nBoxOptim;
#endif
pBox = RegionRects(pRegion);
nBox = RegionNumRects(pRegion); int nBox = RegionNumRects(pRegion);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGetOptimizedRegionBoxes: Going to optimize region at [%p] with [%d] rects.\n", fprintf(stderr, "nxagentGetOptimizedRegionBoxes: Going to optimize region at [%p] with [%d] rects.\n",
...@@ -1899,21 +1768,19 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -1899,21 +1768,19 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
} }
#ifdef DEBUG #ifdef DEBUG
nBoxOptim = nBox; int nBoxOptim = nBox;
#endif #endif
/* /*
* The boxes are now grouped to grown as much * The boxes are now grouped to grown as much as possible, using
* as possible, using their overlapping vertex * their overlapping vertex as rule.
* as rule.
*/ */
for (i = 0; i < nBox; i++) for (int i = 0; i < nBox; i++)
{ {
/* /*
* If the coordinates are (0,0) the box * If the coordinates are (0,0) the box has been already merged,
* has been already merged, so we can skip * so we can skip it.
* it.
*/ */
if (pBox[i].x1 == 0 && pBox[i].y1 == 0 && if (pBox[i].x1 == 0 && pBox[i].y1 == 0 &&
...@@ -1937,7 +1804,7 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -1937,7 +1804,7 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
boxExtents.y2 = pBox[i].y2; boxExtents.y2 = pBox[i].y2;
for (j = i+1; j < nBox; j++) for (int j = i+1; j < nBox; j++)
{ {
if (pBox[j].x1 == 0 && pBox[j].y1 == 0 && if (pBox[j].x1 == 0 && pBox[j].y1 == 0 &&
pBox[j].x2 == 0 && pBox[j].y2 == 0) pBox[j].x2 == 0 && pBox[j].y2 == 0)
...@@ -1951,12 +1818,10 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -1951,12 +1818,10 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
#endif #endif
/* /*
* Each consequent box is merged if its * Each consequent box is merged if its higher side overlaps the
* higher side overlaps the lower side * lower side of current box. In case of ADVANCED_BOXES_DEFRAG
* of current box. * the higher side must be included within a range defined by
* In case of ADVANCED_BOXES_DEFRAG the higher * INCLUDE_MARGIN.
* side must be included within a range
* defined by INCLUDE_MARGIN.
*/ */
#ifndef ADVANCED_BOXES_DEFRAG #ifndef ADVANCED_BOXES_DEFRAG
...@@ -2006,11 +1871,9 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -2006,11 +1871,9 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
} }
/* /*
* By appending a box to another, we have * By appending a box to another, we have to remove it from
* to remove it from the box list. We do * the box list. We do this by setting its coordinates to
* this by setting its coordinates to (0,0) * (0,0) and by checking their value in the main loop.
* and by checking their value in the main
* loop.
*/ */
pBox[j].x1 = pBox[j].y1 = pBox[j].x2 = pBox[j].y2 = 0; pBox[j].x1 = pBox[j].y1 = pBox[j].x2 = pBox[j].y2 = 0;
...@@ -2039,13 +1902,12 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -2039,13 +1902,12 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
#ifdef ADVANCED_BOXES_DEFRAG #ifdef ADVANCED_BOXES_DEFRAG
/* /*
* The new list need to be validated to * The new list need to be validated to avoid boxes
* avoid boxes overlapping. This code may * overlapping. This code may be improved to remove also the
* be improved to remove also the partial- * partial- ly overlapping boxes.
* ly overlapping boxes.
*/ */
for (i = 0; i < nBox; i++) for (int i = 0; i < nBox; i++)
{ {
if (pBox[i].x1 == 0 && pBox[i].y1 == 0 && if (pBox[i].x1 == 0 && pBox[i].y1 == 0 &&
pBox[i].x2 == 0 && pBox[i].y2 == 0) pBox[i].x2 == 0 && pBox[i].y2 == 0)
...@@ -2063,7 +1925,7 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -2063,7 +1925,7 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
boxExtents.x2 = pBox[i].x2; boxExtents.x2 = pBox[i].x2;
boxExtents.y2 = pBox[i].y2; boxExtents.y2 = pBox[i].y2;
for (j = i+1; j < nBox; j++) for (int j = i+1; j < nBox; j++)
{ {
if (pBox[j].x1 == 0 && pBox[j].y1 == 0 && if (pBox[j].x1 == 0 && pBox[j].y1 == 0 &&
pBox[j].x2 == 0 && pBox[j].y2 == 0) pBox[j].x2 == 0 && pBox[j].y2 == 0)
...@@ -2082,9 +1944,8 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -2082,9 +1944,8 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
boxExtents.y2 >= pBox[j].y2)) boxExtents.y2 >= pBox[j].y2))
{ {
/* /*
* If a box is completely inside * If a box is completely inside another, we set its
* another, we set its coordinates * coordinates to 0 to consider it as merged.
* to 0 to consider it as merged.
*/ */
#ifdef DEBUG #ifdef DEBUG
...@@ -2115,19 +1976,14 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion) ...@@ -2115,19 +1976,14 @@ BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion)
unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
{ {
XImage *ximage;
Visual *pVisual;
char *data;
int depth, format, length;
int leftPad = 0; int leftPad = 0;
unsigned long pixel;
depth = pDrawable -> depth; int depth = pDrawable -> depth;
format = (depth == 1) ? XYPixmap : ZPixmap; int format = (depth == 1) ? XYPixmap : ZPixmap;
length = nxagentImageLength(1, 1, format, leftPad, depth); int length = nxagentImageLength(1, 1, format, leftPad, depth);
if ((data = malloc(length)) == NULL) char * data = malloc(length);
if (data == NULL)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentGetColor: WARNING! Failed to allocate memory for the operation.\n"); fprintf(stderr, "nxagentGetColor: WARNING! Failed to allocate memory for the operation.\n");
...@@ -2136,7 +1992,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) ...@@ -2136,7 +1992,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
return -1; return -1;
} }
pVisual = nxagentImageVisual(pDrawable, depth); Visual *pVisual = nxagentImageVisual(pDrawable, depth);
if (pVisual == NULL) if (pVisual == NULL)
{ {
...@@ -2149,7 +2005,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) ...@@ -2149,7 +2005,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
fbGetImage(pDrawable, xPixel, yPixel, 1, 1, format, AllPlanes, data); fbGetImage(pDrawable, xPixel, yPixel, 1, 1, format, AllPlanes, data);
ximage = XCreateImage(nxagentDisplay, pVisual, depth, format, leftPad, (char *) data, XImage *ximage = XCreateImage(nxagentDisplay, pVisual, depth, format, leftPad, (char *) data,
1, 1, BitmapPad(nxagentDisplay), 1, 1, BitmapPad(nxagentDisplay),
nxagentImagePad(1, format, leftPad, 1)); nxagentImagePad(1, format, leftPad, 1));
...@@ -2164,7 +2020,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) ...@@ -2164,7 +2020,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
return -1; return -1;
} }
pixel = XGetPixel(ximage, 0, 0); unsigned long pixel = XGetPixel(ximage, 0, 0);
XDestroyImage(ximage); XDestroyImage(ximage);
...@@ -2172,34 +2028,30 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) ...@@ -2172,34 +2028,30 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
} }
/* /*
* This function could be used to determine * This function could be used to determine the ClearArea color of
* the ClearArea color of corrupted regions * corrupted regions on screen.
* on screen.
*/ */
unsigned long nxagentGetRegionColor(DrawablePtr pDrawable, RegionPtr pRegion) unsigned long nxagentGetRegionColor(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
int xPicker, yPicker;
if (RegionNil(pRegion) == 1) if (RegionNil(pRegion) == 1)
{ {
return nxagentGetDrawableColor(pDrawable); return nxagentGetDrawableColor(pDrawable);
} }
/* /*
* The pixel used as reference is the first * The pixel used as reference is the first outer pixel at the
* outer pixel at the bottom right corner * bottom right corner of corrupted region extents.
* of corrupted region extents.
*/ */
xPicker = pRegion -> extents.x2 + 1; int xPicker = pRegion -> extents.x2 + 1;
if (xPicker > pDrawable -> width) if (xPicker > pDrawable -> width)
{ {
xPicker = pDrawable -> width; xPicker = pDrawable -> width;
} }
yPicker = pRegion -> extents.y2 + 1; int yPicker = pRegion -> extents.y2 + 1;
if (yPicker > pDrawable -> height) if (yPicker > pDrawable -> height)
{ {
...@@ -2211,30 +2063,17 @@ unsigned long nxagentGetRegionColor(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2211,30 +2063,17 @@ unsigned long nxagentGetRegionColor(DrawablePtr pDrawable, RegionPtr pRegion)
unsigned long nxagentGetDrawableColor(DrawablePtr pDrawable) unsigned long nxagentGetDrawableColor(DrawablePtr pDrawable)
{ {
int xPicker, yPicker;
/* /*
* The pixel used to determine the co- * The pixel used to determine the color of a drawable is at
* lor of a drawable is at coordinates * coordinates (x + width - 4, y + 4).
* (x + width - 4, y + 4).
*/ */
xPicker = pDrawable -> width - 4; return nxagentGetColor(pDrawable, pDrawable -> width - 4, 4);
yPicker = 4;
return nxagentGetColor(pDrawable, xPicker, yPicker);
} }
void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
WindowPtr pWin;
BoxPtr pBox;
unsigned long color;
unsigned long backupPixel = 0; unsigned long backupPixel = 0;
int nBox, i;
int restore;
#ifdef DEBUG #ifdef DEBUG
static int nBoxCleared; static int nBoxCleared;
...@@ -2258,13 +2097,13 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2258,13 +2097,13 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion)
return; return;
} }
pWin = (WindowPtr) pDrawable; WindowPtr pWin = (WindowPtr) pDrawable;
restore = 0; int restore = 0;
/* /*
* If the window has already a background, we * If the window has already a background, we can hope it will be
* can hope it will be nice. * nice.
*/ */
if (pWin -> backgroundState != None) if (pWin -> backgroundState != None)
...@@ -2282,7 +2121,7 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2282,7 +2121,7 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion)
backupPixel = pWin -> background.pixel; backupPixel = pWin -> background.pixel;
color = nxagentGetDrawableColor((DrawablePtr) pWin); unsigned long color = nxagentGetDrawableColor((DrawablePtr) pWin);
if (color == -1) if (color == -1)
{ {
...@@ -2302,11 +2141,11 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2302,11 +2141,11 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion)
restore = 1; restore = 1;
} }
pBox = nxagentGetOptimizedRegionBoxes(pRegion); BoxPtr pBox = nxagentGetOptimizedRegionBoxes(pRegion);
nBox = RegionNumRects(pRegion); int nBox = RegionNumRects(pRegion);
for (i = 0; i < nBox; i++) for (int i = 0; i < nBox; i++)
{ {
if (pBox[i].x1 == 0 && pBox[i].y1 == 0 && if (pBox[i].x1 == 0 && pBox[i].y1 == 0 &&
pBox[i].x2 == 0 && pBox[i].y2 == 0) pBox[i].x2 == 0 && pBox[i].y2 == 0)
...@@ -2339,21 +2178,14 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2339,21 +2178,14 @@ void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion)
void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
GCPtr pGC;
BoxPtr pBox;
XRectangle *pRects;
int nrects;
int i;
if (RegionNil(pRegion) == 1) if (RegionNil(pRegion) == 1)
{ {
return; return;
} }
pGC = nxagentGetGraphicContext(pDrawable); GCPtr pGC = nxagentGetGraphicContext(pDrawable);
nrects = RegionNumRects(pRegion); int nrects = RegionNumRects(pRegion);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentFillRemoteRegion: Going to fill remote region [%d,%d,%d,%d] rects [%d] with color [%lu].\n", fprintf(stderr, "nxagentFillRemoteRegion: Going to fill remote region [%d,%d,%d,%d] rects [%d] with color [%lu].\n",
...@@ -2370,11 +2202,10 @@ void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2370,11 +2202,10 @@ void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion)
} }
else else
{ {
pBox = RegionRects(pRegion); BoxPtr pBox = RegionRects(pRegion);
XRectangle *pRects = malloc(nrects * sizeof(XRectangle));
pRects = malloc(nrects * sizeof(XRectangle));
for (i = 0; i < nrects; i++) for (int i = 0; i < nrects; i++)
{ {
pRects[i].x = pBox[i].x1; pRects[i].x = pBox[i].x1;
pRects[i].y = pBox[i].y1; pRects[i].y = pBox[i].y1;
...@@ -2428,20 +2259,14 @@ int nxagentDestroyCorruptedBackgroundResource(void * p, XID id) ...@@ -2428,20 +2259,14 @@ int nxagentDestroyCorruptedBackgroundResource(void * p, XID id)
void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode, void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode,
int nPoints, xPoint *pPoints) int nPoints, xPoint *pPoints)
{ {
RegionPtr pRegion; RegionPtr pRegion = RegionCreate(NullBox, 1);
RegionRec tmpRegion;
BoxRec box, extents;
xPoint *xp;
int np;
np = nPoints;
xp = pPoints;
pRegion = RegionCreate(NullBox, 1);
int np = nPoints;
while (np--) while (np--)
{ {
BoxRec box;
xPoint *xp = pPoints;
if (CoordModePrevious) if (CoordModePrevious)
{ {
box.x1 = box.x2 = (xp-1) -> x + xp -> x; box.x1 = box.x2 = (xp-1) -> x + xp -> x;
...@@ -2463,6 +2288,7 @@ void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode, ...@@ -2463,6 +2288,7 @@ void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode,
* this loop could become less expensive. * this loop could become less expensive.
*/ */
RegionRec tmpRegion;
RegionInit(&tmpRegion, &box, 1); RegionInit(&tmpRegion, &box, 1);
RegionUnion(pRegion, pRegion, &tmpRegion); RegionUnion(pRegion, pRegion, &tmpRegion);
...@@ -2472,7 +2298,7 @@ void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode, ...@@ -2472,7 +2298,7 @@ void nxagentPointsToDirtyRegion(DrawablePtr pDrawable, int mode,
xp++; xp++;
} }
extents = *RegionExtents(pRegion); BoxRec extents = *RegionExtents(pRegion);
RegionReset(pRegion, &extents); RegionReset(pRegion, &extents);
...@@ -2604,35 +2430,27 @@ void nxagentRegionsOnScreen(void) ...@@ -2604,35 +2430,27 @@ void nxagentRegionsOnScreen(void)
#endif #endif
/* /*
* If the synchronization loop breaks and the * If the synchronization loop breaks and the drawable synchronization
* drawable synchronization cannot be completed, * cannot be completed, the remaining data is stored in a bitmap. The
* the remaining data is stored in a bitmap. * synchronization loop is then restarted using the bitmap as source
* The synchronization loop is then restarted * instead of the drawable.
* using the bitmap as source instead of the
* drawable.
*/ */
void nxagentCreateDrawableBitmap(DrawablePtr pDrawable) void nxagentCreateDrawableBitmap(DrawablePtr pDrawable)
{ {
PixmapPtr pBitmap;
GCPtr pGC = NULL; GCPtr pGC = NULL;
RegionPtr pClipRegion = NullRegion; RegionPtr pClipRegion = NullRegion;
int x, y;
int w, h;
int saveTrap;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCreateDrawableBitmap: Creating synchronization bitmap for [%s] at [%p].\n", fprintf(stderr, "nxagentCreateDrawableBitmap: Creating synchronization bitmap for [%s] at [%p].\n",
nxagentDrawableType(pDrawable), (void *) pDrawable); nxagentDrawableType(pDrawable), (void *) pDrawable);
#endif #endif
/* /*
* The bitmap is created only in the * The bitmap is created only in the nxagent.
* nxagent.
*/ */
saveTrap = nxagentGCTrap; int saveTrap = nxagentGCTrap;
nxagentGCTrap = 1; nxagentGCTrap = 1;
...@@ -2646,9 +2464,8 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable) ...@@ -2646,9 +2464,8 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable)
} }
/* /*
* Should create a function to append * Should create a function to append a bitmap to another, instead
* a bitmap to another, instead of * of destroying the old one.
* destroying the old one.
*/ */
if (nxagentDrawableBitmap(pDrawable) != NullPixmap) if (nxagentDrawableBitmap(pDrawable) != NullPixmap)
...@@ -2683,15 +2500,14 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable) ...@@ -2683,15 +2500,14 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable)
} }
/* /*
* FIXME: A better way it would be create the bitmap * FIXME: A better way it would be create the bitmap with the same
* with the same extents of the clipRegion. This * extents of the clipRegion. This requires to save the offset with
* requires to save the offset with respect to the * respect to the drawable origin like in the backing store. This
* drawable origin like in the backing store. This * becomes particularly important when the drawable is a huge
* becomes particularly important when the drawable * window, because the pixmap creation would fail.
* is a huge window, because the pixmap creation
* would fail.
*/ */
PixmapPtr pBitmap;
pBitmap = nxagentCreatePixmap(pDrawable -> pScreen, pDrawable -> width, pDrawable -> height, pDrawable -> depth, 0); pBitmap = nxagentCreatePixmap(pDrawable -> pScreen, pDrawable -> width, pDrawable -> height, pDrawable -> depth, 0);
if (pBitmap == NULL) if (pBitmap == NULL)
...@@ -2707,10 +2523,10 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable) ...@@ -2707,10 +2523,10 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable)
ValidateGC((DrawablePtr) pBitmap, pGC); ValidateGC((DrawablePtr) pBitmap, pGC);
x = pClipRegion -> extents.x1; int x = pClipRegion -> extents.x1;
y = pClipRegion -> extents.y1; int y = pClipRegion -> extents.y1;
w = pClipRegion -> extents.x2 - pClipRegion -> extents.x1; int w = pClipRegion -> extents.x2 - pClipRegion -> extents.x1;
h = pClipRegion -> extents.y2 - pClipRegion -> extents.y1; int h = pClipRegion -> extents.y2 - pClipRegion -> extents.y1;
nxagentCopyArea(pDrawable, (DrawablePtr) pBitmap, pGC, x, y, w, h, x, y); nxagentCopyArea(pDrawable, (DrawablePtr) pBitmap, pGC, x, y, w, h, x, y);
...@@ -2850,9 +2666,8 @@ void nxagentAllocateCorruptedResource(DrawablePtr pDrawable, RESTYPE type) ...@@ -2850,9 +2666,8 @@ void nxagentAllocateCorruptedResource(DrawablePtr pDrawable, RESTYPE type)
if (nxagentPixmapPriv(pRealPixmap) -> corruptedBackgroundId == 0) if (nxagentPixmapPriv(pRealPixmap) -> corruptedBackgroundId == 0)
{ {
/* /*
* When a pixmap is added to the background * When a pixmap is added to the background corrupted resources,
* corrupted resources, it must be removed * it must be removed from the pixmap corrupted resources.
* from the pixmap corrupted resources.
*/ */
nxagentDestroyCorruptedResource(pDrawable, RT_NX_CORR_PIXMAP); nxagentDestroyCorruptedResource(pDrawable, RT_NX_CORR_PIXMAP);
...@@ -2873,8 +2688,8 @@ void nxagentAllocateCorruptedResource(DrawablePtr pDrawable, RESTYPE type) ...@@ -2873,8 +2688,8 @@ void nxagentAllocateCorruptedResource(DrawablePtr pDrawable, RESTYPE type)
else if (type == RT_NX_CORR_PIXMAP) else if (type == RT_NX_CORR_PIXMAP)
{ {
/* /*
* The shared memory pixmaps are always dirty * The shared memory pixmaps are always dirty and shouldn't be
* and shouldn't be synchronized. * synchronized.
*/ */
if (nxagentPixmapUsageCounter((PixmapPtr) pDrawable) >= MINIMUM_PIXMAP_USAGE_COUNTER && if (nxagentPixmapUsageCounter((PixmapPtr) pDrawable) >= MINIMUM_PIXMAP_USAGE_COUNTER &&
...@@ -3044,11 +2859,9 @@ int nxagentSynchronizationPredicate(void) ...@@ -3044,11 +2859,9 @@ int nxagentSynchronizationPredicate(void)
} }
/* /*
* If there are resources to synchronize * If there are resources to synchronize but the conditions to start
* but the conditions to start the loop * the loop are not satisfied, a little delay is requested to check
* are not satisfied, a little delay is * for a new loop as soon as possible.
* requested to check for a new loop as
* soon as possible.
*/ */
return Delayed; return Delayed;
...@@ -3150,7 +2963,6 @@ nxagentSendBackgroundExposeEnd: ...@@ -3150,7 +2963,6 @@ nxagentSendBackgroundExposeEnd:
void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2) void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2)
{ {
WindowPtr pWin = (WindowPtr) p0; WindowPtr pWin = (WindowPtr) p0;
WindowPtr pParent;
struct nxagentExposeBackground *pPair = p2; struct nxagentExposeBackground *pPair = p2;
...@@ -3176,7 +2988,7 @@ void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2) ...@@ -3176,7 +2988,7 @@ void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2)
(void *) pWin); (void *) pWin);
#endif #endif
pParent = pWin -> parent; WindowPtr pParent = pWin -> parent;
while (pParent != NULL) while (pParent != NULL)
{ {
...@@ -3204,21 +3016,14 @@ void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2) ...@@ -3204,21 +3016,14 @@ void nxagentExposeBackgroundPredicate(void *p0, XID x1, void *p2)
int nxagentClipAndSendClearExpose(WindowPtr pWin, void * ptr) int nxagentClipAndSendClearExpose(WindowPtr pWin, void * ptr)
{ {
RegionPtr exposeRgn; RegionPtr remoteExposeRgn = (RegionRec *) ptr;
RegionPtr remoteExposeRgn;
#ifdef DEBUG
BoxRec box;
#endif
remoteExposeRgn = (RegionRec *) ptr;
if (nxagentWindowPriv(pWin) -> deferredBackgroundExpose == 1) if (nxagentWindowPriv(pWin) -> deferredBackgroundExpose == 1)
{ {
exposeRgn = RegionCreate(NULL, 1); RegionPtr exposeRgn = RegionCreate(NULL, 1);
#ifdef DEBUG #ifdef DEBUG
box = *RegionExtents(remoteExposeRgn); BoxRec box = *RegionExtents(remoteExposeRgn);
fprintf(stderr, "nxagentClipAndSendClearExpose: Background expose extents: [%d,%d,%d,%d].\n", fprintf(stderr, "nxagentClipAndSendClearExpose: Background expose extents: [%d,%d,%d,%d].\n",
box.x1, box.y1, box.x2, box.y2); box.x1, box.y1, box.x2, box.y2);
...@@ -3232,9 +3037,8 @@ int nxagentClipAndSendClearExpose(WindowPtr pWin, void * ptr) ...@@ -3232,9 +3037,8 @@ int nxagentClipAndSendClearExpose(WindowPtr pWin, void * ptr)
RegionIntersect(exposeRgn, remoteExposeRgn, &pWin -> clipList); RegionIntersect(exposeRgn, remoteExposeRgn, &pWin -> clipList);
/* /*
* If the region will be synchronized, * If the region will be synchronized, the expose on corrupted
* the expose on corrupted regions can * regions can be ignored.
* be ignored.
*/ */
RegionSubtract(exposeRgn, exposeRgn, nxagentCorruptedRegion((DrawablePtr) pWin)); RegionSubtract(exposeRgn, exposeRgn, nxagentCorruptedRegion((DrawablePtr) pWin));
...@@ -3295,4 +3099,3 @@ void nxagentSendDeferredBackgroundExposures(void) ...@@ -3295,4 +3099,3 @@ void nxagentSendDeferredBackgroundExposures(void)
RegionEmpty(nxagentDeferredBackgroundExposures); RegionEmpty(nxagentDeferredBackgroundExposures);
} }
} }
...@@ -325,16 +325,13 @@ void nxagentEndRedirectToClientsLog(void) ...@@ -325,16 +325,13 @@ void nxagentEndRedirectToClientsLog(void)
char *nxagentGetHomePath(void) char *nxagentGetHomePath(void)
{ {
char *homeEnv;
char *homePath;
if (*nxagentHomeDir == '\0') if (*nxagentHomeDir == '\0')
{ {
/* /*
* Check the NX_HOME environment. * Check the NX_HOME environment.
*/ */
homeEnv = getenv("NX_HOME"); char *homeEnv = getenv("NX_HOME");
if (homeEnv == NULL || *homeEnv == '\0') if (homeEnv == NULL || *homeEnv == '\0')
{ {
...@@ -369,7 +366,7 @@ char *nxagentGetHomePath(void) ...@@ -369,7 +366,7 @@ char *nxagentGetHomePath(void)
#endif #endif
} }
homePath = strdup(nxagentHomeDir); char *homePath = strdup(nxagentHomeDir);
if (homePath == NULL) if (homePath == NULL)
{ {
...@@ -385,19 +382,13 @@ char *nxagentGetHomePath(void) ...@@ -385,19 +382,13 @@ char *nxagentGetHomePath(void)
char *nxagentGetRootPath(void) char *nxagentGetRootPath(void)
{ {
char *rootEnv;
char *homeEnv;
char *rootPath;
struct stat dirStat;
if (*nxagentRootDir == '\0') if (*nxagentRootDir == '\0')
{ {
/* /*
* Check the NX_ROOT environment. * Check the NX_ROOT environment.
*/ */
rootEnv = getenv("NX_ROOT"); char *rootEnv = getenv("NX_ROOT");
if (rootEnv == NULL || *rootEnv == '\0') if (rootEnv == NULL || *rootEnv == '\0')
{ {
...@@ -406,12 +397,11 @@ char *nxagentGetRootPath(void) ...@@ -406,12 +397,11 @@ char *nxagentGetRootPath(void)
#endif #endif
/* /*
* We will determine the root NX directory * We will determine the root NX directory based on the NX_HOME
* based on the NX_HOME or HOME directory * or HOME directory settings.
* settings.
*/ */
homeEnv = nxagentGetHomePath(); char *homeEnv = nxagentGetHomePath();
if (homeEnv == NULL) if (homeEnv == NULL)
{ {
...@@ -443,6 +433,7 @@ char *nxagentGetRootPath(void) ...@@ -443,6 +433,7 @@ char *nxagentGetRootPath(void)
* Create the NX root directory. * Create the NX root directory.
*/ */
struct stat dirStat;
if ((stat(nxagentRootDir, &dirStat) == -1) && (errno == ENOENT)) if ((stat(nxagentRootDir, &dirStat) == -1) && (errno == ENOENT))
{ {
if (mkdir(nxagentRootDir, 0777) < 0 && (errno != EEXIST)) if (mkdir(nxagentRootDir, 0777) < 0 && (errno != EEXIST))
...@@ -478,7 +469,7 @@ char *nxagentGetRootPath(void) ...@@ -478,7 +469,7 @@ char *nxagentGetRootPath(void)
} }
rootPath = strdup(nxagentRootDir); char *rootPath = strdup(nxagentRootDir);
if (rootPath == NULL) if (rootPath == NULL)
{ {
...@@ -494,19 +485,12 @@ char *nxagentGetRootPath(void) ...@@ -494,19 +485,12 @@ char *nxagentGetRootPath(void)
char *nxagentGetSessionPath(void) char *nxagentGetSessionPath(void)
{ {
char *rootPath;
char *sessionPath;
struct stat dirStat;
if (*nxagentSessionDir == '\0') if (*nxagentSessionDir == '\0')
{ {
/* /*
* If nxagentSessionId does not exist we * If nxagentSessionId does not exist we assume that the
* assume that the sessionPath cannot be * sessionPath cannot be realized and do not use the clients log
* realized and do not use the clients * file.
* log file.
*/ */
if (*nxagentSessionId == '\0') if (*nxagentSessionId == '\0')
...@@ -518,7 +502,7 @@ char *nxagentGetSessionPath(void) ...@@ -518,7 +502,7 @@ char *nxagentGetSessionPath(void)
return NULL; return NULL;
} }
rootPath = nxagentGetRootPath(); char *rootPath = nxagentGetRootPath();
if (rootPath == NULL) if (rootPath == NULL)
{ {
...@@ -544,6 +528,7 @@ char *nxagentGetSessionPath(void) ...@@ -544,6 +528,7 @@ char *nxagentGetSessionPath(void)
SAFE_free(rootPath); SAFE_free(rootPath);
struct stat dirStat;
if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT)) if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{ {
if (mkdir(nxagentSessionDir, 0777) < 0 && (errno != EEXIST)) if (mkdir(nxagentSessionDir, 0777) < 0 && (errno != EEXIST))
...@@ -564,7 +549,7 @@ char *nxagentGetSessionPath(void) ...@@ -564,7 +549,7 @@ char *nxagentGetSessionPath(void)
} }
sessionPath = strdup(nxagentSessionDir); char *sessionPath = strdup(nxagentSessionDir);
if (sessionPath == NULL) if (sessionPath == NULL)
{ {
...@@ -580,7 +565,6 @@ char *nxagentGetSessionPath(void) ...@@ -580,7 +565,6 @@ char *nxagentGetSessionPath(void)
void nxagentGetClientsPath(void) void nxagentGetClientsPath(void)
{ {
if (*nxagentClientsLogName == '\0') if (*nxagentClientsLogName == '\0')
{ {
char *sessionPath = nxagentGetSessionPath(); char *sessionPath = nxagentGetSessionPath();
......
...@@ -105,9 +105,8 @@ ...@@ -105,9 +105,8 @@
#include "compext/Compext.h" #include "compext/Compext.h"
/* /*
* Set here the required log level. Please note * Set here the required log level. Please note that if you want to
* that if you want to enable DEBUG here, then * enable DEBUG here, then you need to enable DEBUG even in Rootless.c
* you need to enable DEBUG even in Rootless.c
*/ */
#define PANIC #define PANIC
...@@ -163,8 +162,7 @@ PropertyRequestRec nxagentPropertyRequests[NXNumberOfResources]; ...@@ -163,8 +162,7 @@ PropertyRequestRec nxagentPropertyRequests[NXNumberOfResources];
void nxagentHandleCollectPropertyEvent(XEvent*); void nxagentHandleCollectPropertyEvent(XEvent*);
/* /*
* Finalize the asynchronous handling * Finalize the asynchronous handling of the X_GrabPointer requests.
* of the X_GrabPointer requests.
*/ */
void nxagentHandleCollectGrabPointerEvent(int resource); void nxagentHandleCollectGrabPointerEvent(int resource);
...@@ -172,8 +170,8 @@ void nxagentHandleCollectGrabPointerEvent(int resource); ...@@ -172,8 +170,8 @@ void nxagentHandleCollectGrabPointerEvent(int resource);
Bool nxagentCollectGrabPointerPredicate(Display *display, XEvent *X, XPointer ptr); Bool nxagentCollectGrabPointerPredicate(Display *display, XEvent *X, XPointer ptr);
/* /*
* Used in Handlers.c to synchronize * Used in Handlers.c to synchronize the agent with the remote X
* the agent with the remote X server. * server.
*/ */
void nxagentHandleCollectInputFocusEvent(int resource); void nxagentHandleCollectInputFocusEvent(int resource);
...@@ -193,12 +191,12 @@ static Cursor viewportCursor; ...@@ -193,12 +191,12 @@ static Cursor viewportCursor;
#define nextinc(x) ((x) < MAX_INC ? (x) += INC_STEP : (x)) #define nextinc(x) ((x) < MAX_INC ? (x) += INC_STEP : (x))
/* /*
* Keyboard and pointer are handled as they were real devices by * Keyboard and pointer are handled as they were real devices by Xnest
* Xnest and we inherit this behaviour. The following mask will * and we inherit this behaviour. The following mask will contain the
* contain the event mask selected for the root window of the * event mask selected for the root window of the agent. All the
* agent. All the keyboard and pointer events will be translated * keyboard and pointer events will be translated by the agent and
* by the agent and sent to the internal clients according to * sent to the internal clients according to events selected by the
* events selected by the inferior windows. * inferior windows.
*/ */
static Mask defaultEventMask; static Mask defaultEventMask;
...@@ -206,9 +204,8 @@ static Mask defaultEventMask; ...@@ -206,9 +204,8 @@ static Mask defaultEventMask;
static int lastEventSerial = 0; static int lastEventSerial = 0;
/* /*
* Used to mask the appropriate bits in * Used to mask the appropriate bits in the state reported by
* the state reported by XkbStateNotify * XkbStateNotify and XkbGetIndicatorState.
* and XkbGetIndicatorState.
*/ */
#define CAPSFLAG_IN_REPLY 1 #define CAPSFLAG_IN_REPLY 1
...@@ -221,8 +218,8 @@ CARD32 nxagentLastKeyPressTime = 0; ...@@ -221,8 +218,8 @@ CARD32 nxagentLastKeyPressTime = 0;
Time nxagentLastServerTime = 0; Time nxagentLastServerTime = 0;
/* /*
* Used for storing windows that need to * Used for storing windows that need to receive expose events from
* receive expose events from the agent. * the agent.
*/ */
#define nxagentExposeQueueHead nxagentExposeQueue.exposures[nxagentExposeQueue.start] #define nxagentExposeQueueHead nxagentExposeQueue.exposures[nxagentExposeQueue.start]
...@@ -246,16 +243,14 @@ int GetWindowProperty(WindowPtr pWin, Atom property, long longOffset, ...@@ -246,16 +243,14 @@ int GetWindowProperty(WindowPtr pWin, Atom property, long longOffset,
unsigned char **propData); unsigned char **propData);
/* /*
* Associate a resource to a drawable and * Associate a resource to a drawable and store the region affected by
* store the region affected by the split * the split operation.
* operation.
*/ */
SplitResourceRec nxagentSplitResources[NXNumberOfResources]; SplitResourceRec nxagentSplitResources[NXNumberOfResources];
/* /*
* Associate a resource to an unpack * Associate a resource to an unpack operation.
* operation.
*/ */
UnpackResourceRec nxagentUnpackResources[NXNumberOfResources]; UnpackResourceRec nxagentUnpackResources[NXNumberOfResources];
...@@ -269,8 +264,7 @@ Bool nxagentLastWindowDestroyed = False; ...@@ -269,8 +264,7 @@ Bool nxagentLastWindowDestroyed = False;
Time nxagentLastWindowDestroyedTime = 0; Time nxagentLastWindowDestroyedTime = 0;
/* /*
* Set this flag when an user input event * Set this flag when an user input event is received.
* is received.
*/ */
int nxagentInputEvent = 0; int nxagentInputEvent = 0;
...@@ -294,7 +288,7 @@ void ProcessInputEvents(void) ...@@ -294,7 +288,7 @@ void ProcessInputEvents(void)
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "ProcessInputEvents: Processing input.\n"); fprintf(stderr, "%s: Processing input.\n", __func__);
} }
#endif #endif
...@@ -306,26 +300,10 @@ char * nxagentGetNotifyMode(int mode) ...@@ -306,26 +300,10 @@ char * nxagentGetNotifyMode(int mode)
{ {
switch (mode) switch (mode)
{ {
case NotifyNormal: case NotifyNormal: return "NotifyNormal";
{ case NotifyGrab: return "NotifyGrab";
return "NotifyNormal"; case NotifyUngrab: return "NotifyUngrab";
break; case NotifyWhileGrabbed: return "NotifyWhileGrabbed";
}
case NotifyGrab:
{
return "NotifyGrab";
break;
}
case NotifyUngrab:
{
return "NotifyUngrab";
break;
}
case NotifyWhileGrabbed:
{
return "NotifyWhileGrabbed";
break;
}
} }
return "Unknown"; return "Unknown";
} }
...@@ -474,7 +452,7 @@ void nxagentRemoteWindowsTree(Window window, int level) ...@@ -474,7 +452,7 @@ void nxagentRemoteWindowsTree(Window window, int level)
if (!XQueryTree(nxagentDisplay, window, &rootWin, &parentWin, &childList, if (!XQueryTree(nxagentDisplay, window, &rootWin, &parentWin, &childList,
&numChildren)) &numChildren))
{ {
fprintf(stderr, "nxagentRemoteWindowsTree - XQueryTree failed.\n"); fprintf(stderr, "%s - XQueryTree failed.\n", __func__);
return; return;
} }
...@@ -517,7 +495,6 @@ void nxagentRemoteWindowsTree(Window window, int level) ...@@ -517,7 +495,6 @@ void nxagentRemoteWindowsTree(Window window, int level)
void nxagentInternalWindowInfo(WindowPtr pWin, int indent, Bool newLine) void nxagentInternalWindowInfo(WindowPtr pWin, int indent, Bool newLine)
{ {
int result;
unsigned long ulReturnItems; unsigned long ulReturnItems;
unsigned long ulReturnBytesLeft; unsigned long ulReturnBytesLeft;
Atom atomReturnType; Atom atomReturnType;
...@@ -527,7 +504,7 @@ void nxagentInternalWindowInfo(WindowPtr pWin, int indent, Bool newLine) ...@@ -527,7 +504,7 @@ void nxagentInternalWindowInfo(WindowPtr pWin, int indent, Bool newLine)
fprintf(stderr, "Window ID=[0x%x] %s Remote ID=[0x%x] ", pWin -> drawable.id, fprintf(stderr, "Window ID=[0x%x] %s Remote ID=[0x%x] ", pWin -> drawable.id,
pWin->parent ? "" : "(the root window)", nxagentWindow(pWin)); pWin->parent ? "" : "(the root window)", nxagentWindow(pWin));
result = GetWindowProperty(pWin, MakeAtom("WM_NAME", 7, False) , 0, int result = GetWindowProperty(pWin, MakeAtom("WM_NAME", 7, False) , 0,
sizeof(CARD32), False, AnyPropertyType, sizeof(CARD32), False, AnyPropertyType,
&atomReturnType, &iReturnFormat, &atomReturnType, &iReturnFormat,
&ulReturnItems, &ulReturnBytesLeft, &ulReturnItems, &ulReturnBytesLeft,
...@@ -589,7 +566,7 @@ void nxagentInternalWindowsTree(WindowPtr pWin, int indent) ...@@ -589,7 +566,7 @@ void nxagentInternalWindowsTree(WindowPtr pWin, int indent)
void nxagentSwitchResizeMode(ScreenPtr pScreen) void nxagentSwitchResizeMode(ScreenPtr pScreen)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSwitchResizeMode called.\n"); fprintf(stderr, "%s: Called.\n", __func__);
#endif #endif
int desktopResize = nxagentOption(DesktopResize); int desktopResize = nxagentOption(DesktopResize);
...@@ -728,9 +705,8 @@ static void nxagentToggleAutoGrab(void) ...@@ -728,9 +705,8 @@ static void nxagentToggleAutoGrab(void)
static Bool nxagentExposurePredicate(Display *display, XEvent *event, XPointer window) static Bool nxagentExposurePredicate(Display *display, XEvent *event, XPointer window)
{ {
/* /*
* Handle both Expose and ProcessedExpose events. * Handle both Expose and ProcessedExpose events. The latters are
* The latters are those not filtered by function * those not filtered by function nxagentWindowExposures().
* nxagentWindowExposures().
*/ */
if (window) if (window)
...@@ -866,8 +842,8 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -866,8 +842,8 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
#endif #endif
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new events with " fprintf(stderr, "%s: Going to handle new events with predicate [%p].\n", __func__,
"predicate [%p].\n", *(void **)&predicate); *(void **)&predicate);
#endif #endif
if (nxagentRemoteExposeRegion == NULL) if (nxagentRemoteExposeRegion == NULL)
...@@ -876,37 +852,34 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -876,37 +852,34 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
} }
/* /*
* We must read here, even if apparently there is * We must read here, even if apparently there is nothing to
* nothing to read. The ioctl() based readable * read. The ioctl() based readable function, in fact, is often
* function, in fact, is often unable to detect a * unable to detect a failure of the socket, in particular if the
* failure of the socket, in particular if the * agent was connected to the proxy and the proxy is gone. Thus we
* agent was connected to the proxy and the proxy * must trust the wakeup handler that called us after the select().
* is gone. Thus we must trust the wakeup handler
* that called us after the select().
*/ */
#ifdef TEST #ifdef TEST
if (nxagentPendingEvents(nxagentDisplay) == 0) if (nxagentPendingEvents(nxagentDisplay) == 0)
{ {
fprintf(stderr, "nxagentDispatchEvents: PANIC! No event needs to be dispatched.\n"); fprintf(stderr, "%s: PANIC! No event needs to be dispatched.\n", __func__);
} }
#endif #endif
/* /*
* We want to process all the events already in * We want to process all the events already in the queue, plus any
* the queue, plus any additional event that may * additional event that may be read from the network. If no event
* be read from the network. If no event can be * can be read, we want to continue handling our clients without
* read, we want to continue handling our clients * flushing the output buffer.
* without flushing the output buffer.
*/ */
while (nxagentCheckEvents(nxagentDisplay, &X, predicate != NULL ? predicate : while (nxagentCheckEvents(nxagentDisplay, &X, predicate != NULL ? predicate :
nxagentAnyEventPredicate, NULL) == 1) nxagentAnyEventPredicate, NULL) == 1)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDispatchEvents: Going to handle new event type [%d].\n", fprintf(stderr, "%s: Going to handle new event type [%d].\n", __func__,
X.type); X.type);
#endif #endif
...@@ -921,7 +894,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -921,7 +894,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
case SelectionClear: case SelectionClear:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new SelectionClear event.\n"); fprintf(stderr, "%s: Going to handle new SelectionClear event.\n", __func__);
#endif #endif
nxagentClearSelection(&X); nxagentClearSelection(&X);
...@@ -931,7 +904,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -931,7 +904,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
case SelectionRequest: case SelectionRequest:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new SelectionRequest event.\n"); fprintf(stderr, "%s: Going to handle new SelectionRequest event.\n", __func__);
#endif #endif
nxagentRequestSelection(&X); nxagentRequestSelection(&X);
...@@ -941,7 +914,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -941,7 +914,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
case SelectionNotify: case SelectionNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new SelectionNotify event.\n"); fprintf(stderr, "%s: Going to handle new SelectionNotify event.\n", __func__);
#endif #endif
nxagentHandleSelectionNotifyFromXServer(&X); nxagentHandleSelectionNotifyFromXServer(&X);
...@@ -954,8 +927,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -954,8 +927,7 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
case PropertyNotify: case PropertyNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: PropertyNotify on " fprintf(stderr, "%s: PropertyNotify on prop %d[%s] window %lx state %d\n", __func__,
"prop %d[%s] window %lx state %d\n",
(int)X.xproperty.atom, validateString(XGetAtomName(nxagentDisplay, X.xproperty.atom)), (int)X.xproperty.atom, validateString(XGetAtomName(nxagentDisplay, X.xproperty.atom)),
X.xproperty.window, X.xproperty.state); X.xproperty.window, X.xproperty.state);
#endif #endif
...@@ -968,10 +940,8 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -968,10 +940,8 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
{ {
enum HandleEventResult result; enum HandleEventResult result;
KeySym keysym;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new KeyPress event.\n"); fprintf(stderr, "%s: Going to handle new KeyPress event.\n", __func__);
#endif #endif
nxagentInputEvent = 1; nxagentInputEvent = 1;
...@@ -1023,67 +993,56 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -1023,67 +993,56 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
case doMinimize: case doMinimize:
{ {
minimize = TRUE; minimize = TRUE;
break; break;
} }
case doSwitchFullscreen: case doSwitchFullscreen:
{ {
switchFullscreen = TRUE; switchFullscreen = TRUE;
break; break;
} }
case doSwitchAllScreens: case doSwitchAllScreens:
{ {
switchAllScreens = TRUE; switchAllScreens = TRUE;
break; break;
} }
case doViewportMoveUp: case doViewportMoveUp:
{ {
nxagentMoveViewport(pScreen, 0, -nxagentOption(Height)); nxagentMoveViewport(pScreen, 0, -nxagentOption(Height));
break; break;
} }
case doViewportMoveDown: case doViewportMoveDown:
{ {
nxagentMoveViewport(pScreen, 0, nxagentOption(Height)); nxagentMoveViewport(pScreen, 0, nxagentOption(Height));
break; break;
} }
case doViewportMoveLeft: case doViewportMoveLeft:
{ {
nxagentMoveViewport(pScreen, -nxagentOption(Width), 0); nxagentMoveViewport(pScreen, -nxagentOption(Width), 0);
break; break;
} }
case doViewportMoveRight: case doViewportMoveRight:
{ {
nxagentMoveViewport(pScreen, nxagentOption(Width), 0); nxagentMoveViewport(pScreen, nxagentOption(Width), 0);
break; break;
} }
case doViewportUp: case doViewportUp:
{ {
nxagentMoveViewport(pScreen, 0, -nextinc(viewportInc)); nxagentMoveViewport(pScreen, 0, -nextinc(viewportInc));
break; break;
} }
case doViewportDown: case doViewportDown:
{ {
nxagentMoveViewport(pScreen, 0, +nextinc(viewportInc)); nxagentMoveViewport(pScreen, 0, +nextinc(viewportInc));
break; break;
} }
case doViewportLeft: case doViewportLeft:
{ {
nxagentMoveViewport(pScreen, -nextinc(viewportInc), 0); nxagentMoveViewport(pScreen, -nextinc(viewportInc), 0);
break; break;
} }
case doViewportRight: case doViewportRight:
{ {
nxagentMoveViewport(pScreen, +nextinc(viewportInc), 0); nxagentMoveViewport(pScreen, +nextinc(viewportInc), 0);
break; break;
} }
case doSwitchResizeMode: case doSwitchResizeMode:
...@@ -1108,34 +1067,29 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -1108,34 +1067,29 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
{ {
nxagentSwitchDeferMode(); nxagentSwitchDeferMode();
} }
break; break;
} }
case doAutoGrab: case doAutoGrab:
{ {
nxagentToggleAutoGrab(); nxagentToggleAutoGrab();
break; break;
} }
default: default:
{ {
FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n"); FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n");
break; break;
} }
} }
/* /*
* Elide multiple KeyPress/KeyRelease events of * Elide multiple KeyPress/KeyRelease events of the same key
* the same key and generate a single pair. This * and generate a single pair. This is intended to reduce the
* is intended to reduce the impact of the laten- * impact of the latency on the key auto-repeat, handled by
* cy on the key auto-repeat, handled by the re- * the remote X server. We may optionally do that only if the
* mote X server. We may optionally do that only * timestamps in the events show an exces- sive delay.
* if the timestamps in the events show an exces-
* sive delay.
*/ */
keysym = XKeycodeToKeysym(nxagentDisplay, X.xkey.keycode, 0); KeySym keysym = XKeycodeToKeysym(nxagentDisplay, X.xkey.keycode, 0);
if (nxagentMonitoredDuplicate(keysym) == 1) if (nxagentMonitoredDuplicate(keysym) == 1)
{ {
...@@ -1157,18 +1111,17 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) ...@@ -1157,18 +1111,17 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
int sendKey = 0; int sendKey = 0;
/* /*
FIXME: If we don't flush the queue here, it could happen FIXME: If we don't flush the queue here, it could happen that the
that the inputInfo structure will not be up to date inputInfo structure will not be up to date when we perform the
when we perform the following check on down keys. following check on down keys.
*/ */
ProcessInputEvents(); ProcessInputEvents();
/* /*
FIXME: Don't enqueue the KeyRelease event if the key was FIXME: Don't enqueue the KeyRelease event if the key was not already
not already pressed. This workaround avoids a fake pressed. This workaround avoids a fake KeyPress being enqueued
KeyPress being enqueued by the XKEYBOARD extension. by the XKEYBOARD extension. Another solution would be to let
Another solution would be to let the events the events enqueued and to remove the KeyPress afterwards.
enqueued and to remove the KeyPress afterwards.
*/ */
if (BitIsOn(inputInfo.keyboard -> key -> down, if (BitIsOn(inputInfo.keyboard -> key -> down,
nxagentConvertKeycode(X.xkey.keycode))) nxagentConvertKeycode(X.xkey.keycode)))
...@@ -1177,7 +1130,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1177,7 +1130,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new KeyRelease event.\n"); fprintf(stderr, "%s: Going to handle new KeyRelease event.\n", __func__);
#endif #endif
nxagentInputEvent = 1; nxagentInputEvent = 1;
...@@ -1206,9 +1159,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1206,9 +1159,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
nxagentXkbNumTrap = 0; nxagentXkbNumTrap = 0;
} }
/* Calculate the time elapsed between this and the last event we /* Calculate the time elapsed between this and the last event
received. Add this delta to time we recorded for the last we received. Add this delta to time we recorded for the
KeyPress event we passed on to our clients. */ last KeyPress event we passed on to our clients. */
memset(&x, 0, sizeof(xEvent)); memset(&x, 0, sizeof(xEvent));
x.u.u.type = KeyRelease; x.u.u.type = KeyRelease;
x.u.u.detail = nxagentConvertKeycode(X.xkey.keycode); x.u.u.detail = nxagentConvertKeycode(X.xkey.keycode);
...@@ -1257,7 +1210,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1257,7 +1210,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Going to handle new ButtonPress event.\n"); fprintf(stderr, "%s: Going to handle new ButtonPress event.\n", __func__);
} }
#endif #endif
...@@ -1322,7 +1275,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1322,7 +1275,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Adding ButtonPress event.\n"); fprintf(stderr, "%s: Adding ButtonPress event.\n", __func__);
} }
#endif #endif
...@@ -1356,7 +1309,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1356,7 +1309,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Going to handle new ButtonRelease event.\n"); fprintf(stderr, "%s: Going to handle new ButtonRelease event.\n", __func__);
} }
#endif #endif
...@@ -1396,7 +1349,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1396,7 +1349,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Adding ButtonRelease event.\n"); fprintf(stderr, "%s: Adding ButtonRelease event.\n", __func__);
} }
#endif #endif
...@@ -1430,16 +1383,16 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1430,16 +1383,16 @@ FIXME: Don't enqueue the KeyRelease event if the key was
ScreenPtr pScreen = nxagentScreen(X.xmotion.window); ScreenPtr pScreen = nxagentScreen(X.xmotion.window);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new MotionNotify event.\n"); fprintf(stderr, "%s: Going to handle new MotionNotify event.\n", __func__);
#endif #endif
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Handling motion notify window [%ld] root [%ld] child [%ld].\n", fprintf(stderr, "%s: Handling motion notify window [%ld] root [%ld] child [%ld].\n",
X.xmotion.window, X.xmotion.root, X.xmotion.subwindow); __func__, X.xmotion.window, X.xmotion.root, X.xmotion.subwindow);
fprintf(stderr, "nxagentDispatchEvents: Pointer at [%d][%d] relative root [%d][%d].\n", fprintf(stderr, "%s: Pointer at [%d][%d] relative root [%d][%d].\n", __func__,
X.xmotion.x, X.xmotion.y, X.xmotion.x_root, X.xmotion.y_root); X.xmotion.x, X.xmotion.y, X.xmotion.x_root, X.xmotion.y_root);
} }
#endif #endif
...@@ -1491,7 +1444,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1491,7 +1444,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef NX_DEBUG_INPUT #ifdef NX_DEBUG_INPUT
if (nxagentDebugInput == 1) if (nxagentDebugInput == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Adding motion event [%d, %d] to the queue.\n", fprintf(stderr, "%s: Adding motion event [%d, %d] to the queue.\n", __func__,
x.u.keyButtonPointer.rootX, x.u.keyButtonPointer.rootY); x.u.keyButtonPointer.rootX, x.u.keyButtonPointer.rootY);
} }
#endif #endif
...@@ -1550,12 +1503,12 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1550,12 +1503,12 @@ FIXME: Don't enqueue the KeyRelease event if the key was
WindowPtr pWin; WindowPtr pWin;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Going to handle new FocusIn event [0x%x] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode)); fprintf(stderr, "%s: Going to handle new FocusIn event [0x%lx] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode));
{ {
XlibWindow w; XlibWindow w;
int revert_to; int revert_to;
XGetInputFocus(nxagentDisplay, &w, &revert_to); XGetInputFocus(nxagentDisplay, &w, &revert_to);
fprintf(stderr, "%s: (FocusIn): Event win [0x%x] Focus owner [0x%x] nxagentDefaultWindows[0] [0x%x]\n", __func__, X.xfocus.window, w, nxagentDefaultWindows[0]); fprintf(stderr, "%s: (FocusIn): Event win [0x%lx] Focus owner [0x%lx] nxagentDefaultWindows[0] [0x%x]\n", __func__, X.xfocus.window, w, nxagentDefaultWindows[0]);
} }
#else #else
#ifdef TEST #ifdef TEST
...@@ -1564,9 +1517,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1564,9 +1517,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#endif #endif
/* /*
* Here we change the focus state in the agent. * Here we change the focus state in the agent. It looks like
* It looks like this is needed only for root- * this is needed only for rootless mode at present.
* less mode at the present moment.
*/ */
if (nxagentOption(Rootless) && if (nxagentOption(Rootless) &&
...@@ -1609,7 +1561,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1609,7 +1561,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case FocusOut: case FocusOut:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Going to handle new FocusOut event [0x%x] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode)); fprintf(stderr, "%s: Going to handle new FocusOut event [0x%lx] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode));
#else #else
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: Going to handle new FocusOut event.\n", __func__); fprintf(stderr, "%s: Going to handle new FocusOut event.\n", __func__);
...@@ -1657,9 +1609,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1657,9 +1609,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
if (nxagentOption(ViewOnly) == 0 && nxagentOption(Shadow)) if (nxagentOption(ViewOnly) == 0 && nxagentOption(Shadow))
{ {
XEvent xM; XEvent xM = {0};
memset(&xM, 0, sizeof(XEvent));
xM.type = KeyRelease; xM.type = KeyRelease;
xM.xkey.display = nxagentDisplay; xM.xkey.display = nxagentDisplay;
xM.xkey.type = KeyRelease; xM.xkey.type = KeyRelease;
...@@ -1699,7 +1649,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1699,7 +1649,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case KeymapNotify: case KeymapNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new KeymapNotify event.\n"); fprintf(stderr, "%s: Going to handle new KeymapNotify event.\n", __func__);
#endif #endif
break; break;
...@@ -1708,14 +1658,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1708,14 +1658,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was
{ {
WindowPtr pWin; WindowPtr pWin;
WindowPtr pTLWin = NULL;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new EnterNotify event.\n"); fprintf(stderr, "%s: Going to handle new EnterNotify event.\n", __func__);
#endif #endif
if (nxagentOption(Rootless)) if (nxagentOption(Rootless))
{ {
WindowPtr pTLWin = NULL;
pWin = nxagentWindowPtr(X.xcrossing.window); pWin = nxagentWindowPtr(X.xcrossing.window);
if (pWin != NULL) if (pWin != NULL)
...@@ -1731,7 +1681,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1731,7 +1681,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: nxagentLastEnteredTopLevelWindow [%p].\n", fprintf(stderr, "%s: nxagentLastEnteredTopLevelWindow [%p].\n", __func__,
(void *)nxagentLastEnteredTopLevelWindow); (void *)nxagentLastEnteredTopLevelWindow);
#endif #endif
} }
...@@ -1743,21 +1693,18 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1743,21 +1693,18 @@ FIXME: Don't enqueue the KeyRelease event if the key was
pWin -> drawable.y != X.xcrossing.y_root - X.xcrossing.y - pWin -> borderWidth)) pWin -> drawable.y != X.xcrossing.y_root - X.xcrossing.y - pWin -> borderWidth))
{ {
/* /*
* This code is useful for finding the window * This code is useful for finding the window position. It
* position. It should be re-implemented by * should be re-implemented by following the ICCCM 4.1.5
* following the ICCCM 4.1.5 recommendations. * recommendations.
*/ */
XID values[4];
register XID *value = values;
Mask mask = 0;
ClientPtr pClient = wClient(pWin);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: pWin -> drawable.x [%d] pWin -> drawable.y [%d].\n", fprintf(stderr, "%s: pWin -> drawable.x [%d] pWin -> drawable.y [%d].\n", __func__,
pWin -> drawable.x, pWin -> drawable.y); pWin -> drawable.x, pWin -> drawable.y);
#endif #endif
XID values[4];
register XID *value = values;
*value++ = (XID) (X.xcrossing.x_root - X.xcrossing.x - pWin -> borderWidth); *value++ = (XID) (X.xcrossing.x_root - X.xcrossing.x - pWin -> borderWidth);
*value++ = (XID) (X.xcrossing.y_root - X.xcrossing.y - pWin -> borderWidth); *value++ = (XID) (X.xcrossing.y_root - X.xcrossing.y - pWin -> borderWidth);
...@@ -1766,11 +1713,11 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1766,11 +1713,11 @@ FIXME: Don't enqueue the KeyRelease event if the key was
* nxagentWindowPriv(pWin)->y = (X.xcrossing.y_root - X.xcrossing.y); * nxagentWindowPriv(pWin)->y = (X.xcrossing.y_root - X.xcrossing.y);
*/ */
mask = CWX | CWY; Mask mask = CWX | CWY;
nxagentScreenTrap = 1; nxagentScreenTrap = 1;
ConfigureWindow(pWin, mask, (XID *) values, pClient); ConfigureWindow(pWin, mask, (XID *) values, wClient(pWin));
nxagentScreenTrap = 0; nxagentScreenTrap = 0;
} }
...@@ -1820,7 +1767,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1820,7 +1767,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case LeaveNotify: case LeaveNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new LeaveNotify event.\n"); fprintf(stderr, "%s: Going to handle new LeaveNotify event.\n", __func__);
#endif #endif
if (nxagentOption(Rootless) && X.xcrossing.mode == NotifyNormal && if (nxagentOption(Rootless) && X.xcrossing.mode == NotifyNormal &&
...@@ -1856,7 +1803,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1856,7 +1803,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case DestroyNotify: case DestroyNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new DestroyNotify event.\n"); fprintf(stderr, "%s: Going to handle new DestroyNotify event.\n", __func__);
#endif #endif
if (nxagentParentWindow != (Window) 0 && if (nxagentParentWindow != (Window) 0 &&
...@@ -1872,7 +1819,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1872,7 +1819,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
enum HandleEventResult result; enum HandleEventResult result;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new ClientMessage event.\n"); fprintf(stderr, "%s: Going to handle new ClientMessage event.\n", __func__);
#endif #endif
nxagentHandleClientMessageEvent(&X, &result); nxagentHandleClientMessageEvent(&X, &result);
...@@ -1887,7 +1834,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1887,7 +1834,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case VisibilityNotify: case VisibilityNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new VisibilityNotify event.\n"); fprintf(stderr, "%s: Going to handle new VisibilityNotify event.\n", __func__);
#endif #endif
if (X.xvisibility.window != nxagentDefaultWindows[0]) if (X.xvisibility.window != nxagentDefaultWindows[0])
...@@ -1914,7 +1861,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1914,7 +1861,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Suppressing visibility notify on window [%lx].\n", fprintf(stderr, "%s: Suppressing visibility notify on window [%lx].\n", __func__,
X.xvisibility.window); X.xvisibility.window);
#endif #endif
...@@ -1922,7 +1869,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1922,7 +1869,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Visibility notify state is [%d] with previous [%d].\n", fprintf(stderr, "%s: Visibility notify state is [%d] with previous [%d].\n", __func__,
X.xvisibility.state, nxagentVisibility); X.xvisibility.state, nxagentVisibility);
#endif #endif
...@@ -1933,10 +1880,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1933,10 +1880,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case Expose: case Expose:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDispatchEvents: Going to handle new Expose event.\n"); fprintf(stderr, "%s: Going to handle new Expose event.\n", __func__);
fprintf(stderr, "nxagentDispatchEvents: WARNING! Received Expose event " fprintf(stderr, "%s: WARNING! Received Expose event for drawable [%lx]"
"for drawable [%lx] geometry [%d, %d, %d, %d] count [%d].\n", " geometry [%d, %d, %d, %d] count [%d].\n", __func__,
X.xexpose.window, X.xexpose.x, X.xexpose.y, X.xexpose.width, X.xexpose.window, X.xexpose.x, X.xexpose.y, X.xexpose.width,
X.xexpose.height, X.xexpose.count); X.xexpose.height, X.xexpose.count);
#endif #endif
...@@ -1948,10 +1895,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1948,10 +1895,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case GraphicsExpose: case GraphicsExpose:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDispatchEvents: Going to handle new GraphicsExpose event.\n"); fprintf(stderr, "%s: Going to handle new GraphicsExpose event.\n", __func__);
fprintf(stderr, "nxagentDispatchEvents: WARNING! Received GraphicsExpose event " fprintf(stderr, "%s: WARNING! Received GraphicsExpose event "
"for drawable [%lx] geometry [%d, %d, %d, %d] count [%d].\n", "for drawable [%lx] geometry [%d, %d, %d, %d] count [%d].\n", __func__,
X.xgraphicsexpose.drawable, X.xgraphicsexpose.x, X.xgraphicsexpose.y, X.xgraphicsexpose.drawable, X.xgraphicsexpose.x, X.xgraphicsexpose.y,
X.xgraphicsexpose.width, X.xgraphicsexpose.height, X.xgraphicsexpose.width, X.xgraphicsexpose.height,
X.xgraphicsexpose.count); X.xgraphicsexpose.count);
...@@ -1964,34 +1911,22 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -1964,34 +1911,22 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case NoExpose: case NoExpose:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDispatchEvents: Going to handle new NoExpose event.\n"); fprintf(stderr, "%s: Going to handle new NoExpose event.\n", __func__);
fprintf(stderr, "%s: WARNING! Received NoExpose event for drawable [%lx].\n", __func__, X.xnoexpose.drawable);
fprintf(stderr, "nxagentDispatchEvents: WARNING! Received NoExpose event for "
"drawable [%lx].\n", X.xnoexpose.drawable);
#endif #endif
break; break;
} }
case CirculateNotify: case CirculateNotify:
{ {
/*
* WindowPtr pWin;
* WindowPtr pSib;
* ClientPtr pClient;
* XID values[2];
* register XID *value = values;
* Mask mask = 0;
*/
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentDispatchEvents: Going to handle new CirculateNotify event.\n"); fprintf(stderr, "%s: Going to handle new CirculateNotify event.\n", __func__);
#endif #endif
/* /*
* FIXME: Do we need this? * FIXME: Do we need this?
* *
* pWin = nxagentWindowPtr(X.xcirculate.window); * WindowPtr pWin = nxagentWindowPtr(X.xcirculate.window);
* *
* if (!pWin) * if (!pWin)
* { * {
...@@ -2014,7 +1949,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2014,7 +1949,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case ConfigureNotify: case ConfigureNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new ConfigureNotify event.\n"); fprintf(stderr, "%s: Going to handle new ConfigureNotify event.\n", __func__);
#endif #endif
if (nxagentConfiguredSynchroWindow == X.xconfigure.window) if (nxagentConfiguredSynchroWindow == X.xconfigure.window)
...@@ -2024,14 +1959,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2024,14 +1959,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#ifdef WARNING #ifdef WARNING
if (nxagentVerbose == 1) if (nxagentVerbose == 1)
{ {
fprintf(stderr, "nxagentDispatchEvents: Requested ConfigureNotify changes didn't take place.\n"); fprintf(stderr, "%s: Requested ConfigureNotify changes didn't take place.\n", __func__);
} }
#endif #endif
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Received ConfigureNotify and going to call " fprintf(stderr, "%s: Received ConfigureNotify and going to call nxagentSynchronizeExpose.\n", __func__);
"nxagentSynchronizeExpose.\n");
#endif #endif
nxagentSynchronizeExpose(); nxagentSynchronizeExpose();
...@@ -2046,7 +1980,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2046,7 +1980,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case GravityNotify: case GravityNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new GravityNotify event.\n"); fprintf(stderr, "%s: Going to handle new GravityNotify event.\n", __func__);
#endif #endif
break; break;
...@@ -2054,7 +1988,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2054,7 +1988,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case ReparentNotify: case ReparentNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new ReparentNotify event.\n"); fprintf(stderr, "%s: Going to handle new ReparentNotify event.\n", __func__);
#endif #endif
nxagentHandleReparentNotify(&X); nxagentHandleReparentNotify(&X);
...@@ -2064,7 +1998,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2064,7 +1998,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case UnmapNotify: case UnmapNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new UnmapNotify event.\n"); fprintf(stderr, "%s: Going to handle new UnmapNotify event.\n", __func__);
#endif #endif
if (nxagentOption(Rootless) == 1) if (nxagentOption(Rootless) == 1)
...@@ -2095,7 +2029,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2095,7 +2029,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
case MapNotify: case MapNotify:
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Going to handle new MapNotify event.\n"); fprintf(stderr, "%s: Going to handle new MapNotify event.\n", __func__);
#endif #endif
if (nxagentOption(Rootless) == 1) if (nxagentOption(Rootless) == 1)
...@@ -2106,11 +2040,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2106,11 +2040,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
((pWin = nxagentWindowPtr(X.xmap.window)) != NULL && ((pWin = nxagentWindowPtr(X.xmap.window)) != NULL &&
nxagentWindowTopLevel(pWin) == 1)) nxagentWindowTopLevel(pWin) == 1))
{ {
ClientPtr pClient = wClient(pWin);
nxagentScreenTrap = 1; nxagentScreenTrap = 1;
MapWindow(pWin, pClient); MapWindow(pWin, wClient(pWin));
nxagentScreenTrap = 0; nxagentScreenTrap = 0;
} }
...@@ -2141,8 +2073,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2141,8 +2073,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was
/* /*
* without window manager there will be no ConfigureNotify * without window manager there will be no ConfigureNotify
* event that would trigger xinerama updates. So we do that once * event that would trigger xinerama updates. So we do that
* the nxagent window gets mapped. * once the nxagent window gets mapped.
*/ */
if (!nxagentWMIsRunning && if (!nxagentWMIsRunning &&
X.xmap.window == nxagentDefaultWindows[nxagentScreen(X.xmap.window)->myNum]) X.xmap.window == nxagentDefaultWindows[nxagentScreen(X.xmap.window)->myNum])
...@@ -2158,7 +2090,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2158,7 +2090,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
XMappingEvent *mappingEvent = (XMappingEvent *) &X; XMappingEvent *mappingEvent = (XMappingEvent *) &X;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDispatchEvents: WARNING! Going to handle new MappingNotify event.\n"); fprintf(stderr, "%s: WARNING! Going to handle new MappingNotify event.\n", __func__);
#endif #endif
if (mappingEvent -> request == MappingPointer) if (mappingEvent -> request == MappingPointer)
...@@ -2171,15 +2103,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2171,15 +2103,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was
default: default:
{ {
/* /*
* Let's check if this is a XKB * Let's check if this is a XKB state modification event.
* state modification event.
*/ */
if (nxagentHandleXkbKeyboardStateEvent(&X) == 0 && nxagentHandleXFixesSelectionNotify(&X) == 0) if (nxagentHandleXkbKeyboardStateEvent(&X) == 0 && nxagentHandleXFixesSelectionNotify(&X) == 0)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: WARNING! Unhandled event code [%d].\n", fprintf(stderr, "%s: WARNING! Unhandled event code [%d].\n", __func__, X.type);
X.type);
#endif #endif
} }
...@@ -2280,8 +2210,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2280,8 +2210,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
#endif #endif
/* /*
* Let the underlying X server code * Let the underlying X server code process the input events.
* process the input events.
*/ */
#ifdef BLOCKS #ifdef BLOCKS
...@@ -2291,14 +2220,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2291,14 +2220,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was
ProcessInputEvents(); ProcessInputEvents();
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Output pending flag is [%d] critical [%d].\n", fprintf(stderr, "%s: Output pending flag is [%d] critical [%d].\n", __func__,
NewOutputPending, CriticalOutputPending); NewOutputPending, CriticalOutputPending);
#endif #endif
/* /*
* Write the events to our clients. We may * Write the events to our clients. We may flush only in the case of
* flush only in the case of critical output * critical output but this doesn't seem beneficial.
* but this doesn't seem beneficial.
* *
* if (CriticalOutputPending == 1) * if (CriticalOutputPending == 1)
* { * {
...@@ -2309,19 +2237,17 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2309,19 +2237,17 @@ FIXME: Don't enqueue the KeyRelease event if the key was
if (NewOutputPending == 1) if (NewOutputPending == 1)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDispatchEvents: Flushed the processed events to clients.\n"); fprintf(stderr, "%s: Flushed the processed events to clients.\n", __func__);
#endif #endif
FlushAllOutput(); FlushAllOutput();
} }
#ifdef TEST #ifdef TEST
if (nxagentPendingEvents(nxagentDisplay) > 0) if (nxagentPendingEvents(nxagentDisplay) > 0)
{ {
fprintf(stderr, "nxagentDispatchEvents: WARNING! More events need to be dispatched.\n"); fprintf(stderr, "%s: WARNING! More events need to be dispatched.\n", __func__);
} }
#endif #endif
#ifdef BLOCKS #ifdef BLOCKS
...@@ -2330,8 +2256,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was ...@@ -2330,8 +2256,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was
} }
/* /*
* Functions providing the ad-hoc handling * Functions providing the ad-hoc handling of the remote X events.
* of the remote X events.
*/ */
int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result)
...@@ -2395,7 +2320,7 @@ int nxagentHandlePropertyNotify(XEvent *X) ...@@ -2395,7 +2320,7 @@ int nxagentHandlePropertyNotify(XEvent *X)
if (nxagentOption(Rootless) && !nxagentNotifyMatchChangeProperty((XPropertyEvent *) X)) if (nxagentOption(Rootless) && !nxagentNotifyMatchChangeProperty((XPropertyEvent *) X))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandlePropertyNotify: Property %ld on window %lx.\n", fprintf(stderr, "%s: Property %ld on window %lx.\n", __func__,
X -> xproperty.atom, X -> xproperty.window); X -> xproperty.atom, X -> xproperty.window);
#endif #endif
...@@ -2406,7 +2331,7 @@ int nxagentHandlePropertyNotify(XEvent *X) ...@@ -2406,7 +2331,7 @@ int nxagentHandlePropertyNotify(XEvent *X)
if (resource == -1) if (resource == -1)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandlePropertyNotify: WARNING! Asynchronous get property queue is full.\n"); fprintf(stderr, "%s: WARNING! Asynchronous get property queue is full.\n", __func__);
#endif #endif
return 0; return 0;
...@@ -2422,7 +2347,7 @@ int nxagentHandlePropertyNotify(XEvent *X) ...@@ -2422,7 +2347,7 @@ int nxagentHandlePropertyNotify(XEvent *X)
#ifdef TEST #ifdef TEST
else else
{ {
fprintf(stderr, "nxagentHandlePropertyNotify: Failed to look up remote window property.\n"); fprintf(stderr, "%s: Failed to look up remote window property.\n", __func__);
} }
#endif #endif
} }
...@@ -2432,30 +2357,23 @@ int nxagentHandlePropertyNotify(XEvent *X) ...@@ -2432,30 +2357,23 @@ int nxagentHandlePropertyNotify(XEvent *X)
int nxagentHandleExposeEvent(XEvent *X) int nxagentHandleExposeEvent(XEvent *X)
{ {
WindowPtr pWin = NULL;
Window window = None;
RegionRec sum;
RegionRec add;
BoxRec box;
int index = 0;
int overlap = 0;
StaticResizedWindowStruct *resizedWinPtr = NULL; StaticResizedWindowStruct *resizedWinPtr = NULL;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleExposeEvent: Checking remote expose events.\n"); fprintf(stderr, "%s: Checking remote expose events.\n", __func__);
fprintf(stderr, "%s: Looking for window id [%ld].\n", __func__, X -> xexpose.window);
fprintf(stderr, "nxagentHandleExposeEvent: Looking for window id [%ld].\n",
X -> xexpose.window);
#endif #endif
window = X -> xexpose.window; Window window = X -> xexpose.window;
pWin = nxagentWindowPtr(window); WindowPtr pWin = nxagentWindowPtr(window);
if (pWin != NULL) if (pWin != NULL)
{ {
RegionRec sum;
RegionRec add;
BoxRec box;
RegionInit(&sum, (BoxRec *) NULL, 1); RegionInit(&sum, (BoxRec *) NULL, 1);
/* /*
FIXME: This can be maybe optimized by consuming the FIXME: This can be maybe optimized by consuming the
...@@ -2464,8 +2382,7 @@ FIXME: This can be maybe optimized by consuming the ...@@ -2464,8 +2382,7 @@ FIXME: This can be maybe optimized by consuming the
do do
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleExposeEvent: Adding event for window id [%ld].\n", fprintf(stderr, "%s: Adding event for window id [%ld].\n", __func__, X -> xexpose.window);
X -> xexpose.window);
#endif #endif
box.x1 = pWin -> drawable.x + wBorderWidth(pWin) + X -> xexpose.x; box.x1 = pWin -> drawable.x + wBorderWidth(pWin) + X -> xexpose.x;
...@@ -2501,14 +2418,14 @@ FIXME: This can be maybe optimized by consuming the ...@@ -2501,14 +2418,14 @@ FIXME: This can be maybe optimized by consuming the
while (nxagentCheckEvents(nxagentDisplay, X, nxagentExposurePredicate, while (nxagentCheckEvents(nxagentDisplay, X, nxagentExposurePredicate,
(XPointer) &window) == 1); (XPointer) &window) == 1);
int overlap = 0;
RegionValidate(&sum, &overlap); RegionValidate(&sum, &overlap);
RegionIntersect(&sum, &sum, RegionIntersect(&sum, &sum,
&pWin->drawable.pScreen->root->winSize); &pWin->drawable.pScreen->root->winSize);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleExposeEvent: Sending events for window id [%ld].\n", fprintf(stderr, "%s: Sending events for window id [%ld].\n", __func__, X -> xexpose.window);
X -> xexpose.window);
#endif #endif
/* /*
...@@ -2516,7 +2433,7 @@ FIXME: This can be maybe optimized by consuming the ...@@ -2516,7 +2433,7 @@ FIXME: This can be maybe optimized by consuming the
* save received exposes for later processing. * save received exposes for later processing.
*/ */
index = nxagentLookupByWindow(pWin); int index = nxagentLookupByWindow(pWin);
if (index == -1) if (index == -1)
{ {
...@@ -2535,7 +2452,7 @@ FIXME: This can be maybe optimized by consuming the ...@@ -2535,7 +2452,7 @@ FIXME: This can be maybe optimized by consuming the
nxagentExposeQueue.exposures[index].remoteRegion, &sum); nxagentExposeQueue.exposures[index].remoteRegion, &sum);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleExposeEvent: Added region for window [%u] to position [%d].\n", fprintf(stderr, "%s: Added region for window [%u] to position [%d].\n", __func__,
nxagentWindow(pWin), index); nxagentWindow(pWin), index);
#endif #endif
...@@ -2558,19 +2475,16 @@ FIXME: This can be maybe optimized by consuming the ...@@ -2558,19 +2475,16 @@ FIXME: This can be maybe optimized by consuming the
int nxagentHandleGraphicsExposeEvent(XEvent *X) int nxagentHandleGraphicsExposeEvent(XEvent *X)
{ {
/* /*
* Send an expose event to client, instead of graphics * Send an expose event to client, instead of graphics expose. If
* expose. If target drawable is a backing pixmap, send * target drawable is a backing pixmap, send expose event for the
* expose event for the saved window, else do nothing. * saved window, else do nothing.
*/ */
RegionPtr exposeRegion;
BoxRec rect;
WindowPtr pWin;
StoringPixmapPtr pStoringPixmapRec = NULL; StoringPixmapPtr pStoringPixmapRec = NULL;
miBSWindowPtr pBSwindow = NULL; miBSWindowPtr pBSwindow = NULL;
int drawableType; int drawableType;
pWin = nxagentWindowPtr(X -> xgraphicsexpose.drawable); WindowPtr pWin = nxagentWindowPtr(X -> xgraphicsexpose.drawable);
if (pWin != NULL) if (pWin != NULL)
{ {
...@@ -2588,7 +2502,7 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X) ...@@ -2588,7 +2502,7 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X)
if (pStoringPixmapRec == NULL) if (pStoringPixmapRec == NULL)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleGraphicsExposeEvent: WARNING! Storing pixmap not found.\n"); fprintf(stderr, "%s: WARNING! Storing pixmap not found.\n", __func__);
#endif #endif
return 1; return 1;
...@@ -2599,7 +2513,7 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X) ...@@ -2599,7 +2513,7 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X)
if (pBSwindow == NULL) if (pBSwindow == NULL)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleGraphicsExposeEvent: WARNING! Back storage not found.\n"); fprintf(stderr, "%s: WARNING! Back storage not found.\n", __func__);
#endif #endif
return 1; return 1;
...@@ -2609,38 +2523,37 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X) ...@@ -2609,38 +2523,37 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X)
} }
/* /*
* Rectangle affected by GraphicsExpose * Rectangle affected by GraphicsExpose event.
* event.
*/ */
rect.x1 = X -> xgraphicsexpose.x; BoxRec rect = {
rect.y1 = X -> xgraphicsexpose.y; .x1 = X -> xgraphicsexpose.x,
rect.x2 = rect.x1 + X -> xgraphicsexpose.width; .y1 = X -> xgraphicsexpose.y,
rect.y2 = rect.y1 + X -> xgraphicsexpose.height; .x2 = rect.x1 + X -> xgraphicsexpose.width,
.y2 = rect.y1 + X -> xgraphicsexpose.height,
};
exposeRegion = RegionCreate(&rect, 0); RegionPtr exposeRegion = RegionCreate(&rect, 0);
if (drawableType == DRAWABLE_PIXMAP) if (drawableType == DRAWABLE_PIXMAP)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleGraphicsExposeEvent: Handling GraphicsExpose event on pixmap with id" fprintf(stderr, "%s: Handling GraphicsExpose event on pixmap with id [%lu].\n",
" [%lu].\n", X -> xgraphicsexpose.drawable); __func__, X -> xgraphicsexpose.drawable);
#endif #endif
/* /*
* The exposeRegion coordinates are relative * The exposeRegion coordinates are relative to the pixmap to
* to the pixmap to which GraphicsExpose * which GraphicsExpose event refers. But the BS coordinates of
* event refers. But the BS coordinates of * the savedRegion are relative to the window.
* the savedRegion are relative to the
* window.
*/ */
RegionTranslate(exposeRegion, pStoringPixmapRec -> backingStoreX, RegionTranslate(exposeRegion, pStoringPixmapRec -> backingStoreX,
pStoringPixmapRec -> backingStoreY); pStoringPixmapRec -> backingStoreY);
/* /*
* We remove from SavedRegion the part * We remove from SavedRegion the part affected by the
* affected by the GraphicsExpose event. * GraphicsExpose event.
*/ */
RegionSubtract(&(pBSwindow -> SavedRegion), &(pBSwindow -> SavedRegion), RegionSubtract(&(pBSwindow -> SavedRegion), &(pBSwindow -> SavedRegion),
...@@ -2648,9 +2561,8 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X) ...@@ -2648,9 +2561,8 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X)
} }
/* /*
* Store the exposeRegion in order to send * Store the exposeRegion in order to send the expose event
* the expose event later. The coordinates * later. The coordinates must be relative to the screen.
* must be relative to the screen.
*/ */
RegionTranslate(exposeRegion, pWin -> drawable.x, pWin -> drawable.y); RegionTranslate(exposeRegion, pWin -> drawable.x, pWin -> drawable.y);
...@@ -2667,14 +2579,13 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2667,14 +2579,13 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
*result = doNothing; *result = doNothing;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleClientMessageEvent: ClientMessage event window [%ld] with " fprintf(stderr, "%s: ClientMessage event window [%ld] with type [%ld] format [%d].\n",
"type [%ld] format [%d].\n", X -> xclient.window, X -> xclient.message_type, __func__, X -> xclient.window, X -> xclient.message_type, X -> xclient.format);
X -> xclient.format);
#endif #endif
/* /*
* If window is 0, message_type is 0 and format is * If window is 0, message_type is 0 and format is 32 then we assume
* 32 then we assume event is coming from proxy. * event is coming from proxy.
*/ */
if (X -> xclient.window == 0 && if (X -> xclient.window == 0 &&
...@@ -2693,7 +2604,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2693,7 +2604,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
if (!ValidAtom(message_type)) if (!ValidAtom(message_type))
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleClientMessageEvent: WARNING Invalid type in client message.\n"); fprintf(stderr, "%s: WARNING Invalid type in client message.\n", __func__);
#endif #endif
return 0; return 0;
...@@ -2712,12 +2623,9 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2712,12 +2623,9 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
if (message_type == MakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), False)) if (message_type == MakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), False))
{ {
xEvent x; xEvent x = {0};
memset(&x, 0, sizeof(xEvent));
x.u.u.type = ClientMessage; x.u.u.type = ClientMessage;
x.u.u.detail = X -> xclient.format; x.u.u.detail = X -> xclient.format;
x.u.clientMessage.window = pWin -> drawable.id; x.u.clientMessage.window = pWin -> drawable.id;
x.u.clientMessage.u.l.type = message_type; x.u.clientMessage.u.l.type = message_type;
x.u.clientMessage.u.l.longs0 = nxagentRemoteToLocalAtom(X -> xclient.data.l[0]); x.u.clientMessage.u.l.longs0 = nxagentRemoteToLocalAtom(X -> xclient.data.l[0]);
...@@ -2726,8 +2634,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2726,8 +2634,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
if (!ValidAtom(x.u.clientMessage.u.l.longs0)) if (!ValidAtom(x.u.clientMessage.u.l.longs0))
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleClientMessageEvent: WARNING Invalid value in client message " fprintf(stderr, "%s: WARNING Invalid value in client message of type WM_PROTOCOLS.\n", __func__);
"of type WM_PROTOCOLS.\n");
#endif #endif
return 0; return 0;
...@@ -2735,8 +2642,8 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2735,8 +2642,8 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
#ifdef TEST #ifdef TEST
else else
{ {
fprintf(stderr, "nxagentHandleClientMessageEvent: Sent client message of type WM_PROTOCOLS " fprintf(stderr, "%s: Sent client message of type WM_PROTOCOLS and value [%s].\n", __func__,
"and value [%s].\n", validateString(NameForAtom(x.u.clientMessage.u.l.longs0))); validateString(NameForAtom(x.u.clientMessage.u.l.longs0)));
} }
#endif #endif
...@@ -2745,7 +2652,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2745,7 +2652,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
else else
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleClientMessageEvent: Ignored message type %ld [%s].\n", fprintf(stderr, "%s: Ignored message type %ld [%s].\n", __func__,
(long int) message_type, validateString(NameForAtom(message_type))); (long int) message_type, validateString(NameForAtom(message_type)));
#endif #endif
...@@ -2757,11 +2664,8 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2757,11 +2664,8 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
if (X -> xclient.message_type == nxagentAtoms[1]) /* WM_PROTOCOLS */ if (X -> xclient.message_type == nxagentAtoms[1]) /* WM_PROTOCOLS */
{ {
Atom deleteWMatom, wmAtom; Atom wmAtom = (Atom) X -> xclient.data.l[0];
Atom deleteWMatom = nxagentAtoms[2]; /* WM_DELETE_WINDOW */
wmAtom = (Atom) X -> xclient.data.l[0];
deleteWMatom = nxagentAtoms[2]; /* WM_DELETE_WINDOW */
if (wmAtom == deleteWMatom) if (wmAtom == deleteWMatom)
{ {
...@@ -2772,7 +2676,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) ...@@ -2772,7 +2676,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result)
else else
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "Events: WM_DELETE_WINDOW arrived Atom = %u.\n", wmAtom); fprintf(stderr, "%s: WM_DELETE_WINDOW arrived Atom = %u.\n", __func__, wmAtom);
#endif #endif
if (X -> xclient.window == nxagentIconWindow) if (X -> xclient.window == nxagentIconWindow)
...@@ -2905,14 +2809,12 @@ int nxagentHandleXkbKeyboardStateEvent(XEvent *X) ...@@ -2905,14 +2809,12 @@ int nxagentHandleXkbKeyboardStateEvent(XEvent *X)
int nxagentHandleXFixesSelectionNotify(XEvent *X) int nxagentHandleXFixesSelectionNotify(XEvent *X)
{ {
Atom local;
XFixesSelectionEvent *xfixesEvent = (XFixesSelectionEvent *) X; XFixesSelectionEvent *xfixesEvent = (XFixesSelectionEvent *) X;
if (nxagentXFixesInfo.Initialized == 0) if (nxagentXFixesInfo.Initialized == 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: XFixes not initialized - doing nothing.\n"); fprintf(stderr, "%s: XFixes not initialized - doing nothing.\n", __func__);
#endif #endif
return 0; return 0;
} }
...@@ -2920,35 +2822,33 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X) ...@@ -2920,35 +2822,33 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X)
if (xfixesEvent -> type != (nxagentXFixesInfo.EventBase + XFixesSelectionNotify)) if (xfixesEvent -> type != (nxagentXFixesInfo.EventBase + XFixesSelectionNotify))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: event type is [%d] - doing nothing.\n", xfixesEvent->type); fprintf(stderr, "%s: event type is [%d] - doing nothing.\n", __func__, xfixesEvent->type);
#endif #endif
return 0; return 0;
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: Handling event.\n"); fprintf(stderr, "%s: Handling event.\n", __func__);
#endif #endif
local = nxagentRemoteToLocalAtom(xfixesEvent -> xfixesselection.selection); Atom local = nxagentRemoteToLocalAtom(xfixesEvent -> xfixesselection.selection);
if (SelectionCallback) if (SelectionCallback)
{ {
int i = nxagentFindCurrentSelectionIndex(local); int i = nxagentFindCurrentSelectionIndex(local);
if (i < NumCurrentSelections) if (i < NumCurrentSelections)
{ {
SelectionInfoRec info;
if (CurrentSelections[i].client != 0) if (CurrentSelections[i].client != 0)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: Do nothing.\n"); fprintf(stderr, "%s: Do nothing.\n", __func__);
#endif #endif
return 1; return 1;
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: Calling callbacks for %d [%s] selection.\n", fprintf(stderr, "%s: Calling callbacks for %d [%s] selection.\n", __func__,
CurrentSelections[i].selection, NameForAtom(CurrentSelections[i].selection)); CurrentSelections[i].selection, NameForAtom(CurrentSelections[i].selection));
#endif #endif
...@@ -2956,31 +2856,25 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X) ...@@ -2956,31 +2856,25 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X)
fprintf(stderr, "%s: CurrentSelections[i].lastTimeChanged [%d]\n", __func__, CurrentSelections[i].lastTimeChanged.milliseconds); fprintf(stderr, "%s: CurrentSelections[i].lastTimeChanged [%d]\n", __func__, CurrentSelections[i].lastTimeChanged.milliseconds);
fprintf(stderr, "%s: Event timestamp [%ld]\n", __func__, xfixesEvent->xfixesselection.timestamp); fprintf(stderr, "%s: Event timestamp [%ld]\n", __func__, xfixesEvent->xfixesselection.timestamp);
fprintf(stderr, "%s: Event selection timestamp [%ld]\n", __func__, xfixesEvent->xfixesselection.selection_timestamp); fprintf(stderr, "%s: Event selection timestamp [%ld]\n", __func__, xfixesEvent->xfixesselection.selection_timestamp);
fprintf(stderr, "%s: Event selection window [0x%x]\n", __func__, xfixesEvent->xfixesselection.window); fprintf(stderr, "%s: Event selection window [0x%lx]\n", __func__, xfixesEvent->xfixesselection.window);
fprintf(stderr, "%s: Event selection owner [0x%x]\n", __func__, xfixesEvent->xfixesselection.owner); fprintf(stderr, "%s: Event selection owner [0x%lx]\n", __func__, xfixesEvent->xfixesselection.owner);
fprintf(stderr, "%s: Event selection [%s]\n", __func__, NameForAtom(nxagentRemoteToLocalAtom(xfixesEvent->xfixesselection.selection))); fprintf(stderr, "%s: Event selection [%s]\n", __func__, NameForAtom(nxagentRemoteToLocalAtom(xfixesEvent->xfixesselection.selection)));
fprintf(stderr, "nxagentHandleXFixesSelectionNotify: Subtype "); fprintf(stderr, "%s: Subtype ", __func__);
switch (xfixesEvent -> xfixesselection.subtype) switch (xfixesEvent -> xfixesselection.subtype)
{ {
case SelectionSetOwner: case SelectionSetOwner: fprintf(stderr, "SelectionSetOwner.\n"); break;
fprintf(stderr, "SelectionSetOwner.\n"); case SelectionWindowDestroy: fprintf(stderr, "SelectionWindowDestroy.\n"); break;
break; case SelectionClientClose: fprintf(stderr, "SelectionClientClose.\n"); break;
case SelectionWindowDestroy: default: fprintf(stderr, ".\n"); break;
fprintf(stderr, "SelectionWindowDestroy.\n");
break;
case SelectionClientClose:
fprintf(stderr, "SelectionClientClose.\n");
break;
default:
fprintf(stderr, ".\n");
break;
} }
#endif #endif
info.selection = &CurrentSelections[i]; SelectionInfoRec info = {
info.kind = xfixesEvent->xfixesselection.subtype; .selection = &CurrentSelections[i],
.kind = xfixesEvent->xfixesselection.subtype
};
/* /*
* The trap indicates that we are triggered by a clipboard event * The trap indicates that we are triggered by a clipboard event
...@@ -3007,10 +2901,8 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3007,10 +2901,8 @@ int nxagentHandleProxyEvent(XEvent *X)
case NXStartSplitNotify: case NXStartSplitNotify:
{ {
/* /*
* We should never receive such events * We should never receive such events in the event loop, as
* in the event loop, as they should * they should be caught at the time the split is initiated.
* be caught at the time the split is
* initiated.
*/ */
#ifdef PANIC #ifdef PANIC
...@@ -3019,13 +2911,11 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3019,13 +2911,11 @@ int nxagentHandleProxyEvent(XEvent *X)
if (X -> xclient.data.l[0] == NXNoSplitNotify) if (X -> xclient.data.l[0] == NXNoSplitNotify)
{ {
fprintf(stderr, "nxagentHandleProxyEvent: PANIC! NXNoSplitNotify received " fprintf(stderr, "%s: PANIC! NXNoSplitNotify received with client [%d].\n", __func__, client);
"with client [%d].\n", client);
} }
else else
{ {
fprintf(stderr, "nxagentHandleProxyEvent: PANIC! NXStartSplitNotify received " fprintf(stderr, "%s: PANIC! NXStartSplitNotify received with client [%d].\n", __func__, client);
"with client [%d].\n", client);
} }
#endif #endif
...@@ -3035,10 +2925,9 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3035,10 +2925,9 @@ int nxagentHandleProxyEvent(XEvent *X)
case NXCommitSplitNotify: case NXCommitSplitNotify:
{ {
/* /*
* We need to commit an image. Image can be the * We need to commit an image. Image can be the result of a
* result of a PutSubImage() generated by Xlib, * PutSubImage() generated by Xlib, so there can be more than a
* so there can be more than a single image to * single image to commit, even if only one PutImage was perfor-
* commit, even if only one PutImage was perfor-
* med by the agent. * med by the agent.
*/ */
...@@ -3047,8 +2936,8 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3047,8 +2936,8 @@ int nxagentHandleProxyEvent(XEvent *X)
int position = (int) X -> xclient.data.l[3]; int position = (int) X -> xclient.data.l[3];
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleProxyEvent: NXCommitSplitNotify received with " fprintf(stderr, "%s: NXCommitSplitNotify received with client [%d]"
"client [%d] request [%d] and position [%d].\n", " request [%d] and position [%d].\n", __func__,
client, request, position); client, request, position);
#endif #endif
...@@ -3059,15 +2948,14 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3059,15 +2948,14 @@ int nxagentHandleProxyEvent(XEvent *X)
case NXEndSplitNotify: case NXEndSplitNotify:
{ {
/* /*
* All images for the split were transferred and * All images for the split were transferred and we need to
* we need to restart the client. * restart the client.
*/ */
int client = (int) X -> xclient.data.l[1]; int client = (int) X -> xclient.data.l[1];
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleProxyEvent: NXEndSplitNotify received with " fprintf(stderr, "%s: NXEndSplitNotify received with client [%d].\n", __func__, client);
"client [%d].\n", client);
#endif #endif
nxagentHandleEndSplitEvent(client); nxagentHandleEndSplitEvent(client);
...@@ -3081,7 +2969,7 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3081,7 +2969,7 @@ int nxagentHandleProxyEvent(XEvent *X)
*/ */
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleProxyEvent: NXEmptySplitNotify received.\n"); fprintf(stderr, "%s: NXEmptySplitNotify received.\n", __func__);
#endif #endif
nxagentHandleEmptySplitEvent(); nxagentHandleEmptySplitEvent();
...@@ -3093,8 +2981,7 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3093,8 +2981,7 @@ int nxagentHandleProxyEvent(XEvent *X)
#ifdef TEST #ifdef TEST
int resource = (int) X -> xclient.data.l[1]; int resource = (int) X -> xclient.data.l[1];
fprintf(stderr, "nxagentHandleProxyEvent: NXCollectPropertyNotify received with resource [%d].\n", fprintf(stderr, "%s: NXCollectPropertyNotify received with resource [%d].\n", __func__, resource);
resource);
#endif #endif
nxagentHandleCollectPropertyEvent(X); nxagentHandleCollectPropertyEvent(X);
...@@ -3106,8 +2993,7 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3106,8 +2993,7 @@ int nxagentHandleProxyEvent(XEvent *X)
int resource = (int) X -> xclient.data.l[1]; int resource = (int) X -> xclient.data.l[1];
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleProxyEvent: NXCollectGrabPointerNotify received with resource [%d].\n", fprintf(stderr, "%s: NXCollectGrabPointerNotify received with resource [%d].\n", __func__, resource);
resource);
#endif #endif
nxagentHandleCollectGrabPointerEvent(resource); nxagentHandleCollectGrabPointerEvent(resource);
...@@ -3123,8 +3009,7 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3123,8 +3009,7 @@ int nxagentHandleProxyEvent(XEvent *X)
*/ */
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleProxyEvent: NXCollectInputFocusNotify received with resource [%d].\n", fprintf(stderr, "%s: NXCollectInputFocusNotify received with resource [%d].\n", __func__, resource);
resource);
#endif #endif
nxagentHandleCollectInputFocusEvent(resource); nxagentHandleCollectInputFocusEvent(resource);
...@@ -3138,7 +3023,7 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3138,7 +3023,7 @@ int nxagentHandleProxyEvent(XEvent *X)
*/ */
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleProxyEvent: WARNING! Not a recognized ClientMessage proxy event [%d].\n", fprintf(stderr, "%s: WARNING! Not a recognized ClientMessage proxy event [%d].\n", __func__,
(int) X -> xclient.data.l[0]); (int) X -> xclient.data.l[0]);
#endif #endif
...@@ -3148,9 +3033,8 @@ int nxagentHandleProxyEvent(XEvent *X) ...@@ -3148,9 +3033,8 @@ int nxagentHandleProxyEvent(XEvent *X)
} }
/* /*
* In this function it is assumed that we never * In this function it is assumed that we never get a configure with
* get a configure with both stacking order and * both stacking order and geometry changed, this way we can ignore
* geometry changed, this way we can ignore
* stacking changes if the geometry has changed. * stacking changes if the geometry has changed.
*/ */
...@@ -3190,7 +3074,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X) ...@@ -3190,7 +3074,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X)
if (geometryChanged) if (geometryChanged)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCheckWindowConfiguration: Configure frame. No restack.\n"); fprintf(stderr, "%s: Configure frame. No restack.\n", __func__);
#endif #endif
return 1; return 1;
...@@ -3198,13 +3082,12 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X) ...@@ -3198,13 +3082,12 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X)
#ifdef TEST #ifdef TEST
{ {
fprintf(stderr, "nxagentCheckWindowConfiguration: Before restacking top level window [%p]\n", fprintf(stderr, "%s: Before restacking top level window [%p]\n", __func__,
(void *) nxagentWindowPtr(X -> window)); (void *) nxagentWindowPtr(X -> window));
for (WindowPtr pSib = screenInfo.screens[0]->root -> firstChild; pSib; pSib = pSib -> nextSib) for (WindowPtr pSib = screenInfo.screens[0]->root -> firstChild; pSib; pSib = pSib -> nextSib)
{ {
fprintf(stderr, "nxagentCheckWindowConfiguration: Top level window: [%p].\n", fprintf(stderr, "%s: Top level window: [%p].\n", __func__, (void *) pSib);
(void *) pSib);
} }
} }
#endif #endif
...@@ -3219,15 +3102,14 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X) ...@@ -3219,15 +3102,14 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X)
else else
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentCheckWindowConfiguration: WARNING! Failed QueryTree request.\n"); fprintf(stderr, "%s: WARNING! Failed QueryTree request.\n", __func__);
#endif #endif
} }
SAFE_XFree(children_return); SAFE_XFree(children_return);
#if 0 #if 0
fprintf(stderr, "nxagentCheckWindowConfiguration: Trees match: %s\n", fprintf(stderr, "%s: Trees match: %s\n", __func__, nxagentRootlessTreesMatch() ? "Yes" : "No");
nxagentRootlessTreesMatch() ? "Yes" : "No");
#endif #endif
return 1; return 1;
...@@ -3237,30 +3119,28 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3237,30 +3119,28 @@ int nxagentHandleConfigureNotify(XEvent* X)
{ {
if (nxagentOption(Rootless) == True) if (nxagentOption(Rootless) == True)
{ {
ClientPtr pClient;
WindowPtr pWinWindow;
WindowPtr pWin;
int sendEventAnyway = 0; int sendEventAnyway = 0;
pWinWindow = nxagentWindowPtr(X -> xconfigure.window); WindowPtr pWinWindow = nxagentWindowPtr(X -> xconfigure.window);
#ifdef TEST #ifdef TEST
{ {
WindowPtr pWinEvent = nxagentWindowPtr(X -> xconfigure.event); WindowPtr pWinEvent = nxagentWindowPtr(X -> xconfigure.event);
fprintf(stderr, "nxagentHandleConfigureNotify: Generating window is [%p][%ld] target [%p][%ld].\n", fprintf(stderr, "%s: Generating window is [%p][%ld] target [%p][%ld].\n", __func__,
(void *) pWinEvent, X -> xconfigure.event, (void *) pWinWindow, X -> xconfigure.window); (void *) pWinEvent, X -> xconfigure.event, (void *) pWinWindow, X -> xconfigure.window);
} }
#endif #endif
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleConfigureNotify: New configuration for window [%p][%ld] is [%d][%d][%d][%d] " fprintf(stderr, "%s: New configuration for window [%p][%ld] is [%d][%d][%d][%d] send_event [%i].\n",
"send_event [%i].\n", (void *) pWinWindow, X -> xconfigure.window, __func__, (void *) pWinWindow, X -> xconfigure.window,
X -> xconfigure.x, X -> xconfigure.y, X -> xconfigure.width, X -> xconfigure.x, X -> xconfigure.y, X -> xconfigure.width,
X -> xconfigure.height, X -> xconfigure.send_event); X -> xconfigure.height, X -> xconfigure.send_event);
#endif #endif
if ((pWin = nxagentRootlessTopLevelWindow(X -> xconfigure.window)) != NULL) WindowPtr pWin = nxagentRootlessTopLevelWindow(X -> xconfigure.window);
if (pWin != NULL)
{ {
/* /*
* Checking for new geometry or stacking order changes. * Checking for new geometry or stacking order changes.
...@@ -3274,11 +3154,9 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3274,11 +3154,9 @@ int nxagentHandleConfigureNotify(XEvent* X)
if (nxagentWindowTopLevel(pWinWindow) && !X -> xconfigure.override_redirect) if (nxagentWindowTopLevel(pWinWindow) && !X -> xconfigure.override_redirect)
{ {
XID values[5]; XID values[5];
Mask mask = 0;
register XID *value = values; register XID *value = values;
pClient = wClient(pWinWindow); Mask mask = CWHeight | CWWidth | CWBorderWidth;
/* FIXME: override_redirect is always FALSE here */ /* FIXME: override_redirect is always FALSE here */
if (X -> xconfigure.send_event || !nxagentWMIsRunning || if (X -> xconfigure.send_event || !nxagentWMIsRunning ||
...@@ -3306,26 +3184,23 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3306,26 +3184,23 @@ int nxagentHandleConfigureNotify(XEvent* X)
* nxagentWindowPriv(pWinWindow)->height = X -> xconfigure.height; * nxagentWindowPriv(pWinWindow)->height = X -> xconfigure.height;
*/ */
mask |= CWHeight | CWWidth | CWBorderWidth;
nxagentScreenTrap = 1; nxagentScreenTrap = 1;
ConfigureWindow(pWinWindow, mask, (XID *) values, pClient); ConfigureWindow(pWinWindow, mask, (XID *) values, wClient(pWinWindow));
nxagentScreenTrap = 0; nxagentScreenTrap = 0;
nxagentCheckWindowConfiguration((XConfigureEvent*)X); nxagentCheckWindowConfiguration((XConfigureEvent*)X);
/* /*
* This workaround should help with * This workaround should help with Java 1.6.0 that seems to
* Java 1.6.0 that seems to ignore * ignore non-synthetic events.
* non-synthetic events.
*/ */
if (nxagentOption(ClientOs) == ClientOsWinnt) if (nxagentOption(ClientOs) == ClientOsWinnt)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleConfigureNotify: Apply workaround for NXWin.\n"); fprintf(stderr, "%s: Apply workaround for NXWin.\n", __func__);
#endif #endif
sendEventAnyway = 1; sendEventAnyway = 1;
...@@ -3333,11 +3208,9 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3333,11 +3208,9 @@ int nxagentHandleConfigureNotify(XEvent* X)
if (sendEventAnyway || X -> xconfigure.send_event) if (sendEventAnyway || X -> xconfigure.send_event)
{ {
xEvent x; xEvent x = {0};
memset(&x, 0, sizeof(xEvent)); x.u.u.type = X -> xconfigure.type | 0x80;
x.u.u.type = X -> xconfigure.type;
x.u.u.type |= 0x80;
x.u.configureNotify.event = pWinWindow -> drawable.id; x.u.configureNotify.event = pWinWindow -> drawable.id;
x.u.configureNotify.window = pWinWindow -> drawable.id; x.u.configureNotify.window = pWinWindow -> drawable.id;
...@@ -3358,7 +3231,7 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3358,7 +3231,7 @@ int nxagentHandleConfigureNotify(XEvent* X)
x.u.configureNotify.borderWidth = X -> xconfigure.border_width; x.u.configureNotify.borderWidth = X -> xconfigure.border_width;
x.u.configureNotify.override = X -> xconfigure.override_redirect; x.u.configureNotify.override = X -> xconfigure.override_redirect;
TryClientEvents(pClient, &x, 1, 1, 1, 0); TryClientEvents(wClient(pWinWindow), &x, 1, 1, 1, 0);
} }
return 1; return 1;
...@@ -3367,15 +3240,14 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3367,15 +3240,14 @@ int nxagentHandleConfigureNotify(XEvent* X)
else else
{ {
/* /*
* Save the position of the agent default window. Don't * Save the position of the agent default window. Don't save the
* save the values if the agent is in fullscreen mode. * values if the agent is in fullscreen mode.
* *
* If we use these values to restore the position of a * If we use these values to restore the position of a window
* window after that we have dynamically changed the * after that we have dynamically changed the fullscreen
* fullscreen attribute, depending on the behaviour of * attribute, depending on the behaviour of window manager, we
* window manager, we could be not able to place the * could be not able to place the window exactly in the requested
* window exactly in the requested position, so let the * position, so let the window manager do the job for us.
* window manager do the job for us.
*/ */
ScreenPtr pScreen = nxagentScreen(X -> xconfigure.window); ScreenPtr pScreen = nxagentScreen(X -> xconfigure.window);
...@@ -3517,7 +3389,7 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3517,7 +3389,7 @@ int nxagentHandleConfigureNotify(XEvent* X)
if (doRandR) if (doRandR)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr,"nxagentHandleConfigureNotify: Width %d Height %d.\n", fprintf(stderr,"%s: Width %d Height %d.\n", __func__,
nxagentOption(Width), nxagentOption(Height)); nxagentOption(Width), nxagentOption(Height));
#endif #endif
...@@ -3533,7 +3405,8 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3533,7 +3405,8 @@ int nxagentHandleConfigureNotify(XEvent* X)
if ( (X -> xconfigure.window == DefaultRootWindow(nxagentDisplay)) || nxagentFullscreenWindow ) if ( (X -> xconfigure.window == DefaultRootWindow(nxagentDisplay)) || nxagentFullscreenWindow )
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleConfigureNotify: remote root window has changed: %d,%d %dx%d\n", X -> xconfigure.x, X -> xconfigure.y, X -> xconfigure.width, X -> xconfigure.height); fprintf(stderr, "%s: remote root window has changed: %d,%d %dx%d\n", __func__,
X -> xconfigure.x, X -> xconfigure.y, X -> xconfigure.width, X -> xconfigure.height);
#endif #endif
nxagentChangeOption(RootX, X -> xconfigure.x); nxagentChangeOption(RootX, X -> xconfigure.x);
...@@ -3555,17 +3428,11 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3555,17 +3428,11 @@ int nxagentHandleConfigureNotify(XEvent* X)
int nxagentHandleReparentNotify(XEvent* X) int nxagentHandleReparentNotify(XEvent* X)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleReparentNotify: Going to handle a new reparent event.\n"); fprintf(stderr, "%s: Going to handle a new reparent event.\n", __func__);
#endif #endif
if (nxagentOption(Rootless)) if (nxagentOption(Rootless))
{ {
XlibWindow w;
XlibWindow root_return = 0;
XlibWindow parent_return = 0;
XlibWindow *children_return = NULL;
unsigned int nchildren_return = 0;
Status result;
WindowPtr pWin = nxagentWindowPtr(X -> xreparent.window); WindowPtr pWin = nxagentWindowPtr(X -> xreparent.window);
#ifdef TEST #ifdef TEST
...@@ -3574,7 +3441,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3574,7 +3441,7 @@ int nxagentHandleReparentNotify(XEvent* X)
WindowPtr pParent = nxagentWindowPtr(X -> xreparent.parent); WindowPtr pParent = nxagentWindowPtr(X -> xreparent.parent);
WindowPtr pEvent = nxagentWindowPtr(X -> xreparent.event); WindowPtr pEvent = nxagentWindowPtr(X -> xreparent.event);
fprintf(stderr, "nxagentHandleReparentNotify: event %p[%lx] window %p[%lx] parent %p[%lx] at (%d, %d)\n", fprintf(stderr, "%s: event %p[%lx] window %p[%lx] parent %p[%lx] at (%d, %d)\n", __func__,
(void*)pEvent, X -> xreparent.event, (void*)pWin, X -> xreparent.window, (void*)pEvent, X -> xreparent.event, (void*)pWin, X -> xreparent.window,
(void*)pParent, X -> xreparent.parent, X -> xreparent.x, X -> xreparent.y); (void*)pParent, X -> xreparent.parent, X -> xreparent.x, X -> xreparent.y);
} }
...@@ -3584,13 +3451,17 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3584,13 +3451,17 @@ int nxagentHandleReparentNotify(XEvent* X)
if (nxagentWindowTopLevel(pWin)) if (nxagentWindowTopLevel(pWin))
{ {
/* /*
* If the window manager reparents our top level * If the window manager reparents our top level window, we need
* window, we need to know the new top level * to know the new top level ancestor.
* ancestor.
*/ */
w = None; XlibWindow w = None;
parent_return = X -> xreparent.parent; XlibWindow root_return = 0;
XlibWindow *children_return = NULL;
unsigned int nchildren_return = 0;
Status result;
XlibWindow parent_return = X -> xreparent.parent;
while (parent_return != RootWindow(nxagentDisplay, 0)) while (parent_return != RootWindow(nxagentDisplay, 0))
{ {
...@@ -3603,7 +3474,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3603,7 +3474,7 @@ int nxagentHandleReparentNotify(XEvent* X)
if (!result) if (!result)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleReparentNotify: WARNING! Failed QueryTree request.\n"); fprintf(stderr, "%s: WARNING! Failed QueryTree request.\n", __func__);
#endif #endif
break; break;
...@@ -3617,9 +3488,8 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3617,9 +3488,8 @@ int nxagentHandleReparentNotify(XEvent* X)
nxagentRootlessAddTopLevelWindow(pWin, w); nxagentRootlessAddTopLevelWindow(pWin, w);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleReparentNotify: new top level window [%ld].\n", w); fprintf(stderr, "%s: new top level window [%ld].\n", __func__, w);
fprintf(stderr, "nxagentHandleReparentNotify: reparented window [%ld].\n", fprintf(stderr, "%s: reparented window [%ld].\n", __func__, X -> xreparent.window);
X -> xreparent.window);
#endif #endif
result = XQueryTree(nxagentDisplay, DefaultRootWindow(nxagentDisplay), result = XQueryTree(nxagentDisplay, DefaultRootWindow(nxagentDisplay),
...@@ -3632,7 +3502,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3632,7 +3502,7 @@ int nxagentHandleReparentNotify(XEvent* X)
else else
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleReparentNotify: WARNING! Failed QueryTree request.\n"); fprintf(stderr, "%s: WARNING! Failed QueryTree request.\n", __func__);
#endif #endif
} }
...@@ -3641,8 +3511,8 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3641,8 +3511,8 @@ int nxagentHandleReparentNotify(XEvent* X)
else else
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentHandleReparentNotify: Window at [%p] has been reparented to [%ld]" fprintf(stderr, "%s: Window at [%p] has been reparented to [%ld] top level parent [%ld].\n",
" top level parent [%ld].\n", (void *) pWin, X -> xreparent.parent, w); __func__, (void *) pWin, X -> xreparent.parent, w);
#endif #endif
nxagentRootlessDelTopLevelWindow(pWin); nxagentRootlessDelTopLevelWindow(pWin);
...@@ -3654,33 +3524,25 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3654,33 +3524,25 @@ int nxagentHandleReparentNotify(XEvent* X)
else if (nxagentWMIsRunning && nxagentOption(Fullscreen) == 0 && else if (nxagentWMIsRunning && nxagentOption(Fullscreen) == 0 &&
nxagentOption(WMBorderWidth) == -1) nxagentOption(WMBorderWidth) == -1)
{ {
XlibWindow w;
XlibWindow rootReturn = 0;
XlibWindow parentReturn = 0;
XlibWindow junk;
XlibWindow *childrenReturn = NULL;
unsigned int nchildrenReturn = 0;
XWindowAttributes attributes;
int x, y;
/* /*
* Calculate the absolute upper-left X e Y * Calculate the absolute upper-left X e Y
*/ */
XWindowAttributes attributes;
if ((XGetWindowAttributes(nxagentDisplay, X -> xreparent.window, if ((XGetWindowAttributes(nxagentDisplay, X -> xreparent.window,
&attributes) == 0)) &attributes) == 0))
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleReparentNotify: WARNING! " fprintf(stderr, "%s: WARNING! XGetWindowAttributes failed.\n", __func__);
"XGetWindowAttributes failed.\n");
#endif #endif
return 1; return 1;
} }
x = attributes.x; int x = attributes.x;
y = attributes.y; int y = attributes.y;
XlibWindow junk;
XTranslateCoordinates(nxagentDisplay, X -> xreparent.window, XTranslateCoordinates(nxagentDisplay, X -> xreparent.window,
attributes.root, -attributes.border_width, attributes.root, -attributes.border_width,
-attributes.border_width, &x, &y, &junk); -attributes.border_width, &x, &y, &junk);
...@@ -3689,11 +3551,14 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3689,11 +3551,14 @@ int nxagentHandleReparentNotify(XEvent* X)
* Calculate the parent X and parent Y. * Calculate the parent X and parent Y.
*/ */
w = X -> xreparent.parent; XlibWindow w = X -> xreparent.parent;
if (w != DefaultRootWindow(nxagentDisplay)) if (w != DefaultRootWindow(nxagentDisplay))
{ {
int xParent, yParent; XlibWindow rootReturn = 0;
XlibWindow parentReturn = 0;
XlibWindow *childrenReturn = NULL;
unsigned int nchildrenReturn = 0;
do do
{ {
...@@ -3718,23 +3583,19 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3718,23 +3583,19 @@ int nxagentHandleReparentNotify(XEvent* X)
if (XGetWindowAttributes(nxagentDisplay, w, &attributes) == 0) if (XGetWindowAttributes(nxagentDisplay, w, &attributes) == 0)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentHandleReparentNotify: WARNING! " fprintf(stderr, "%s: WARNING! XGetWindowAttributes failed for parent window.\n", __func__);
"XGetWindowAttributes failed for parent window.\n");
#endif #endif
return 1; return 1;
} }
xParent = attributes.x;
yParent = attributes.y;
/* /*
* Difference between Absolute X and Parent X gives thickness of side frame. * Difference between Absolute X and Parent X gives thickness of side frame.
* Difference between Absolute Y and Parent Y gives thickness of title bar. * Difference between Absolute Y and Parent Y gives thickness of title bar.
*/ */
nxagentChangeOption(WMBorderWidth, (x - xParent)); nxagentChangeOption(WMBorderWidth, (x - attributes.x));
nxagentChangeOption(WMTitleHeight, (y - yParent)); nxagentChangeOption(WMTitleHeight, (y - attributes.y));
} }
} }
...@@ -3789,12 +3650,9 @@ void nxagentDisablePointerEvents(void) ...@@ -3789,12 +3650,9 @@ void nxagentDisablePointerEvents(void)
void nxagentSendFakeKey(int key) void nxagentSendFakeKey(int key)
{ {
xEvent fake; Time now = GetTimeInMillis();
Time now;
now = GetTimeInMillis();
memset(&fake, 0, sizeof(xEvent)); xEvent fake = {0};
fake.u.u.type = KeyPress; fake.u.u.type = KeyPress;
fake.u.u.detail = key; fake.u.u.detail = key;
fake.u.keyButtonPointer.time = now; fake.u.keyButtonPointer.time = now;
...@@ -3810,9 +3668,7 @@ void nxagentSendFakeKey(int key) ...@@ -3810,9 +3668,7 @@ void nxagentSendFakeKey(int key)
int nxagentInitXkbKeyboardState(void) int nxagentInitXkbKeyboardState(void)
{ {
XEvent X; XEvent X = {0};
unsigned int modifiers;
XkbEvent *xkbev = (XkbEvent *) &X; XkbEvent *xkbev = (XkbEvent *) &X;
...@@ -3825,8 +3681,7 @@ int nxagentInitXkbKeyboardState(void) ...@@ -3825,8 +3681,7 @@ int nxagentInitXkbKeyboardState(void)
fprintf(stderr, "%s: Initializing XKB state.\n", __func__); fprintf(stderr, "%s: Initializing XKB state.\n", __func__);
#endif #endif
memset(&X, 0, sizeof(XEvent)); unsigned int modifiers;
XkbGetIndicatorState(nxagentDisplay, XkbUseCoreKbd, &modifiers); XkbGetIndicatorState(nxagentDisplay, XkbUseCoreKbd, &modifiers);
xkbev -> state.locked_mods = 0x0; xkbev -> state.locked_mods = 0x0;
...@@ -3873,17 +3728,13 @@ int nxagentWaitForResource(GetResourceFuncPtr pGetResource, PredicateFuncPtr pPr ...@@ -3873,17 +3728,13 @@ int nxagentWaitForResource(GetResourceFuncPtr pGetResource, PredicateFuncPtr pPr
void nxagentGrabPointerAndKeyboard(XEvent *X) void nxagentGrabPointerAndKeyboard(XEvent *X)
{ {
unsigned long now;
int resource;
int result;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGrabPointerAndKeyboard: Grabbing pointer and keyboard with event at [%p].\n", fprintf(stderr, "%s: Grabbing pointer and keyboard with event at [%p].\n", __func__,
(void *) X); (void *) X);
#endif #endif
unsigned long now;
if (X != NULL) if (X != NULL)
{ {
now = X -> xcrossing.time; now = X -> xcrossing.time;
...@@ -3894,14 +3745,12 @@ void nxagentGrabPointerAndKeyboard(XEvent *X) ...@@ -3894,14 +3745,12 @@ void nxagentGrabPointerAndKeyboard(XEvent *X)
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGrabPointerAndKeyboard: Going to grab the keyboard in context [B1].\n"); fprintf(stderr, "%s: Going to grab the keyboard in context [B1].\n", __func__);
#endif #endif
if (nxagentFullscreenWindow) int result = XGrabKeyboard(nxagentDisplay,
result = XGrabKeyboard(nxagentDisplay, nxagentFullscreenWindow, nxagentFullscreenWindow ? nxagentFullscreenWindow
True, GrabModeAsync, GrabModeAsync, now); : RootWindow(nxagentDisplay, DefaultScreen(nxagentDisplay)),
else
result = XGrabKeyboard(nxagentDisplay, RootWindow(nxagentDisplay, DefaultScreen(nxagentDisplay)),
True, GrabModeAsync, GrabModeAsync, now); True, GrabModeAsync, GrabModeAsync, now);
if (result != GrabSuccess) if (result != GrabSuccess)
...@@ -3919,19 +3768,18 @@ void nxagentGrabPointerAndKeyboard(XEvent *X) ...@@ -3919,19 +3768,18 @@ void nxagentGrabPointerAndKeyboard(XEvent *X)
#endif #endif
/* /*
* The smart scheduler could be stopped while * The smart scheduler could be stopped while waiting for the
* waiting for the reply. In this case we need * reply. In this case we need to yield explicitly to avoid to be
* to yield explicitly to avoid to be stuck in * stuck in the dispatch loop forever.
* the dispatch loop forever.
*/ */
isItTimeToYield = 1; isItTimeToYield = 1;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGrabPointerAndKeyboard: Going to grab the pointer in context [B2].\n"); fprintf(stderr, "%s: Going to grab the pointer in context [B2].\n", __func__);
#endif #endif
resource = nxagentWaitForResource(NXGetCollectGrabPointerResource, int resource = nxagentWaitForResource(NXGetCollectGrabPointerResource,
nxagentCollectGrabPointerPredicate); nxagentCollectGrabPointerPredicate);
if (nxagentFullscreenWindow) if (nxagentFullscreenWindow)
...@@ -3949,7 +3797,7 @@ void nxagentGrabPointerAndKeyboard(XEvent *X) ...@@ -3949,7 +3797,7 @@ void nxagentGrabPointerAndKeyboard(XEvent *X)
if (X != NULL) if (X != NULL)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGrabPointerAndKeyboard: Going to force focus in context [B4].\n"); fprintf(stderr, "%s: Going to force focus in context [B4].\n", __func__);
#endif #endif
XSetInputFocus(nxagentDisplay, nxagentFullscreenWindow, XSetInputFocus(nxagentDisplay, nxagentFullscreenWindow,
...@@ -3962,7 +3810,7 @@ void nxagentUngrabPointerAndKeyboard(XEvent *X) ...@@ -3962,7 +3810,7 @@ void nxagentUngrabPointerAndKeyboard(XEvent *X)
unsigned long now; unsigned long now;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentUngrabPointerAndKeyboard: Ungrabbing pointer and keyboard with event at [%p].\n", fprintf(stderr, "%s: Ungrabbing pointer and keyboard with event at [%p].\n", __func__,
(void *) X); (void *) X);
#endif #endif
...@@ -3976,13 +3824,13 @@ void nxagentUngrabPointerAndKeyboard(XEvent *X) ...@@ -3976,13 +3824,13 @@ void nxagentUngrabPointerAndKeyboard(XEvent *X)
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentUngrabPointerAndKeyboard: Going to ungrab the keyboard in context [B5].\n"); fprintf(stderr, "%s: Going to ungrab the keyboard in context [B5].\n", __func__);
#endif #endif
XUngrabKeyboard(nxagentDisplay, now); XUngrabKeyboard(nxagentDisplay, now);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentUngrabPointerAndKeyboard: Going to ungrab the pointer in context [B6].\n"); fprintf(stderr, "%s: Going to ungrab the pointer in context [B6].\n", __func__);
#endif #endif
XUngrabPointer(nxagentDisplay, now); XUngrabPointer(nxagentDisplay, now);
...@@ -4031,28 +3879,19 @@ void nxagentHandleCollectGrabPointerEvent(int resource) ...@@ -4031,28 +3879,19 @@ void nxagentHandleCollectGrabPointerEvent(int resource)
if (NXGetCollectedGrabPointer(nxagentDisplay, resource, &status) == 0) if (NXGetCollectedGrabPointer(nxagentDisplay, resource, &status) == 0)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentHandleCollectGrabPointerEvent: PANIC! Failed to get GrabPointer " fprintf(stderr, "%s: PANIC! Failed to get GrabPointer reply for resource [%d].\n", __func__, resource);
"reply for resource [%d].\n", resource);
#endif #endif
} }
} }
void nxagentHandleCollectPropertyEvent(XEvent *X) void nxagentHandleCollectPropertyEvent(XEvent *X)
{ {
Window window;
Atom property;
Atom atomReturnType;
int resultFormat;
unsigned long ulReturnItems;
unsigned long ulReturnBytesLeft;
unsigned char *pszReturnData = NULL;
int result;
int resource = X -> xclient.data.l[1]; int resource = X -> xclient.data.l[1];
if (X -> xclient.data.l[2] == False) if (X -> xclient.data.l[2] == False)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentHandleCollectPropertyEvent: Failed to get reply data for client [%d].\n", fprintf (stderr, "%s: Failed to get reply data for client [%d].\n", __func__,
resource); resource);
#endif #endif
...@@ -4065,7 +3904,13 @@ void nxagentHandleCollectPropertyEvent(XEvent *X) ...@@ -4065,7 +3904,13 @@ void nxagentHandleCollectPropertyEvent(XEvent *X)
} }
else else
{ {
result = NXGetCollectedProperty(nxagentDisplay, Atom atomReturnType;
int resultFormat;
unsigned long ulReturnItems;
unsigned long ulReturnBytesLeft;
unsigned char *pszReturnData = NULL;
int result = NXGetCollectedProperty(nxagentDisplay,
resource, resource,
&atomReturnType, &atomReturnType,
&resultFormat, &resultFormat,
...@@ -4075,8 +3920,8 @@ void nxagentHandleCollectPropertyEvent(XEvent *X) ...@@ -4075,8 +3920,8 @@ void nxagentHandleCollectPropertyEvent(XEvent *X)
if (result == True) if (result == True)
{ {
window = nxagentPropertyRequests[resource].window; Window window = nxagentPropertyRequests[resource].window;
property = nxagentPropertyRequests[resource].property; Atom property = nxagentPropertyRequests[resource].property;
nxagentImportProperty(window, property, atomReturnType, resultFormat, nxagentImportProperty(window, property, atomReturnType, resultFormat,
ulReturnItems, ulReturnBytesLeft, pszReturnData); ulReturnItems, ulReturnBytesLeft, pszReturnData);
...@@ -4084,7 +3929,7 @@ void nxagentHandleCollectPropertyEvent(XEvent *X) ...@@ -4084,7 +3929,7 @@ void nxagentHandleCollectPropertyEvent(XEvent *X)
else else
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentHandleCollectPropertyEvent: Failed to get reply data for client [%d].\n", fprintf (stderr, "%s: Failed to get reply data for client [%d].\n", __func__,
resource); resource);
#endif #endif
} }
...@@ -4097,19 +3942,17 @@ void nxagentHandleCollectPropertyEvent(XEvent *X) ...@@ -4097,19 +3942,17 @@ void nxagentHandleCollectPropertyEvent(XEvent *X)
void nxagentSynchronizeExpose(void) void nxagentSynchronizeExpose(void)
{ {
WindowPtr pWin;
if (nxagentExposeQueue.length <= 0) if (nxagentExposeQueue.length <= 0)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSynchronizeExpose: PANIC! Called with nxagentExposeQueue.length [%d].\n", fprintf(stderr, "%s: PANIC! Called with nxagentExposeQueue.length [%d].\n", __func__,
nxagentExposeQueue.length); nxagentExposeQueue.length);
#endif #endif
return; return;
} }
pWin = nxagentExposeQueueHead.pWindow; WindowPtr pWin = nxagentExposeQueueHead.pWindow;
if (pWin) if (pWin)
{ {
...@@ -4136,8 +3979,8 @@ void nxagentSynchronizeExpose(void) ...@@ -4136,8 +3979,8 @@ void nxagentSynchronizeExpose(void)
((pWin -> eventMask|wOtherEventMasks(pWin)) & ExposureMask)) ((pWin -> eventMask|wOtherEventMasks(pWin)) & ExposureMask))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSynchronizeExpose: Going to call miWindowExposures" fprintf(stderr, "%s: Going to call miWindowExposures for window [%d] - rects [%d].\n",
" for window [%d] - rects [%d].\n", nxagentWindow(pWin), __func__, nxagentWindow(pWin),
RegionNumRects(nxagentExposeQueueHead.remoteRegion)); RegionNumRects(nxagentExposeQueueHead.remoteRegion));
#endif #endif
...@@ -4152,16 +3995,13 @@ void nxagentSynchronizeExpose(void) ...@@ -4152,16 +3995,13 @@ void nxagentSynchronizeExpose(void)
{ {
RegionDestroy(nxagentExposeQueueHead.localRegion); RegionDestroy(nxagentExposeQueueHead.localRegion);
} }
nxagentExposeQueueHead.localRegion = NullRegion; nxagentExposeQueueHead.localRegion = NullRegion;
if (nxagentExposeQueueHead.remoteRegion != NullRegion) if (nxagentExposeQueueHead.remoteRegion != NullRegion)
{ {
RegionDestroy(nxagentExposeQueueHead.remoteRegion); RegionDestroy(nxagentExposeQueueHead.remoteRegion);
} }
nxagentExposeQueueHead.remoteRegion = NullRegion; nxagentExposeQueueHead.remoteRegion = NullRegion;
nxagentExposeQueueHead.remoteRegionIsCompleted = False; nxagentExposeQueueHead.remoteRegionIsCompleted = False;
nxagentExposeQueue.start = (nxagentExposeQueue.start + 1) % EXPOSED_SIZE; nxagentExposeQueue.start = (nxagentExposeQueue.start + 1) % EXPOSED_SIZE;
...@@ -4197,13 +4037,11 @@ void nxagentRemoveDuplicatedKeys(XEvent *X) ...@@ -4197,13 +4037,11 @@ void nxagentRemoveDuplicatedKeys(XEvent *X)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentRemoveDuplicatedKeys: Trying to read more events " fprintf(stderr, "%s: Trying to read more events from the X server.\n", __func__);
"from the X server.\n");
if (nxagentReadEvents(nxagentDisplay) > 0) if (nxagentReadEvents(nxagentDisplay) > 0)
{ {
fprintf(stderr, "nxagentRemoveDuplicatedKeys: Successfully read more events " fprintf(stderr, "%s: Successfully read more events from the X server.\n", __func__);
"from the X server.\n");
} }
#else #else
...@@ -4280,7 +4118,7 @@ void nxagentInitRemoteExposeRegion(void) ...@@ -4280,7 +4118,7 @@ void nxagentInitRemoteExposeRegion(void)
if (nxagentRemoteExposeRegion == NULL) if (nxagentRemoteExposeRegion == NULL)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentInitRemoteExposeRegion: PANIC! Failed to create expose region.\n"); fprintf(stderr, "%s: PANIC! Failed to create expose region.\n", __func__);
#endif #endif
} }
} }
...@@ -4291,7 +4129,7 @@ void nxagentForwardRemoteExpose(void) ...@@ -4291,7 +4129,7 @@ void nxagentForwardRemoteExpose(void)
if (RegionNotEmpty(nxagentRemoteExposeRegion)) if (RegionNotEmpty(nxagentRemoteExposeRegion))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentForwardRemoteExpose: Going to forward events.\n"); fprintf(stderr, "%s: Going to forward events.\n", __func__);
#endif #endif
TraverseTree(screenInfo.screens[0]->root, nxagentClipAndSendExpose, (void *)nxagentRemoteExposeRegion); TraverseTree(screenInfo.screens[0]->root, nxagentClipAndSendExpose, (void *)nxagentRemoteExposeRegion);
...@@ -4306,13 +4144,12 @@ void nxagentForwardRemoteExpose(void) ...@@ -4306,13 +4144,12 @@ void nxagentForwardRemoteExpose(void)
void nxagentAddRectToRemoteExposeRegion(BoxPtr rect) void nxagentAddRectToRemoteExposeRegion(BoxPtr rect)
{ {
RegionRec exposeRegion;
if (nxagentRemoteExposeRegion == NULL) if (nxagentRemoteExposeRegion == NULL)
{ {
return; return;
} }
RegionRec exposeRegion;
RegionInit(&exposeRegion, rect, 1); RegionInit(&exposeRegion, rect, 1);
RegionUnion(nxagentRemoteExposeRegion, RegionUnion(nxagentRemoteExposeRegion,
...@@ -4326,7 +4163,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr) ...@@ -4326,7 +4163,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr)
RegionPtr remoteExposeRgn = (RegionRec *) ptr; RegionPtr remoteExposeRgn = (RegionRec *) ptr;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClipAndSendExpose: Called.\n"); fprintf(stderr, "%s: Called.\n", __func__);
#endif #endif
if (pWin -> drawable.class != InputOnly) if (pWin -> drawable.class != InputOnly)
...@@ -4336,12 +4173,12 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr) ...@@ -4336,12 +4173,12 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr)
#ifdef DEBUG #ifdef DEBUG
BoxRec box = *RegionExtents(remoteExposeRgn); BoxRec box = *RegionExtents(remoteExposeRgn);
fprintf(stderr, "nxagentClipAndSendExpose: Root expose extents: [%d] [%d] [%d] [%d].\n", fprintf(stderr, "%s: Root expose extents: [%d] [%d] [%d] [%d].\n", __func__,
box.x1, box.y1, box.x2, box.y2); box.x1, box.y1, box.x2, box.y2);
box = *RegionExtents(&pWin -> clipList); box = *RegionExtents(&pWin -> clipList);
fprintf(stderr, "nxagentClipAndSendExpose: Clip list extents for window at [%p]: [%d] [%d] [%d] [%d].\n", fprintf(stderr, "%s: Clip list extents for window at [%p]: [%d] [%d] [%d] [%d].\n", __func__,
(void *)pWin, box.x1, box.y1, box.x2, box.y2); (void *)pWin, box.x1, box.y1, box.x2, box.y2);
#endif #endif
...@@ -4350,14 +4187,13 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr) ...@@ -4350,14 +4187,13 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr)
if (RegionNotEmpty(exposeRgn)) if (RegionNotEmpty(exposeRgn))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClipAndSendExpose: Forwarding expose to window at [%p] pWin.\n", fprintf(stderr, "%s: Forwarding expose to window at [%p] pWin.\n", __func__,
(void *)pWin); (void *)pWin);
#endif #endif
/* /*
* The miWindowExposures() clears out the * The miWindowExposures() clears out the region parameters, so
* region parameters, so the subtract ope- * the subtract ope- ration must be done before calling it.
* ration must be done before calling it.
*/ */
RegionSubtract(remoteExposeRgn, remoteExposeRgn, exposeRgn); RegionSubtract(remoteExposeRgn, remoteExposeRgn, exposeRgn);
...@@ -4371,7 +4207,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr) ...@@ -4371,7 +4207,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr)
if (RegionNotEmpty(remoteExposeRgn)) if (RegionNotEmpty(remoteExposeRgn))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClipAndSendExpose: Region not empty. Walk children.\n"); fprintf(stderr, "%s: Region not empty. Walk children.\n", __func__);
#endif #endif
return WT_WALKCHILDREN; return WT_WALKCHILDREN;
...@@ -4379,7 +4215,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr) ...@@ -4379,7 +4215,7 @@ int nxagentClipAndSendExpose(WindowPtr pWin, void * ptr)
else else
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClipAndSendExpose: Region empty. Stop walking.\n"); fprintf(stderr, "%s: Region empty. Stop walking.\n", __func__);
#endif #endif
return WT_STOPWALKING; return WT_STOPWALKING;
...@@ -4391,13 +4227,10 @@ int nxagentUserInput(void *p) ...@@ -4391,13 +4227,10 @@ int nxagentUserInput(void *p)
int result = 0; int result = 0;
/* /*
* This function is used as callback in * This function is used as callback in the polling handler of agent
* the polling handler of agent in shadow * in shadow mode. When inside the polling loop the handlers are
* mode. When inside the polling loop the * never called, so we have to dispatch enqueued events to
* handlers are never called, so we have * eventually change the nxagentInputEvent status.
* to dispatch enqueued events to eventu-
* ally change the nxagentInputEvent sta-
* tus.
*/ */
if (nxagentOption(Shadow) == 1 && if (nxagentOption(Shadow) == 1 &&
...@@ -4414,11 +4247,9 @@ int nxagentUserInput(void *p) ...@@ -4414,11 +4247,9 @@ int nxagentUserInput(void *p)
} }
/* /*
* The agent working in shadow mode synch- * The agent working in shadow mode synchronizes the remote X server
* ronizes the remote X server even if a * even if a button/key is not released (i.e. when scrolling a long
* button/key is not released (i.e. when * browser's page), in order to update the screen smoothly.
* scrolling a long browser's page), in
* order to update the screen smoothly.
*/ */
if (nxagentOption(Shadow) == 1) if (nxagentOption(Shadow) == 1)
...@@ -4429,9 +4260,8 @@ int nxagentUserInput(void *p) ...@@ -4429,9 +4260,8 @@ int nxagentUserInput(void *p)
if (result == 0) if (result == 0)
{ {
/* /*
* If there is at least one button/key down, * If there is at least one button/key down, we are receiving an
* we are receiving an input. This is not a * input. This is not a condition to break a synchronization loop
* condition to break a synchronization loop
* if there is enough bandwidth. * if there is enough bandwidth.
*/ */
...@@ -4440,7 +4270,7 @@ int nxagentUserInput(void *p) ...@@ -4440,7 +4270,7 @@ int nxagentUserInput(void *p)
nxagentKeyDown > 0)) nxagentKeyDown > 0))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentUserInput: Buttons [%d] Keys [%d].\n", fprintf(stderr, "%s: Buttons [%d] Keys [%d].\n", __func__,
inputInfo.pointer -> button -> buttonsDown, nxagentKeyDown); inputInfo.pointer -> button -> buttonsDown, nxagentKeyDown);
#endif #endif
...@@ -4456,7 +4286,7 @@ int nxagentHandleRRScreenChangeNotify(XEvent *X) ...@@ -4456,7 +4286,7 @@ int nxagentHandleRRScreenChangeNotify(XEvent *X)
XRRScreenChangeNotifyEvent *Xr = (XRRScreenChangeNotifyEvent *) X; XRRScreenChangeNotifyEvent *Xr = (XRRScreenChangeNotifyEvent *) X;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentHandleRRScreenChangeNotify called.\n"); fprintf(stderr, "%s: Called.\n", __func__);
#endif #endif
nxagentResizeScreen(screenInfo.screens[DefaultScreen(nxagentDisplay)], Xr -> width, Xr -> height, nxagentResizeScreen(screenInfo.screens[DefaultScreen(nxagentDisplay)], Xr -> width, Xr -> height,
...@@ -4471,13 +4301,11 @@ int nxagentHandleRRScreenChangeNotify(XEvent *X) ...@@ -4471,13 +4301,11 @@ int nxagentHandleRRScreenChangeNotify(XEvent *X)
} }
/* /*
* Returns true if there is any event waiting to * Returns true if there is any event waiting to be dispatched. This
* be dispatched. This function is critical for * function is critical for the performance because it is called very,
* the performance because it is called very, * very often. It must also handle the case when the display is
* very often. It must also handle the case when * down. The display descriptor, in fact, may have been reused by some
* the display is down. The display descriptor, * other client.
* in fact, may have been reused by some other
* client.
*/ */
int nxagentPendingEvents(Display *dpy) int nxagentPendingEvents(Display *dpy)
...@@ -4485,7 +4313,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4485,7 +4313,7 @@ int nxagentPendingEvents(Display *dpy)
if (_XGetIOError(dpy) != 0) if (_XGetIOError(dpy) != 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentPendingEvents: Returning error with display down.\n"); fprintf(stderr, "%s: Returning error with display down.\n", __func__);
#endif #endif
return -1; return -1;
...@@ -4493,7 +4321,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4493,7 +4321,7 @@ int nxagentPendingEvents(Display *dpy)
else if (XQLength(dpy) > 0) else if (XQLength(dpy) > 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentPendingEvents: Returning true with [%d] events queued.\n", fprintf(stderr, "%s: Returning true with [%d] events queued.\n", __func__,
XQLength(dpy)); XQLength(dpy));
#endif #endif
...@@ -4508,7 +4336,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4508,7 +4336,7 @@ int nxagentPendingEvents(Display *dpy)
if (readable > 0) if (readable > 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentPendingEvents: Returning true with [%d] bytes readable.\n", fprintf(stderr, "%s: Returning true with [%d] bytes readable.\n", __func__,
readable); readable);
#endif #endif
...@@ -4516,7 +4344,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4516,7 +4344,7 @@ int nxagentPendingEvents(Display *dpy)
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentPendingEvents: Returning false with [%d] bytes readable.\n", fprintf(stderr, "%s: Returning false with [%d] bytes readable.\n", __func__,
readable); readable);
#endif #endif
...@@ -4524,7 +4352,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4524,7 +4352,7 @@ int nxagentPendingEvents(Display *dpy)
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentPendingEvents: WARNING! Error detected on the X display.\n"); fprintf(stderr, "%s: WARNING! Error detected on the X display.\n", __func__);
#endif #endif
NXForceDisplayError(dpy); NXForceDisplayError(dpy);
...@@ -4540,7 +4368,7 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4540,7 +4368,7 @@ int nxagentPendingEvents(Display *dpy)
int nxagentWaitEvents(Display *dpy, useconds_t msec) int nxagentWaitEvents(Display *dpy, useconds_t msec)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentWaitEvents called.\n"); fprintf(stderr, "%s: Called.\n", __func__);
#endif #endif
NXFlushDisplay(dpy, NXFlushLink); NXFlushDisplay(dpy, NXFlushLink);
...@@ -4625,37 +4453,26 @@ static const char *nxagentGrabStateToString(int state) ...@@ -4625,37 +4453,26 @@ static const char *nxagentGrabStateToString(int state)
{ {
switch (state) switch (state)
{ {
case 0: case 0: return "NOT_GRABBED";
return "NOT_GRABBED"; case 1: return "THAWED";
case 1: case 2: return "THAWED_BOTH";
return "THAWED"; case 3: return "FREEZE_NEXT_EVENT";
case 2: case 4: return "FREEZE_BOTH_NEXT_EVENT";
return "THAWED_BOTH"; case 5: return "FROZEN_NO_EVENT";
case 3: case 6: return "FROZEN_WITH_EVENT";
return "FREEZE_NEXT_EVENT"; case 7: return "THAW_OTHERS";
case 4: default: return "unknown state";
return "FREEZE_BOTH_NEXT_EVENT";
case 5:
return "FROZEN_NO_EVENT";
case 6:
return "FROZEN_WITH_EVENT";
case 7:
return "THAW_OTHERS";
default:
return "unknown state";
} }
} }
void nxagentDumpInputDevicesState(void) void nxagentDumpInputDevicesState(void)
{ {
DeviceIntPtr dev;
GrabPtr grab;
WindowPtr pWin = NULL; WindowPtr pWin = NULL;
fprintf(stderr, "\n*** Dump input devices state: BEGIN ***" fprintf(stderr, "\n*** Dump input devices state: BEGIN ***"
"\nKeys down:"); "\nKeys down:");
dev = inputInfo.keyboard; DeviceIntPtr dev = inputInfo.keyboard;
for (int i = 0; i < DOWN_LENGTH; i++) for (int i = 0; i < DOWN_LENGTH; i++)
{ {
...@@ -4683,7 +4500,7 @@ void nxagentDumpInputDevicesState(void) ...@@ -4683,7 +4500,7 @@ void nxagentDumpInputDevicesState(void)
dev -> fromPassiveGrab ? "Yes" : "No", dev -> fromPassiveGrab ? "Yes" : "No",
dev -> activatingKey); dev -> activatingKey);
grab = dev -> grab; GrabPtr grab = dev -> grab;
if (grab) if (grab)
{ {
......
...@@ -159,8 +159,7 @@ static struct _nxagentFailedToReconnectFonts ...@@ -159,8 +159,7 @@ static struct _nxagentFailedToReconnectFonts
} nxagentFailedToReconnectFonts = {NULL, NULL, 0, 0}; } nxagentFailedToReconnectFonts = {NULL, NULL, 0, 0};
/* /*
* This is used if nxagentFullGeneration is true * This is used if nxagentFullGeneration is true in CloseDisplay().
* in CloseDisplay().
*/ */
void nxagentFreeFontCache(void) void nxagentFreeFontCache(void)
...@@ -218,8 +217,7 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) ...@@ -218,8 +217,7 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames)
} }
/* /*
* Avoid querying again the remote * Avoid querying again the remote fonts.
* fonts.
*/ */
if (nxagentRemoteFontList.length > 0) if (nxagentRemoteFontList.length > 0)
...@@ -228,13 +226,11 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) ...@@ -228,13 +226,11 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames)
} }
/* /*
* We can't retrieve the full remote font * We can't retrieve the full remote font list with a single query,
* list with a single query, because the * because the number of dashes in the pattern acts as a rule to
* number of dashes in the pattern acts as * select how to search for the font names, so the pattern '*' is
* a rule to select how to search for the * useful to retrieve the font aliases, while the other one will
* font names, so the pattern '*' is useful * select the 'real' fonts.
* to retrieve the font aliases, while the
* other one will select the 'real' fonts.
*/ */
for (int p = 0; p < patternsQt; p++) for (int p = 0; p < patternsQt; p++)
...@@ -246,8 +242,8 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) ...@@ -246,8 +242,8 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames)
#endif #endif
/* /*
* Add the ListFont request pattern to the list with * Add the ListFont request pattern to the list with the last
* the last requested maxnames. * requested maxnames.
*/ */
nxagentListRemoteAddName(searchPattern, maxNames); nxagentListRemoteAddName(searchPattern, maxNames);
...@@ -686,11 +682,10 @@ int nxagentDestroyNewFontResourceType(void * p, XID id) ...@@ -686,11 +682,10 @@ int nxagentDestroyNewFontResourceType(void * p, XID id)
#endif #endif
/* /*
FIXME: It happens that this resource had been already FIXME: It happens that this resource had been already destroyed. We
destroyed. We should verify if the same font is should verify if the same font is assigned both to the server
assigned both to the server client and another client and another client. We had a crash when freeing server
client. We had a crash when freeing server client client resources.
resources.
*/ */
if (nxagentFontPriv((FontPtr) p) != NULL) if (nxagentFontPriv((FontPtr) p) != NULL)
{ {
...@@ -706,14 +701,12 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -706,14 +701,12 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
char substFontBuf[512];; char substFontBuf[512];;
/* X Logical Font Description Conventions /* X Logical Font Description Conventions require 14 fields in the
* require 14 fields in the font names. * font names.
* *
*/ */
char *searchFields[FIELDS+1]; char *searchFields[FIELDS+1];
char *fontNameFields[FIELDS+1]; char *fontNameFields[FIELDS+1];
int i;
int j;
int numSearchFields = 0; int numSearchFields = 0;
int numFontFields = 0; int numFontFields = 0;
int weight = 0; int weight = 0;
...@@ -753,7 +746,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -753,7 +746,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
} }
else else
{ {
for (i = 1 ; i < nxagentRemoteFontList.length ; i++) for (int i = 1 ; i < nxagentRemoteFontList.length ; i++)
{ {
numSearchFields = nxagentSplitString(nxagentRemoteFontList.list[i]->name, searchFields, FIELDS+1, "-"); numSearchFields = nxagentSplitString(nxagentRemoteFontList.list[i]->name, searchFields, FIELDS+1, "-");
...@@ -778,7 +771,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -778,7 +771,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
tempWeight = 0; tempWeight = 0;
for (j = 0; j < FIELDS; j++) for (int j = 0; j < FIELDS; j++)
{ {
if (strcasecmp(searchFields[fieldOrder[j]], fontNameFields[fieldOrder[j]]) == 0 || if (strcasecmp(searchFields[fieldOrder[j]], fontNameFields[fieldOrder[j]]) == 0 ||
strcmp(searchFields[fieldOrder[j]], "") == 0 || strcmp(searchFields[fieldOrder[j]], "") == 0 ||
...@@ -806,7 +799,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -806,7 +799,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
#endif #endif
} }
for (j = 0; j < numSearchFields; j++) for (int j = 0; j < numSearchFields; j++)
{ {
SAFE_free(searchFields[j]); SAFE_free(searchFields[j]);
} }
...@@ -823,7 +816,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -823,7 +816,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
fontStruct = nxagentLoadQueryFont(dpy, substFontBuf, pFont); fontStruct = nxagentLoadQueryFont(dpy, substFontBuf, pFont);
for (j = 0; j < numFontFields; j++) for (int j = 0; j < numFontFields; j++)
{ {
SAFE_free(fontNameFields[j]); SAFE_free(fontNameFields[j]);
} }
...@@ -833,13 +826,12 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -833,13 +826,12 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2)
{ {
nxagentPrivFont *privFont;
Bool *pBool = (Bool*)param2; Bool *pBool = (Bool*)param2;
if (pFont == NULL || !*pBool) if (pFont == NULL || !*pBool)
return; return;
privFont = nxagentFontPriv(pFont); nxagentPrivFont *privFont = nxagentFontPriv(pFont);
#ifdef NXAGENT_RECONNECT_FONT_DEBUG #ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf(stderr, "nxagentFontDisconnect: pFont %p, XID %lx\n", fprintf(stderr, "nxagentFontDisconnect: pFont %p, XID %lx\n",
...@@ -936,13 +928,12 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id) ...@@ -936,13 +928,12 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id)
static void nxagentFontReconnect(FontPtr pFont, XID param1, void * param2) static void nxagentFontReconnect(FontPtr pFont, XID param1, void * param2)
{ {
int i; int i;
nxagentPrivFont *privFont;
Bool *pBool = (Bool*)param2; Bool *pBool = (Bool*)param2;
if (pFont == NULL) if (pFont == NULL)
return; return;
privFont = nxagentFontPriv(pFont); nxagentPrivFont *privFont = nxagentFontPriv(pFont);
#ifdef NXAGENT_RECONNECT_FONT_DEBUG #ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf(stderr, "nxagentFontReconnect: pFont %p - XID %lx - name %s\n", fprintf(stderr, "nxagentFontReconnect: pFont %p - XID %lx - name %s\n",
...@@ -1067,8 +1058,7 @@ static void nxagentCleanCacheAfterReconnect(void) ...@@ -1067,8 +1058,7 @@ static void nxagentCleanCacheAfterReconnect(void)
for (j = CACHE_INDEX - 1; CACHE_FSTRUCT(j) == NULL; j--); for (j = CACHE_INDEX - 1; CACHE_FSTRUCT(j) == NULL; j--);
/* /*
* Now we can swap the two entry * Now we can swap the two entry and reduce the Cache index
* and reduce the Cache index
*/ */
swapEntryPtr = CACHE_ENTRY(i); swapEntryPtr = CACHE_ENTRY(i);
CACHE_ENTRY(i) = CACHE_ENTRY(j); CACHE_ENTRY(i) = CACHE_ENTRY(j);
...@@ -1109,9 +1099,8 @@ Bool nxagentReconnectAllFonts(void *p0) ...@@ -1109,9 +1099,8 @@ Bool nxagentReconnectAllFonts(void *p0)
#endif #endif
/* /*
* The resource type RT_NX_FONT is created on the * The resource type RT_NX_FONT is created on the server client
* server client only, so we can avoid to loop * only, so we can avoid to loop through all the clients.
* through all the clients.
*/ */
FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT,
...@@ -1341,9 +1330,8 @@ Bool nxagentDisconnectAllFonts(void) ...@@ -1341,9 +1330,8 @@ Bool nxagentDisconnectAllFonts(void)
nxagentFreeCacheBeforeReconnect(); nxagentFreeCacheBeforeReconnect();
/* /*
* The resource type RT_NX_FONT is created on the * The resource type RT_NX_FONT is created on the server client
* server client only, so we can avoid to loop * only, so we can avoid to loop through all the clients.
* through all the clients.
*/ */
FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT,
...@@ -1630,26 +1618,17 @@ int nxagentFreeFont(XFontStruct *fs) ...@@ -1630,26 +1618,17 @@ int nxagentFreeFont(XFontStruct *fs)
int nxagentSplitString(char *string, char *fields[], int nfields, char *sep) int nxagentSplitString(char *string, char *fields[], int nfields, char *sep)
{ {
int seplen; int seplen = strlen(sep);
int fieldlen; int len = strlen(string);
int last;
int len;
int i;
char *current;
char *next;
seplen = strlen(sep);
len = strlen(string);
current = string; char *current = string;
i = 0; int i = 0;
last = 0; int last = 0;
for (;;) for (;;)
{ {
next = NULL; char *next = NULL;
if (current < string + len) if (current < string + len)
{ {
...@@ -1662,7 +1641,7 @@ int nxagentSplitString(char *string, char *fields[], int nfields, char *sep) ...@@ -1662,7 +1641,7 @@ int nxagentSplitString(char *string, char *fields[], int nfields, char *sep)
last = 1; last = 1;
} }
fieldlen = next - current; int fieldlen = next - current;
if (i < nfields) if (i < nfields)
{ {
...@@ -1689,8 +1668,6 @@ int nxagentSplitString(char *string, char *fields[], int nfields, char *sep) ...@@ -1689,8 +1668,6 @@ int nxagentSplitString(char *string, char *fields[], int nfields, char *sep)
char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution) char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution)
{ {
char *scalableFontName; char *scalableFontName;
const char *s;
int field;
/* FIXME: use str(n)dup()? */ /* FIXME: use str(n)dup()? */
if ((scalableFontName = malloc(strlen(fontName) + 1)) == NULL) if ((scalableFontName = malloc(strlen(fontName) + 1)) == NULL)
...@@ -1709,9 +1686,9 @@ char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution) ...@@ -1709,9 +1686,9 @@ char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution)
goto MakeScalableFontNameError; goto MakeScalableFontNameError;
} }
s = fontName; const char *s = fontName;
field = 0; int field = 0;
while (s != NULL) while (s != NULL)
{ {
......
...@@ -66,6 +66,7 @@ is" without express or implied warranty. ...@@ -66,6 +66,7 @@ is" without express or implied warranty.
#include "../../fb/fb.h" #include "../../fb/fb.h"
RESTYPE RT_NX_GC; RESTYPE RT_NX_GC;
/* /*
* Set here the required log level. * Set here the required log level.
*/ */
...@@ -142,8 +143,6 @@ static GCOps nxagentOps = ...@@ -142,8 +143,6 @@ static GCOps nxagentOps =
Bool nxagentCreateGC(GCPtr pGC) Bool nxagentCreateGC(GCPtr pGC)
{ {
FbGCPrivPtr pPriv;
pGC->clientClipType = CT_NONE; pGC->clientClipType = CT_NONE;
pGC->clientClip = NULL; pGC->clientClip = NULL;
...@@ -163,11 +162,9 @@ Bool nxagentCreateGC(GCPtr pGC) ...@@ -163,11 +162,9 @@ Bool nxagentCreateGC(GCPtr pGC)
} }
/* /*
* We create the GC based on the default * We create the GC based on the default drawables. The proxy knows
* drawables. The proxy knows this and * this and optimizes the encoding of the create GC message to
* optimizes the encoding of the create * include the id of the drawable in the checksum.
* GC message to include the id of the
* drawable in the checksum.
*/ */
nxagentGCPriv(pGC)->gc = XCreateGC(nxagentDisplay, nxagentGCPriv(pGC)->gc = XCreateGC(nxagentDisplay,
...@@ -178,7 +175,7 @@ Bool nxagentCreateGC(GCPtr pGC) ...@@ -178,7 +175,7 @@ Bool nxagentCreateGC(GCPtr pGC)
fprintf(stderr, "nxagentCreateGC: GC [%p]\n", (void *) pGC); fprintf(stderr, "nxagentCreateGC: GC [%p]\n", (void *) pGC);
#endif #endif
pPriv = (pGC)->devPrivates[fbGCPrivateIndex].ptr; FbGCPrivPtr pPriv = (pGC)->devPrivates[fbGCPrivateIndex].ptr;
fbGetRotatedPixmap(pGC) = 0; fbGetRotatedPixmap(pGC) = 0;
fbGetExpose(pGC) = 1; fbGetExpose(pGC) = 1;
...@@ -187,24 +184,18 @@ Bool nxagentCreateGC(GCPtr pGC) ...@@ -187,24 +184,18 @@ Bool nxagentCreateGC(GCPtr pGC)
pPriv->bpp = BitsPerPixel (pGC->depth); pPriv->bpp = BitsPerPixel (pGC->depth);
nxagentGCPriv(pGC)->nClipRects = 0;
memset(&(nxagentGCPriv(pGC) -> lastServerValues), 0, sizeof(XGCValues));
/* /*
* Init to default GC values. * Init to default GC values.
*/ */
memset(&(nxagentGCPriv(pGC) -> lastServerValues), 0, sizeof(XGCValues));
nxagentGCPriv(pGC) -> lastServerValues.background = 1; nxagentGCPriv(pGC) -> lastServerValues.background = 1;
nxagentGCPriv(pGC) -> lastServerValues.plane_mask = ~0; nxagentGCPriv(pGC) -> lastServerValues.plane_mask = ~0;
nxagentGCPriv(pGC) -> lastServerValues.graphics_exposures = 1; nxagentGCPriv(pGC) -> lastServerValues.graphics_exposures = 1;
nxagentGCPriv(pGC) -> lastServerValues.dashes = 4; nxagentGCPriv(pGC) -> lastServerValues.dashes = 4;
nxagentGCPriv(pGC) -> nClipRects = 0;
nxagentGCPriv(pGC) -> mid = FakeClientID(serverClient -> index); nxagentGCPriv(pGC) -> mid = FakeClientID(serverClient -> index);
nxagentGCPriv(pGC) -> pPixmap = NULL; nxagentGCPriv(pGC) -> pPixmap = NULL;
AddResource(nxagentGCPriv(pGC) -> mid, RT_NX_GC, (void *) pGC); AddResource(nxagentGCPriv(pGC) -> mid, RT_NX_GC, (void *) pGC);
...@@ -214,8 +205,6 @@ Bool nxagentCreateGC(GCPtr pGC) ...@@ -214,8 +205,6 @@ Bool nxagentCreateGC(GCPtr pGC)
void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
{ {
PixmapPtr lastTile, lastStipple;
DrawablePtr pVirtual = (pDrawable -> type == DRAWABLE_PIXMAP) ? DrawablePtr pVirtual = (pDrawable -> type == DRAWABLE_PIXMAP) ?
nxagentVirtualDrawable(pDrawable) : nxagentVirtualDrawable(pDrawable) :
pDrawable; pDrawable;
...@@ -233,9 +222,9 @@ void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) ...@@ -233,9 +222,9 @@ void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
pGC -> tile.pixmap = nxagentVirtualPixmap(pGC -> tile.pixmap); pGC -> tile.pixmap = nxagentVirtualPixmap(pGC -> tile.pixmap);
} }
lastTile = pGC -> tile.pixmap; PixmapPtr lastTile = pGC -> tile.pixmap;
lastStipple = pGC->stipple; PixmapPtr lastStipple = pGC->stipple;
if (lastStipple) if (lastStipple)
{ {
...@@ -251,8 +240,8 @@ void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) ...@@ -251,8 +240,8 @@ void nxagentValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
if (pVirtual -> bitsPerPixel == 0) if (pVirtual -> bitsPerPixel == 0)
{ {
/* /*
* Don't enter fbValidateGC() with 0 bpp * Don't enter fbValidateGC() with 0 bpp or agent will block in a
* or agent will block in a endless loop. * endless loop.
*/ */
#ifdef WARNING #ifdef WARNING
...@@ -331,13 +320,11 @@ void nxagentChangeGC(GCPtr pGC, unsigned long mask) ...@@ -331,13 +320,11 @@ void nxagentChangeGC(GCPtr pGC, unsigned long mask)
nxagentGCTrap == 0) nxagentGCTrap == 0)
{ {
/* /*
* If the tile is corrupted and is not too * If the tile is corrupted and is not too large, it can be
* much large, it can be synchronized imme- * synchronized immediately. In the other cases, the tile is
* diately. In the other cases, the tile is * cleared with a solid color to become usable. This approach
* cleared with a solid color to become usa- * should solve the high delay on slow links waiting for a
* ble. This approach should solve the high * background tile to be synchronized.
* delay on slow links waiting for a back-
* ground tile to be synchronized.
*/ */
if (nxagentOption(DeferLevel) >= 2 && if (nxagentOption(DeferLevel) >= 2 &&
...@@ -473,7 +460,7 @@ void nxagentCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) ...@@ -473,7 +460,7 @@ void nxagentCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCopyGC: Copying the GC with source at [%p] destination " fprintf(stderr, "nxagentCopyGC: Copying the GC with source at [%p] destination "
"at [%p] mask [%lu].\n", pGCSrc, pGCDst, mask); "at [%p] mask [%lu].\n", (void *)pGCSrc, (void *)pGCDst, mask);
#endif #endif
/* /*
...@@ -485,8 +472,8 @@ void nxagentCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) ...@@ -485,8 +472,8 @@ void nxagentCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
XCopyGC(nxagentDisplay, nxagentGC(pGCSrc), mask, nxagentGC(pGCDst)); XCopyGC(nxagentDisplay, nxagentGC(pGCSrc), mask, nxagentGC(pGCDst));
/* /*
* Copy the private foreground field * Copy the private foreground field of the GC if GCForeground is
* of the GC if GCForeground is set. * set.
*/ */
nxagentCopyGCPriv(GCForeground,foreground,pGCSrc,mask,pGCDst); nxagentCopyGCPriv(GCForeground,foreground,pGCSrc,mask,pGCDst);
...@@ -510,9 +497,6 @@ void nxagentDestroyGC(GCPtr pGC) ...@@ -510,9 +497,6 @@ void nxagentDestroyGC(GCPtr pGC)
void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
{ {
int i, size;
BoxPtr pBox;
XRectangle *pRects;
int clipsMatch = 0; int clipsMatch = 0;
#ifdef TEST #ifdef TEST
...@@ -525,13 +509,11 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -525,13 +509,11 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
case CT_NONE: case CT_NONE:
{ {
clipsMatch = (pGC -> clientClipType == None); clipsMatch = (pGC -> clientClipType == None);
break; break;
} }
case CT_REGION: case CT_REGION:
{ {
clipsMatch = nxagentCompareRegions(pGC -> clientClip, (RegionPtr) pValue); clipsMatch = nxagentCompareRegions(pGC -> clientClip, (RegionPtr) pValue);
break; break;
} }
case CT_UNSORTED: case CT_UNSORTED:
...@@ -540,17 +522,13 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -540,17 +522,13 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
case CT_YXBANDED: case CT_YXBANDED:
{ {
RegionPtr pReg = RegionFromRects(nRects, (xRectangle *)pValue, type); RegionPtr pReg = RegionFromRects(nRects, (xRectangle *)pValue, type);
clipsMatch = nxagentCompareRegions(pGC -> clientClip, pReg); clipsMatch = nxagentCompareRegions(pGC -> clientClip, pReg);
RegionDestroy(pReg); RegionDestroy(pReg);
break; break;
} }
default: default:
{ {
clipsMatch = 0; clipsMatch = 0;
break; break;
} }
} }
...@@ -570,19 +548,19 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -570,19 +548,19 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
{ {
XSetClipMask(nxagentDisplay, nxagentGC(pGC), None); XSetClipMask(nxagentDisplay, nxagentGC(pGC), None);
} }
break; break;
} }
case CT_REGION: case CT_REGION:
{ {
if (clipsMatch == 0 && nxagentGCTrap == 0) if (clipsMatch == 0 && nxagentGCTrap == 0)
{ {
XRectangle *pRects;
nRects = RegionNumRects((RegionPtr)pValue); nRects = RegionNumRects((RegionPtr)pValue);
size = nRects * sizeof(*pRects); int size = nRects * sizeof(*pRects);
pRects = (XRectangle *) malloc(size); pRects = (XRectangle *) malloc(size);
pBox = RegionRects((RegionPtr)pValue); BoxPtr pBox = RegionRects((RegionPtr)pValue);
for (i = nRects; i-- > 0;) for (int i = nRects; i-- > 0;)
{ {
pRects[i].x = pBox[i].x1; pRects[i].x = pBox[i].x1;
pRects[i].y = pBox[i].y1; pRects[i].y = pBox[i].y1;
...@@ -594,7 +572,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -594,7 +572,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pRects, nRects, Unsorted); pRects, nRects, Unsorted);
SAFE_free(pRects); SAFE_free(pRects);
} }
break; break;
} }
case CT_PIXMAP: case CT_PIXMAP:
...@@ -623,7 +600,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -623,7 +600,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, Unsorted); (XRectangle *)pValue, nRects, Unsorted);
} }
break; break;
} }
case CT_YSORTED: case CT_YSORTED:
...@@ -634,7 +610,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -634,7 +610,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, YSorted); (XRectangle *)pValue, nRects, YSorted);
} }
break; break;
} }
case CT_YXSORTED: case CT_YXSORTED:
...@@ -645,7 +620,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -645,7 +620,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, YXSorted); (XRectangle *)pValue, nRects, YXSorted);
} }
break; break;
} }
case CT_YXBANDED: case CT_YXBANDED:
...@@ -656,7 +630,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -656,7 +630,6 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, YXBanded); (XRectangle *)pValue, nRects, YXBanded);
} }
break; break;
} }
} }
...@@ -669,9 +642,8 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -669,9 +642,8 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
case CT_YXBANDED: case CT_YXBANDED:
{ {
/* /*
* Other parts of the server can only * Other parts of the server can only deal with CT_NONE,
* deal with CT_NONE, CT_PIXMAP and * CT_PIXMAP and CT_REGION client clips.
* CT_REGION client clips.
*/ */
pGC->clientClip = (void *) RegionFromRects(nRects, pGC->clientClip = (void *) RegionFromRects(nRects,
...@@ -742,8 +714,6 @@ void nxagentDestroyClipHelper(GCPtr pGC) ...@@ -742,8 +714,6 @@ void nxagentDestroyClipHelper(GCPtr pGC)
void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc) void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
{ {
RegionPtr pRgn;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCopyClip: Going to copy clip from GC [%p] to GC [%p]\n", fprintf(stderr, "nxagentCopyClip: Going to copy clip from GC [%p] to GC [%p]\n",
(void *) pGCDst, (void *) pGCSrc); (void *) pGCDst, (void *) pGCSrc);
...@@ -754,7 +724,7 @@ void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc) ...@@ -754,7 +724,7 @@ void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
case CT_REGION: case CT_REGION:
if (nxagentGCPriv(pGCSrc)->pPixmap == NULL) if (nxagentGCPriv(pGCSrc)->pPixmap == NULL)
{ {
pRgn = RegionCreate(NULL, 1); RegionPtr pRgn = RegionCreate(NULL, 1);
RegionCopy(pRgn, pGCSrc->clientClip); RegionCopy(pRgn, pGCSrc->clientClip);
nxagentChangeClip(pGCDst, CT_REGION, pRgn, 0); nxagentChangeClip(pGCDst, CT_REGION, pRgn, 0);
} }
...@@ -777,11 +747,9 @@ void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc) ...@@ -777,11 +747,9 @@ void nxagentCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
nxagentChangeClip(pGCDst, CT_PIXMAP, pGCSrc->clientClip, 0); nxagentChangeClip(pGCDst, CT_PIXMAP, pGCSrc->clientClip, 0);
break; break;
case CT_NONE: case CT_NONE:
nxagentDestroyClip(pGCDst); nxagentDestroyClip(pGCDst);
break; break;
} }
} }
...@@ -896,7 +864,7 @@ int nxagentDestroyNewGCResourceType(void * p, XID id) ...@@ -896,7 +864,7 @@ int nxagentDestroyNewGCResourceType(void * p, XID id)
*/ */
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentDestroyNewGCResourceType: Destroying mirror id [%ld] for GC at [%p].\n", fprintf(stderr, "nxagentDestroyNewGCResourceType: Destroying mirror id [%u] for GC at [%p].\n",
nxagentGCPriv((GCPtr) p) -> mid, (void *) p); nxagentGCPriv((GCPtr) p) -> mid, (void *) p);
#endif #endif
...@@ -1029,7 +997,6 @@ static void nxagentReconnectGC(void *param0, XID param1, void * param2) ...@@ -1029,7 +997,6 @@ static void nxagentReconnectGC(void *param0, XID param1, void * param2)
Bool nxagentReconnectAllGCs(void *p0) Bool nxagentReconnectAllGCs(void *p0)
{ {
int cid;
Bool GCSuccess = True; Bool GCSuccess = True;
#ifdef DEBUG #ifdef DEBUG
...@@ -1037,14 +1004,13 @@ Bool nxagentReconnectAllGCs(void *p0) ...@@ -1037,14 +1004,13 @@ Bool nxagentReconnectAllGCs(void *p0)
#endif #endif
/* /*
* The resource type RT_NX_GC is created on the * The resource type RT_NX_GC is created on the server client only,
* server client only, so we can avoid to loop * so we can avoid to loop through all the clients.
* through all the clients.
*/ */
FindClientResourcesByType(clients[serverClient -> index], RT_NX_GC, nxagentReconnectGC, &GCSuccess); FindClientResourcesByType(clients[serverClient -> index], RT_NX_GC, nxagentReconnectGC, &GCSuccess);
for (cid = 0; (cid < MAXCLIENTS) && GCSuccess; cid++) for (int cid = 0; (cid < MAXCLIENTS) && GCSuccess; cid++)
{ {
if (clients[cid]) if (clients[cid])
{ {
...@@ -1076,21 +1042,18 @@ void nxagentDisconnectGC(void * p0, XID x1, void * p2) ...@@ -1076,21 +1042,18 @@ void nxagentDisconnectGC(void * p0, XID x1, void * p2)
fprintf(stderr, "nxagentDisconnectGC: WARNING! pGC is NULL.\n"); fprintf(stderr, "nxagentDisconnectGC: WARNING! pGC is NULL.\n");
#endif #endif
} }
return; return;
} }
if (pGC -> stipple) if (pGC -> stipple)
{ {
PixmapPtr pMap = pGC -> stipple; PixmapPtr pMap = pGC -> stipple;
nxagentDisconnectPixmap(nxagentRealPixmap(pMap), 0, pBool); nxagentDisconnectPixmap(nxagentRealPixmap(pMap), 0, pBool);
} }
} }
Bool nxagentDisconnectAllGCs(void) Bool nxagentDisconnectAllGCs(void)
{ {
int cid;
Bool success = True; Bool success = True;
#ifdef DEBUG #ifdef DEBUG
...@@ -1098,15 +1061,14 @@ Bool nxagentDisconnectAllGCs(void) ...@@ -1098,15 +1061,14 @@ Bool nxagentDisconnectAllGCs(void)
#endif #endif
/* /*
* The resource type RT_NX_GC is created on the * The resource type RT_NX_GC is created on the server client only,
* server client only, so we can avoid to loop * so we can avoid to loop through all the clients.
* through all the clients.
*/ */
FindClientResourcesByType(clients[serverClient -> index], RT_NX_GC, FindClientResourcesByType(clients[serverClient -> index], RT_NX_GC,
(FindResType) nxagentDisconnectGC, &success); (FindResType) nxagentDisconnectGC, &success);
for (cid = 0; (cid < MAXCLIENTS) && success; cid++) for (int cid = 0; (cid < MAXCLIENTS) && success; cid++)
{ {
if (clients[cid]) if (clients[cid])
{ {
...@@ -1132,10 +1094,6 @@ Bool nxagentDisconnectAllGCs(void) ...@@ -1132,10 +1094,6 @@ Bool nxagentDisconnectAllGCs(void)
static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
{ {
int i, size;
BoxPtr pBox;
XRectangle *pRects;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentReconnectClip: going to change clip on GC [%p]\n", fprintf(stderr, "nxagentReconnectClip: going to change clip on GC [%p]\n",
(void *) pGC); (void *) pGC);
...@@ -1152,15 +1110,14 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1152,15 +1110,14 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
case CT_NONE: case CT_NONE:
XSetClipMask(nxagentDisplay, nxagentGC(pGC), None); XSetClipMask(nxagentDisplay, nxagentGC(pGC), None);
break; break;
case CT_REGION: case CT_REGION:
if (nxagentGCPriv(pGC)->pPixmap == NULL) if (nxagentGCPriv(pGC)->pPixmap == NULL)
{ {
nRects = RegionNumRects((RegionPtr)pValue); nRects = RegionNumRects((RegionPtr)pValue);
size = nRects * sizeof(*pRects); int size = nRects * sizeof(XRectangle *);
pRects = (XRectangle *) malloc(size); XRectangle *pRects = (XRectangle *) malloc(size);
pBox = RegionRects((RegionPtr)pValue); BoxPtr pBox = RegionRects((RegionPtr)pValue);
for (i = nRects; i-- > 0;) { for (int i = nRects; i-- > 0;) {
pRects[i].x = pBox[i].x1; pRects[i].x = pBox[i].x1;
pRects[i].y = pBox[i].y1; pRects[i].y = pBox[i].y1;
pRects[i].width = pBox[i].x2 - pBox[i].x1; pRects[i].width = pBox[i].x2 - pBox[i].x1;
...@@ -1168,10 +1125,9 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1168,10 +1125,9 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
} }
/* /*
* Originally, the clip origin area were 0,0 * Originally, the clip origin area were 0,0 but it didn't
* but it didn't work with kedit and family, * work with kedit and family, because it got the clip mask of
* because it got the clip mask of the pixmap * the pixmap all traslated.
* all traslated.
*/ */
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y, XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y,
...@@ -1185,11 +1141,8 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1185,11 +1141,8 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
XSetClipOrigin(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y); XSetClipOrigin(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y);
} }
break; break;
case CT_PIXMAP: case CT_PIXMAP:
XSetClipMask(nxagentDisplay, nxagentGC(pGC), XSetClipMask(nxagentDisplay, nxagentGC(pGC),
nxagentPixmap((PixmapPtr)pValue)); nxagentPixmap((PixmapPtr)pValue));
...@@ -1204,25 +1157,21 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1204,25 +1157,21 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
type = CT_REGION; type = CT_REGION;
break; break;
case CT_UNSORTED: case CT_UNSORTED:
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), XSetClipRectangles(nxagentDisplay, nxagentGC(pGC),
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, Unsorted); (XRectangle *)pValue, nRects, Unsorted);
break; break;
case CT_YSORTED: case CT_YSORTED:
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), XSetClipRectangles(nxagentDisplay, nxagentGC(pGC),
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, YSorted); (XRectangle *)pValue, nRects, YSorted);
break; break;
case CT_YXSORTED: case CT_YXSORTED:
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), XSetClipRectangles(nxagentDisplay, nxagentGC(pGC),
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
(XRectangle *)pValue, nRects, YXSorted); (XRectangle *)pValue, nRects, YXSorted);
break; break;
case CT_YXBANDED: case CT_YXBANDED:
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), XSetClipRectangles(nxagentDisplay, nxagentGC(pGC),
pGC->clipOrg.x, pGC->clipOrg.y, pGC->clipOrg.x, pGC->clipOrg.y,
...@@ -1241,8 +1190,8 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1241,8 +1190,8 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
case CT_YXBANDED: case CT_YXBANDED:
/* /*
* other parts of server can only deal with CT_NONE, * other parts of server can only deal with CT_NONE, CT_PIXMAP
* CT_PIXMAP and CT_REGION client clips. * and CT_REGION client clips.
*/ */
pGC->clientClip = (void *) RegionFromRects(nRects, pGC->clientClip = (void *) RegionFromRects(nRects,
...@@ -1262,8 +1211,6 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1262,8 +1211,6 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2) static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2)
{ {
int i;
/* /*
* It returns 1 if regions are equal, 0 otherwise * It returns 1 if regions are equal, 0 otherwise
*/ */
...@@ -1292,7 +1239,7 @@ static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2) ...@@ -1292,7 +1239,7 @@ static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2)
else if ((*RegionExtents(r1)).y2 != (*RegionExtents(r2)).y2) return 0; else if ((*RegionExtents(r1)).y2 != (*RegionExtents(r2)).y2) return 0;
else else
{ {
for (i = 0; i < RegionNumRects(r1); i++) for (int i = 0; i < RegionNumRects(r1); i++)
{ {
if (RegionRects(r1)[i].x1 != RegionRects(r2)[i].x1) return 0; if (RegionRects(r1)[i].x1 != RegionRects(r2)[i].x1) return 0;
else if (RegionRects(r1)[i].x2 != RegionRects(r2)[i].x2) return 0; else if (RegionRects(r1)[i].x2 != RegionRects(r2)[i].x2) return 0;
...@@ -1300,23 +1247,19 @@ static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2) ...@@ -1300,23 +1247,19 @@ static int nxagentCompareRegions(RegionPtr r1, RegionPtr r2)
else if (RegionRects(r1)[i].y2 != RegionRects(r2)[i].y2) return 0; else if (RegionRects(r1)[i].y2 != RegionRects(r2)[i].y2) return 0;
} }
} }
return 1; return 1;
} }
/* /*
* This function have to be called in the place * This function have to be called in the place of GetScratchGC if the
* of GetScratchGC if the GC will be used to per- * GC will be used to perform operations also on the remote X Server.
* form operations also on the remote X Server. * This is why we call the XChangeGC at the end of the function.
* This is why we call the XChangeGC at the end of
* the function.
*/ */
GCPtr nxagentGetScratchGC(unsigned depth, ScreenPtr pScreen) GCPtr nxagentGetScratchGC(unsigned depth, ScreenPtr pScreen)
{ {
/* /*
* The GC trap is temporarily disabled in * The GC trap is temporarily disabled in order to allow the remote
* order to allow the remote clipmask reset * clipmask reset requested by GetScratchGC().
* requested by GetScratchGC().
*/ */
int nxagentSaveGCTrap = nxagentGCTrap; int nxagentSaveGCTrap = nxagentGCTrap;
...@@ -1368,8 +1311,7 @@ GCPtr nxagentGetScratchGC(unsigned depth, ScreenPtr pScreen) ...@@ -1368,8 +1311,7 @@ GCPtr nxagentGetScratchGC(unsigned depth, ScreenPtr pScreen)
} }
/* /*
* This function is only a wrapper for * This function is only a wrapper for FreeScratchGC.
* FreeScratchGC.
*/ */
void nxagentFreeScratchGC(GCPtr pGC) void nxagentFreeScratchGC(GCPtr pGC)
{ {
...@@ -1386,18 +1328,14 @@ void nxagentFreeScratchGC(GCPtr pGC) ...@@ -1386,18 +1328,14 @@ void nxagentFreeScratchGC(GCPtr pGC)
} }
/* /*
* The GCs belonging to this list are used * The GCs belonging to this list are used only in the synchronization
* only in the synchronization put images, * put images, to be sure they preserve the default values and to
* to be sure they preserve the default va- * avoid XChangeGC() requests.
* lues and to avoid XChangeGC() requests.
*/ */
GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable) GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable)
{ {
int i; for (int i = 0; i < nxagentGraphicContextsSize; i++)
int result;
for (i = 0; i < nxagentGraphicContextsSize; i++)
{ {
if (pDrawable -> depth == nxagentGraphicContexts[i].depth) if (pDrawable -> depth == nxagentGraphicContexts[i].depth)
{ {
...@@ -1416,7 +1354,7 @@ GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable) ...@@ -1416,7 +1354,7 @@ GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable)
fprintf(stderr, "nxagentGetGraphicContext: Going to reconnect the GC.\n"); fprintf(stderr, "nxagentGetGraphicContext: Going to reconnect the GC.\n");
#endif #endif
result = 1; int result = 1;
nxagentReconnectGC(nxagentGraphicContexts[i].pGC, (XID) 0, &result); nxagentReconnectGC(nxagentGraphicContexts[i].pGC, (XID) 0, &result);
...@@ -1441,18 +1379,12 @@ GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable) ...@@ -1441,18 +1379,12 @@ GCPtr nxagentGetGraphicContext(DrawablePtr pDrawable)
GCPtr nxagentCreateGraphicContext(int depth) GCPtr nxagentCreateGraphicContext(int depth)
{ {
GCPtr pGC;
nxagentGraphicContextsPtr nxagentGCs;
XID attributes[2];
/* /*
* We have not found a GC, so we have * We have not found a GC, so we have to spread the list and add a
* to spread the list and add a new GC. * new GC.
*/ */
nxagentGCs = realloc(nxagentGraphicContexts, (nxagentGraphicContextsSize + 1) * sizeof(nxagentGraphicContextsRec)); nxagentGraphicContextsPtr nxagentGCs = realloc(nxagentGraphicContexts, (nxagentGraphicContextsSize + 1) * sizeof(nxagentGraphicContextsRec));
if (nxagentGCs == NULL) if (nxagentGCs == NULL)
{ {
...@@ -1465,7 +1397,7 @@ GCPtr nxagentCreateGraphicContext(int depth) ...@@ -1465,7 +1397,7 @@ GCPtr nxagentCreateGraphicContext(int depth)
nxagentGraphicContexts = nxagentGCs; nxagentGraphicContexts = nxagentGCs;
pGC = CreateScratchGC(nxagentDefaultScreen, depth); GCPtr pGC = CreateScratchGC(nxagentDefaultScreen, depth);
if (pGC == NULL) if (pGC == NULL)
{ {
...@@ -1481,6 +1413,8 @@ GCPtr nxagentCreateGraphicContext(int depth) ...@@ -1481,6 +1413,8 @@ GCPtr nxagentCreateGraphicContext(int depth)
* Color used in nxagentFillRemoteRegion(). * Color used in nxagentFillRemoteRegion().
*/ */
XID attributes[2];
attributes[0] = 0xc1c1c1; attributes[0] = 0xc1c1c1;
if (depth == 15 || depth == 16) if (depth == 15 || depth == 16)
...@@ -1489,9 +1423,8 @@ GCPtr nxagentCreateGraphicContext(int depth) ...@@ -1489,9 +1423,8 @@ GCPtr nxagentCreateGraphicContext(int depth)
} }
/* /*
* The IncludeInferiors property is useful to * The IncludeInferiors property is useful to solve problems when
* solve problems when synchronizing windows * synchronizing windows covered by an invisible child.
* covered by an invisible child.
*/ */
attributes[1] = IncludeInferiors; attributes[1] = IncludeInferiors;
...@@ -1513,32 +1446,25 @@ GCPtr nxagentCreateGraphicContext(int depth) ...@@ -1513,32 +1446,25 @@ GCPtr nxagentCreateGraphicContext(int depth)
} }
/* /*
* This initialization is called in the InitOutput() * This initialization is called in the InitOutput() function
* function immediately after opening the screen, * immediately after opening the screen, which is used to create the
* which is used to create the GCs. * GCs.
*/ */
void nxagentAllocateGraphicContexts(void) void nxagentAllocateGraphicContexts(void)
{ {
int *depths; int *depths = nxagentDepths;
int i;
depths = nxagentDepths; for (int i = 0; i < nxagentNumDepths; i++)
for (i = 0; i < nxagentNumDepths; i++)
{ {
nxagentCreateGraphicContext(*depths); nxagentCreateGraphicContext(*depths);
depths++; depths++;
} }
} }
void nxagentDisconnectGraphicContexts(void) void nxagentDisconnectGraphicContexts(void)
{ {
int i; for (int i = 0; i < nxagentGraphicContextsSize; i++)
for (i = 0; i < nxagentGraphicContextsSize; i++)
{ {
nxagentGraphicContexts[i].dirty = 1; nxagentGraphicContexts[i].dirty = 1;
} }
......
...@@ -95,8 +95,7 @@ static int nxagentSaveGCTrap; ...@@ -95,8 +95,7 @@ static int nxagentSaveGCTrap;
RegionPtr nxagentBitBlitHelper(GC *pGC); RegionPtr nxagentBitBlitHelper(GC *pGC);
/* /*
* The NX agent implementation of the * The NX agent implementation of the X server's graphics functions.
* X server's graphics functions.
*/ */
void nxagentFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, void nxagentFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans,
...@@ -170,7 +169,7 @@ void nxagentQueryBestSize(int class, unsigned short *pwidth, ...@@ -170,7 +169,7 @@ void nxagentQueryBestSize(int class, unsigned short *pwidth,
case StippleShape: case StippleShape:
width = *pwidth; width = *pwidth;
if (!width) break; if (!width) break;
/* Return the closes power of two not less than what they gave me */ /* Return the closest power of two not less than what they gave me */
test = 0x80000000; test = 0x80000000;
/* Find the highest 1 bit in the width given */ /* Find the highest 1 bit in the width given */
while(!(test & width)) while(!(test & width))
...@@ -192,9 +191,8 @@ RegionPtr nxagentBitBlitHelper(GC *pGC) ...@@ -192,9 +191,8 @@ RegionPtr nxagentBitBlitHelper(GC *pGC)
#endif #endif
/* /*
* Force NullRegion. We consider enough the graphics * Force NullRegion. We consider enough the graphics expose events
* expose events generated internally by the nxagent * generated internally by the nxagent server.
* server.
*/ */
#ifdef TEST #ifdef TEST
...@@ -205,28 +203,22 @@ RegionPtr nxagentBitBlitHelper(GC *pGC) ...@@ -205,28 +203,22 @@ RegionPtr nxagentBitBlitHelper(GC *pGC)
} }
/* /*
* The deferring of X_RenderCompositeTrapezoids caused * The deferring of X_RenderCompositeTrapezoids caused an ugly effect
* an ugly effect on pulldown menu: as the background * on pulldown menu: as the background may be not synchronized, the
* may be not synchronized, the text floats in an invi- * text floats in an invisible window. To avoid such effects, we use a
* sible window. To avoid such effects, we use a system * system to guess if the destination target of a copy area is a
* to guess if the destination target of a copy area * popup, by assuming that those kind of windows use the override
* is a popup, by assuming that those kind of windows * redirect property.
* use the override redirect property.
*/ */
int nxagentWindowIsPopup(DrawablePtr pDrawable) int nxagentWindowIsPopup(DrawablePtr pDrawable)
{ {
WindowPtr parent;
int windowIsPopup;
int level;
if (pDrawable -> type != DRAWABLE_WINDOW) if (pDrawable -> type != DRAWABLE_WINDOW)
{ {
return 0; return 0;
} }
windowIsPopup = 0; int windowIsPopup = 0;
if (((WindowPtr) pDrawable) -> overrideRedirect == 1) if (((WindowPtr) pDrawable) -> overrideRedirect == 1)
{ {
...@@ -234,16 +226,14 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable) ...@@ -234,16 +226,14 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable)
} }
else else
{ {
parent = ((WindowPtr) pDrawable) -> parent; WindowPtr parent = ((WindowPtr) pDrawable) -> parent;
/* /*
* Go up on the tree until a parent * Go up on the tree until a parent exists or 4 windows has been
* exists or 4 windows has been che- * checked. This seems a good limit to up children's popup.
* cked. This seems a good limit to
* up children's popup.
*/ */
level = 0; int level = 0;
while (parent != NULL && ++level <= 4) while (parent != NULL && ++level <= 4)
{ {
...@@ -255,7 +245,6 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable) ...@@ -255,7 +245,6 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable)
if (parent -> overrideRedirect == 1) if (parent -> overrideRedirect == 1)
{ {
windowIsPopup = 1; windowIsPopup = 1;
break; break;
} }
...@@ -272,33 +261,25 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable) ...@@ -272,33 +261,25 @@ int nxagentWindowIsPopup(DrawablePtr pDrawable)
} }
/* /*
* This function returns 1 if the * This function returns 1 if the XCopyArea request must be skipped.
* XCopyArea request must be skipped.
*/ */
int nxagentDeferCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, int nxagentDeferCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
GCPtr pGC, int srcx, int srcy, int width, GCPtr pGC, int srcx, int srcy, int width,
int height, int dstx, int dsty) int height, int dstx, int dsty)
{ {
RegionPtr pSrcRegion;
RegionPtr pClipRegion, pCorruptedRegion;
RegionRec corruptedRegion, tmpRegion;
/* /*
* If the destination drawable is a popup * If the destination drawable is a popup window, we try to
* window, we try to synchronize the source * synchronize the source drawable to show a nice menu. Anyway if
* drawable to show a nice menu. Anyway if * this synchronization breaks, the copy area is handled in the
* this synchronization breaks, the copy area * normal way.
* is handled in the normal way.
*/ */
/* /*
FIXME: The popup could be synchronized with one FIXME: The popup could be synchronized with one single put image,
single put image, clipped to the corrup- clipped to the corrupted region. As an intermediate step, the
ted region. As an intermediate step, the pixmap to synchronize could be copied on a cleared scratch
pixmap to synchronize could be copied on pixmap, in order to have a solid color in the clipped regions.
a cleared scratch pixmap, in order to
have a solid color in the clipped regions.
*/ */
if (nxagentOption(DeferLevel) >= 2 && if (nxagentOption(DeferLevel) >= 2 &&
...@@ -306,7 +287,7 @@ FIXME: The popup could be synchronized with one ...@@ -306,7 +287,7 @@ FIXME: The popup could be synchronized with one
nxagentPixmapContainTrapezoids((PixmapPtr) pSrcDrawable) == 1 && nxagentPixmapContainTrapezoids((PixmapPtr) pSrcDrawable) == 1 &&
nxagentWindowIsPopup(pDstDrawable) == 1) nxagentWindowIsPopup(pDstDrawable) == 1)
{ {
pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height); RegionPtr pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDeferCopyArea: Copying to a popup menu. Source region [%d,%d,%d,%d].\n", fprintf(stderr, "nxagentDeferCopyArea: Copying to a popup menu. Source region [%d,%d,%d,%d].\n",
...@@ -314,6 +295,7 @@ FIXME: The popup could be synchronized with one ...@@ -314,6 +295,7 @@ FIXME: The popup could be synchronized with one
pSrcRegion -> extents.x2, pSrcRegion -> extents.y2); pSrcRegion -> extents.x2, pSrcRegion -> extents.y2);
#endif #endif
RegionRec corruptedRegion;
RegionInit(&corruptedRegion, NullBox, 1); RegionInit(&corruptedRegion, NullBox, 1);
RegionIntersect(&corruptedRegion, RegionIntersect(&corruptedRegion,
...@@ -340,27 +322,24 @@ FIXME: The popup could be synchronized with one ...@@ -340,27 +322,24 @@ FIXME: The popup could be synchronized with one
} }
/* /*
* We are going to decide if the source drawable * We are going to decide if the source drawable must be
* must be synchronized before using it, or if * synchronized before using it, or if the copy will be clipped to
* the copy will be clipped to the synchronized * the synchronized source region.
* source region.
*/ */
if ((pDstDrawable -> type == DRAWABLE_PIXMAP && if ((pDstDrawable -> type == DRAWABLE_PIXMAP &&
nxagentOption(DeferLevel) > 0) || nxagentOption(DeferLevel) >= 3) nxagentOption(DeferLevel) > 0) || nxagentOption(DeferLevel) >= 3)
{ {
pClipRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, RegionPtr pClipRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy,
width, height); width, height);
/* /*
* We called this variable pCorruptedRegion * We called this variable pCorruptedRegion because in the worst
* because in the worst case the corrupted * case the corrupted region will be equal to the destination
* region will be equal to the destination * region. The GC's clip mask is used to narrow the destination.
* region. The GC's clip mask is used to
* narrow the destination.
*/ */
pCorruptedRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, RegionPtr pCorruptedRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty,
width, height); width, height);
#ifdef DEBUG #ifdef DEBUG
...@@ -393,6 +372,7 @@ FIXME: The popup could be synchronized with one ...@@ -393,6 +372,7 @@ FIXME: The popup could be synchronized with one
} }
else else
{ {
RegionRec tmpRegion;
RegionInit(&tmpRegion, NullBox, 1); RegionInit(&tmpRegion, NullBox, 1);
#ifdef DEBUG #ifdef DEBUG
...@@ -419,28 +399,27 @@ FIXME: The popup could be synchronized with one ...@@ -419,28 +399,27 @@ FIXME: The popup could be synchronized with one
} }
/* /*
* The corrupted region on the destination * The corrupted region on the destination drawable is composed by
* drawable is composed by the areas of the * the areas of the destination that we are not going to copy.
* destination that we are not going to copy.
*/ */
RegionSubtract(pCorruptedRegion, pCorruptedRegion, pClipRegion); RegionSubtract(pCorruptedRegion, pCorruptedRegion, pClipRegion);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDeferCopyArea: Recomputed clip region is [%d,%d,%d,%d][%ld].\n", fprintf(stderr, "nxagentDeferCopyArea: Recomputed clip region is [%d,%d,%d,%d][%d].\n",
pClipRegion -> extents.x1, pClipRegion -> extents.y1, pClipRegion -> extents.x1, pClipRegion -> extents.y1,
pClipRegion -> extents.x2, pClipRegion -> extents.y2, pClipRegion -> extents.x2, pClipRegion -> extents.y2,
RegionNumRects(pClipRegion)); RegionNumRects(pClipRegion));
fprintf(stderr, "nxagentDeferCopyArea: Inherited corrupted region is [%d,%d,%d,%d][%ld].\n", fprintf(stderr, "nxagentDeferCopyArea: Inherited corrupted region is [%d,%d,%d,%d][%d].\n",
pCorruptedRegion -> extents.x1, pCorruptedRegion -> extents.y1, pCorruptedRegion -> extents.x1, pCorruptedRegion -> extents.y1,
pCorruptedRegion -> extents.x2, pCorruptedRegion -> extents.y2, pCorruptedRegion -> extents.x2, pCorruptedRegion -> extents.y2,
RegionNumRects(pCorruptedRegion)); RegionNumRects(pCorruptedRegion));
#endif #endif
/* /*
* The destination drawable inherits both the * The destination drawable inherits both the synchronized and the
* synchronized and the corrupted region. * corrupted region.
*/ */
if (RegionNil(pClipRegion) == 0) if (RegionNil(pClipRegion) == 0)
...@@ -455,20 +434,15 @@ FIXME: The popup could be synchronized with one ...@@ -455,20 +434,15 @@ FIXME: The popup could be synchronized with one
if (RegionNil(pClipRegion) == 0) if (RegionNil(pClipRegion) == 0)
{ {
GCPtr targetGC;
CARD32 targetAttributes[2];
Bool pClipRegionFree = True; Bool pClipRegionFree = True;
/* /*
* As we want to copy only the synchronized * As we want to copy only the synchronized areas of the source
* areas of the source drawable, we create * drawable, we create a new GC copying the original one and
* a new GC copying the original one and
* setting a new clip mask. * setting a new clip mask.
*/ */
targetGC = GetScratchGC(pDstDrawable -> depth, pDstDrawable -> pScreen); GCPtr targetGC = GetScratchGC(pDstDrawable -> depth, pDstDrawable -> pScreen);
ValidateGC(pDstDrawable, targetGC); ValidateGC(pDstDrawable, targetGC);
...@@ -479,9 +453,8 @@ FIXME: The popup could be synchronized with one ...@@ -479,9 +453,8 @@ FIXME: The popup could be synchronized with one
if (RegionNumRects(pClipRegion) == 1) if (RegionNumRects(pClipRegion) == 1)
{ {
/* /*
* If the region to copy is formed by one * If the region to copy is formed by one rectangle, we change
* rectangle, we change only the copy coor- * only the copy coordinates.
* dinates.
*/ */
srcx = srcx + pClipRegion -> extents.x1 - dstx; srcx = srcx + pClipRegion -> extents.x1 - dstx;
...@@ -495,11 +468,12 @@ FIXME: The popup could be synchronized with one ...@@ -495,11 +468,12 @@ FIXME: The popup could be synchronized with one
} }
else else
{ {
CARD32 targetAttributes[2];
/* /*
* Setting the clip mask origin. This * Setting the clip mask origin. This operation must precede
* operation must precede the clip chan- * the clip change, because the origin information is used in
* ge, because the origin information is * the XSetClipRectangles().
* used in the XSetClipRectangles().
*/ */
targetAttributes[0] = 0; targetAttributes[0] = 0;
...@@ -514,8 +488,8 @@ FIXME: The popup could be synchronized with one ...@@ -514,8 +488,8 @@ FIXME: The popup could be synchronized with one
nxagentChangeClip(targetGC, CT_REGION, pClipRegion, 0); nxagentChangeClip(targetGC, CT_REGION, pClipRegion, 0);
/* /*
* Next call to nxagentChangeClip() will destroy * Next call to nxagentChangeClip() will destroy pClipRegion,
* pClipRegion, so it has not to be freed. * so it has not to be freed.
*/ */
pClipRegionFree = False; pClipRegionFree = False;
...@@ -549,9 +523,8 @@ FIXME: The popup could be synchronized with one ...@@ -549,9 +523,8 @@ FIXME: The popup could be synchronized with one
#endif #endif
/* /*
* The pClipRegion is destroyed calling nxagentChangeClip(), * The pClipRegion is destroyed calling nxagentChangeClip(), so
* so we deallocate it explicitly only if we don't change * we deallocate it explicitly only if we don't change the clip.
* the clip.
*/ */
nxagentFreeRegion(pSrcDrawable, pClipRegion); nxagentFreeRegion(pSrcDrawable, pClipRegion);
...@@ -563,7 +536,7 @@ FIXME: The popup could be synchronized with one ...@@ -563,7 +536,7 @@ FIXME: The popup could be synchronized with one
} }
else else
{ {
pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height); RegionPtr pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentDeferCopyArea: Source region [%d,%d,%d,%d].\n", fprintf(stderr, "nxagentDeferCopyArea: Source region [%d,%d,%d,%d].\n",
...@@ -571,6 +544,7 @@ FIXME: The popup could be synchronized with one ...@@ -571,6 +544,7 @@ FIXME: The popup could be synchronized with one
pSrcRegion -> extents.x2, pSrcRegion -> extents.y2); pSrcRegion -> extents.x2, pSrcRegion -> extents.y2);
#endif #endif
RegionRec corruptedRegion;
RegionInit(&corruptedRegion, NullBox, 1); RegionInit(&corruptedRegion, NullBox, 1);
RegionIntersect(&corruptedRegion, RegionIntersect(&corruptedRegion,
...@@ -598,12 +572,6 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -598,12 +572,6 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
GCPtr pGC, int srcx, int srcy, int width, GCPtr pGC, int srcx, int srcy, int width,
int height, int dstx, int dsty) int height, int dstx, int dsty)
{ {
int leftPad = 0;
unsigned int format;
unsigned long planeMask = 0xffffffff;
RegionPtr pDstRegion;
int skip = 0; int skip = 0;
#ifdef TEST #ifdef TEST
...@@ -614,9 +582,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -614,9 +582,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
#endif #endif
/* /*
* Here, before using fbDoCopy() called by fbCopyArea(), * Here, before using fbDoCopy() called by fbCopyArea(), it should be
* it should be provided that the cast in fbDoCopy() from * provided that the cast in fbDoCopy() from int to short int would
* int to short int would not cut off significative bits. * not cut off significative bits.
*/ */
if (dstx + pDstDrawable->x + width > 32767) if (dstx + pDstDrawable->x + width > 32767)
...@@ -725,9 +693,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -725,9 +693,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
} }
/* /*
* Try to detect if the copy area is to a window * Try to detect if the copy area is to a window that is unmapped or
* that is unmapped or fully covered. Similarly * fully covered. Similarly to the check in Image.c, this is of
* to the check in Image.c, this is of little use. * little use.
*/ */
if (nxagentOption(IgnoreVisibility) == 0 && pDstDrawable -> type == DRAWABLE_WINDOW && if (nxagentOption(IgnoreVisibility) == 0 && pDstDrawable -> type == DRAWABLE_WINDOW &&
...@@ -743,24 +711,21 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -743,24 +711,21 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
} }
/* /*
* If the pixmap is on shared memory, we can't * If the pixmap is on shared memory, we can't know if the pixmap
* know if the pixmap content is changed and * content is changed and so have to translate the operation in a
* so have to translate the operation in a put * put image operation. This can seriously affect the performance.
* image operation. This can seriously affect
* the performance.
*/ */
if (pSrcDrawable -> type == DRAWABLE_PIXMAP && if (pSrcDrawable -> type == DRAWABLE_PIXMAP &&
nxagentIsShmPixmap((PixmapPtr) pSrcDrawable)) nxagentIsShmPixmap((PixmapPtr) pSrcDrawable))
{ {
char *data; char *data;
int depth, length;
depth = pSrcDrawable -> depth; int depth = pSrcDrawable -> depth;
format = (depth == 1) ? XYPixmap : ZPixmap; unsigned int format = (depth == 1) ? XYPixmap : ZPixmap;
length = nxagentImageLength(width, height, format, leftPad, depth); int length = nxagentImageLength(width, height, format, 0, depth);
if ((data = malloc(length)) == NULL) if ((data = malloc(length)) == NULL)
{ {
...@@ -771,15 +736,16 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -771,15 +736,16 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
return NullRegion; return NullRegion;
} }
unsigned long planeMask = 0xffffffff;
fbGetImage(nxagentVirtualDrawable(pSrcDrawable), srcx, srcy, width, height, format, planeMask, data); fbGetImage(nxagentVirtualDrawable(pSrcDrawable), srcx, srcy, width, height, format, planeMask, data);
/* /*
* If the source is a shared memory pixmap, * If the source is a shared memory pixmap, put the image directly
* put the image directly to the destination. * to the destination.
*/ */
nxagentPutImage(pDstDrawable, pGC, depth, dstx, dsty, nxagentPutImage(pDstDrawable, pGC, depth, dstx, dsty,
width, height, leftPad, format, data); width, height, 0, format, data);
#ifdef TEST #ifdef TEST
fprintf(stderr,"nxagentCopyArea: Realize Pixmap %p virtual %p x %d y %d w %d h %d\n", fprintf(stderr,"nxagentCopyArea: Realize Pixmap %p virtual %p x %d y %d w %d h %d\n",
...@@ -790,10 +756,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -790,10 +756,9 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
SAFE_free(data); SAFE_free(data);
/* /*
* If the source is a shared memory pixmap, the * If the source is a shared memory pixmap, the content of the
* content of the framebuffer has been placed * framebuffer has been placed directly on the destination so we
* directly on the destination so we can skip * can skip the copy area operation.
* the copy area operation.
*/ */
skip = 1; skip = 1;
...@@ -825,13 +790,13 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -825,13 +790,13 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
nxagentGC(pGC), srcx, srcy, width, height, dstx, dsty); nxagentGC(pGC), srcx, srcy, width, height, dstx, dsty);
/* /*
* The copy area restored the synchroni- * The copy area restored the synchronization status of
* zation status of destination drawable. * destination drawable.
*/ */
if (nxagentDrawableStatus(pDstDrawable) == NotSynchronized) if (nxagentDrawableStatus(pDstDrawable) == NotSynchronized)
{ {
pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height); RegionPtr pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height);
nxagentUnmarkCorruptedRegion(pDstDrawable, pDstRegion); nxagentUnmarkCorruptedRegion(pDstDrawable, pDstRegion);
...@@ -876,8 +841,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -876,8 +841,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
else if (pDstDrawable -> type == DRAWABLE_PIXMAP) else if (pDstDrawable -> type == DRAWABLE_PIXMAP)
{ {
/* /*
* If we are here the source drawable * If we are here the source drawable must be a window.
* must be a window.
*/ */
if (((WindowPtr) pSrcDrawable) -> viewable) if (((WindowPtr) pSrcDrawable) -> viewable)
...@@ -894,8 +858,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -894,8 +858,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
else else
{ {
/* /*
* If we are here the source drawable * If we are here the source drawable must be a window.
* must be a window.
*/ */
if (((WindowPtr) pSrcDrawable) -> viewable) if (((WindowPtr) pSrcDrawable) -> viewable)
...@@ -918,13 +881,6 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -918,13 +881,6 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
GCPtr pGC, int srcx, int srcy, int width, int height, GCPtr pGC, int srcx, int srcy, int width, int height,
int dstx, int dsty, unsigned long plane) int dstx, int dsty, unsigned long plane)
{ {
unsigned int format;
int leftPad = 0;
unsigned long planeMask = 0xffffffff;
RegionPtr pSrcRegion, pDstRegion;
RegionRec corruptedRegion;
int skip = 0; int skip = 0;
#ifdef TEST #ifdef TEST
...@@ -963,24 +919,21 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -963,24 +919,21 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
} }
/* /*
* If the pixmap is on shared memory, we can't * If the pixmap is on shared memory, we can't know if the pixmap
* know if the pixmap content is changed and * content is changed and so have to translate the operation in a
* so have to translate the operation in a put * put image operation. This can seriously affect the performance.
* image operation. This can seriously affect
* the performance.
*/ */
if (pSrcDrawable -> type == DRAWABLE_PIXMAP && if (pSrcDrawable -> type == DRAWABLE_PIXMAP &&
nxagentIsShmPixmap((PixmapPtr) pSrcDrawable)) nxagentIsShmPixmap((PixmapPtr) pSrcDrawable))
{ {
char *data; char *data;
int depth, length;
depth = pSrcDrawable -> depth; int depth = pSrcDrawable -> depth;
format = (depth == 1) ? XYPixmap : ZPixmap; unsigned int format = (depth == 1) ? XYPixmap : ZPixmap;
length = nxagentImageLength(width, height, format, leftPad, depth); int length = nxagentImageLength(width, height, format, 0, depth);
if ((data = malloc(length)) == NULL) if ((data = malloc(length)) == NULL)
{ {
...@@ -991,15 +944,16 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -991,15 +944,16 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
return 0; return 0;
} }
unsigned long planeMask = 0xffffffff;
fbGetImage(nxagentVirtualDrawable(pSrcDrawable), srcx, srcy, width, height, format, planeMask, data); fbGetImage(nxagentVirtualDrawable(pSrcDrawable), srcx, srcy, width, height, format, planeMask, data);
/* /*
* If the source is a shared memory pixmap, * If the source is a shared memory pixmap, put the image directly
* put the image directly to the destination. * to the destination.
*/ */
nxagentPutImage(pDstDrawable, pGC, depth, dstx, dsty, nxagentPutImage(pDstDrawable, pGC, depth, dstx, dsty,
width, height, leftPad, format, data); width, height, 0, format, data);
#ifdef TEST #ifdef TEST
fprintf(stderr,"nxagentCopyPlane: Synchronize Pixmap %p virtual %p x %d y %d w %d h %d \n", fprintf(stderr,"nxagentCopyPlane: Synchronize Pixmap %p virtual %p x %d y %d w %d h %d \n",
...@@ -1010,10 +964,9 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -1010,10 +964,9 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
SAFE_free(data); SAFE_free(data);
/* /*
* If the source is a shared memory pixmap, the * If the source is a shared memory pixmap, the content of the
* content of the framebuffer has been placed * framebuffer has been placed directly on the destination so we
* directly on the destination so we can skip * can skip the copy plane operation.
* the copy plane operation.
*/ */
skip = 1; skip = 1;
...@@ -1024,7 +977,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -1024,7 +977,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
if (pDstDrawable -> type == DRAWABLE_PIXMAP && if (pDstDrawable -> type == DRAWABLE_PIXMAP &&
nxagentOption(DeferLevel) > 0) nxagentOption(DeferLevel) > 0)
{ {
pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height); RegionPtr pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height);
nxagentMarkCorruptedRegion(pDstDrawable, pDstRegion); nxagentMarkCorruptedRegion(pDstDrawable, pDstRegion);
...@@ -1034,7 +987,9 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -1034,7 +987,9 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
} }
else else
{ {
pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height); RegionPtr pSrcRegion = nxagentCreateRegion(pSrcDrawable, NULL, srcx, srcy, width, height);
RegionRec corruptedRegion;
RegionInit(&corruptedRegion, NullBox, 1); RegionInit(&corruptedRegion, NullBox, 1);
...@@ -1050,7 +1005,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -1050,7 +1005,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
nxagentSynchronizeRegion(pSrcDrawable, &corruptedRegion /*pSrcRegion*/, NEVER_BREAK, NULL); nxagentSynchronizeRegion(pSrcDrawable, &corruptedRegion /*pSrcRegion*/, NEVER_BREAK, NULL);
pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height); RegionPtr pDstRegion = nxagentCreateRegion(pDstDrawable, pGC, dstx, dsty, width, height);
nxagentUnmarkCorruptedRegion(pDstDrawable, pDstRegion); nxagentUnmarkCorruptedRegion(pDstDrawable, pDstRegion);
...@@ -1464,34 +1419,30 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape, ...@@ -1464,34 +1419,30 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
} }
/* /*
* The coordinate-mode must be CoordModePrevious * The coordinate-mode must be CoordModePrevious to make better use
* to make better use of differential encoding of * of differential encoding of X_FillPoly request by the side of
* X_FillPoly request by the side of proxy. * proxy.
*/ */
if (mode == CoordModeOrigin) if (mode == CoordModeOrigin)
{ {
int i;
mode = CoordModePrevious; mode = CoordModePrevious;
newPoints = malloc(nPoints * sizeof(xPoint)); newPoints = malloc(nPoints * sizeof(xPoint));
/* /*
* The first point is always relative * The first point is always relative to the drawable's origin.
* to the drawable's origin.
*/ */
newPoints[0].x = pPoints[0].x; newPoints[0].x = pPoints[0].x;
newPoints[0].y = pPoints[0].y; newPoints[0].y = pPoints[0].y;
/* /*
* If coordinate-mode is CoordModePrevious, * If coordinate-mode is CoordModePrevious, the points following
* the points following the first are rela- * the first are relative to the previous point.
* tive to the previous point.
*/ */
for (i = 1; i < nPoints; i++) for (int i = 1; i < nPoints; i++)
{ {
newPoints[i].x = pPoints[i].x - pPoints[i-1].x; newPoints[i].x = pPoints[i].x - pPoints[i-1].x;
newPoints[i].y = pPoints[i].y - pPoints[i-1].y; newPoints[i].y = pPoints[i].y - pPoints[i-1].y;
...@@ -1551,10 +1502,6 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape, ...@@ -1551,10 +1502,6 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
int nRectangles, xRectangle *pRectangles) int nRectangles, xRectangle *pRectangles)
{ {
RegionPtr rectRegion;
int inheritCorruptedRegion;
#ifdef TEST #ifdef TEST
if (nRectangles == 1) if (nRectangles == 1)
...@@ -1586,15 +1533,14 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, ...@@ -1586,15 +1533,14 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
} }
/* /*
* The PolyFillRect acts in two ways: if the GC * The PolyFillRect acts in two ways: if the GC has a corrupted
* has a corrupted tile, the operation propagates * tile, the operation propagates the corrupted region on the
* the corrupted region on the destination. In * destination. In other cases, because the PolyFillRect will cover
* other cases, because the PolyFillRect will * the destination, any corrupted region intersecting the target
* cover the destination, any corrupted region * will be cleared.
* intersecting the target will be cleared.
*/ */
inheritCorruptedRegion = 0; int inheritCorruptedRegion = 0;
if (pGC -> fillStyle == FillTiled && if (pGC -> fillStyle == FillTiled &&
pGC -> tileIsPixel == 0 && pGC -> tile.pixmap != NULL) pGC -> tileIsPixel == 0 && pGC -> tile.pixmap != NULL)
...@@ -1616,7 +1562,7 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, ...@@ -1616,7 +1562,7 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
if (inheritCorruptedRegion == 1 || nxagentDrawableStatus(pDrawable) == NotSynchronized) if (inheritCorruptedRegion == 1 || nxagentDrawableStatus(pDrawable) == NotSynchronized)
{ {
rectRegion = RegionFromRects(nRectangles, pRectangles, CT_REGION); RegionPtr rectRegion = RegionFromRects(nRectangles, pRectangles, CT_REGION);
if (pGC -> clientClip != NULL) if (pGC -> clientClip != NULL)
{ {
...@@ -1639,10 +1585,9 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, ...@@ -1639,10 +1585,9 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
if (inheritCorruptedRegion == 1) if (inheritCorruptedRegion == 1)
{ {
/* /*
* The fill style should affect the cor- * The fill style should affect the corrupted region
* rupted region propagation: if the tile * propagation: if the tile is not completely corrupted the
* is not completely corrupted the region * region should be 'tiled' over the destination.
* should be 'tiled' over the destination.
*/ */
nxagentMarkCorruptedRegion(pDrawable, rectRegion); nxagentMarkCorruptedRegion(pDrawable, rectRegion);
...@@ -1656,11 +1601,10 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, ...@@ -1656,11 +1601,10 @@ void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
else else
{ {
/* /*
* The stipple mask computation could cause * The stipple mask computation could cause an high
* an high fragmentation of the destination * fragmentation of the destination region. An analysis should
* region. An analysis should be done to exa- * be done to examine the better solution (e.g.rdesktop uses
* mine the better solution (e.g.rdesktop * stipples to draw texts).
* uses stipples to draw texts).
*/ */
#ifdef TEST #ifdef TEST
...@@ -1784,11 +1728,8 @@ void nxagentPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, ...@@ -1784,11 +1728,8 @@ void nxagentPolyFillArc(DrawablePtr pDrawable, GCPtr pGC,
int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x,
int y, int count, char *string) int y, int count, char *string)
{ {
int width;
/* /*
* While the session is suspended * While the session is suspended the font structure is NULL.
* the font structure is NULL.
*/ */
if (nxagentFontStruct(pGC -> font) == NULL) if (nxagentFontStruct(pGC -> font) == NULL)
...@@ -1796,7 +1737,7 @@ int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, ...@@ -1796,7 +1737,7 @@ int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x,
return x; return x;
} }
width = XTextWidth(nxagentFontStruct(pGC->font), string, count); int width = XTextWidth(nxagentFontStruct(pGC->font), string, count);
if (nxagentGCTrap == 1) if (nxagentGCTrap == 1)
{ {
...@@ -1857,11 +1798,8 @@ int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, ...@@ -1857,11 +1798,8 @@ int nxagentPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x,
int nxagentPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int nxagentPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x,
int y, int count, unsigned short *string) int y, int count, unsigned short *string)
{ {
int width;
/* /*
* While the session is suspended * While the session is suspended the font structure is NULL.
* the font structure is NULL.
*/ */
if (nxagentFontStruct(pGC -> font) == NULL) if (nxagentFontStruct(pGC -> font) == NULL)
...@@ -1869,7 +1807,7 @@ int nxagentPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, ...@@ -1869,7 +1807,7 @@ int nxagentPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x,
return x; return x;
} }
width = XTextWidth16(nxagentFontStruct(pGC->font), (XChar2b *)string, count); int width = XTextWidth16(nxagentFontStruct(pGC->font), (XChar2b *)string, count);
if (nxagentGCTrap == 1) if (nxagentGCTrap == 1)
{ {
......
...@@ -57,47 +57,42 @@ ...@@ -57,47 +57,42 @@
#undef DUMP #undef DUMP
/* /*
* Log begin and end of the important * Log begin and end of the important handlers.
* handlers.
*/ */
#undef BLOCKS #undef BLOCKS
/* /*
* If not defined, flush immediately * If not defined, flush immediately upon entering the block handler.
* upon entering the block handler.
*/ */
#define FLUSH_AFTER_MULTIPLE_READS #define FLUSH_AFTER_MULTIPLE_READS
/* /*
* The soft limit should roughly match * The soft limit should roughly match the size of the Xlib I/O
* the size of the Xlib I/O buffer. * buffer.
*/ */
#define BYTES_BEFORE_SOFT_TOKEN 2048 #define BYTES_BEFORE_SOFT_TOKEN 2048
#define BYTES_BEFORE_HARD_TOKEN 65536 #define BYTES_BEFORE_HARD_TOKEN 65536
/* /*
* Maximum number of synchronization * Maximum number of synchronization requests before waiting for the
* requests before waiting for the
* remote. * remote.
*/ */
#define TOKENS_PENDING_LIMIT 8 #define TOKENS_PENDING_LIMIT 8
/* /*
* Limits are very unobtrusive. We don't * Limits are very unobtrusive. We don't want to interfere with the
* want to interfere with the normal * normal dispatching.
* dispatching.
*/ */
#define BYTES_BEFORE_YIELD 1048576 #define BYTES_BEFORE_YIELD 1048576
#define TIME_BEFORE_YIELD 500 #define TIME_BEFORE_YIELD 500
/* /*
* Dynamically reduce the display buffer * Dynamically reduce the display buffer size after a congestion.
* size after a congestion.
*/ */
#undef DYNAMIC_DISPLAY_BUFFER #undef DYNAMIC_DISPLAY_BUFFER
...@@ -116,16 +111,14 @@ extern void nxagentDumpInputDevicesState(void); ...@@ -116,16 +111,14 @@ extern void nxagentDumpInputDevicesState(void);
#endif #endif
/* /*
* Used in the handling of the X desktop * Used in the handling of the X desktop manager protocol.
* manager protocol.
*/ */
int nxagentXdmcpUp = 0; int nxagentXdmcpUp = 0;
int nxagentXdmcpAlertUp = 0; int nxagentXdmcpAlertUp = 0;
/* /*
* Also used in the block, wakeup and * Also used in the block, wakeup and sync handlers.
* sync handlers.
*/ */
int nxagentBuffer; int nxagentBuffer;
...@@ -136,30 +129,28 @@ double nxagentBytesIn; ...@@ -136,30 +129,28 @@ double nxagentBytesIn;
double nxagentBytesOut; double nxagentBytesOut;
/* /*
* Total number of descriptors ready * Total number of descriptors ready as reported by the wakeup
* as reported by the wakeup handler. * handler.
*/ */
int nxagentReady; int nxagentReady;
/* /*
* Timestamp of the last write to the * Timestamp of the last write to the remote display.
* remote display.
*/ */
int nxagentFlush; int nxagentFlush;
/* /*
* Arbitrate the bandwidth among our * Arbitrate the bandwidth among our clients.
* clients.
*/ */
struct _TokensRec nxagentTokens = { 0, 0, 0 }; struct _TokensRec nxagentTokens = { 0, 0, 0 };
struct _DispatchRec nxagentDispatch = { UNDEFINED, 0, 0, 0 }; struct _DispatchRec nxagentDispatch = { UNDEFINED, 0, 0, 0 };
/* /*
* Called just before blocking, waiting * Called just before blocking, waiting for our clients or the X
* for our clients or the X server. * server.
*/ */
extern int nxagentSkipImage; extern int nxagentSkipImage;
...@@ -179,15 +170,13 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -179,15 +170,13 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
static int now; static int now;
/* /*
* Pending bytes to write to the * Pending bytes to write to the network.
* network.
*/ */
static int flushable; static int flushable;
/* /*
* Set if we need to synchronize * Set if we need to synchronize any drawable.
* any drawable.
*/ */
static int synchronize; static int synchronize;
...@@ -242,8 +231,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -242,8 +231,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#endif #endif
/* /*
* Slow down the agent if the session is * Slow down the agent if the session is not connected to a valid
* not connected to a valid display. * display.
*/ */
if (NXDisplayError(nxagentDisplay) == 1 && nxagentShadowCounter == 0 && nxagentOption(SleepTime) > 0) if (NXDisplayError(nxagentDisplay) == 1 && nxagentShadowCounter == 0 && nxagentOption(SleepTime) > 0)
...@@ -263,8 +252,7 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -263,8 +252,7 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#endif #endif
/* /*
* Update the shadow display. This is * Update the shadow display. This is only for test purposes.
* only for test purposes.
*/ */
#ifdef DUMP #ifdef DUMP
...@@ -276,17 +264,14 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -276,17 +264,14 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#endif #endif
/* /*
* We need this here because some window * We need this here because some window configuration changes can
* configuration changes can be generated * be generated by the X server outside the control of the DIX.
* by the X server outside the control of
* the DIX.
*/ */
nxagentFlushConfigureWindow(); nxagentFlushConfigureWindow();
/* /*
* Check whether there is any drawable to * Check whether there is any drawable to synchronize.
* synchronize.
*/ */
#ifdef TEST #ifdef TEST
...@@ -300,33 +285,28 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -300,33 +285,28 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
nxagentCorruptedPixmaps > 0); nxagentCorruptedPixmaps > 0);
/* /*
* The synchronization function requires a mask as * The synchronization function requires a mask as parameter:
* parameter:
* *
* EVENT_BREAK Breaks if an user input, like * EVENT_BREAK Breaks if an user input, like a key press
* a key press or a mouse move, * or a mouse move, is detected.
* is detected.
* *
* CONGESTION_BREAK Breaks if the congestion beco- * CONGESTION_BREAK Breaks if the congestion becomes greater
* mes greater than 4. * than 4.
* *
* BLOCKING_BREAK Breaks if the display descript- * BLOCKING_BREAK Breaks if the display descriptor becomes
* or becomes blocked for write * blocked for write during the loop.
* during the loop.
* *
* ALWAYS_BREAK Any of the previous conditions * ALWAYS_BREAK Any of the previous conditions is met.
* is met.
* *
* NEVER_BREAK The loop continues until all * NEVER_BREAK The loop continues until all the drawables
* the drawables are synchronized. * are synchronized.
*/ */
if (synchronize == 1) if (synchronize == 1)
{ {
/* /*
* We should not enter the synchronization * We should not enter the synchronization loop if there is any
* loop if there is any user input pending, * user input pending, i.e. if we are in the middle of a scroll
* i.e. if we are in the middle of a scroll
* operation. * operation.
*/ */
...@@ -361,9 +341,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -361,9 +341,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#endif #endif
/* /*
* Check if we have more corrupted resources * Check if we have more corrupted resources and whether the
* and whether the conditions are satisfied * conditions are satisfied to continue with the synchronization.
* to continue with the synchronization.
*/ */
synchronize = (nxagentCongestion <= 4 && synchronize = (nxagentCongestion <= 4 &&
...@@ -405,9 +384,9 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -405,9 +384,9 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
} }
/* /*
* If the remote X server is blocking, reduce the * If the remote X server is blocking, reduce the amount of data
* amount of data sent in a single display update * sent in a single display update by reducing the size of the
* by reducing the size of the display buffer. * display buffer.
*/ */
#ifdef DYNAMIC_DISPLAY_BUFFER #ifdef DYNAMIC_DISPLAY_BUFFER
...@@ -445,8 +424,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -445,8 +424,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#endif /* #ifdef DYNAMIC_DISPLAY_BUFFER */ #endif /* #ifdef DYNAMIC_DISPLAY_BUFFER */
/* /*
* Dispatch to the clients the events that * Dispatch to the clients the events that may have become
* may have become available. * available.
*/ */
if (nxagentPendingEvents(nxagentDisplay) > 0) if (nxagentPendingEvents(nxagentDisplay) > 0)
...@@ -459,9 +438,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -459,9 +438,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
} }
/* /*
* Check if there is any data remaining, * Check if there is any data remaining, either in the display
* either in the display buffer or in * buffer or in the NX transport.
* the NX transport.
*/ */
flushable = NXDisplayFlushable(nxagentDisplay); flushable = NXDisplayFlushable(nxagentDisplay);
...@@ -471,9 +449,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -471,9 +449,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#ifdef FLUSH_AFTER_MULTIPLE_READS #ifdef FLUSH_AFTER_MULTIPLE_READS
/* /*
* Flush all the outstanding data if * Flush all the outstanding data if the wakeup handler didn't
* the wakeup handler didn't detect * detect any activity.
* any activity.
*/ */
if (nxagentReady == 0 || now - nxagentFlush >= if (nxagentReady == 0 || now - nxagentFlush >=
...@@ -487,8 +464,7 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -487,8 +464,7 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
NXFlushDisplay(nxagentDisplay, NXFlushLink); NXFlushDisplay(nxagentDisplay, NXFlushLink);
/* /*
* New events may have become available * New events may have become available after the flush.
* after the flush.
*/ */
if (nxagentPendingEvents(nxagentDisplay) > 0) if (nxagentPendingEvents(nxagentDisplay) > 0)
...@@ -516,9 +492,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -516,9 +492,8 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
#else /* #ifdef FLUSH_AFTER_MULTIPLE_READS */ #else /* #ifdef FLUSH_AFTER_MULTIPLE_READS */
/* /*
* We are entering the select. Tell the NX * We are entering the select. Tell the NX transport to write any
* transport to write any produced data to * produced data to the remote end.
* the remote end.
*/ */
NXFlushDisplay(nxagentDisplay, NXFlushLink); NXFlushDisplay(nxagentDisplay, NXFlushLink);
...@@ -556,12 +531,11 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) ...@@ -556,12 +531,11 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask)
} }
/* /*
* WaitForSomething() sets a zero timeout if there * WaitForSomething() sets a zero timeout if there are clients with
* are clients with input, but doesn't stop the * input, but doesn't stop the timer. The select is then interrupted
* timer. The select is then interrupted to update * to update the schedule time even if, what the dispatcher cares,
* the schedule time even if, what the dispatcher * is only the number of ticks at the time the client is scheduled
* cares, is only the number of ticks at the time * in.
* the client is scheduled in.
*/ */
#ifdef DEBUG #ifdef DEBUG
...@@ -641,8 +615,7 @@ void nxagentWakeupHandler(void * data, int count, void * mask) ...@@ -641,8 +615,7 @@ void nxagentWakeupHandler(void * data, int count, void * mask)
else if (nxagentQueuedEvents(nxagentDisplay) == 1) else if (nxagentQueuedEvents(nxagentDisplay) == 1)
{ {
/* /*
* We may have left some events in * We may have left some events in the queue.
* the queue.
*/ */
#ifdef TEST #ifdef TEST
...@@ -674,9 +647,8 @@ void nxagentWakeupHandler(void * data, int count, void * mask) ...@@ -674,9 +647,8 @@ void nxagentWakeupHandler(void * data, int count, void * mask)
#endif #endif
/* /*
* If the XDM connection can't be established * If the XDM connection can't be established we'll need to create a
* we'll need to create a dialog to notify the * dialog to notify the user and give him/her a chance to terminate
* user and give him/her a chance to terminate
* the session. * the session.
*/ */
...@@ -813,14 +785,12 @@ void nxagentShadowBlockHandler(void * data, struct timeval **timeout, void * mas ...@@ -813,14 +785,12 @@ void nxagentShadowBlockHandler(void * data, struct timeval **timeout, void * mas
} }
/* /*
* We are entering the select. Tell the NX * We are entering the select. Tell the NX transport to write any
* transport to write any produced data to * produced data to the remote end.
* the remote end.
*/ */
/* /*
FIXME: Must queue multiple writes and handle FIXME: Must queue multiple writes and handle the events by resembling
the events by resembling the ordinary the ordinary block handler.
block handler.
*/ */
NXFlushDisplay(nxagentDisplay, NXFlushLink); NXFlushDisplay(nxagentDisplay, NXFlushLink);
...@@ -929,8 +899,7 @@ void nxagentShadowWakeupHandler(void * data, int count, void * mask) ...@@ -929,8 +899,7 @@ void nxagentShadowWakeupHandler(void * data, int count, void * mask)
else if (nxagentQueuedEvents(nxagentDisplay) == 1) else if (nxagentQueuedEvents(nxagentDisplay) == 1)
{ {
/* /*
* We may have left some events in * We may have left some events in the queue.
* the queue.
*/ */
#ifdef TEST #ifdef TEST
...@@ -1022,13 +991,11 @@ Bool nxagentCollectInputFocusPredicate(Display *display, XEvent *X, XPointer ptr ...@@ -1022,13 +991,11 @@ Bool nxagentCollectInputFocusPredicate(Display *display, XEvent *X, XPointer ptr
void nxagentDispatchHandler(ClientPtr client, int in, int out) void nxagentDispatchHandler(ClientPtr client, int in, int out)
{ {
/* /*
* This function is called by the dispatcher (with 0 * This function is called by the dispatcher (with 0 bytes out)
* bytes out) after a new request has been processed. * after a new request has been processed. It is also called by the
* It is also called by the write handler (with 0 * write handler (with 0 bytes in) after more data has been written
* bytes in) after more data has been written to the * to the display. It may be optionally called in the block and
* display. It may be optionally called in the block * wakeup handlers. In this case both in and out must be 0.
* and wakeup handlers. In this case both in and out
* must be 0.
*/ */
if (out > 0) if (out > 0)
...@@ -1050,14 +1017,12 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1050,14 +1017,12 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
#endif #endif
/* /*
* Don't take care of the synchronization if * Don't take care of the synchronization if the NX transport is
* the NX transport is running. The NX trans- * running. The NX transport has its own token-based control flow.
* port has its own token-based control flow.
* *
* We can't produce more output here because * We can't produce more output here because we are in the middle
* we are in the middle of the flush. We will * of the flush. We will take care of the sync requests when
* take care of the sync requests when called * called by the dispatcher.
* by the dispatcher.
*/ */
if (nxagentOption(LinkType) == LINK_TYPE_NONE) if (nxagentOption(LinkType) == LINK_TYPE_NONE)
...@@ -1079,8 +1044,8 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1079,8 +1044,8 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
{ {
/* /*
* Pay attention to the next client if this * Pay attention to the next client if this client produced
* client produced enough output. * enough output.
*/ */
if (nxagentBytesOut - nxagentDispatch.out > BYTES_BEFORE_YIELD) if (nxagentBytesOut - nxagentDispatch.out > BYTES_BEFORE_YIELD)
...@@ -1142,12 +1107,11 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1142,12 +1107,11 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
#endif #endif
/* /*
* When using the dumb scheduler, before reading from * When using the dumb scheduler, before reading from another
* another client, the dispatcher tries to drain all * client, the dispatcher tries to drain all the input from the
* the input from the client being processed. This * client being processed. This means that, if isItTimeToYield is
* means that, if isItTimeToYield is never set and the * never set and the client never produces any output, we'll stick
* client never produces any output, we'll stick into * into the inner dispatch loop forever.
* the inner dispatch loop forever.
*/ */
if (!SmartScheduleSignalEnable) if (!SmartScheduleSignalEnable)
...@@ -1228,10 +1192,9 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1228,10 +1192,9 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
else if (nxagentTokens.soft > BYTES_BEFORE_SOFT_TOKEN) else if (nxagentTokens.soft > BYTES_BEFORE_SOFT_TOKEN)
{ {
/* /*
* Alternatively, the amounts of bytes * Alternatively, the amounts of bytes accounted for each sync
* accounted for each sync request may * request may be decreased according to the number of pending
* be decreased according to the number * replies already awaited.
* of pending replies already awaited.
* *
* else if (nxagentTokens.soft > (BYTES_BEFORE_SOFT_TOKEN / (nxagentTokens.pending + 1))) * else if (nxagentTokens.soft > (BYTES_BEFORE_SOFT_TOKEN / (nxagentTokens.pending + 1)))
*/ */
...@@ -1239,9 +1202,8 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1239,9 +1202,8 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
int resource; int resource;
/* /*
* Wait eventually for the number of * Wait eventually for the number of synchronization requests to
* synchronization requests to return * return below the limit.
* below the limit.
*/ */
#ifdef TEST #ifdef TEST
......
...@@ -59,9 +59,8 @@ ...@@ -59,9 +59,8 @@
#undef DUMP #undef DUMP
/* /*
* Don't pack the images having a width, a * Don't pack the images having a width, a height or a data size
* height or a data size smaller or equal * smaller or equal to these thresholds.
* to these thresholds.
*/ */
#define IMAGE_PACK_WIDTH 2 #define IMAGE_PACK_WIDTH 2
...@@ -69,16 +68,14 @@ ...@@ -69,16 +68,14 @@
#define IMAGE_PACK_LENGTH 512 #define IMAGE_PACK_LENGTH 512
/* /*
* Compress the image with a lossless encoder * Compress the image with a lossless encoder if the percentage of
* if the percentage of discrete pixels in the * discrete pixels in the image is below this threshold.
* image is below this threshold.
*/ */
#define IMAGE_UNIQUE_RATIO 10 #define IMAGE_UNIQUE_RATIO 10
/* /*
* Preferred pack and split parameters we * Preferred pack and split parameters we got from the NX transport.
* got from the NX transport.
*/ */
int nxagentPackLossless = -1; int nxagentPackLossless = -1;
...@@ -94,8 +91,8 @@ int nxagentAlphaEnabled = 0; ...@@ -94,8 +91,8 @@ int nxagentAlphaEnabled = 0;
int nxagentAlphaCompat = 0; int nxagentAlphaCompat = 0;
/* /*
* Used to reformat image when connecting to * Used to reformat image when connecting to displays having different
* displays having different byte order. * byte order.
*/ */
extern void nxagentBitOrderInvert(unsigned char *, int); extern void nxagentBitOrderInvert(unsigned char *, int);
...@@ -103,22 +100,20 @@ extern void nxagentTwoByteSwap(unsigned char *, register int); ...@@ -103,22 +100,20 @@ extern void nxagentTwoByteSwap(unsigned char *, register int);
extern void nxagentFourByteSwap(register unsigned char *, register int); extern void nxagentFourByteSwap(register unsigned char *, register int);
/* /*
* Store the last visual used to unpack * Store the last visual used to unpack the images for the given
* the images for the given client. * client.
*/ */
static VisualID nxagentUnpackVisualId[MAX_CONNECTIONS]; static VisualID nxagentUnpackVisualId[MAX_CONNECTIONS];
/* /*
* Store the last alpha data set for the * Store the last alpha data set for the client.
* client.
*/ */
typedef struct _UnpackAlpha typedef struct _UnpackAlpha
{ {
char *data; char *data;
int size; int size;
} UnpackAlphaRec; } UnpackAlphaRec;
typedef UnpackAlphaRec *UnpackAlphaPtr; typedef UnpackAlphaRec *UnpackAlphaPtr;
...@@ -126,9 +121,8 @@ typedef UnpackAlphaRec *UnpackAlphaPtr; ...@@ -126,9 +121,8 @@ typedef UnpackAlphaRec *UnpackAlphaPtr;
static UnpackAlphaPtr nxagentUnpackAlpha[MAX_CONNECTIONS]; static UnpackAlphaPtr nxagentUnpackAlpha[MAX_CONNECTIONS];
/* /*
* Encode the imade alpha channel by using * Encode the imade alpha channel by using a specific encoding,
* a specific encoding, separating it from * separating it from the rest of the RGB data.
* the rest of the RGB data.
*/ */
static char *nxagentImageAlpha(XImage *ximage); static char *nxagentImageAlpha(XImage *ximage);
...@@ -141,10 +135,9 @@ static void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientP ...@@ -141,10 +135,9 @@ static void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientP
static char *nxagentImageCopy(XImage *source, XImage *destination); static char *nxagentImageCopy(XImage *source, XImage *destination);
/* /*
* Return true if the image can be cached. * Return true if the image can be cached. Don't cache the images
* Don't cache the images packed with the * packed with the bitmap method as the encoding is little more
* bitmap method as the encoding is little * expensive than a copy.
* more expensive than a copy.
*/ */
#define nxagentNeedCache(image, method) \ #define nxagentNeedCache(image, method) \
...@@ -152,10 +145,8 @@ static char *nxagentImageCopy(XImage *source, XImage *destination); ...@@ -152,10 +145,8 @@ static char *nxagentImageCopy(XImage *source, XImage *destination);
((method) != PACK_BITMAP_16M_COLORS) ((method) != PACK_BITMAP_16M_COLORS)
/* /*
* With the bitmap encoding, if the image * With the bitmap encoding, if the image is 32 bits-per-pixel the 4th
* is 32 bits-per-pixel the 4th byte is not * byte is not transmitted, so we don't need to clean the image.
* transmitted, so we don't need to clean
* the image.
*/ */
#define nxagentNeedClean(image, method) \ #define nxagentNeedClean(image, method) \
...@@ -180,7 +171,6 @@ typedef struct _ImageStatisticsRec ...@@ -180,7 +171,6 @@ typedef struct _ImageStatisticsRec
double totalMatches; double totalMatches;
double totalEncoded; double totalEncoded;
double totalAdded; double totalAdded;
} ImageStatisticsRec; } ImageStatisticsRec;
ImageStatisticsRec nxagentImageStatistics; ImageStatisticsRec nxagentImageStatistics;
...@@ -188,11 +178,10 @@ ImageStatisticsRec nxagentImageStatistics; ...@@ -188,11 +178,10 @@ ImageStatisticsRec nxagentImageStatistics;
int nxagentImageReformat(char *base, int nbytes, int bpp, int order) int nxagentImageReformat(char *base, int nbytes, int bpp, int order)
{ {
/* /*
* This is used whenever we need to swap the image data. * This is used whenever we need to swap the image data. If we got
* If we got an image from an X server having a different * an image from an X server having a different endianness, we will
* endianness, we will need to reformat the image to match * need to reformat the image to match our own image-order so that
* our own image-order so that ProcGetImage can return * ProcGetImage can return the expected format to the client.
* the expected format to the client.
*/ */
switch (bpp) switch (bpp)
...@@ -266,7 +255,6 @@ int nxagentImageLength(int width, int height, int format, int leftPad, int depth ...@@ -266,7 +255,6 @@ int nxagentImageLength(int width, int height, int format, int leftPad, int depth
else if (format == XYPixmap) else if (format == XYPixmap)
{ {
line = BitmapBytePad(width + leftPad); line = BitmapBytePad(width + leftPad);
line *= depth; line *= depth;
} }
else if (format == ZPixmap) else if (format == ZPixmap)
...@@ -298,10 +286,9 @@ int nxagentImagePad(int width, int format, int leftPad, int depth) ...@@ -298,10 +286,9 @@ int nxagentImagePad(int width, int format, int leftPad, int depth)
} }
/* /*
* Only copy the data, not the structure. * Only copy the data, not the structure. The data pointed by the
* The data pointed by the destination is * destination is lost. Used to clone two images that point to the
* lost. Used to clone two images that * same data.
* point to the same data.
*/ */
char *nxagentImageCopy(XImage *source, XImage *destination) char *nxagentImageCopy(XImage *source, XImage *destination)
...@@ -330,21 +317,13 @@ char *nxagentImageCopy(XImage *source, XImage *destination) ...@@ -330,21 +317,13 @@ char *nxagentImageCopy(XImage *source, XImage *destination)
char *nxagentImageAlpha(XImage *image) char *nxagentImageAlpha(XImage *image)
{ {
char *pData;
char *pSrcData;
char *pDstData;
int size;
int offset;
/* /*
* Use one byte per pixel. * Use one byte per pixel.
*/ */
size = (image -> bytes_per_line * image -> height) >> 2; int size = (image -> bytes_per_line * image -> height) >> 2;
pData = malloc(size); char *pData = malloc(size);
if (pData == NULL) if (pData == NULL)
{ {
...@@ -352,14 +331,13 @@ char *nxagentImageAlpha(XImage *image) ...@@ -352,14 +331,13 @@ char *nxagentImageAlpha(XImage *image)
} }
/* /*
* The image is supposed to be in * The image is supposed to be in server order.
* server order.
*/ */
offset = (image -> byte_order == MSBFirst) ? 0 : 3; int offset = (image -> byte_order == MSBFirst) ? 0 : 3;
pSrcData = image -> data; char *pSrcData = image -> data;
pDstData = pData; char *pDstData = pData;
while (size-- > 0) while (size-- > 0)
{ {
...@@ -372,8 +350,7 @@ char *nxagentImageAlpha(XImage *image) ...@@ -372,8 +350,7 @@ char *nxagentImageAlpha(XImage *image)
} }
/* /*
* Write down the image cache statistics * Write down the image cache statistics to the buffer.
* to the buffer.
*/ */
void nxagentImageStatisticsHandler(char **buffer, int type) void nxagentImageStatisticsHandler(char **buffer, int type)
...@@ -389,9 +366,8 @@ FIXME: Agent cache statistics have to be implemented. ...@@ -389,9 +366,8 @@ FIXME: Agent cache statistics have to be implemented.
} }
/* /*
* This should be called only for drawables * This should be called only for drawables having a depth of 32. In
* having a depth of 32. In the other cases, * the other cases, it would only generate useless traffic.
* it would only generate useless traffic.
*/ */
void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pClient) void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pClient)
...@@ -412,16 +388,15 @@ void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pCli ...@@ -412,16 +388,15 @@ void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pCli
} }
/* /*
* If we are synchronizing the drawable, discard * If we are synchronizing the drawable, discard any unpack alpha
* any unpack alpha stored for the client. The * stored for the client. The alpha data, in fact, may be still
* alpha data, in fact, may be still traveling * traveling and so we either wait until the end of the split or
* and so we either wait until the end of the * send a fresh copy.
* split or send a fresh copy.
*/ */
/* /*
FIXME: Here the split trap is always set and so the caching of FIXME: Here the split trap is always set and so the caching of the
the alpha channel is useless. I remember we set the trap alpha channel is useless. I remember we set the trap because of
because of the cursor but why is it always set now? the cursor but why is it always set now?
*/ */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSetUnpackAlpha: Checking alpha channel for client [%d] with trap [%d].\n", fprintf(stderr, "nxagentSetUnpackAlpha: Checking alpha channel for client [%d] with trap [%d].\n",
...@@ -439,9 +414,8 @@ FIXME: Here the split trap is always set and so the caching of ...@@ -439,9 +414,8 @@ FIXME: Here the split trap is always set and so the caching of
#endif #endif
/* /*
* Check if we are connected to a newer proxy * Check if we are connected to a newer proxy version and so can
* version and so can send the alpha data in * send the alpha data in compressed form.
* compressed form.
*/ */
if (nxagentAlphaCompat == 0) if (nxagentAlphaCompat == 0)
...@@ -488,16 +462,14 @@ FIXME: Here the split trap is always set and so the caching of ...@@ -488,16 +462,14 @@ FIXME: Here the split trap is always set and so the caching of
} }
/* /*
* The NX agent's implementation of the * The NX agent's implementation of the X server's image functions.
* X server's image functions.
*/ */
void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
int dstX, int dstY, int dstWidth, int dstHeight, int dstX, int dstY, int dstWidth, int dstHeight,
int leftPad, int format, char *data) int leftPad, int format, char *data)
{ {
int length; /* will be checked at nxagentPutImageEnd */
RegionPtr pRegion = NullRegion; RegionPtr pRegion = NullRegion;
int resource = 0; int resource = 0;
...@@ -511,21 +483,18 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -511,21 +483,18 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
#endif #endif
/* /*
* If the display is down and there is not an * If the display is down and there is not an nxagent attached,
* nxagent attached, sleep for a while but * sleep for a while but still give a chance to the client to write
* still give a chance to the client to write
* to the framebuffer. * to the framebuffer.
*/ */
length = nxagentImageLength(dstWidth, dstHeight, format, leftPad, depth); int length = nxagentImageLength(dstWidth, dstHeight, format, leftPad, depth);
if (nxagentShadowCounter == 0 && if (nxagentShadowCounter == 0 &&
NXDisplayError(nxagentDisplay) == 1 && NXDisplayError(nxagentDisplay) == 1 &&
nxagentOption(SleepTime) > 0) nxagentOption(SleepTime) > 0)
{ {
int us; int us = nxagentOption(SleepTime) * 4 * (length / 1024);
us = nxagentOption(SleepTime) * 4 * (length / 1024);
us = (us < 10000 ? 10000 : (us > 1000000 ? 1000000 : us)); us = (us < 10000 ? 10000 : (us > 1000000 ? 1000000 : us));
...@@ -538,11 +507,11 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -538,11 +507,11 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
} }
/* /*
* This is of little use because clients usually write * This is of little use because clients usually write to windows
* to windows only after an expose event, and, in the * only after an expose event, and, in the rare case they use a
* rare case they use a direct put image to the window * direct put image to the window (for a media player it should be a
* (for a media player it should be a necessity), they * necessity), they are likely to monitor the visibility of the
* are likely to monitor the visibility of the window. * window.
*/ */
if (nxagentOption(IgnoreVisibility) == 0 && pDrawable -> type == DRAWABLE_WINDOW && if (nxagentOption(IgnoreVisibility) == 0 && pDrawable -> type == DRAWABLE_WINDOW &&
...@@ -559,9 +528,8 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -559,9 +528,8 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
} }
/* /*
* This is more interesting. Check if the operation * This is more interesting. Check if the operation will produce a
* will produce a visible result based on the clip * visible result based on the clip list of the window and the GC.
* list of the window and the GC.
*/ */
pRegion = nxagentCreateRegion(pDrawable, pGC, dstX, dstY, dstWidth, dstHeight); pRegion = nxagentCreateRegion(pDrawable, pGC, dstX, dstY, dstWidth, dstHeight);
...@@ -618,9 +586,8 @@ FIXME: Should use these. ...@@ -618,9 +586,8 @@ FIXME: Should use these.
} }
/* /*
* We are going to realize the operation * We are going to realize the operation on the real display. Let's
* on the real display. Let's check if * check if the link is down.
* the link is down.
*/ */
if (NXDisplayError(nxagentDisplay) == 1) if (NXDisplayError(nxagentDisplay) == 1)
...@@ -629,13 +596,11 @@ FIXME: Should use these. ...@@ -629,13 +596,11 @@ FIXME: Should use these.
} }
/* /*
* Mark the region as corrupted and skip the operation * Mark the region as corrupted and skip the operation if we went
* if we went out of bandwidth. The drawable will be * out of bandwidth. The drawable will be synchronized at later
* synchronized at later time. Don't do that if the * time. Don't do that if the image is likely to be a shape or a
* image is likely to be a shape or a clip mask, if we * clip mask, if we are here because we are actually synchronizing
* are here because we are actually synchronizing the * the drawable or if the drawable's corrupted region is over-age.
* drawable or if the drawable's corrupted region is
* over-age.
*/ */
if (NXAGENT_SHOULD_DEFER_PUTIMAGE(pDrawable)) if (NXAGENT_SHOULD_DEFER_PUTIMAGE(pDrawable))
...@@ -687,8 +652,7 @@ FIXME: Should use these. ...@@ -687,8 +652,7 @@ FIXME: Should use these.
#endif #endif
/* /*
* Check whether we need to enclose the * Check whether we need to enclose the image in a split sequence.
* image in a split sequence.
*/ */
/* /*
FIXME: Should we disable the split with link LAN? FIXME: Should we disable the split with link LAN?
...@@ -700,12 +664,11 @@ FIXME: Should we disable the split with link LAN? ...@@ -700,12 +664,11 @@ FIXME: Should we disable the split with link LAN?
split = (nxagentOption(Streaming) == 1 && split = (nxagentOption(Streaming) == 1 &&
nxagentOption(LinkType) != LINK_TYPE_NONE nxagentOption(LinkType) != LINK_TYPE_NONE
/* /*
FIXME: Do we stream the images from GLX or Xv? If we do that, FIXME: Do we stream the images from GLX or Xv? If we do that, we
we should also write on the frame buffer, including the should also write on the frame buffer, including the images put
images put on windows, to be able to reconstruct the on windows, to be able to reconstruct the region that is out of
region that is out of sync. Surely we should not try to sync. Surely we should not try to cache the GLX and Xv images
cache the GLX and Xv images in memory or save them in in memory or save them in the image cache on disk.
the image cache on disk.
*/ */
/* /*
FIXME: Temporarily stream the GLX data. FIXME: Temporarily stream the GLX data.
...@@ -716,21 +679,18 @@ FIXME: Temporarily stream the GLX data. ...@@ -716,21 +679,18 @@ FIXME: Temporarily stream the GLX data.
); );
/* /*
* Never split images whose depth * Never split images whose depth is less than 15.
* is less than 15.
*/ */
if (split == 1 && (nxagentSplitTrap == 1 || depth < 15)) if (split == 1 && (nxagentSplitTrap == 1 || depth < 15))
{ {
#ifdef TEST #ifdef TEST
if (nxagentSplitTrap == 1 || if (nxagentSplitTrap == 1 ||
nxagentReconnectTrap == 1) nxagentReconnectTrap == 1)
{ {
fprintf(stderr, "nxagentPutImage: Not splitting with reconnection [%d] trap [%d] " fprintf(stderr, "nxagentPutImage: Not splitting with reconnection [%d] trap [%d] "
"depth [%d].\n", nxagentSplitTrap, nxagentReconnectTrap, depth); "depth [%d].\n", nxagentSplitTrap, nxagentReconnectTrap, depth);
} }
#endif #endif
split = 0; split = 0;
...@@ -744,7 +704,6 @@ FIXME: Temporarily stream the GLX data. ...@@ -744,7 +704,6 @@ FIXME: Temporarily stream the GLX data.
#endif #endif
#ifdef TEST #ifdef TEST
if (split == 1) if (split == 1)
{ {
fprintf(stderr, "nxagentPutImage: Splitting the image with size [%d] " fprintf(stderr, "nxagentPutImage: Splitting the image with size [%d] "
...@@ -757,13 +716,11 @@ FIXME: Temporarily stream the GLX data. ...@@ -757,13 +716,11 @@ FIXME: Temporarily stream the GLX data.
"link [%d] GLX [%d] Xv [%d].\n", length, nxagentOption(LinkType), "link [%d] GLX [%d] Xv [%d].\n", length, nxagentOption(LinkType),
nxagentGlxTrap, nxagentXvTrap); nxagentGlxTrap, nxagentXvTrap);
} }
#endif #endif
/* /*
* If the image was originated by a GLX * If the image was originated by a GLX or Xvideo request,
* or Xvideo request, temporarily disable * temporarily disable the use of the cache.
* the use of the cache.
*/ */
if (nxagentOption(LinkType) != LINK_TYPE_NONE && if (nxagentOption(LinkType) != LINK_TYPE_NONE &&
...@@ -779,17 +736,15 @@ FIXME: Temporarily stream the GLX data. ...@@ -779,17 +736,15 @@ FIXME: Temporarily stream the GLX data.
} }
/* /*
* Enclose the next messages in a split * Enclose the next messages in a split sequence. The proxy will
* sequence. The proxy will tell us if * tell us if the split took place.
* the split took place.
*/ */
if (split == 1) if (split == 1)
{ {
/* /*
* If the drawable is already being split, * If the drawable is already being split, expand the
* expand the region. Currently drawables * region. Currently drawables can't have more than a single split
* can't have more than a single split
* region. * region.
*/ */
...@@ -800,9 +755,8 @@ FIXME: Temporarily stream the GLX data. ...@@ -800,9 +755,8 @@ FIXME: Temporarily stream the GLX data.
(void *) pDrawable); (void *) pDrawable);
#endif #endif
/* /*
FIXME: Should probably intersect the region with FIXME: Should probably intersect the region with the region being
the region being split to also invalidate split to also invalidate the commits.
the commits.
*/ */
nxagentMarkCorruptedRegion(pDrawable, pRegion); nxagentMarkCorruptedRegion(pDrawable, pRegion);
...@@ -811,9 +765,8 @@ FIXME: Should probably intersect the region with ...@@ -811,9 +765,8 @@ FIXME: Should probably intersect the region with
else else
{ {
/* /*
* Assign a new resource to the drawable. * Assign a new resource to the drawable. Will also assign the
* Will also assign the GC to use for the * GC to use for the operation.
* operation.
*/ */
resource = nxagentCreateSplit(pDrawable, &pGC); resource = nxagentCreateSplit(pDrawable, &pGC);
...@@ -835,12 +788,11 @@ FIXME: Should probably intersect the region with ...@@ -835,12 +788,11 @@ FIXME: Should probably intersect the region with
NXEndSplit(nxagentDisplay, resource); NXEndSplit(nxagentDisplay, resource);
/* /*
* Now we need to check if all the messages went * Now we need to check if all the messages went straight through
* straight through the output stream or any of * the output stream or any of them required a split. If no split
* them required a split. If no split will take * will take place, we will remove the association with the
* place, we will remove the association with the * drawable and release the resource at the time we will handle
* drawable and release the resource at the time * the no-split event.
* we will handle the no-split event.
*/ */
split = nxagentWaitSplitEvent(resource); split = nxagentWaitSplitEvent(resource);
...@@ -854,10 +806,9 @@ FIXME: Should probably intersect the region with ...@@ -854,10 +806,9 @@ FIXME: Should probably intersect the region with
#endif #endif
/* /*
* Marking the corrupted region we will check * Marking the corrupted region we will check if the region
* if the region intersects the split region, * intersects the split region, therefore the split region must
* therefore the split region must be added * be added later.
* later.
*/ */
nxagentMarkCorruptedRegion(pDrawable, pRegion); nxagentMarkCorruptedRegion(pDrawable, pRegion);
...@@ -873,9 +824,8 @@ FIXME: Should probably intersect the region with ...@@ -873,9 +824,8 @@ FIXME: Should probably intersect the region with
} }
/* /*
* The split value could be changed by a * The split value could be changed by a no-split event in the block
* no-split event in the block above, so * above, so here we have to check the value again.
* here we have to check the value again.
*/ */
if (split == 0) if (split == 0)
...@@ -883,9 +833,8 @@ FIXME: Should probably intersect the region with ...@@ -883,9 +833,8 @@ FIXME: Should probably intersect the region with
if (nxagentDrawableStatus(pDrawable) == NotSynchronized) if (nxagentDrawableStatus(pDrawable) == NotSynchronized)
{ {
/* /*
* We just covered the drawable with * We just covered the drawable with a solid image. We can
* a solid image. We can consider the * consider the overlapping region as synchronized.
* overlapping region as synchronized.
*/ */
#ifdef TEST #ifdef TEST
...@@ -923,15 +872,9 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -923,15 +872,9 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
int x, int y, int w, int h, int leftPad, int x, int y, int w, int h, int leftPad,
int format, char *data) int format, char *data)
{ {
int length;
int bytesPerLine;
int numSubImages;
int totalHeight;
/* /*
* NXPutPackedImage is longer than PutPackedImage * NXPutPackedImage is longer than PutPackedImage so that we
* so that we subtract the bigger one to be sure. * subtract the bigger one to be sure.
*/ */
const int subSize = (MAX_REQUEST_SIZE << 2) - sizeof(xNXPutPackedImageReq); const int subSize = (MAX_REQUEST_SIZE << 2) - sizeof(xNXPutPackedImageReq);
...@@ -942,7 +885,6 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -942,7 +885,6 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
XImage *image = NULL; XImage *image = NULL;
if (NXDisplayError(nxagentDisplay) == 1) if (NXDisplayError(nxagentDisplay) == 1)
{ {
#ifdef TEST #ifdef TEST
...@@ -953,8 +895,7 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -953,8 +895,7 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
} }
/* /*
* Get the visual according to the * Get the visual according to the drawable and depth.
* drawable and depth.
*/ */
pVisual = nxagentImageVisual(pDrawable, depth); pVisual = nxagentImageVisual(pDrawable, depth);
...@@ -972,21 +913,21 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -972,21 +913,21 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
* Get bytes per line according to format. * Get bytes per line according to format.
*/ */
bytesPerLine = nxagentImagePad(w, format, leftPad, depth); int bytesPerLine = nxagentImagePad(w, format, leftPad, depth);
if (nxagentOption(Shadow) == 1 && format == ZPixmap && if (nxagentOption(Shadow) == 1 && format == ZPixmap &&
(nxagentOption(XRatio) != DONT_SCALE || (nxagentOption(XRatio) != DONT_SCALE ||
nxagentOption(YRatio) != DONT_SCALE) && nxagentOption(YRatio) != DONT_SCALE) &&
pDrawable == (DrawablePtr) nxagentShadowPixmapPtr) pDrawable == (DrawablePtr) nxagentShadowPixmapPtr)
{ {
int scaledx;
int scaledy;
image = XCreateImage(nxagentDisplay, pVisual, depth, ZPixmap, image = XCreateImage(nxagentDisplay, pVisual, depth, ZPixmap,
0, data, w, h, BitmapPad(nxagentDisplay), bytesPerLine); 0, data, w, h, BitmapPad(nxagentDisplay), bytesPerLine);
if (image != NULL) if (image != NULL)
{ {
int scaledx;
int scaledy;
image -> byte_order = IMAGE_BYTE_ORDER; image -> byte_order = IMAGE_BYTE_ORDER;
image -> bitmap_bit_order = BITMAP_BIT_ORDER; image -> bitmap_bit_order = BITMAP_BIT_ORDER;
...@@ -1021,13 +962,13 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -1021,13 +962,13 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
goto nxagentRealizeImageEnd; goto nxagentRealizeImageEnd;
} }
totalHeight = h; int totalHeight = h;
length = bytesPerLine * h; int length = bytesPerLine * h;
h = (subSize < length ? subSize : length) / bytesPerLine; h = (subSize < length ? subSize : length) / bytesPerLine;
numSubImages = totalHeight / h + 1; int numSubImages = totalHeight / h + 1;
while (numSubImages > 0) while (numSubImages > 0)
{ {
...@@ -1096,13 +1037,13 @@ void nxagentPutSubImage(DrawablePtr pDrawable, GCPtr pGC, int depth, ...@@ -1096,13 +1037,13 @@ void nxagentPutSubImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
/* /*
* XCreateImage is the place where the leftPad should be passed. * XCreateImage is the place where the leftPad should be passed.
* The image data is received from our client unmodified. In * The image data is received from our client unmodified. In theory
* theory what we would need to do is just creating an appropri- * what we would need to do is just creating an appropriate XImage
* ate XImage structure based on the incoming data and let Xlib * structure based on the incoming data and let Xlib do the
* do the rest. Probably we don't have to pass leftPad again in * rest. Probably we don't have to pass leftPad again in the src_x
* the src_x of XPutImage otherwise the src_x would make Xlib * of XPutImage otherwise the src_x would make Xlib to take into
* to take into account the xoffset field twice. Unfortunately * account the xoffset field twice. Unfortunately passing the
* passing the leftPad doesn't work. * leftPad doesn't work.
* *
* plainImage = XCreateImage(nxagentDisplay, pVisual, * plainImage = XCreateImage(nxagentDisplay, pVisual,
* depth, format, leftPad, data, * depth, format, leftPad, data,
...@@ -1156,10 +1097,9 @@ FIXME: Should use an unpack resource here. ...@@ -1156,10 +1097,9 @@ FIXME: Should use an unpack resource here.
#endif #endif
/* /*
* We got the image data from the X client or * We got the image data from the X client or from the frame-buffer
* from the frame-buffer with our own endianness. * with our own endianness. Byte swap the image data if the display
* Byte swap the image data if the display has * has a different endianness than our own.
* a different endianness than our own.
*/ */
if (nxagentImageNormalize(plainImage) != 0) if (nxagentImageNormalize(plainImage) != 0)
...@@ -1176,10 +1116,9 @@ FIXME: Should use an unpack resource here. ...@@ -1176,10 +1116,9 @@ FIXME: Should use an unpack resource here.
#endif #endif
/* /*
* Check if the user requested to pack the * Check if the user requested to pack the image but don't pack it
* image but don't pack it if we are not * if we are not connected to a proxy or if the depth is less than
* connected to a proxy or if the depth is * 15 bpp.
* less than 15 bpp.
*/ */
pack = (nxagentOption(LinkType) != LINK_TYPE_NONE && pack = (nxagentOption(LinkType) != LINK_TYPE_NONE &&
...@@ -1190,9 +1129,8 @@ FIXME: Should use an unpack resource here. ...@@ -1190,9 +1129,8 @@ FIXME: Should use an unpack resource here.
if (pack == 1 && lossless == 0) if (pack == 1 && lossless == 0)
{ {
/* /*
* Force the image to be sent as a plain * Force the image to be sent as a plain bitmap if we don't have
* bitmap if we don't have any lossless * any lossless encoder available.
* encoder available.
*/ */
if (w <= IMAGE_PACK_WIDTH || h <= IMAGE_PACK_HEIGHT || if (w <= IMAGE_PACK_WIDTH || h <= IMAGE_PACK_HEIGHT ||
...@@ -1231,8 +1169,8 @@ FIXME: Should use an unpack resource here. ...@@ -1231,8 +1169,8 @@ FIXME: Should use an unpack resource here.
if (pack == 1) if (pack == 1)
{ {
/* /*
* Set the geometry and alpha channel * Set the geometry and alpha channel to be used for the unpacked
* to be used for the unpacked image. * image.
*/ */
if (nxagentUnpackVisualId[client -> index] != pVisual -> visualid) if (nxagentUnpackVisualId[client -> index] != pVisual -> visualid)
...@@ -1248,9 +1186,8 @@ FIXME: Should use an unpack resource here. ...@@ -1248,9 +1186,8 @@ FIXME: Should use an unpack resource here.
} }
/* /*
* Check if the image is supposed to carry * Check if the image is supposed to carry the alpha data in the
* the alpha data in the fourth byte and, * fourth byte and, if so, send the alpha channel using the
* if so, send the alpha channel using the
* specific encoding. * specific encoding.
*/ */
...@@ -1260,46 +1197,43 @@ FIXME: Should use an unpack resource here. ...@@ -1260,46 +1197,43 @@ FIXME: Should use an unpack resource here.
} }
/* /*
* If the image doesn't come from the XVideo or the * If the image doesn't come from the XVideo or the GLX extension
* GLX extension try to locate it in the cache. The * try to locate it in the cache. The case of the lossless trap is
* case of the lossless trap is also special, as we * also special, as we want to eventually encode the image again
* want to eventually encode the image again using * using a lossless compression.
* a lossless compression.
*/ */
/* /*
FIXME: Should try to locate the image anyway, if the lossless FIXME: Should try to locate the image anyway, if the lossless trap is
trap is set, and if the image was encoded by a lossy set, and if the image was encoded by a lossy compressor, roll
compressor, roll back the changes and encode the image back the changes and encode the image again using the preferred
again using the preferred method. method.
*/ */
if (nxagentNeedCache(plainImage, packMethod) && if (nxagentNeedCache(plainImage, packMethod) &&
nxagentGlxTrap == 0 && nxagentXvTrap == 0 && nxagentGlxTrap == 0 && nxagentXvTrap == 0 &&
nxagentLosslessTrap == 0 && NXImageCacheSize > 0) nxagentLosslessTrap == 0 && NXImageCacheSize > 0)
{ {
/* /*
* Be sure that the padding bits are * Be sure that the padding bits are cleaned before calculating
* cleaned before calculating the MD5 * the MD5 checksum.
* checksum.
*/ */
/* /*
FIXME: There should be a callback registered by the agent that FIXME: There should be a callback registered by the agent that
provides a statistics report, in text format, telling provides a statistics report, in text format, telling for
for example how many images were searched in the cache, example how many images were searched in the cache, how many
how many were found, how many drawables are to be synch- were found, how many drawables are to be synchronized,
ronized, etc. This statistics report would be included etc. This statistics report would be included by the proxy in
by the proxy in its stat output. its stat output.
*/ */
clean = 1; clean = 1;
NXCleanImage(plainImage); NXCleanImage(plainImage);
/* /*
* Will return a pointer to the image and checksum * Will return a pointer to the image and checksum taken from
* taken from the cache, if found. If the image is * the cache, if found. If the image is not found, the function
* not found, the function returns a null image and * returns a null image and a pointer to the calculated
* a pointer to the calculated checksum. It is up * checksum. It is up to the application to free the memory. We
* to the application to free the memory. We will * will use the checksum to add the image in the cache.
* use the checksum to add the image in the cache.
*/ */
packedImage = NXCacheFindImage(plainImage, &packMethod, &packedChecksum); packedImage = NXCacheFindImage(plainImage, &packMethod, &packedChecksum);
...@@ -1336,9 +1270,8 @@ FIXME: There should be a callback registered by the agent that ...@@ -1336,9 +1270,8 @@ FIXME: There should be a callback registered by the agent that
} }
/* /*
* If a specific encoder was not mandated, * If a specific encoder was not mandated, try to guess if a
* try to guess if a lossless encoder will * lossless encoder will compress better.
* compress better.
*/ */
if (lossless == 0 && nxagentOption(Adaptive) == 1) if (lossless == 0 && nxagentOption(Adaptive) == 1)
...@@ -1366,8 +1299,7 @@ FIXME: There should be a callback registered by the agent that ...@@ -1366,8 +1299,7 @@ FIXME: There should be a callback registered by the agent that
} }
/* /*
* Encode the image using the selected * Encode the image using the selected pack method.
* pack method.
*/ */
if (packMethod == PACK_RLE_16M_COLORS || if (packMethod == PACK_RLE_16M_COLORS ||
...@@ -1375,13 +1307,11 @@ FIXME: There should be a callback registered by the agent that ...@@ -1375,13 +1307,11 @@ FIXME: There should be a callback registered by the agent that
packMethod == PACK_BITMAP_16M_COLORS) packMethod == PACK_BITMAP_16M_COLORS)
{ {
/* /*
* Cleanup the image if we didn't do that yet. * Cleanup the image if we didn't do that yet. We assume that
* We assume that the JPEG and PNG compression * the JPEG and PNG compression methods will actually ignore the
* methods will actually ignore the padding * padding bytes. In other words, bitmap images producing the
* bytes. In other words, bitmap images prod- * same visual output should produce compressed images that are
* ucing the same visual output should produce * bitwise the same regardless the padding bits.
* compressed images that are bitwise the same
* regardless the padding bits.
*/ */
if (clean == 0) if (clean == 0)
...@@ -1397,30 +1327,25 @@ FIXME: There should be a callback registered by the agent that ...@@ -1397,30 +1327,25 @@ FIXME: There should be a callback registered by the agent that
switch (packMethod) switch (packMethod)
{ {
/* /*
* If nothing is done by the bitmap encoder, * If nothing is done by the bitmap encoder, it saves an
* it saves an allocation and a memory copy * allocation and a memory copy by setting the data field of
* by setting the data field of the packed * the packed image to the original data. We need to check
* image to the original data. We need to * this at the time we will free the packed image.
* check this at the time we will free the
* packed image.
*/ */
case PACK_BITMAP_16M_COLORS: case PACK_BITMAP_16M_COLORS:
{ {
packedImage = NXEncodeBitmap(plainImage, packMethod, packQuality); packedImage = NXEncodeBitmap(plainImage, packMethod, packQuality);
break; break;
} }
case PACK_RGB_16M_COLORS: case PACK_RGB_16M_COLORS:
{ {
packedImage = NXEncodeRgb(plainImage, packMethod, packQuality); packedImage = NXEncodeRgb(plainImage, packMethod, packQuality);
break; break;
} }
default: default:
{ {
packedImage = NXEncodeRle(plainImage, packMethod, packQuality); packedImage = NXEncodeRle(plainImage, packMethod, packQuality);
break; break;
} }
} }
...@@ -1447,8 +1372,8 @@ FIXME: There should be a callback registered by the agent that ...@@ -1447,8 +1372,8 @@ FIXME: There should be a callback registered by the agent that
} }
/* /*
* If we didn't produce a valid packed * If we didn't produce a valid packed image, send the image as a X
* image, send the image as a X bitmap. * bitmap.
*/ */
if (packedImage != NULL) if (packedImage != NULL)
...@@ -1467,10 +1392,8 @@ FIXME: There should be a callback registered by the agent that ...@@ -1467,10 +1392,8 @@ FIXME: There should be a callback registered by the agent that
0, 0, x, y, w, h); 0, 0, x, y, w, h);
/* /*
* Add the image only if we have a valid * Add the image only if we have a valid checksum. This is the
* checksum. This is the case only if we * case only if we originally tried to find the image in cache.
* originally tried to find the image in
* cache.
*/ */
if (NXImageCacheSize > 0 && packedChecksum != NULL) if (NXImageCacheSize > 0 && packedChecksum != NULL)
...@@ -1481,9 +1404,8 @@ FIXME: There should be a callback registered by the agent that ...@@ -1481,9 +1404,8 @@ FIXME: There should be a callback registered by the agent that
#endif #endif
/* /*
* Check if both the plain and the packed * Check if both the plain and the packed image point to the
* image point to the same data. In this * same data. In this case we need a copy.
* case we need a copy.
*/ */
if (packedImage -> data == plainImage -> data && if (packedImage -> data == plainImage -> data &&
...@@ -1504,19 +1426,17 @@ FIXME: There should be a callback registered by the agent that ...@@ -1504,19 +1426,17 @@ FIXME: There should be a callback registered by the agent that
else else
{ {
/* /*
* Clean the image to help the proxy to match * Clean the image to help the proxy to match the checksum in its
* the checksum in its cache. Do that only if * cache. Do that only if the differential compression is enabled
* the differential compression is enabled and * and if the image is not supposed to carry the alpha data in the
* if the image is not supposed to carry the * fourth byte of the pixel.
* alpha data in the fourth byte of the pixel.
*/ */
/* /*
FIXME: If we failed to encode the image by any of the available FIXME: If we failed to encode the image by any of the available
methods, for example if we couldn't allocate memory, we methods, for example if we couldn't allocate memory, we may
may need to ripristinate the alpha channel, that in the need to ripristinate the alpha channel, that in the meanwhile
meanwhile was sent in the unpack alpha message. This can was sent in the unpack alpha message. This can be done here, if
be done here, if the clean flag is true and we are going the clean flag is true and we are going to send a plain image.
to send a plain image.
*/ */
if (clean == 0) if (clean == 0)
{ {
...@@ -1610,17 +1530,14 @@ void nxagentGetImage(DrawablePtr pDrawable, int x, int y, int w, int h, ...@@ -1610,17 +1530,14 @@ void nxagentGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
} }
/* /*
* We have to reset the visual cache before * We have to reset the visual cache before connecting to another
* connecting to another display, so that a * display, so that a new unpack geometry can be communicated to the
* new unpack geometry can be communicated * new proxy.
* to the new proxy.
*/ */
void nxagentResetVisualCache(void) void nxagentResetVisualCache(void)
{ {
int i; for (int i = 0; i < MAX_CONNECTIONS; i++)
for (i = 0; i < MAX_CONNECTIONS; i++)
{ {
nxagentUnpackVisualId[i] = None; nxagentUnpackVisualId[i] = None;
} }
...@@ -1628,9 +1545,7 @@ void nxagentResetVisualCache(void) ...@@ -1628,9 +1545,7 @@ void nxagentResetVisualCache(void)
void nxagentResetAlphaCache(void) void nxagentResetAlphaCache(void)
{ {
int i; for (int i = 0; i < MAX_CONNECTIONS; i++)
for (i = 0; i < MAX_CONNECTIONS; i++)
{ {
if (nxagentUnpackAlpha[i]) if (nxagentUnpackAlpha[i])
{ {
...@@ -1643,53 +1558,23 @@ void nxagentResetAlphaCache(void) ...@@ -1643,53 +1558,23 @@ void nxagentResetAlphaCache(void)
int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
XImage **pImage, int *scaledx, int *scaledy) XImage **pImage, int *scaledx, int *scaledy)
{ {
int x1;
int x2;
int y1;
int y2;
int xx1;
int xx2;
int yy1;
int yy2;
int newWidth;
int newHeight;
int i;
int j;
int k;
int l;
unsigned long val;
XImage *newImage;
XImage *image = *pImage; XImage *image = *pImage;
#ifdef FAST_GET_PUT_PIXEL
register char *srcPixel;
register char *dstPixel;
int i;
#endif
if (image == NULL) if (image == NULL)
{ {
return 0; return 0;
} }
x1 = (xRatio * x) >> PRECISION; int x1 = (xRatio * x) >> PRECISION;
x2 = (xRatio * (x + image -> width)) >> PRECISION; int x2 = (xRatio * (x + image -> width)) >> PRECISION;
y1 = (yRatio * y) >> PRECISION; int y1 = (yRatio * y) >> PRECISION;
y2 = (yRatio * (y + image -> height)) >> PRECISION; int y2 = (yRatio * (y + image -> height)) >> PRECISION;
newWidth = x2 - x1; int newWidth = x2 - x1;
newHeight = y2 - y1; int newHeight = y2 - y1;
newImage = XCreateImage(nxagentDisplay, NULL, image -> depth, image -> format, 0, NULL, XImage *newImage = XCreateImage(nxagentDisplay, NULL, image -> depth, image -> format, 0, NULL,
newWidth, newHeight, BitmapPad(nxagentDisplay), newWidth, newHeight, BitmapPad(nxagentDisplay),
PixmapBytePad(newWidth, image -> depth)); PixmapBytePad(newWidth, image -> depth));
...@@ -1725,39 +1610,40 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, ...@@ -1725,39 +1610,40 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
newImage -> width = newWidth; newImage -> width = newWidth;
newImage -> height = newHeight; newImage -> height = newHeight;
for (j = y; j < y + image -> height; j++) for (int j = y; j < y + image -> height; j++)
{ {
yy1 = (yRatio * j) >> PRECISION; int yy1 = (yRatio * j) >> PRECISION;
yy2 = (yRatio * (j + 1)) >> PRECISION; int yy2 = (yRatio * (j + 1)) >> PRECISION;
for (i = x; i < x + image -> width; i++) for (int i = x; i < x + image -> width; i++)
{ {
unsigned long val;
#ifndef FAST_GET_PUT_PIXEL #ifndef FAST_GET_PUT_PIXEL
val = XGetPixel(image, i - x, j - y); val = XGetPixel(image, i - x, j - y);
#else #else
srcPixel = &image -> data[(j * image -> bytes_per_line) + char * srcPixel = &image -> data[(j * image -> bytes_per_line) +
((i * image -> bits_per_pixel) >> 3)]; ((i * image -> bits_per_pixel) >> 3)];
char * dstPixel = (char *) &val;
dstPixel = (char *) &val;
val = 0; val = 0;
for (i = (image -> bits_per_pixel + 7) >> 3; --i >= 0; ) for (int m = (image -> bits_per_pixel + 7) >> 3; --m >= 0; )
{ {
*dstPixel++ = *srcPixel++; *dstPixel++ = *srcPixel++;
} }
#endif #endif
xx1 = (xRatio * i) >> PRECISION; int xx1 = (xRatio * i) >> PRECISION;
xx2 = (xRatio * (i + 1)) >> PRECISION; int xx2 = (xRatio * (i + 1)) >> PRECISION;
for (l = yy1; l < yy2; l++) for (int l = yy1; l < yy2; l++)
{ {
for (k = xx1; k < xx2; k++) for (int k = xx1; k < xx2; k++)
{ {
#ifndef FAST_GET_PUT_PIXEL #ifndef FAST_GET_PUT_PIXEL
...@@ -1765,12 +1651,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, ...@@ -1765,12 +1651,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
#else #else
dstPixel = &newImage -> data[((l - y1) * newImage -> bytes_per_line) + char *dstPixel = &newImage -> data[((l - y1) * newImage -> bytes_per_line) +
(((k - x1) * newImage -> bits_per_pixel) >> 3)]; (((k - x1) * newImage -> bits_per_pixel) >> 3)];
srcPixel = (char *) &val; char *srcPixel = (char *) &val;
for (i = (newImage -> bits_per_pixel + 7) >> 3; --i >= 0; ) for (int m = (newImage -> bits_per_pixel + 7) >> 3; --m >= 0; )
{ {
*dstPixel++ = *srcPixel++; *dstPixel++ = *srcPixel++;
} }
...@@ -1794,19 +1680,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, ...@@ -1794,19 +1680,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
char *nxagentAllocateImageData(int width, int height, int depth, int *length, int *format) char *nxagentAllocateImageData(int width, int height, int depth, int *length, int *format)
{ {
char *data;
int leftPad;
leftPad = 0;
*format = (depth == 1) ? XYPixmap : ZPixmap; *format = (depth == 1) ? XYPixmap : ZPixmap;
*length = nxagentImageLength(width, height, *format, leftPad, depth); *length = nxagentImageLength(width, height, *format, 0, depth);
data = NULL;
if ((data = malloc(*length)) == NULL) char *data = malloc(*length);
if (data == NULL)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentAllocateImageData: WARNING! Failed to allocate [%d] bytes of memory.\n", *length); fprintf(stderr, "nxagentAllocateImageData: WARNING! Failed to allocate [%d] bytes of memory.\n", *length);
......
...@@ -89,44 +89,35 @@ is" without express or implied warranty. ...@@ -89,44 +89,35 @@ is" without express or implied warranty.
/* /*
* ProcVector array defined in tables.c. * ProcVector array defined in tables.c.
*/ */
extern int (*ProcVector[256])(ClientPtr); extern int (*ProcVector[256])(ClientPtr);
/* /*
* From the fb code. * From the fb code.
*/ */
extern int fbGCPrivateIndex; extern int fbGCPrivateIndex;
#ifdef DPMSExtension
/* /*
* Stubs for the DPMS extension. * Stubs for the DPMS extension.
*/ */
#ifdef DPMSExtension
void DPMSSet(int level); void DPMSSet(int level);
int DPMSGet(int *level); int DPMSGet(int *level);
Bool DPMSSupported(void); Bool DPMSSupported(void);
#endif #endif
/* /*
* Our error logging function. * Our error logging function.
*/ */
void OsVendorVErrorFFunction(const char *f, va_list args); void OsVendorVErrorFFunction(const char *f, va_list args);
/* /*
* True if this is a fatal error. * True if this is a fatal error.
*/ */
extern int OsVendorVErrorFFatal; extern int OsVendorVErrorFFatal;
/* /*
* Redirect the error output to a * Redirect the error output to a different file
* different file
*/ */
extern void (*OsVendorStartRedirectErrorFProc)(); extern void (*OsVendorStartRedirectErrorFProc)();
extern void (*OsVendorEndRedirectErrorFProc)(); extern void (*OsVendorEndRedirectErrorFProc)();
...@@ -136,11 +127,8 @@ void OsVendorStartRedirectErrorFFunction(); ...@@ -136,11 +127,8 @@ void OsVendorStartRedirectErrorFFunction();
void OsVendorEndRedirectErrorFFunction(); void OsVendorEndRedirectErrorFFunction();
/* /*
* Called by InitGlobals() in the * Called by InitGlobals() in the new X server tree.
* new X server tree.
*/ */
static void nxagentGrabServerCallback(CallbackListPtr *callbacks, void *data, static void nxagentGrabServerCallback(CallbackListPtr *callbacks, void *data,
void *args); void *args);
...@@ -164,12 +152,11 @@ void ddxInitGlobals(void) ...@@ -164,12 +152,11 @@ void ddxInitGlobals(void)
} }
/* /*
* Set if the remote display supports * Set if the remote display supports backing store.
* backing store.
*/ */
/* /*
FIXME: These, if not removed, should at least FIXME: These, if not removed, should at least be moved to Display.h
be moved to Display.h and Display.c. and Display.c.
*/ */
int nxagentBackingStore; int nxagentBackingStore;
int nxagentSaveUnder; int nxagentSaveUnder;
...@@ -187,7 +174,6 @@ int nxagentSaveUnder; ...@@ -187,7 +174,6 @@ int nxagentSaveUnder;
* nxagentOpenScreen * nxagentOpenScreen
* InitInput * InitInput
*/ */
int nxagentDoFullGeneration = 1; int nxagentDoFullGeneration = 1;
/* /*
...@@ -197,9 +183,8 @@ int nxagentDoFullGeneration = 1; ...@@ -197,9 +183,8 @@ int nxagentDoFullGeneration = 1;
Bool nxagentX2go; Bool nxagentX2go;
/* /*
* Check if agent is x2go agent * Check if agent is X2goAgent
*/ */
void checkX2goAgent(void) void checkX2goAgent(void)
{ {
#ifdef TEST #ifdef TEST
...@@ -215,11 +200,9 @@ void checkX2goAgent(void) ...@@ -215,11 +200,9 @@ void checkX2goAgent(void)
nxagentX2go = False; nxagentX2go = False;
} }
/* /*
* Called at X server's initialization. * Called at X server's initialization.
*/ */
void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
{ {
/* /*
...@@ -244,8 +227,8 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) ...@@ -244,8 +227,8 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
} }
/* /*
* Avoid slowness due to buggy_repeat workaround * Avoid slowness due to buggy_repeat workaround in libcairo
* in libcairo versions >= 1.10. * versions >= 1.10.
*/ */
SetVendorRelease(70000000); SetVendorRelease(70000000);
...@@ -260,9 +243,8 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) ...@@ -260,9 +243,8 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
} }
/* /*
* Unset the LD_LIBRARY_PATH variable in * Unset the LD_LIBRARY_PATH variable in Popen() before calling
* Popen() before calling execl() in the * execl() in the child process.
* child process.
*/ */
NXUnsetLibraryPath(1); NXUnsetLibraryPath(1);
...@@ -314,15 +296,13 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) ...@@ -314,15 +296,13 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
nxagentInitBSPixmapList(); nxagentInitBSPixmapList();
/* /*
* Open the display. We are at the early startup and * Open the display. We are at the early startup and the information
* the information we'll get from the remote X server * we'll get from the remote X server will mandate some of the
* will mandate some of the characteristics of the * characteristics of the session, like the screen depth. Note that
* session, like the screen depth. Note that this re- * this reliance on the remote display at session startup should be
* liance on the remote display at session startup * removed. We should always operate at 32 bpp, internally, and do
* should be removed. We should always operate at 32 * the required translations as soon as the graphic operation needs
* bpp, internally, and do the required translations * to be realized on the remote display.
* as soon as the graphic operation needs to be real-
* ized on the remote display.
*/ */
nxagentOpenDisplay(argc, argv); nxagentOpenDisplay(argc, argv);
...@@ -393,9 +373,8 @@ FIXME: These variables, if not removed at all because have probably ...@@ -393,9 +373,8 @@ FIXME: These variables, if not removed at all because have probably
nxagentNumScreens = screenInfo->numScreens; nxagentNumScreens = screenInfo->numScreens;
/* /*
* Initialize the GCs used by the synchro- * Initialize the GCs used by the synchronization put images. We do
* nization put images. We do it here beca- * it here because we use the nxagentDefaultScreen.
* use we use the nxagentDefaultScreen.
*/ */
nxagentAllocateGraphicContexts(); nxagentAllocateGraphicContexts();
...@@ -403,8 +382,7 @@ FIXME: These variables, if not removed at all because have probably ...@@ -403,8 +382,7 @@ FIXME: These variables, if not removed at all because have probably
nxagentDoFullGeneration = nxagentFullGeneration; nxagentDoFullGeneration = nxagentFullGeneration;
/* /*
* Use a solid black root window * Use a solid black root window background.
* background.
*/ */
if (!whiteRoot) if (!whiteRoot)
...@@ -419,15 +397,12 @@ FIXME: These variables, if not removed at all because have probably ...@@ -419,15 +397,12 @@ FIXME: These variables, if not removed at all because have probably
nxagentInitAtoms(); nxagentInitAtoms();
} }
void void nxagentNotifyConnection(int fd, int ready, void *data)
nxagentNotifyConnection(int fd, int ready, void *data)
{ {
nxagentDispatchEvents(NULL); nxagentDispatchEvents(NULL);
} }
void InitInput(argc, argv) void InitInput(int argc, char *argv[])
int argc;
char *argv[];
{ {
void *ptr, *kbd; void *ptr, *kbd;
...@@ -440,9 +415,8 @@ void InitInput(argc, argv) ...@@ -440,9 +415,8 @@ void InitInput(argc, argv)
mieqInit(kbd, ptr); mieqInit(kbd, ptr);
/* /*
* Add the display descriptor to the * Add the display descriptor to the set of descriptors awaited by
* set of descriptors awaited by the * the dispatcher.
* dispatcher.
*/ */
nxagentAddXConnection(); nxagentAddXConnection();
...@@ -457,10 +431,9 @@ void InitInput(argc, argv) ...@@ -457,10 +431,9 @@ void InitInput(argc, argv)
} }
/* /*
* We let the proxy flush the link on our behalf * We let the proxy flush the link on our behalf after having opened
* after having opened the display. We are now * the display. We are now entering the dispatcher. From now on
* entering the dispatcher. From now on we'll * we'll flush the proxy link explicitly.
* flush the proxy link explicitly.
*/ */
#ifdef TEST #ifdef TEST
...@@ -471,11 +444,9 @@ void InitInput(argc, argv) ...@@ -471,11 +444,9 @@ void InitInput(argc, argv)
} }
/* /*
* DDX specific abort routine. This is called * DDX specific abort routine. This is called by AbortServer() that,
* by AbortServer() that, in turn, is called * in turn, is called by FatalError().
* by FatalError().
*/ */
void AbortDDX(void) void AbortDDX(void)
{ {
nxagentDoFullGeneration = True; nxagentDoFullGeneration = True;
...@@ -483,9 +454,8 @@ void AbortDDX(void) ...@@ -483,9 +454,8 @@ void AbortDDX(void)
nxagentCloseDisplay(); nxagentCloseDisplay();
/* /*
* Do the required finalization if we * Do the required finalization if we are not going through the
* are not going through the normal * normal X server shutdown.
* X server shutdown.
*/ */
if ((dispatchException & DE_TERMINATE) == 0) if ((dispatchException & DE_TERMINATE) == 0)
...@@ -497,7 +467,6 @@ void AbortDDX(void) ...@@ -497,7 +467,6 @@ void AbortDDX(void)
/* /*
* Called by GiveUp(). * Called by GiveUp().
*/ */
void ddxGiveUp(void) void ddxGiveUp(void)
{ {
AbortDDX(); AbortDDX();
...@@ -515,12 +484,10 @@ void OsVendorInit(void) ...@@ -515,12 +484,10 @@ void OsVendorInit(void)
void OsVendorFatalError(void) void OsVendorFatalError(void)
{ {
/* /*
* Let the session terminate gracely * Let the session terminate gracely from an user's standpoint.
* from an user's standpoint.
*/ */
fprintf(stderr, "Session: Aborting session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Aborting session at '%s'.\n", GetTimeAsString());
fprintf(stderr, "Session: Session aborted at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Session aborted at '%s'.\n", GetTimeAsString());
} }
...@@ -566,7 +533,6 @@ static void nxagentGrabServerCallback(CallbackListPtr *callbacks, void *data, ...@@ -566,7 +533,6 @@ static void nxagentGrabServerCallback(CallbackListPtr *callbacks, void *data,
} }
#ifdef DPMSExtension #ifdef DPMSExtension
void DPMSSet(int level) void DPMSSet(int level)
{ {
} }
...@@ -580,5 +546,4 @@ Bool DPMSSupported(void) ...@@ -580,5 +546,4 @@ Bool DPMSSupported(void)
{ {
return 0; return 0;
} }
#endif #endif
...@@ -104,10 +104,9 @@ static void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, cha ...@@ -104,10 +104,9 @@ static void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, cha
#endif #endif
/* /*
* Unfortunately we cannot just include XKBlib.h. * Unfortunately we cannot just include XKBlib.h. It conflicts with
* It conflicts with the server side definitions * the server side definitions of the same symbols. This is more a X
* of the same symbols. This is more a X problem * problem than our.
* than our.
*/ */
#ifdef XKB #ifdef XKB
...@@ -158,8 +157,7 @@ static char *nxagentRemoteOptions = NULL; ...@@ -158,8 +157,7 @@ static char *nxagentRemoteOptions = NULL;
XkbAgentInfoRec nxagentXkbInfo = { -1, -1, -1, -1, -1 }; XkbAgentInfoRec nxagentXkbInfo = { -1, -1, -1, -1, -1 };
/* /*
* Keyboard status, updated through XKB * Keyboard status, updated through XKB events.
* events.
*/ */
XkbAgentStateRec nxagentXkbState = { 0, 0, 0, 0, 0 }; XkbAgentStateRec nxagentXkbState = { 0, 0, 0, 0, 0 };
...@@ -283,9 +281,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -283,9 +281,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
/* /*
* We want to prevent agent generating auto-repeated * We want to prevent agent generating auto-repeated
* keystrokes. Let's intercept any attempt by appli- * keystrokes. Let's intercept any attempt by appli- cations to
* cations to change the default timeouts on the * change the default timeouts on the nxagent device.
* nxagent device.
*/ */
#ifdef TEST #ifdef TEST
...@@ -305,8 +302,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -305,8 +302,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
#endif #endif
/* /*
* If enabled, propagate the changes to the * If enabled, propagate the changes to the devices attached to the
* devices attached to the real X server. * real X server.
*/ */
if (nxagentOption(DeviceControl)) if (nxagentOption(DeviceControl))
...@@ -315,10 +312,7 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -315,10 +312,7 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
fprintf(stderr, "%s: WARNING! Propagating changes to keyboard settings.\n", __func__); fprintf(stderr, "%s: WARNING! Propagating changes to keyboard settings.\n", __func__);
#endif #endif
unsigned long value_mask = KBKeyClickPercent | unsigned long value_mask = KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration;
KBBellPercent |
KBBellPitch |
KBBellDuration;
XKeyboardControl values = { XKeyboardControl values = {
.key_click_percent = ctrl->click, .key_click_percent = ctrl->click,
...@@ -328,8 +322,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -328,8 +322,8 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
}; };
/* /*
* Don't propagate the auto repeat mode. It is forced to be * Don't propagate the auto repeat mode. It is forced to be off in
* off in the agent server. * the agent server.
* *
* value_mask |= KBAutoRepeatMode; * value_mask |= KBAutoRepeatMode;
* values.auto_repeat_mode = ctrl->autoRepeat ? * values.auto_repeat_mode = ctrl->autoRepeat ?
...@@ -339,9 +333,9 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -339,9 +333,9 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
XChangeKeyboardControl(nxagentDisplay, value_mask, &values); XChangeKeyboardControl(nxagentDisplay, value_mask, &values);
/* /*
* At this point, we need to walk through the vector and * At this point, we need to walk through the vector and compare
* compare it to the current server vector. If there are * it to the current server vector. If there are differences,
* differences, report them. * report them.
*/ */
value_mask = KBLed | KBLedMode; value_mask = KBLed | KBLedMode;
...@@ -403,11 +397,11 @@ N/A ...@@ -403,11 +397,11 @@ N/A
#endif #endif
/* /*
* Prevent agent from generating auto-repeat keystroke. * Prevent agent from generating auto-repeat keystroke. Note
* Note that this is working only if XKB is enabled. * that this is working only if XKB is enabled. A better
* A better solution should account cases where XKB is * solution should account cases where XKB is not
* not available. Check also the behaviour of the * available. Check also the behaviour of the DeviceControl
* DeviceControl nxagent option. * nxagent option.
*/ */
XkbDfltRepeatDelay = ~ 0; XkbDfltRepeatDelay = ~ 0;
...@@ -432,7 +426,6 @@ N/A ...@@ -432,7 +426,6 @@ N/A
min_keycode, min_keycode,
max_keycode - min_keycode + 1, max_keycode - min_keycode + 1,
&mapWidth); &mapWidth);
if (keymap64 == NULL) if (keymap64 == NULL)
{ {
XFreeModifiermap(modifier_keymap); XFreeModifiermap(modifier_keymap);
...@@ -607,8 +600,8 @@ XkbError: ...@@ -607,8 +600,8 @@ XkbError:
} }
/* /*
* There is no description for pc105 on Solaris. * There is no description for pc105 on Solaris. Need to
* Need to revert to the closest approximation. * revert to the closest approximation.
*/ */
#ifdef TEST #ifdef TEST
...@@ -870,7 +863,6 @@ void nxagentNotifyKeyboardChanges(int oldMinKeycode, int oldMaxKeycode) ...@@ -870,7 +863,6 @@ void nxagentNotifyKeyboardChanges(int oldMinKeycode, int oldMaxKeycode)
#endif #endif
xEvent event = {0}; xEvent event = {0};
event.u.u.type = MappingNotify; event.u.u.type = MappingNotify;
event.u.mappingNotify.request = MappingKeyboard; event.u.mappingNotify.request = MappingKeyboard;
event.u.mappingNotify.firstKeyCode = inputInfo.keyboard -> key -> curKeySyms.minKeyCode; event.u.mappingNotify.firstKeyCode = inputInfo.keyboard -> key -> curKeySyms.minKeyCode;
...@@ -943,12 +935,11 @@ int nxagentResetKeyboard(void) ...@@ -943,12 +935,11 @@ int nxagentResetKeyboard(void)
} }
#endif #endif
dev->key=NULL; dev->key = NULL;
} }
dev->focus=NULL; dev->focus = NULL;
dev->kbdfeed = NULL;
dev->kbdfeed=NULL;
#ifdef XKB #ifdef XKB
nxagentTuneXkbWrapper(); nxagentTuneXkbWrapper();
......
...@@ -80,6 +80,7 @@ miTrapezoids (CARD8 op, ...@@ -80,6 +80,7 @@ miTrapezoids (CARD8 op,
xDst = traps[0].left.p1.x >> 16; xDst = traps[0].left.p1.x >> 16;
yDst = traps[0].left.p1.y >> 16; yDst = traps[0].left.p1.y >> 16;
#ifdef NXAGENT_SERVER
if (nxagentTrapezoidExtents != NullBox) if (nxagentTrapezoidExtents != NullBox)
{ {
memcpy(&bounds, nxagentTrapezoidExtents, sizeof(BoxRec)); memcpy(&bounds, nxagentTrapezoidExtents, sizeof(BoxRec));
...@@ -92,7 +93,9 @@ miTrapezoids (CARD8 op, ...@@ -92,7 +93,9 @@ miTrapezoids (CARD8 op,
memcpy(nxagentTrapezoidExtents, &bounds, sizeof(BoxRec)); memcpy(nxagentTrapezoidExtents, &bounds, sizeof(BoxRec));
} }
#else
miTrapezoidBounds (ntrap, traps, &bounds);
#endif
if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
return; return;
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
......
...@@ -34,10 +34,9 @@ ...@@ -34,10 +34,9 @@
#include "Utils.h" #include "Utils.h"
/* /*
* Instead of having a single options repository * Instead of having a single options repository data could be
* data could be attached to the display or the * attached to the display or the screen. The macro nxagentOption()
* screen. The macro nxagentOption() should make * should make the transition simple.
* the transition simple.
*/ */
AgentOptionsRec nxagentOptions; AgentOptionsRec nxagentOptions;
...@@ -52,8 +51,8 @@ AgentOptionsPtr nxagentOptionsPtr = &nxagentOptions; ...@@ -52,8 +51,8 @@ AgentOptionsPtr nxagentOptionsPtr = &nxagentOptions;
unsigned int nxagentPrintGeometryFlags = 0; unsigned int nxagentPrintGeometryFlags = 0;
/* /*
* This must be called at startup to initialize * This must be called at startup to initialize the options repository
* the options repository to the default values. * to the default values.
*/ */
void nxagentInitOptions(void) void nxagentInitOptions(void)
...@@ -176,12 +175,10 @@ void nxagentInitOptions(void) ...@@ -176,12 +175,10 @@ void nxagentInitOptions(void)
} }
/* /*
* This is called at session reconnection * This is called at session reconnection to reset some options to
* to reset some options to their default * their default values. The reason to avoid calling the
* values. The reason to avoid calling the * nxagentInitOptions() is that not all the options can change value
* nxagentInitOptions() is that not all the * when reconnecting.
* options can change value when reconnec-
* ting.
*/ */
void nxagentResetOptions(void) void nxagentResetOptions(void)
......
...@@ -94,346 +94,267 @@ typedef enum _KeycodeConversion ...@@ -94,346 +94,267 @@ typedef enum _KeycodeConversion
typedef struct _AgentOptions typedef struct _AgentOptions
{ {
/* /*
* Link type of the NX connection or none, * Link type of the NX connection or none, if this is a direct X11
* if this is a direct X11 connection. * connection.
*/ */
int LinkType; int LinkType;
/* /*
* Is agent running in desktop mode? This * Is agent running in desktop mode? This is presently the default.
* is presently the default.
*/ */
int Desktop; int Desktop;
/* /*
* True if user activated rootless mode. * True if user activated rootless mode.
*/ */
int Rootless; int Rootless;
/* /*
* True for shadow mode. * True for shadow mode.
*/ */
int Shadow; int Shadow;
/* /*
* True if user activated persistent mode. * True if user activated persistent mode.
*/ */
int Persistent; int Persistent;
/* /*
* True if user activated fullscreen mode. * True if user activated fullscreen mode.
*/ */
int Fullscreen; int Fullscreen;
/* /*
* True if the fullscreen NX session will * True if the fullscreen NX session will extend on all available
* extend on all available screens. * screens.
*/ */
int AllScreens; int AllScreens;
/* /*
* Set to the auto-disconnect timeout, if * Set to the auto-disconnect timeout, if the user activated this
* the user activated this feature. * feature.
*/ */
int Timeout; int Timeout;
/* /*
* Geometry of the agent's window. * Geometry of the agent's window.
*/ */
int X, Y, Width, Height;
int X;
int Y;
int Width;
int Height;
int BorderWidth; int BorderWidth;
/* /*
* Geometry of the agent's window in window * Geometry of the agent's window in window mode. Used to restore
* mode. Used to restore window size when * window size when switching back to window mode from fullscreen.
* switching back to window mode from full-
* screen.
*/ */
int WMBorderWidth; int WMBorderWidth;
int WMTitleHeight; int WMTitleHeight;
int SavedX; int SavedX, SavedY, SavedWidth, SavedHeight;
int SavedY;
int SavedWidth;
int SavedHeight;
int SavedRootWidth; int SavedRootWidth, SavedRootHeight;
int SavedRootHeight;
/* /*
* Set if agent is running nested in another * Set if agent is running nested in another agent X server.
* agent X server.
*/ */
int Nested; int Nested;
/* /*
* Selected backing-store mode. * Selected backing-store mode.
*/ */
BackingStoreMode BackingStore; BackingStoreMode BackingStore;
/* /*
* Selected clipboard mode. * Selected clipboard mode.
*/ */
ClipboardMode Clipboard; ClipboardMode Clipboard;
/* /*
* Enable agent to use the MITSHM extension in * Enable agent to use the MITSHM extension in path from remote
* path from remote proxy to the real X server. * proxy to the real X server.
*/ */
int SharedMemory; int SharedMemory;
/* /*
* Enable agent to use shared Pixmaps * Enable agent to use shared Pixmaps
*/ */
int SharedPixmaps; int SharedPixmaps;
/* /*
* Enable agent to propagate keyboard and pointer * Enable agent to propagate keyboard and pointer device
* device configuration to the remote X server. * configuration to the remote X server.
*/ */
int DeviceControl; int DeviceControl;
/* /*
* Explicitly asked config propagation. * Explicitly asked config propagation.
*/ */
int DeviceControlUserDefined; int DeviceControlUserDefined;
/* /*
* Resuming keyboard device corrects keymap if session * Resuming keyboard device corrects keymap if session migrates
* migrates across platforms with different keycode * across platforms with different keycode layout.
* layout.
*/ */
int ResetKeyboardAtResume; int ResetKeyboardAtResume;
/* /*
* Reset server when the last client disconnects. * Reset server when the last client disconnects.
*/ */
int Reset; int Reset;
/* /*
* Geometry of the agent root window, relative to * Geometry of the agent root window, relative to the agent default
* the agent default window. * window.
*/ */
int RootX, RootY, RootWidth, RootHeight;
int RootX;
int RootY;
int RootWidth;
int RootHeight;
/* /*
* Horizontal and vertical span of the * Horizontal and vertical span of the agent viewport.
* agent viewport.
*/ */
int ViewportXSpan, ViewportYSpan;
int ViewportXSpan;
int ViewportYSpan;
/* /*
* True if the user can resize the desktop * True if the user can resize the desktop by dragging the window
* by dragging the window border. * border.
*/ */
int DesktopResize; int DesktopResize;
/* /*
* The scaling ratio of the shadow agent. * The scaling ratio of the shadow agent.
*/ */
int Ratio, XRatio, YRatio;
int Ratio; float FloatRatio, FloatXRatio, FloatYRatio;
int XRatio;
int YRatio;
float FloatRatio;
float FloatXRatio;
float FloatYRatio;
/* /*
* The shadow agent uses the Damage extension. * The shadow agent uses the Damage extension.
*/ */
int UseDamage; int UseDamage;
/* /*
* Was the agent run with the -B option? * Was the agent run with the -B option?
*/ */
int Binder; int Binder;
char *BinderOptions; char *BinderOptions;
/* /*
* Set if the agent has to connect to a * Set if the agent has to connect to a desktop manager to start the
* desktop manager to start the session. * session.
*/ */
int Xdmcp; int Xdmcp;
/* /*
* Size of the Xlib display buffer. The * Size of the Xlib display buffer. The default is set according to
* default is set according to the link * the link type.
* type.
*/ */
int DisplayBuffer; int DisplayBuffer;
/* /*
* Buffer coalescence timeout. * Buffer coalescence timeout.
*/ */
int DisplayCoalescence; int DisplayCoalescence;
/* /*
* Use the composite extension when * Use the composite extension when available on the remote display.
* available on the remote display.
*/ */
int Composite; int Composite;
/* /*
* If set, don't skip internal operations * If set, don't skip internal operations when the agent window is
* when the agent window is not fully visible. * not fully visible.
*/ */
int IgnoreVisibility; int IgnoreVisibility;
/* /*
* If set, prevent the shadow session to * If set, prevent the shadow session to interact with master
* interact with master display. * display.
*/ */
int ViewOnly; int ViewOnly;
/* /*
* If true select a lossy or lossless comp- * If true select a lossy or lossless compression method based on
* ression method based on the characterist- * the characteristics of the image.
* ics of the image.
*/ */
int Adaptive; int Adaptive;
/* /*
* Stream the images and update the display * Stream the images and update the display when the image has been
* when the image has been completely trans- * completely transerred.
* ferred.
*/ */
int Streaming; int Streaming;
/* /*
* Use a lazy approach in updating the remote * Use a lazy approach in updating the remote display. This means
* display. This means delaying the bandwidth * delaying the bandwidth consuming graphic operations and
* consuming graphic operations and synchroniz- * synchronizing the screen at idle time.
* ing the screen at idle time.
*/ */
int DeferLevel; int DeferLevel;
/* /*
* Maximum elapsed time before a new full * Maximum elapsed time before a new full synchronization.
* synchronization.
*/ */
unsigned long DeferTimeout; unsigned long DeferTimeout;
/* /*
* Maximum size of the tile used when sending * Maximum size of the tile used when sending an image to the remote
* an image to the remote display. * display.
*/ */
int TileWidth, TileHeight;
int TileWidth;
int TileHeight;
/* /*
* Enabling/disabling the pulldown menu. * Enabling/disabling the pulldown menu.
*/ */
int Menu; int Menu;
/* /*
* Enabling/disabling the magic pixel. * Enabling/disabling the magic pixel.
*/ */
int MagicPixel; int MagicPixel;
/* /*
* Specify the Operative System of the client. * Specify the Operative System of the client.
*/ */
int ClientOs; int ClientOs;
/* /*
* Inhibit some XKEYBOARD requests. * Inhibit some XKEYBOARD requests.
*/ */
int InhibitXkb; int InhibitXkb;
/* /*
* Maximum number of bytes that can be pasted from * Maximum number of bytes that can be pasted from an NX session
* an NX session into an external application. * into an external application.
*/ */
int CopyBufferSize; int CopyBufferSize;
/* /*
* Max image data rate to the encoder input. * Max image data rate to the encoder input.
*/ */
int ImageRateLimit; int ImageRateLimit;
/* /*
* True if agent should not exit if there are no * True if agent should not exit if there are no clients in rootless
* clients in rootless mode * mode
*/ */
int NoRootlessExit; int NoRootlessExit;
/* /*
* Store if the user wants Xinerama. There are variables called * Store if the user wants Xinerama. There are variables called
* noPanoramiXExtension and noRRXineramaExtensison in os/utils.c but * noPanoramiXExtension and noRRXineramaExtensison in os/utils.c but
* we cannot rely on them because RandR and PanoramiX change their * we cannot rely on them because RandR and PanoramiX change their
* values when trying to initialize. So we use this variable to * values when trying to initialize. So we use this variable to save
* save the user preference provided by the -/+(rr)xinerama parameter(s) * the user preference provided by the -/+(rr)xinerama parameter(s)
* before initializing those extensions. * before initializing those extensions.
*/ */
int Xinerama; int Xinerama;
/* /*
* Sleep delay in microseconds. * Sleep delay in microseconds.
*/ */
unsigned int SleepTime; unsigned int SleepTime;
/* /*
* Tolerance - tightens or loosens reconnect checks. * Tolerance - tightens or loosens reconnect checks.
*/ */
ToleranceChecksMode ReconnectTolerance; ToleranceChecksMode ReconnectTolerance;
/* /*
...@@ -473,8 +394,7 @@ extern AgentOptionsPtr nxagentOptionsPtr; ...@@ -473,8 +394,7 @@ extern AgentOptionsPtr nxagentOptionsPtr;
extern void nxagentInitOptions(void); extern void nxagentInitOptions(void);
/* /*
* Initialize some options to the default values * Initialize some options to the default values at reconnection.
* at reconnection.
*/ */
extern void nxagentResetOptions(void); extern void nxagentResetOptions(void);
...@@ -486,8 +406,8 @@ extern void nxagentResetOptions(void); ...@@ -486,8 +406,8 @@ extern void nxagentResetOptions(void);
extern void nxagentSaveOptions(void); extern void nxagentSaveOptions(void);
/* /*
* Restore the options reset by nxagentResetOptions * Restore the options reset by nxagentResetOptions to their backup
* to their backup value. * value.
*/ */
extern void nxagentRestoreOptions(void); extern void nxagentRestoreOptions(void);
......
...@@ -56,8 +56,6 @@ static int nxagentComparePixels(const void *p1, const void *p2) ...@@ -56,8 +56,6 @@ static int nxagentComparePixels(const void *p1, const void *p2)
int nxagentUniquePixels(XImage *image) int nxagentUniquePixels(XImage *image)
{ {
int i = 0;
int pixels[PIXEL_ELEMENTS]; int pixels[PIXEL_ELEMENTS];
int elements = PIXEL_ELEMENTS; int elements = PIXEL_ELEMENTS;
...@@ -132,15 +130,14 @@ int nxagentUniquePixels(XImage *image) ...@@ -132,15 +130,14 @@ int nxagentUniquePixels(XImage *image)
#endif #endif
/* /*
* Take one pixel every n from the image and * Take one pixel every n from the image and add it to the array.
* add it to the array.
*/ */
switch (image -> bits_per_pixel) switch (image -> bits_per_pixel)
{ {
case 32: case 32:
{ {
for (i = 0; i < elements; i++) for (int i = 0; i < elements; i++)
{ {
pixels[i] = Get32(next, image -> byte_order); pixels[i] = Get32(next, image -> byte_order);
...@@ -156,7 +153,7 @@ int nxagentUniquePixels(XImage *image) ...@@ -156,7 +153,7 @@ int nxagentUniquePixels(XImage *image)
} }
case 24: case 24:
{ {
for (i = 0; i < elements; i++) for (int i = 0; i < elements; i++)
{ {
pixels[i] = Get24(next, image -> byte_order); pixels[i] = Get24(next, image -> byte_order);
...@@ -174,14 +171,12 @@ int nxagentUniquePixels(XImage *image) ...@@ -174,14 +171,12 @@ int nxagentUniquePixels(XImage *image)
case 15: case 15:
{ {
/* /*
* Note that the padding bytes at the end * Note that the padding bytes at the end of the scanline are
* of the scanline are included in the set. * included in the set. This is not a big problem. What we want
* This is not a big problem. What we want * to find out is just how compressible is the image data.
* to find out is just how compressible is
* the image data.
*/ */
for (i = 0; i < elements; i++) for (int i = 0; i < elements; i++)
{ {
pixels[i] = Get16(next, image -> byte_order); pixels[i] = Get16(next, image -> byte_order);
...@@ -212,7 +207,7 @@ int nxagentUniquePixels(XImage *image) ...@@ -212,7 +207,7 @@ int nxagentUniquePixels(XImage *image)
qsort(pixels, elements, sizeof(int), nxagentComparePixels); qsort(pixels, elements, sizeof(int), nxagentComparePixels);
for (i = 0; i < elements; i++) for (int i = 0; i < elements; i++)
{ {
if (last != pixels[i]) if (last != pixels[i])
{ {
......
...@@ -66,8 +66,8 @@ is" without express or implied warranty. ...@@ -66,8 +66,8 @@ is" without express or implied warranty.
#undef DEBUG #undef DEBUG
/* /*
* The nxagentReversePointerMap array is used to * The nxagentReversePointerMap array is used to memorize remote
* memorize remote display pointer map. * display pointer map.
*/ */
unsigned char nxagentReversePointerMap[MAXBUTTONS]; unsigned char nxagentReversePointerMap[MAXBUTTONS];
...@@ -76,13 +76,12 @@ void nxagentChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl) ...@@ -76,13 +76,12 @@ void nxagentChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl)
{ {
/* /*
* The original behaviour was to reset the pointer settings * The original behaviour was to reset the pointer settings
* (acceleration and alas) to the default values. What the * (acceleration and alas) to the default values. What the average
* average user expects, on the contrary, is to have agent * user expects, on the contrary, is to have agent inheriting
* inheriting whatever value is set on the real X display. * whatever value is set on the real X display. Having to reflect
* Having to reflect changes made inside the agent session, * changes made inside the agent session, the correct behavior would
* the correct behavior would be saving the original values * be saving the original values and restoring them as soon as focus
* and restoring them as soon as focus leaves the agent's * leaves the agent's window.
* window.
*/ */
if (nxagentOption(DeviceControl) == True) if (nxagentOption(DeviceControl) == True)
...@@ -104,10 +103,6 @@ void nxagentChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl) ...@@ -104,10 +103,6 @@ void nxagentChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl)
int nxagentPointerProc(DeviceIntPtr pDev, int onoff) int nxagentPointerProc(DeviceIntPtr pDev, int onoff)
{ {
CARD8 map[MAXBUTTONS];
int nmap;
int i;
switch (onoff) switch (onoff)
{ {
case DEVICE_INIT: case DEVICE_INIT:
...@@ -121,8 +116,10 @@ int nxagentPointerProc(DeviceIntPtr pDev, int onoff) ...@@ -121,8 +116,10 @@ int nxagentPointerProc(DeviceIntPtr pDev, int onoff)
return Success; return Success;
} }
nmap = XGetPointerMapping(nxagentDisplay, map, MAXBUTTONS); CARD8 map[MAXBUTTONS];
for (i = 0; i <= nmap; i++)
int nmap = XGetPointerMapping(nxagentDisplay, map, MAXBUTTONS);
for (int i = 0; i <= nmap; i++)
map[i] = i; /* buttons are already mapped */ map[i] = i; /* buttons are already mapped */
InitPointerDeviceStruct((DevicePtr) pDev, map, nmap, InitPointerDeviceStruct((DevicePtr) pDev, map, nmap,
miPointerGetMotionEvents, miPointerGetMotionEvents,
...@@ -174,10 +171,6 @@ int nxagentPointerProc(DeviceIntPtr pDev, int onoff) ...@@ -174,10 +171,6 @@ int nxagentPointerProc(DeviceIntPtr pDev, int onoff)
void nxagentInitPointerMap(void) void nxagentInitPointerMap(void)
{ {
int numButtons;
int i;
unsigned char pointerMap[MAXBUTTONS]; unsigned char pointerMap[MAXBUTTONS];
#ifdef DEBUG #ifdef DEBUG
...@@ -185,13 +178,13 @@ void nxagentInitPointerMap(void) ...@@ -185,13 +178,13 @@ void nxagentInitPointerMap(void)
"pointer map from remote display.\n"); "pointer map from remote display.\n");
#endif #endif
numButtons = XGetPointerMapping(nxagentDisplay, pointerMap, MAXBUTTONS); int numButtons = XGetPointerMapping(nxagentDisplay, pointerMap, MAXBUTTONS);
/* /*
* Computing revers pointer map. * Computing revers pointer map.
*/ */
for (i = 1; i <= numButtons; i++) for (int i = 1; i <= numButtons; i++)
{ {
nxagentReversePointerMap[pointerMap[i - 1]] = i; nxagentReversePointerMap[pointerMap[i - 1]] = i;
} }
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "compext/Compext.h" #include "compext/Compext.h"
/* /*
* Set here the required log level. * Set here the required log level.
*/ */
...@@ -47,9 +46,8 @@ ...@@ -47,9 +46,8 @@
#undef DEBUG #undef DEBUG
/* /*
* This should be a macro but for now * This should be a macro but for now we make it a real function to
* we make it a real function to log * log a warning in the logs.
* a warning in the logs.
*/ */
DrawablePtr nxagentSplitDrawable(DrawablePtr pDrawable) DrawablePtr nxagentSplitDrawable(DrawablePtr pDrawable)
...@@ -73,13 +71,11 @@ DrawablePtr nxagentSplitDrawable(DrawablePtr pDrawable) ...@@ -73,13 +71,11 @@ DrawablePtr nxagentSplitDrawable(DrawablePtr pDrawable)
void nxagentInitSplitResources(void) void nxagentInitSplitResources(void)
{ {
int resource;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentInitSplitResources: Initializing the split resources.\n"); fprintf(stderr, "nxagentInitSplitResources: Initializing the split resources.\n");
#endif #endif
for (resource = 0; resource < NXNumberOfResources; resource++) for (int resource = 0; resource < NXNumberOfResources; resource++)
{ {
SplitResourcePtr pResource = &nxagentSplitResources[resource]; SplitResourcePtr pResource = &nxagentSplitResources[resource];
...@@ -97,8 +93,6 @@ SplitResourcePtr nxagentAllocSplitResource(void) ...@@ -97,8 +93,6 @@ SplitResourcePtr nxagentAllocSplitResource(void)
{ {
int resource; int resource;
SplitResourcePtr pResource;
for (;;) for (;;)
{ {
resource = NXAllocSplit(nxagentDisplay, NXAnyResource); resource = NXAllocSplit(nxagentDisplay, NXAnyResource);
...@@ -124,7 +118,7 @@ FIXME: Must deal with the case all resources are exausted. ...@@ -124,7 +118,7 @@ FIXME: Must deal with the case all resources are exausted.
} }
} }
pResource = &nxagentSplitResources[resource]; SplitResourcePtr pResource = &nxagentSplitResources[resource];
if (pResource -> pending != 0 || pResource -> split != NXNoResource || if (pResource -> pending != 0 || pResource -> split != NXNoResource ||
pResource -> unpack != NXNoResource || pResource -> drawable != NULL || pResource -> unpack != NXNoResource || pResource -> drawable != NULL ||
...@@ -217,13 +211,11 @@ FIXME: This must be implemented. ...@@ -217,13 +211,11 @@ FIXME: This must be implemented.
void nxagentReleaseAllSplits(void) void nxagentReleaseAllSplits(void)
{ {
int resource;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentReleaseAllSplits: Going to release all the split resources.\n"); fprintf(stderr, "nxagentReleaseAllSplits: Going to release all the split resources.\n");
#endif #endif
for (resource = 0; resource < NXNumberOfResources; resource++) for (int resource = 0; resource < NXNumberOfResources; resource++)
{ {
SplitResourcePtr pResource = &nxagentSplitResources[resource]; SplitResourcePtr pResource = &nxagentSplitResources[resource];
...@@ -329,11 +321,9 @@ static void nxagentCheckResource(SplitResourcePtr pResource, int resource) ...@@ -329,11 +321,9 @@ static void nxagentCheckResource(SplitResourcePtr pResource, int resource)
int nxagentCreateSplit(DrawablePtr pDrawable, GCPtr *pGC) int nxagentCreateSplit(DrawablePtr pDrawable, GCPtr *pGC)
{ {
SplitResourcePtr pResource;
pDrawable = nxagentSplitDrawable(pDrawable); pDrawable = nxagentSplitDrawable(pDrawable);
pResource = nxagentAllocSplitResource(); SplitResourcePtr pResource = nxagentAllocSplitResource();
if (pDrawable -> type == DRAWABLE_PIXMAP) if (pDrawable -> type == DRAWABLE_PIXMAP)
{ {
...@@ -348,8 +338,7 @@ int nxagentCreateSplit(DrawablePtr pDrawable, GCPtr *pGC) ...@@ -348,8 +338,7 @@ int nxagentCreateSplit(DrawablePtr pDrawable, GCPtr *pGC)
pResource -> commit = 1; pResource -> commit = 1;
/* /*
* Make a copy of the GC so the client * Make a copy of the GC so the client can safely remove it.
* can safely remove it.
*/ */
pResource -> gc = CreateScratchGC(pDrawable -> pScreen, pDrawable -> depth); pResource -> gc = CreateScratchGC(pDrawable -> pScreen, pDrawable -> depth);
...@@ -400,17 +389,14 @@ FIXME: What do we do here? ...@@ -400,17 +389,14 @@ FIXME: What do we do here?
} }
/* /*
* Set the region to be the current * Set the region to be the current streaming region.
* streaming region.
*/ */
void nxagentRegionSplit(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentRegionSplit(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
SplitResourcePtr pResource;
pDrawable = nxagentSplitDrawable(pDrawable); pDrawable = nxagentSplitDrawable(pDrawable);
pResource = nxagentSplitResource(pDrawable); SplitResourcePtr pResource = nxagentSplitResource(pDrawable);
#ifdef TEST #ifdef TEST
...@@ -442,18 +428,16 @@ void nxagentRegionSplit(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -442,18 +428,16 @@ void nxagentRegionSplit(DrawablePtr pDrawable, RegionPtr pRegion)
} }
/* /*
* Remove the association between the drawable * Remove the association between the drawable and the split
* and the split resource. The resource is not * resource. The resource is not deallocated until the end of the
* deallocated until the end of the split. * split.
*/ */
void nxagentReleaseSplit(DrawablePtr pDrawable) void nxagentReleaseSplit(DrawablePtr pDrawable)
{ {
SplitResourcePtr pResource;
pDrawable = nxagentSplitDrawable(pDrawable); pDrawable = nxagentSplitDrawable(pDrawable);
pResource = nxagentSplitResource(pDrawable); SplitResourcePtr pResource = nxagentSplitResource(pDrawable);
if (pResource == NULL) if (pResource == NULL)
{ {
...@@ -477,10 +461,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable) ...@@ -477,10 +461,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable)
if (pResource -> region != NullRegion) if (pResource -> region != NullRegion)
{ {
/* /*
* If we have a region the commits * If we have a region the commits had to be still valid. In this
* had to be still valid. In this * case tell the proxy to abort the data transfer.
* case tell the proxy to abort the
* data transfer.
*/ */
#ifdef TEST #ifdef TEST
...@@ -528,8 +510,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable) ...@@ -528,8 +510,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable)
} }
/* /*
* Remove the association between the * Remove the association between the drawable and the resource
* drawable and the resource record. * record.
*/ */
#ifdef TEST #ifdef TEST
...@@ -547,9 +529,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable) ...@@ -547,9 +529,8 @@ void nxagentReleaseSplit(DrawablePtr pDrawable)
} }
/* /*
* Invalidate the commits and remove the * Invalidate the commits and remove the association between the
* association between the resource and * resource and the drawable.
* the drawable.
*/ */
pResource -> drawable = NULL; pResource -> drawable = NULL;
...@@ -558,11 +539,9 @@ void nxagentReleaseSplit(DrawablePtr pDrawable) ...@@ -558,11 +539,9 @@ void nxagentReleaseSplit(DrawablePtr pDrawable)
void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion) void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion)
{ {
SplitResourcePtr pResource;
pDrawable = nxagentSplitDrawable(pDrawable); pDrawable = nxagentSplitDrawable(pDrawable);
pResource = nxagentSplitResource(pDrawable); SplitResourcePtr pResource = nxagentSplitResource(pDrawable);
if (pResource == NULL) if (pResource == NULL)
{ {
...@@ -607,9 +586,8 @@ void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -607,9 +586,8 @@ void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion)
#endif #endif
/* /*
* If a null region is passed as parameter, * If a null region is passed as parameter, we assume that all the
* we assume that all the commits have to * commits have to be discarded.
* be discarded.
*/ */
if (pRegion == NullRegion) if (pRegion == NullRegion)
...@@ -626,9 +604,8 @@ void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -626,9 +604,8 @@ void nxagentValidateSplit(DrawablePtr pDrawable, RegionPtr pRegion)
RegionRec tmpRegion; RegionRec tmpRegion;
/* /*
* Check if the provided region overlaps * Check if the provided region overlaps the area covered by the
* the area covered by the image being * image being streamed.
* streamed.
*/ */
RegionInit(&tmpRegion, NullBox, 1); RegionInit(&tmpRegion, NullBox, 1);
...@@ -698,10 +675,9 @@ void nxagentFreeSplit(int resource) ...@@ -698,10 +675,9 @@ void nxagentFreeSplit(int resource)
else else
{ {
/* /*
* The end of the split has come after we have * The end of the split has come after we have invalidated the
* invalidated the operation and removed the * operation and removed the association to the drawable. This
* association to the drawable. This happens, * happens, for example, if the drawable is destroyed.
* for example, if the drawable is destroyed.
*/ */
fprintf(stderr, "nxagentFreeSplit: WARNING! Releasing invalidated resource [%d].\n", fprintf(stderr, "nxagentFreeSplit: WARNING! Releasing invalidated resource [%d].\n",
...@@ -718,8 +694,8 @@ void nxagentFreeSplit(int resource) ...@@ -718,8 +694,8 @@ void nxagentFreeSplit(int resource)
} }
/* /*
FIXME: This must be enabled when the vanilla FIXME: This must be enabled when the vanilla synchronization procedure
synchronization procedure is working. is working.
*/ */
#define USE_FINISH_SPLIT #define USE_FINISH_SPLIT
...@@ -747,8 +723,7 @@ void nxagentWaitDrawable(DrawablePtr pDrawable) ...@@ -747,8 +723,7 @@ void nxagentWaitDrawable(DrawablePtr pDrawable)
#endif #endif
/* /*
* Be sure we intercept an I/O error * Be sure we intercept an I/O error as well as an interrupt.
* as well as an interrupt.
*/ */
#ifdef USE_FINISH_SPLIT #ifdef USE_FINISH_SPLIT
...@@ -762,21 +737,18 @@ void nxagentWaitDrawable(DrawablePtr pDrawable) ...@@ -762,21 +737,18 @@ void nxagentWaitDrawable(DrawablePtr pDrawable)
for (;;) for (;;)
{ {
/* /*
* Handling all the possible events here * Handling all the possible events here preempts the queue and
* preempts the queue and makes a better * makes a better use of the link.
* use of the link.
* *
* We should better use XIfEvent() instead * We should better use XIfEvent() instead of looping again and
* of looping again and again through the * again through the event queue.
* event queue.
*/ */
nxagentDispatchEvents(NULL); nxagentDispatchEvents(NULL);
/* /*
* Wait indefinitely until the resource * Wait indefinitely until the resource is released or the display
* is released or the display is shut * is shut down.
* down.
*/ */
if (nxagentSplitResource(pDrawable) == NULL || if (nxagentSplitResource(pDrawable) == NULL ||
...@@ -821,16 +793,14 @@ void nxagentWaitCommitEvent(int resource) ...@@ -821,16 +793,14 @@ void nxagentWaitCommitEvent(int resource)
XEvent event; XEvent event;
/* /*
* Check if there is any commit pending. As * Check if there is any commit pending. As we are at it, handle any
* we are at it, handle any commit, even those * commit, even those commits pertaining to other resources.
* commits pertaining to other resources.
* *
* We can receive some commits even if we'll * We can receive some commits even if we'll later receive a
* later receive a no-split event. The proxy, * no-split event. The proxy, in fact, may have missed to find the
* in fact, may have missed to find the image * image in the memory cache and could have loaded it from disk (so
* in the memory cache and could have loaded it * requiring a commit) before we marked the end of the split
* from disk (so requiring a commit) before we * sequence.
* marked the end of the split sequence.
*/ */
while (nxagentCheckEvents(nxagentDisplay, &event, while (nxagentCheckEvents(nxagentDisplay, &event,
...@@ -866,9 +836,8 @@ int nxagentWaitSplitEvent(int resource) ...@@ -866,9 +836,8 @@ int nxagentWaitSplitEvent(int resource)
int split = 0; int split = 0;
/* /*
* Don't flush the link. We only want to * Don't flush the link. We only want to query the NX transport to
* query the NX transport to check whether * check whether the operation caused a split.
* the operation caused a split.
*/ */
NXFlushDisplay(nxagentDisplay, NXFlushBuffer); NXFlushDisplay(nxagentDisplay, NXFlushBuffer);
...@@ -1223,10 +1192,9 @@ void nxagentSetCorruptedTimestamp(DrawablePtr pDrawable) ...@@ -1223,10 +1192,9 @@ void nxagentSetCorruptedTimestamp(DrawablePtr pDrawable)
} }
/* /*
* Reset the timestamp taken when the drawable * Reset the timestamp taken when the drawable became initially
* became initially corrupted. The timestamp is * corrupted. The timestamp is reset only after the drawable has been
* reset only after the drawable has been fully * fully synchronized.
* synchronized.
*/ */
void nxagentResetCorruptedTimestamp(DrawablePtr pDrawable) void nxagentResetCorruptedTimestamp(DrawablePtr pDrawable)
...@@ -1253,4 +1221,3 @@ void nxagentResetCorruptedTimestamp(DrawablePtr pDrawable) ...@@ -1253,4 +1221,3 @@ void nxagentResetCorruptedTimestamp(DrawablePtr pDrawable)
} }
} }
} }
...@@ -64,19 +64,17 @@ Visual nxagentAlphaVisual; ...@@ -64,19 +64,17 @@ Visual nxagentAlphaVisual;
Visual *nxagentVisual(VisualPtr pVisual) Visual *nxagentVisual(VisualPtr pVisual)
{ {
XVisualInfo visual; XVisualInfo visual = {
.class = pVisual->class,
int i; .bits_per_rgb = pVisual->bitsPerRGBValue,
.colormap_size = pVisual->ColormapEntries,
visual.class = pVisual->class; .depth = pVisual->nplanes,
visual.bits_per_rgb = pVisual->bitsPerRGBValue; .red_mask = pVisual->redMask,
visual.colormap_size = pVisual->ColormapEntries; .green_mask = pVisual->greenMask,
visual.depth = pVisual->nplanes; .blue_mask = pVisual->blueMask
visual.red_mask = pVisual->redMask; };
visual.green_mask = pVisual->greenMask;
visual.blue_mask = pVisual->blueMask; for (int i = 0; i < nxagentNumVisuals; i++)
for (i = 0; i < nxagentNumVisuals; i++)
{ {
if (nxagentCompareVisuals(visual, nxagentVisuals[i]) == 1) if (nxagentCompareVisuals(visual, nxagentVisuals[i]) == 1)
{ {
...@@ -89,9 +87,7 @@ Visual *nxagentVisual(VisualPtr pVisual) ...@@ -89,9 +87,7 @@ Visual *nxagentVisual(VisualPtr pVisual)
Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual) Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual)
{ {
int i; for (int i = 0; i < pScreen->numVisuals; i++)
for (i = 0; i < pScreen->numVisuals; i++)
{ {
if (pScreen->visuals[i].vid == visual) if (pScreen->visuals[i].vid == visual)
{ {
...@@ -104,9 +100,7 @@ Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual) ...@@ -104,9 +100,7 @@ Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual)
Colormap nxagentDefaultVisualColormap(Visual *visual) Colormap nxagentDefaultVisualColormap(Visual *visual)
{ {
int i; for (int i = 0; i < nxagentNumVisuals; i++)
for (i = 0; i < nxagentNumVisuals; i++)
{ {
if (nxagentVisuals[i].visual == visual) if (nxagentVisuals[i].visual == visual)
{ {
...@@ -117,18 +111,16 @@ Colormap nxagentDefaultVisualColormap(Visual *visual) ...@@ -117,18 +111,16 @@ Colormap nxagentDefaultVisualColormap(Visual *visual)
return None; return None;
} }
#if 0
/* /*
* This is currently unused. It should serve * This is currently unused. It should serve the scope of matching a
* the scope of matching a visual whenever * visual whenever a drawable has a different depth than the real
* a drawable has a different depth than the * display.
* real display.
*/ */
Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth) Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth)
{ {
int i; for (int i = 0; i < pScreen->numVisuals; i++)
for (i = 0; i < pScreen->numVisuals; i++)
{ {
if (pScreen->visuals[i].nplanes == depth) if (pScreen->visuals[i].nplanes == depth)
{ {
...@@ -138,11 +130,11 @@ Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth) ...@@ -138,11 +130,11 @@ Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth)
return NULL; return NULL;
} }
#endif
/* /*
* Create a fake 32 bits depth visual and * Create a fake 32 bits depth visual and initialize it based on the
* initialize it based on the endianness * endianness of the remote display.
* of the remote display.
*/ */
void nxagentInitAlphaVisual(void) void nxagentInitAlphaVisual(void)
...@@ -150,9 +142,8 @@ void nxagentInitAlphaVisual(void) ...@@ -150,9 +142,8 @@ void nxagentInitAlphaVisual(void)
nxagentAlphaVisual.visualid = XAllocID(nxagentDisplay); nxagentAlphaVisual.visualid = XAllocID(nxagentDisplay);
/* /*
* Color masks are referred to bits inside * Color masks are referred to bits inside the pixel. This is
* the pixel. This is independent from the * independent from the endianness.
* endianness.
*/ */
nxagentAlphaVisual.red_mask = 0x00ff0000; nxagentAlphaVisual.red_mask = 0x00ff0000;
......
...@@ -42,7 +42,10 @@ is" without express or implied warranty. ...@@ -42,7 +42,10 @@ is" without express or implied warranty.
Visual *nxagentVisual(VisualPtr pVisual); Visual *nxagentVisual(VisualPtr pVisual);
Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual); Visual *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual);
#if 0
Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth); Visual *nxagentVisualFromDepth(ScreenPtr pScreen, int depth);
#endif
Colormap nxagentDefaultVisualColormap(Visual *visual); Colormap nxagentDefaultVisualColormap(Visual *visual);
...@@ -50,17 +53,14 @@ Colormap nxagentDefaultVisualColormap(Visual *visual); ...@@ -50,17 +53,14 @@ Colormap nxagentDefaultVisualColormap(Visual *visual);
nxagentVisualFromID((pScreen), (pScreen) -> rootVisual) nxagentVisualFromID((pScreen), (pScreen) -> rootVisual)
/* /*
* Visual generated by Xorg and Xfree86 at * Visual generated by Xorg and Xfree86 at 16-bit depth differs on the
* 16-bit depth differs on the bits_per_rgb * bits_per_rgb value, so we avoid checking it.
* value, so we avoid checking it.
*/ */
/* /*
* Some Solaris X servers uses the color * Some Solaris X servers uses the color masks inverted, so that the
* masks inverted, so that the red and * red and the blue mask are switched. To reconnect the session on
* the blue mask are switched. To reconnect * this displays, we do a double check, as workaround.
* the session on this displays, we do a
* double check, as workaround.
*/ */
#define nxagentCompareVisuals(v1, v2) \ #define nxagentCompareVisuals(v1, v2) \
......
...@@ -1037,6 +1037,7 @@ miSetShape(pWin) ...@@ -1037,6 +1037,7 @@ miSetShape(pWin)
(pWin, 0, 0, pOldClip, (pWin, 0, 0, pOldClip,
pWin->drawable.x, pWin->drawable.y); pWin->drawable.x, pWin->drawable.y);
#ifdef NXAGENT_SERVER
/* /*
* Applies to NXAGENT_SERVER builds: * Applies to NXAGENT_SERVER builds:
* *
...@@ -1056,6 +1057,9 @@ miSetShape(pWin) ...@@ -1056,6 +1057,9 @@ miSetShape(pWin)
*/ */
if (WasViewable && pOldClip) if (WasViewable && pOldClip)
#else
if (WasViewable)
#endif
RegionDestroy(pOldClip); RegionDestroy(pOldClip);
if (bsExposed) if (bsExposed)
{ {
......
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