open-src/app/xstdcmap/6661101.patch
changeset 309 cdb665e70efa
equal deleted inserted replaced
308:8dff8932c417 309:cdb665e70efa
       
     1 --- xstdcmap.c.orig	Thu Feb  7 13:18:40 2008
       
     2 +++ xstdcmap.c	Thu Feb  7 13:22:03 2008
       
     3 @@ -107,6 +107,15 @@
       
     4  };
       
     5  #define NOPTIONS (sizeof optionTable / sizeof optionTable[0])
       
     6  
       
     7 +#ifdef __sun
       
     8 +/* we don't define this on the command line */
       
     9 +#define SUNSOFT_BUYBACK 1
       
    10 +#endif
       
    11 +
       
    12 +#ifdef SUNSOFT_BUYBACK
       
    13 +static void maybeDeleteDefaultGrayMap();
       
    14 +#endif
       
    15 +
       
    16  static void usage(Status status);
       
    17  
       
    18  static void 
       
    19 @@ -283,6 +292,22 @@
       
    20      for (i=0; i < NPROPERTIES; i++) {
       
    21  
       
    22  	if (propertyTable[i].delete) {
       
    23 +#ifdef SUNSOFT_BUYBACK
       
    24 +	    if (i == DEFAULT) { 
       
    25 +                /*
       
    26 +                 * REMIND: We are deleting the RGB_DEFAULT_MAPs
       
    27 +                 * these might have been set up by a DPS client.
       
    28 +		 * If so there may be a DEFAULT_GRAY map with
       
    29 +		 * the same kilid. So if we kill that client to
       
    30 +		 * delete the color ramps, we delete the pixels
       
    31 +		 * of the grayramp but not the property.
       
    32 +		 * See if this is going to happen and if so,
       
    33 +		 * delete the DEFAULT_GRAY property. (1195388)
       
    34 +                 */
       
    35 +                maybeDeleteDefaultGrayMap();
       
    36 +            }
       
    37 +#endif /* SUNSOFT_BUYBACK */
       
    38 +
       
    39  	    XmuDeleteStandardColormap(dpy, screen, propertyTable[i].property);
       
    40  	    if (verbose)
       
    41  		fprintf(stderr, "%s: %s was deleted or did not exist.\n",
       
    42 @@ -373,3 +398,45 @@
       
    43      /* Muffle compiler */
       
    44      return 0;
       
    45  }
       
    46 +
       
    47 +#ifdef SUNSOFT_BUYBACK
       
    48 +static void
       
    49 +maybeDeleteDefaultGrayMap()
       
    50 +{
       
    51 +        Atom    atom = XInternAtom(dpy, "DEFAULT_GRAY", True);
       
    52 +        int     i, count;
       
    53 +        XStandardColormap *defaultMaps;
       
    54 +        XStandardColormap *pGray;
       
    55 +
       
    56 +        if (atom == None)
       
    57 +            return;
       
    58 +
       
    59 +        if (!XGetRGBColormaps(dpy, DefaultRootWindow(dpy), &pGray, &count,
       
    60 +                atom)) {
       
    61 +            return;
       
    62 +        }
       
    63 +	/* We found DEFAULT_GRAY property */
       
    64 +        if (XGetRGBColormaps(dpy, DefaultRootWindow(dpy), &defaultMaps, &count,
       
    65 +                XA_RGB_DEFAULT_MAP)) {
       
    66 +	    /*
       
    67 +	     * we found some XA_RGB_DEFAULT_MAPs, see if any of them have
       
    68 +	     * the same killid as the gray ramp we found above
       
    69 +	     */
       
    70 +            for (i=0; i<count; i++) {
       
    71 +                if (pGray->killid == defaultMaps[i].killid) {
       
    72 +                    /*
       
    73 +		     * Got one. 
       
    74 +                     * Delete the property, deleting the rgb map will free
       
    75 +                     * the pixels (it calls XKillClient())
       
    76 +                     */
       
    77 +                    XDeleteProperty(dpy, DefaultRootWindow(dpy), atom);
       
    78 +                    break;
       
    79 +                }
       
    80 +            }
       
    81 +	    XFree(defaultMaps);
       
    82 +        }
       
    83 +
       
    84 +        XFree(pGray);
       
    85 +}
       
    86 +#endif /* SUNSOFT_BUYBACK */
       
    87 +