josh@concept.viewlogic.com (Josh Marantz) (02/01/91)
I have several applications that want to use a specific color arrangement of (say) 16 colors that are aligned so as to facilitate using raster operations such as GXor and GXcopyInverted. This works great when I allocate the color cells for each process, but is wasteful because I wind up duplicating the whole color arrangement. (This is all in the default color map). I worked out a scheme for having the first application that is run put a property on the root window that says what the color arrangement should be (i.e. the plane mask and the pixel numbers for the allocated colors). Subsequent runs look for that property and use the same color entries, and this works great. The problem comes when the first application exits, but subsequent applications stay up. The server allows those color cells to be reused, which makes the subsequent applications go technicolor. In fact, the property on the root window is still there, and new invocations will also get the bogus colors. I have to explicitly delete the property off the root window and restart the applications to get everything back to normal. So I'd like to have the best of all worlds, where everyone gets the cool colors, but the precious color map is not depleted by duplicate entries. What's the best way to do this? I can envision more sophisticated schemes where the property on the root window points to a window (possibly unmapped) owned by the original application. Then everyone that wants to use those colors can select for destroy events on that window, but then there might be a race condition to figure out who should "take over" ownership of the colors. Also, there is no guarantee that the same pixel values will be assigned by another call to XAllocColorCells. This could easily get chaotic. Another strategy is to have the original application use a close-down-mode of RetainTemporary or RetainPermanent (I'm not clear on the difference between the two) but of course the client may create lots of other resources that need to be killed if the client exits abnormally. Do I have to write a new client that sets up the color map, exits with RetainPermanent, and leaves the color map up there forever? Maybe properties could be used to implement some sort reference counting scheme, but that would be susceptible to clients exiting abnormally without decrementing the reference count that's held by a property in the root window. Has anybody else tackled this issue? What do you think is the best approach? -Josh -- Joshua Marantz Viewlogic Systems, Inc. josh@viewlogic.com Why not pass the time by playing a little solitaire?
keith@expo.lcs.mit.EDU (Keith Packard) (02/01/91)
> The problem comes when the first application exits, but subsequent > applications stay up. The server allows those color cells to be > reused, which makes the subsequent applications go technicolor. Have the client which creates the property open another server connection for this, allocate the colors, create a 1x1 pixmap, set the close down mode to RetainPermanent and put the XID of the pixmap along with the other infomation inside that property on the root window. To get rid of the shared colors, you'll just need to do a KillClient on the pixmap ID (which is what it's for). Check out how the various root-window setting applications register the root pixel value inside a property along with a pixmap.