Info file xfaq.info, produced by Makeinfo, -*- Text -*- from input file xfaq.texinfo.  File: xfaq.info, Node: Topic 142, Next: Topic 143, Prev: Topic 141, Up: Topic 113 Why doesn't GXxor produce mathematically-correct color values? ============================================================== When using GXxor you may expect that drawing with a value of black on a background of black, for example, should produce white. However, the drawing operation does not work on RGB values but on colormap indices. The color that the resulting colormap index actually points to is undefined and visually random unless you have actually filled it in yourself. [On many X servers Black and White often 0/1 or 1/0; programs taking advantage of this mathematical coincidence will break.] If you want to be combining colors with GXxor, then you should be allocating a number of your own color cells and filling them with your chosen pre-computed values. If you want to use GXxor simply to switch between two colors, then you can take the shortcut of setting the background color in the GC (graphics context) to 0 and the foreground color to a value such that when it draws over red, say, the result is blue, and when it draws over blue the result is red. This foreground value is itself the XOR of the colormap indices of red and blue. [Thanks to Chris Flatters (`cflatter@zia.aoc.nrao.EDU') and Ken Whaley (`whaley@spectre.pa.dec.com'), 2/91]  File: xfaq.info, Node: Topic 143, Next: Topic 144, Prev: Topic 142, Up: Topic 113 Why does every color I allocate show up as black? ================================================= Make sure you're using 16 bits and not 8. The red, green, and blue fields of an XColor structure are scaled so that 0 is nothing and 65535 is full-blast. If you forget to scale (using, for example, 0-255 for each color) the XAllocColor function will perform correctly but the resulting color is usually black. [Thanks to Paul Asente, `asente@adobe.com', 7/91]  File: xfaq.info, Node: Topic 144, Next: Topic 145, Prev: Topic 143, Up: Topic 113 Why can't my program get a standard colormap? ============================================= I have an image-processing program which uses XGetRGBColormap() to get the standard colormap, but it doesn't work. XGetRGBColormap() when used with the property XA_RGB_DEFAULT_MAP does not create a standard colormap -- it just returns one if one already exists. Use xstdcmap or do what it does in order to create the standard colormap first. [1/91; from der Mouse (`mouse@larry.mcrcim.mcgill.edu')]  File: xfaq.info, Node: Topic 145, Next: Topic 146, Prev: Topic 144, Up: Topic 113 Why does the pixmap I copy to the screen show up as garbage? ============================================================ The initial contents of pixmaps are undefined. This means that most servers will allocate the memory and leave around whatever happens to be there -- which is usually garbage. You probably want to clear the pixmap first using XFillRectangle() with a function of GXcopy and a foreground pixel of whatever color you want as your background (or 0L if you are using the pixmap as a mask). [courtesy Dave Lemke of NCD and Stuart Marks of Sun]  File: xfaq.info, Node: Topic 146, Next: Topic 147, Prev: Topic 145, Up: Topic 113 How do I check whether a window ID is valid? ============================================ My program has the ID of a window on a remote display. I want to check whether the window exists before doing anything with it. Because X is asynchronous, there isn't a guarantee that the window would still exist between the time that you got the ID and the time you sent an event to the window or otherwise manipulated it. What you should do is send the event without checking, but install an error handler to catch any BadWindow errors, which would indicate that the window no longer exists. This scheme will work except on the [rare] occasion that the original window has been destroyed and its ID reallocated to another window. [courtesy Ken Lee (`klee@synoptics.com'), 4/90]  File: xfaq.info, Node: Topic 147, Next: Topic 148, Prev: Topic 146, Up: Topic 113 Can I have two applications draw to the same window? ==================================================== Yes. The X server assigns IDs to windows and other resources (actually, the server assigns some bits, the client others), and any application that knows the ID can manipulate the resource [almost any X server resource, except for GCs and private color cells, can be shared]. The problem you face is how to disseminate the window ID to multiple applications. A simple way to handle this (and which solves the problem of the applications' running on different machines) is in the first application to create a specially-named property on the root-window and put the window ID into it. The second application then retrieves the property, whose name it also knows, and then can draw whatever it wants into the window. [Note: this scheme works iff there is only one instance of the first application running, and the scheme is subject to the limitations mentioned in the Question about using window IDs on remote displays.] Note also that you will still need to coordinate any higher-level cooperation among your applications. Note also that two processes can share a window but should not try to use the same server connection. If one process is a child of the other, it should close down the connection to the server and open its own connection. [mostly courtesy Phil Karlton (`karlton@wpd.sgi.com') 6/90]  File: xfaq.info, Node: Topic 148, Next: Topic 149, Prev: Topic 147, Up: Topic 113 Why can't my program work with tvtwm or swm? ============================================ A number of applications, including xwd, xwininfo, and xsetroot, do not handle the virtual root window which tvtwm and swm use; they typically return the wrong child of root. A general solution is to add this code or to use it in your own application where you would normally use RootWindow(dpy,screen): /* Function Name: GetVRoot * Description: Gets the root window, even if it's a virtual root * Arguments: the display and the screen * Returns: the root window for the client */ #include Window GetVRoot(dpy, scr) Display *dpy; int scr; { Window rootReturn, parentReturn, *children; unsigned int numChildren; Window root = RootWindow(dpy, scr); Atom __SWM_VROOT = None; int i; __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False); XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren); for (i = 0; i < numChildren; i++) { Atom actual_type; int actual_format; long nitems, bytesafter; Window *newRoot = NULL; if (XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1, False, XA_WINDOW, &actual_type, &actual_format, &nitems, &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) { root = *newRoot; break; } } return root; } [courtesy David Elliott (`dce@smsc.sony.com'). Similar code is in ssetroot, a version of xsetroot distributed with tvtwm. 2/91] A header file by Andreas Stolcke of ICSI on `export.lcs.mit.edu':contrib/vroot.h functions similarly by providing macros for RootWindow and DefaultRootWindow; code can include this header file first to run properly in the presence of a virtual desktop.  File: xfaq.info, Node: Topic 149, Next: Topic 150, Prev: Topic 148, Up: Topic 113 How do I keep a window from being resized by the user? ====================================================== Resizing the window is done through the window manager; window managers can pay attention to the size hints your application places on the window, but there is no guarantee that the window manager will listen. You can try setting the minimum and maximum size hints to your target size and hope for the best. [1/91]  File: xfaq.info, Node: Topic 150, Next: Topic 151, Prev: Topic 149, Up: Topic 113 How do I keep a window in the foreground at all times? ====================================================== It's rather antisocial for an application to constantly raise itself [e.g. by tracking VisibilityNotify events] so that it isn't overlapped -- imagine the conflict between two such programs running. The only sure way to have your window appear on the top of the stack is to make the window override-redirect; this means that you are temporarily assuming window-management duties while the window is up, so you want to do this infrequently and then only for short periods of time (e.g. for popup menus or other short parameter-setting windows). [thanks to der Mouse (`mouse@larry.mcrcim.mcgill.edu'); 7/92]  File: xfaq.info, Node: Topic 151, Next: Topic 152, Prev: Topic 150, Up: Topic 113 How do I make text and bitmaps blink in X? ========================================== There is no easy way. Unless you're willing to depend on some sort of extension (as yet non-existent), you have to arrange for the blinking yourself, either by redrawing the contents periodically or, if possible, by playing games with the colormap and changing the color of the contents. [Thanks to `mouse@larry.mcrcim.mcgill.edu' (der Mouse), 7/91]  File: xfaq.info, Node: Topic 152, Next: Topic 153, Prev: Topic 151, Up: Topic 113 How do I get a double-click in Xlib? ==================================== Users of Xt have the support of the translation manager to help get notification of double-clicking. There is no good way to get only a double-click in Xlib, because the protocol does not provide enough support to do double-clicks. You have to do client-side timeouts, unless the single-click action is such that you can defer actually taking it until you next see an event from the server. Thus, you have to do timeouts, which means system-dependent code. On most UNIXish implementations, you can use XConnectionNumber to get the file descriptor of the X connection and then use select() or something similar on that. Note that many user-interface references suggest that a double-click be used to extend the action indicated by a single-click; if this is the case in your interface then you can execute the first action and as a compromise check the timestamp on the second event to determine whether it, too, should be the single-click action or the double-click action. [Thanks to `mouse@larry.mcrcim.mcgill.edu' (der Mouse), 4/93]  File: xfaq.info, Node: Topic 153, Next: Topic 154, Prev: Topic 152, Up: Topic 113 How do I render rotated text? ============================= Xlib intentionally does not provide such sophisticated graphics capabilities, leaving them up to server-extensions or clients-side graphics libraries. Your only choice, if you want to stay within the core X protocol, is to render the text into a pixmap, read it back via XGetImage(), rotate it "by hand" with whatever matrices you want, and put it back to the server via XPutImage(); more specifically: 1) create a bitmap B and write your text to it. 2) create an XYBitmap image I from B (via XGetImage). 3) create an XYBitmap Image I2 big enough to handle the transformation. 4) for each x,y in I2, I2(x,y) = I(a,b) where a = x * cos(theta) - y * sin(theta) b = x * sin(theta) + y * cos(theta) 5) render I2 Note that you should be careful how you implement this not to lose bits; an algorithm based on shear transformations may in fact be better. The high-level server-extensions and graphics packages available for X also permit rendering of rotated text: Display PostScript, PEX, PHiGS, and GKS, although most are not capable of arbitrary rotation and probably do not use the same fonts that would be found on a printer. In addition, if you have enough access to the server to install a font on it, you can create a font which consists of letters rotated at some predefined angle. Your application can then itself figure out placement of each glyph. [courtesy der Mouse (`mouse@larry.mcrcim.mcgill.edu'), Eric Taylor (`etaylor@wilkins.bmc.tmc.edu'), and Ken Lee (`klee@synoptics.com'), 11/90; Liam Quin (`lee@sq.com'), 12/90] InterViews (C++ UI toolkit, in the X contrib software) has support for rendering rotated fonts in X. It could be one source of example code. [Brian R. Smith (`brsmith@cs.umn.edu'), 3/91] Another possibility is to use the Hershey Fonts; they are stroke-rendered and can be used by X by converting them into XDrawLine requests. [`eric@pencom.com', 10/91] The xrotfont program by Alan Richardson (`mppa3@syma.sussex.ac.uk') (posted to `comp.sources.x' July 14 1992) paints a rotated font by implementing the method above and by using an outline (Hershey) font. The xvertext package by Alan Richardson (`mppa3@syma.sussex.ac.uk') is a set of functions to facilitate the writing of text at any angle. It is on export as contrib/`xvertext.5.0.shar.Z'. O'Reilly's X Resource Volume 3 includes information from HP about modifications to the X fonts server which provide for rotated and scaled text.  File: xfaq.info, Node: Topic 154, Prev: Topic 153, Up: Topic 113 What is the X Registry? (How do I reserve names?) ================================================= There are places in the X Toolkit, in applications, and in the X protocol that define and use string names. The context is such that conflicts are possible if different components use the same name for different things. The MIT X Consortium maintains a registry of names in these domains: orgainization names, selection names, selection targets, resource types, application classes, and class extension record types; and several others. The list as of 7/91 is in the directory mit/doc/Registry on the R5 tape; it is also available by sending "send docs registry" to the xstuff mail server. To register names (first come, first served) or to ask questions send to `xregistry@expo.lcs.mit.edu'; be sure to include a postal address for confirmation. [11/90; condensed from Asente/Swick Appendix H]