summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:55 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:55 +0000
commitf7cb26f3488672da827d30962b940f3e11e49b4a (patch)
treed4ed9463d4127c85662706da54e723cacbf54113
R6.6 is the Xorg base-lineXORG-MAINXORG-STABLE
-rw-r--r--dsimple.c523
-rw-r--r--dsimple.h81
-rw-r--r--list.c293
-rw-r--r--list.h117
-rw-r--r--multiVis.c1249
-rw-r--r--multiVis.h60
-rw-r--r--wsutils.h350
-rw-r--r--xwd.c664
-rw-r--r--xwd.man130
9 files changed, 3467 insertions, 0 deletions
diff --git a/dsimple.c b/dsimple.c
new file mode 100644
index 0000000..210d121
--- /dev/null
+++ b/dsimple.c
@@ -0,0 +1,523 @@
+/* $Xorg: dsimple.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
+/*
+
+Copyright 1993, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <stdio.h>
+/*
+ * Other_stuff.h: Definitions of routines in other_stuff.
+ *
+ * Written by Mark Lillibridge. Last updated 7/1/87
+ */
+
+unsigned long Resolve_Color();
+Pixmap Bitmap_To_Pixmap();
+Window Select_Window();
+void out();
+void blip();
+Window Window_With_Name();
+void Fatal_Error();
+
+/*
+ * Just_display: A group of routines designed to make the writting of simple
+ * X11 applications which open a display but do not open
+ * any windows much faster and easier. Unless a routine says
+ * otherwise, it may be assumed to require program_name, dpy,
+ * and screen already defined on entry.
+ *
+ * Written by Mark Lillibridge. Last updated 7/1/87
+ */
+
+
+/* This stuff is defined in the calling program by just_display.h */
+extern char *program_name;
+extern Display *dpy;
+extern int screen;
+
+
+/*
+ * Malloc: like malloc but handles out of memory using Fatal_Error.
+ */
+char *Malloc(size)
+ unsigned size;
+{
+ char *data, *malloc();
+
+ if (!(data = malloc(size)))
+ Fatal_Error("Out of memory!");
+
+ return(data);
+}
+
+
+/*
+ * Realloc: like Malloc except for realloc, handles NULL using Malloc.
+ */
+char *Realloc(ptr, size)
+ char *ptr;
+ int size;
+{
+ char *new_ptr, *realloc();
+
+ if (!ptr)
+ return(Malloc(size));
+
+ if (!(new_ptr = realloc(ptr, size)))
+ Fatal_Error("Out of memory!");
+
+ return(new_ptr);
+}
+
+
+/*
+ * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
+ * If found, remove it from command line. Don't go past a lone -.
+ */
+char *Get_Display_Name(pargc, argv)
+ int *pargc; /* MODIFIED */
+ char **argv; /* MODIFIED */
+{
+ int argc = *pargc;
+ char **pargv = argv+1;
+ char *displayname = NULL;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ char *arg = argv[i];
+
+ if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
+ if (++i >= argc) usage ();
+
+ displayname = argv[i];
+ *pargc -= 2;
+ continue;
+ }
+ if (!strcmp(arg,"-")) {
+ while (i<argc)
+ *pargv++ = argv[i++];
+ break;
+ }
+ *pargv++ = arg;
+ }
+
+ *pargv = NULL;
+ return (displayname);
+}
+
+
+/*
+ * Open_Display: Routine to open a display with correct error handling.
+ * Does not require dpy or screen defined on entry.
+ */
+Display *Open_Display(display_name)
+char *display_name;
+{
+ Display *d;
+
+ d = XOpenDisplay(display_name);
+ if (d == NULL) {
+ fprintf (stderr, "%s: unable to open display '%s'\n",
+ program_name, XDisplayName (display_name));
+ usage ();
+ /* doesn't return */
+ }
+
+ return(d);
+}
+
+
+/*
+ * Setup_Display_And_Screen: This routine opens up the correct display (i.e.,
+ * it calls Get_Display_Name) and then stores a
+ * pointer to it in dpy. The default screen
+ * for this display is then stored in screen.
+ * Does not require dpy or screen defined.
+ */
+void Setup_Display_And_Screen(argc, argv)
+int *argc; /* MODIFIED */
+char **argv; /* MODIFIED */
+{
+ dpy = Open_Display (Get_Display_Name(argc, argv));
+ screen = DefaultScreen(dpy);
+}
+
+
+/*
+ * Open_Font: This routine opens a font with error handling.
+ */
+XFontStruct *Open_Font(name)
+char *name;
+{
+ XFontStruct *font;
+
+ if (!(font=XLoadQueryFont(dpy, name)))
+ Fatal_Error("Unable to open font %s!", name);
+
+ return(font);
+}
+
+
+/*
+ * Beep: Routine to beep the display.
+ */
+void Beep()
+{
+ XBell(dpy, 50);
+}
+
+
+/*
+ * ReadBitmapFile: same as XReadBitmapFile except it returns the bitmap
+ * directly and handles errors using Fatal_Error.
+ */
+static void _bitmap_error(status, filename)
+ int status;
+ char *filename;
+{
+ if (status == BitmapOpenFailed)
+ Fatal_Error("Can't open file %s!", filename);
+ else if (status == BitmapFileInvalid)
+ Fatal_Error("file %s: Bad bitmap format.", filename);
+ else
+ Fatal_Error("Out of memory!");
+}
+
+Pixmap ReadBitmapFile(d, filename, width, height, x_hot, y_hot)
+ Drawable d;
+ char *filename;
+ int *width, *height, *x_hot, *y_hot;
+{
+ Pixmap bitmap;
+ int status;
+
+ status = XReadBitmapFile(dpy, RootWindow(dpy, screen), filename,
+ (unsigned int *)width, (unsigned int *)height,
+ &bitmap, x_hot, y_hot);
+ if (status != BitmapSuccess)
+ _bitmap_error(status, filename);
+
+ return(bitmap);
+}
+
+
+/*
+ * WriteBitmapFile: same as XWriteBitmapFile except it handles errors
+ * using Fatal_Error.
+ */
+void WriteBitmapFile(filename, bitmap, width, height, x_hot, y_hot)
+ char *filename;
+ Pixmap bitmap;
+ int width, height, x_hot, y_hot;
+{
+ int status;
+
+ status= XWriteBitmapFile(dpy, filename, bitmap, width, height, x_hot,
+ y_hot);
+ if (status != BitmapSuccess)
+ _bitmap_error(status, filename);
+}
+
+
+/*
+ * Select_Window_Args: a rountine to provide a common interface for
+ * applications that need to allow the user to select one
+ * window on the screen for special consideration.
+ * This routine implements the following command line
+ * arguments:
+ *
+ * -root Selects the root window.
+ * -id <id> Selects window with id <id>. <id> may
+ * be either in decimal or hex.
+ * -name <name> Selects the window with name <name>.
+ *
+ * Call as Select_Window_Args(&argc, argv) in main before
+ * parsing any of your program's command line arguments.
+ * Select_Window_Args will remove its arguments so that
+ * your program does not have to worry about them.
+ * The window returned is the window selected or 0 if
+ * none of the above arguments was present. If 0 is
+ * returned, Select_Window should probably be called after
+ * all command line arguments, and other setup is done.
+ * For examples of usage, see xwininfo, xwd, or xprop.
+ */
+Window Select_Window_Args(rargc, argv)
+ int *rargc;
+ char **argv;
+#define ARGC (*rargc)
+{
+ int nargc=1;
+ int argc;
+ char **nargv;
+ Window w=0;
+
+ nargv = argv+1; argc = ARGC;
+#define OPTION argv[0]
+#define NXTOPTP ++argv, --argc>0
+#define NXTOPT if (++argv, --argc==0) usage()
+#define COPYOPT nargv++[0]=OPTION, nargc++
+
+ while (NXTOPTP) {
+ if (!strcmp(OPTION, "-")) {
+ COPYOPT;
+ while (NXTOPTP)
+ COPYOPT;
+ break;
+ }
+ if (!strcmp(OPTION, "-root")) {
+ w=RootWindow(dpy, screen);
+ continue;
+ }
+ if (!strcmp(OPTION, "-name")) {
+ NXTOPT;
+ w = Window_With_Name(dpy, RootWindow(dpy, screen),
+ OPTION);
+ if (!w)
+ Fatal_Error("No window with name %s exists!",OPTION);
+ continue;
+ }
+ if (!strcmp(OPTION, "-id")) {
+ NXTOPT;
+ w=0;
+ sscanf(OPTION, "0x%lx", &w);
+ if (!w)
+ sscanf(OPTION, "%ld", &w);
+ if (!w)
+ Fatal_Error("Invalid window id format: %s.", OPTION);
+ continue;
+ }
+ COPYOPT;
+ }
+ ARGC = nargc;
+
+ return(w);
+}
+
+/*
+ * Other_stuff: A group of routines which do common X11 tasks.
+ *
+ * Written by Mark Lillibridge. Last updated 7/1/87
+ */
+
+extern Display *dpy;
+extern int screen;
+
+/*
+ * Resolve_Color: This routine takes a color name and returns the pixel #
+ * that when used in the window w will be of color name.
+ * (WARNING: The colormap of w MAY be modified! )
+ * If colors are run out of, only the first n colors will be
+ * as correct as the hardware can make them where n depends
+ * on the display. This routine does not require wind to
+ * be defined.
+ */
+unsigned long Resolve_Color(w, name)
+ Window w;
+ char *name;
+{
+ XColor c;
+ Colormap colormap;
+ XWindowAttributes wind_info;
+
+ /*
+ * The following is a hack to insure machines without a rgb table
+ * handle at least white & black right.
+ */
+ if (!strcmp(name, "white"))
+ name="#ffffffffffff";
+ if (!strcmp(name, "black"))
+ name="#000000000000";
+
+ XGetWindowAttributes(dpy, w, &wind_info);
+ colormap = wind_info.colormap;
+
+ if (!XParseColor(dpy, colormap, name, &c))
+ Fatal_Error("Bad color format '%s'.", name);
+
+ if (!XAllocColor(dpy, colormap, &c))
+ Fatal_Error("XAllocColor failed!");
+
+ return(c.pixel);
+}
+
+
+/*
+ * Bitmap_To_Pixmap: Convert a bitmap to a 2 colored pixmap. The colors come
+ * from the foreground and background colors of the gc.
+ * Width and height are required solely for efficiency.
+ * If needed, they can be obtained via. XGetGeometry.
+ */
+Pixmap Bitmap_To_Pixmap(dpy, d, gc, bitmap, width, height)
+ Display *dpy;
+ Drawable d;
+ GC gc;
+ Pixmap bitmap;
+ int width, height;
+{
+ Pixmap pix;
+ int x;
+ unsigned int i, depth;
+ Drawable root;
+
+ if (!XGetGeometry(dpy, d, &root, &x, &x, &i, &i, &i, &depth))
+ return(0);
+
+ pix = XCreatePixmap(dpy, d, width, height, (int)depth);
+
+ XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, 1);
+
+ return(pix);
+}
+
+
+/*
+ * blip: a debugging routine. Prints Blip! on stderr with flushing.
+ */
+void blip()
+{
+ outl("blip!");
+}
+
+
+/*
+ * Routine to let user select a window using the mouse
+ */
+
+Window Select_Window(dpy)
+ Display *dpy;
+{
+ int status;
+ Cursor cursor;
+ XEvent event;
+ Window target_win = None, root = RootWindow(dpy,screen);
+ int buttons = 0;
+
+ /* Make the target cursor */
+ cursor = XCreateFontCursor(dpy, XC_crosshair);
+
+ /* Grab the pointer using target cursor, letting it room all over */
+ status = XGrabPointer(dpy, root, False,
+ ButtonPressMask|ButtonReleaseMask, GrabModeSync,
+ GrabModeAsync, root, cursor, CurrentTime);
+ if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
+
+ /* Let the user select a window... */
+ while ((target_win == None) || (buttons != 0)) {
+ /* allow one more event */
+ XAllowEvents(dpy, SyncPointer, CurrentTime);
+ XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
+ switch (event.type) {
+ case ButtonPress:
+ if (target_win == None) {
+ target_win = event.xbutton.subwindow; /* window selected */
+ if (target_win == None) target_win = root;
+ }
+ buttons++;
+ break;
+ case ButtonRelease:
+ if (buttons > 0) /* there may have been some down before we started */
+ buttons--;
+ break;
+ }
+ }
+
+ XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
+
+ return(target_win);
+}
+
+
+/*
+ * Window_With_Name: routine to locate a window with a given name on a display.
+ * If no window with the given name is found, 0 is returned.
+ * If more than one window has the given name, the first
+ * one found will be returned. Only top and its subwindows
+ * are looked at. Normally, top should be the RootWindow.
+ */
+Window Window_With_Name(dpy, top, name)
+ Display *dpy;
+ Window top;
+ char *name;
+{
+ Window *children, dummy;
+ unsigned int nchildren;
+ int i;
+ Window w=0;
+ char *window_name;
+
+ if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
+ return(top);
+
+ if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
+ return(0);
+
+ for (i=0; i<nchildren; i++) {
+ w = Window_With_Name(dpy, children[i], name);
+ if (w)
+ break;
+ }
+ if (children) XFree ((char *)children);
+ return(w);
+}
+
+/*
+ * outl: a debugging routine. Flushes stdout then prints a message on stderr
+ * and flushes stderr. Used to print messages when past certain points
+ * in code so we can tell where we are. Outl may be invoked like
+ * printf with up to 7 arguments.
+ */
+/* VARARGS1 */
+outl(msg, arg0,arg1,arg2,arg3,arg4,arg5,arg6)
+ char *msg;
+ char *arg0, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
+{
+ fflush(stdout);
+ fprintf(stderr, msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+ fprintf(stderr, "\n");
+ fflush(stderr);
+}
+
+
+/*
+ * Standard fatal error routine - call like printf but maximum of 7 arguments.
+ * Does not require dpy or screen defined.
+ */
+/* VARARGS1 */
+void Fatal_Error(msg, arg0,arg1,arg2,arg3,arg4,arg5,arg6)
+char *msg;
+char *arg0, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
+{
+ fflush(stdout);
+ fflush(stderr);
+ fprintf(stderr, "%s: error: ", program_name);
+ fprintf(stderr, msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+ fprintf(stderr, "\n");
+ exit(1);
+}
diff --git a/dsimple.h b/dsimple.h
new file mode 100644
index 0000000..a634848
--- /dev/null
+++ b/dsimple.h
@@ -0,0 +1,81 @@
+/* $Xorg: dsimple.h,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
+/*
+
+Copyright 1993, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+/*
+ * Just_display.h: This file contains the definitions needed to use the
+ * functions in just_display.c. It also declares the global
+ * variables dpy, screen, and program_name which are needed to
+ * use just_display.c.
+ *
+ * Written by Mark Lillibridge. Last updated 7/1/87
+ *
+ * Send bugs, etc. to chariot@athena.mit.edu.
+ */
+
+ /* Global variables used by routines in just_display.c */
+
+char *program_name = "unknown_program"; /* Name of this program */
+Display *dpy; /* The current display */
+int screen; /* The current screen */
+
+#define INIT_NAME program_name=argv[0] /* use this in main to setup
+ program_name */
+
+ /* Declaritions for functions in just_display.c */
+
+void Fatal_Error();
+char *Malloc();
+char *Realloc();
+char *Get_Display_Name();
+Display *Open_Display();
+void Setup_Display_And_Screen();
+XFontStruct *Open_Font();
+void Beep();
+Pixmap ReadBitmapFile();
+void WriteBitmapFile();
+Window Select_Window_Args();
+
+#define X_USAGE "[host:display]" /* X arguments handled by
+ Get_Display_Name */
+#define SELECT_USAGE "[{-root|-id <id>|-font <font>|-name <name>}]"
+
+/*
+ * Other_stuff.h: Definitions of routines in other_stuff.
+ *
+ * Written by Mark Lillibridge. Last updated 7/1/87
+ *
+ * Send bugs, etc. to chariot@athena.mit.edu.
+ */
+
+unsigned long Resolve_Color();
+Pixmap Bitmap_To_Pixmap();
+Window Select_Window();
+void out();
+void blip();
+Window Window_With_Name();
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..08f271f
--- /dev/null
+++ b/list.c
@@ -0,0 +1,293 @@
+/* $Xorg: list.c,v 1.5 2001/02/09 02:06:03 xorgcvs Exp $ */
+/** ------------------------------------------------------------------------
+ This file contains routines for manipulating generic lists.
+ Lists are implemented with a "harness". In other words, each
+ node in the list consists of two pointers, one to the data item
+ and one to the next node in the list. The head of the list is
+ the same struct as each node, but the "item" ptr is used to point
+ to the current member of the list (used by the first_in_list and
+ next_in_list functions).
+
+Copyright 1994 Hewlett-Packard Co.
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+ ----------------------------------------------------------------------- **/
+
+#include <stdio.h>
+#include "list.h"
+
+
+/** ------------------------------------------------------------------------
+ Sets the pointers of the specified list to NULL.
+ --------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+void zero_list(list_ptr lp)
+#else
+void zero_list(lp)
+ list_ptr lp;
+#endif
+{
+ lp->next = NULL;
+ lp->ptr.item = NULL;
+}
+
+
+/** ------------------------------------------------------------------------
+ Adds item to the list pointed to by lp. Finds the end of the
+ list, then mallocs a new list node onto the end of the list.
+ The item pointer in the new node is set to "item" passed in,
+ and the next pointer in the new node is set to NULL.
+ Returns 1 if successful, 0 if the malloc failed.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+int add_to_list(list_ptr lp, void *item)
+#else
+int add_to_list(lp, item)
+ list_ptr lp;
+ void *item;
+#endif
+{
+ while (lp->next) {
+ lp = lp->next;
+ }
+ if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
+
+ return 0;
+ }
+ lp->next->ptr.item = item;
+ lp->next->next = NULL;
+
+ return 1;
+}
+
+
+/** ------------------------------------------------------------------------
+ Creates a new list and sets its pointers to NULL.
+ Returns a pointer to the new list.
+ -------------------------------------------------------------------- **/
+list_ptr new_list ()
+{
+ list_ptr lp;
+
+ if ((lp = (list_ptr) malloc( sizeof( list_item)))) {
+ lp->next = NULL;
+ lp->ptr.item = NULL;
+ }
+
+ return lp;
+}
+
+
+/** ------------------------------------------------------------------------
+ Creates a new list head, pointing to the same list as the one
+ passed in. If start_at_curr is TRUE, the new list's first item
+ is the "current" item (as set by calls to first/next_in_list()).
+ If start_at_curr is FALSE, the first item in the new list is the
+ same as the first item in the old list. In either case, the
+ curr pointer in the new list is the same as in the old list.
+ Returns a pointer to the new list head.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+list_ptr dup_list_head(list_ptr lp, int start_at_curr)
+#else
+list_ptr dup_list_head(lp, start_at_curr)
+ list_ptr lp;
+ int start_at_curr;
+#endif
+{
+ list_ptr new_list;
+
+ if ((new_list = (list_ptr) malloc( sizeof( list_item))) == NULL) {
+
+ return (list_ptr)NULL;
+ }
+ new_list->next = start_at_curr ? lp->ptr.curr : lp->next;
+ new_list->ptr.curr = lp->ptr.curr;
+
+ return new_list;
+}
+
+
+/** ------------------------------------------------------------------------
+ Returns the number of items in the list.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+unsigned int list_length(list_ptr lp)
+#else
+unsigned int list_length(lp)
+ list_ptr lp;
+#endif
+{
+ unsigned int count = 0;
+
+ while (lp->next) {
+ count++;
+ lp = lp->next;
+ }
+
+ return count;
+}
+
+
+/** ------------------------------------------------------------------------
+ Scans thru list, looking for a node whose ptr.item is equal to
+ the "item" passed in. "Equal" here means the same address - no
+ attempt is made to match equivalent values stored in different
+ locations. If a match is found, that node is deleted from the
+ list. Storage for the node is freed, but not for the item itself.
+ Returns a pointer to the item, so the caller can free it if it
+ so desires. If a match is not found, returns NULL.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+void *delete_from_list(list_ptr lp, void *item)
+#else
+void *delete_from_list(lp, item)
+ list_ptr lp;
+ void *item;
+#endif
+{
+ list_ptr new_next;
+
+ while (lp->next) {
+ if (lp->next->ptr.item == item) {
+ new_next = lp->next->next;
+ free (lp->next);
+ lp->next = new_next;
+
+ return item;
+ }
+ lp = lp->next;
+ }
+
+ return NULL;
+}
+
+
+/** ------------------------------------------------------------------------
+ Deletes each node in the list *except the head*. This allows
+ the deletion of lists where the head is not malloced or created
+ with new_list(). If free_items is true, each item pointed to
+ from the node is freed, in addition to the node itself.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+void delete_list(list_ptr lp, int free_items)
+#else
+void delete_list(lp, free_items)
+ list_ptr lp;
+ int free_items;
+#endif
+{
+ list_ptr del_node;
+ void *item;
+
+ while (lp->next) {
+ del_node = lp->next;
+ item = del_node->ptr.item;
+ lp->next = del_node->next;
+ free (del_node);
+ if (free_items) {
+ free( item);
+ }
+ }
+}
+
+#if NeedFunctionPrototypes
+void delete_list_destroying(list_ptr lp, void destructor(void *item))
+#else
+void delete_list_destroying(lp, destructor)
+ list_ptr lp;
+ void (*destructor)();
+#endif
+{
+ list_ptr del_node;
+ void *item;
+
+ while (lp->next) {
+ del_node = lp->next;
+ item = del_node->ptr.item;
+ lp->next = del_node->next;
+ free( del_node);
+ if (destructor) {
+ destructor( item);
+ }
+ }
+}
+
+
+/** ------------------------------------------------------------------------
+ Returns a ptr to the first *item* (not list node) in the list.
+ Sets the list head node's curr ptr to the first node in the list.
+ Returns NULL if the list is empty.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+void * first_in_list(list_ptr lp)
+#else
+void * first_in_list(lp)
+ list_ptr lp;
+#endif
+{
+ if (! lp) {
+
+ return NULL;
+ }
+ lp->ptr.curr = lp->next;
+
+ return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
+}
+
+/** ------------------------------------------------------------------------
+ Returns a ptr to the next *item* (not list node) in the list.
+ Sets the list head node's curr ptr to the next node in the list.
+ first_in_list must have been called prior.
+ Returns NULL if no next item.
+ -------------------------------------------------------------------- **/
+#if NeedFunctionPrototypes
+void * next_in_list(list_ptr lp)
+#else
+void * next_in_list(lp)
+ list_ptr lp;
+#endif
+{
+ if (! lp) {
+
+ return NULL;
+ }
+ if (lp->ptr.curr) {
+ lp->ptr.curr = lp->ptr.curr->next;
+ }
+
+ return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
+}
+
+#if NeedFunctionPrototypes
+int list_is_empty(list_ptr lp)
+#else
+int list_is_empty(lp)
+ list_ptr lp;
+#endif
+{
+ return (lp == NULL || lp->next == NULL);
+}
+
diff --git a/list.h b/list.h
new file mode 100644
index 0000000..02ce815
--- /dev/null
+++ b/list.h
@@ -0,0 +1,117 @@
+/* $Xorg: list.h,v 1.4 2001/02/09 02:06:03 xorgcvs Exp $ */
+/** ------------------------------------------------------------------------
+ This file contains routines for manipulating generic lists.
+ Lists are implemented with a "harness". In other words, each
+ node in the list consists of two pointers, one to the data item
+ and one to the next node in the list. The head of the list is
+ the same struct as each node, but the "item" ptr is used to point
+ to the current member of the list (used by the first_in_list and
+ next_in_list functions).
+
+Copyright 1994 Hewlett-Packard Co.
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+ -------------------------------------------------------------------- **/
+
+#ifndef LIST_DEF
+#define LIST_DEF
+
+#define LESS -1
+#define EQUAL 0
+#define GREATER 1
+#define DUP_WHOLE_LIST 0
+#define START_AT_CURR 1
+
+typedef struct _list_item {
+ struct _list_item *next;
+ union {
+ void *item; /* in normal list node, pts to data */
+ struct _list_item *curr; /* in list head, pts to curr for 1st, next */
+ } ptr;
+} list, list_item, *list_ptr;
+
+typedef void (*DESTRUCT_FUNC_PTR)(
+#if NeedFunctionPrototypes
+void *
+#endif
+);
+
+void zero_list(
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ );
+int add_to_list (
+#if NeedFunctionPrototypes
+ list_ptr , void *
+#endif
+ );
+list_ptr new_list (
+#if NeedFunctionPrototypes
+ void
+#endif
+ );
+list_ptr dup_list_head (
+#if NeedFunctionPrototypes
+ list_ptr , int
+#endif
+ );
+unsigned int list_length(
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ );
+void *delete_from_list (
+#if NeedFunctionPrototypes
+ list_ptr , void *
+#endif
+ );
+void delete_list(
+#if NeedFunctionPrototypes
+ list_ptr , int
+#endif
+ );
+void delete_list_destroying (
+#if NeedFunctionPrototypes
+ list_ptr , DESTRUCT_FUNC_PTR
+#endif
+ );
+void *first_in_list (
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ );
+void *next_in_list (
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ );
+int list_is_empty (
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ );
+
+#endif
diff --git a/multiVis.c b/multiVis.c
new file mode 100644
index 0000000..66e32b6
--- /dev/null
+++ b/multiVis.c
@@ -0,0 +1,1249 @@
+/* $Xorg: multiVis.c,v 1.5 2001/02/09 02:06:03 xorgcvs Exp $ */
+/** ------------------------------------------------------------------------
+ This file contains functions to create a list of regions which
+ tile a specified window. Each region contains all visible
+ portions of the window which are drawn with the same visual.
+ If the window consists of subwindows of two different visual types,
+ there will be two regions in the list. The list can be traversed
+ to correctly pull an image of the window using XGetImage or the
+ Image Library.
+
+Copyright 1994 Hewlett-Packard Co.
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+ ------------------------------------------------------------------------ **/
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/X.h>
+#include <stdio.h>
+#include "list.h"
+#include "wsutils.h"
+#include "multiVis.h"
+static char *vis_class_str[] = { "StaticGray" , "GrayScale" , "StaticColor",
+ "PseudoColor","TrueColor","DirectColor" } ;
+/* These structures are copied from X11/region.h. For some reason
+ * they're invisible from the outside.
+ */
+typedef struct {
+ short x1, x2, y1, y2;
+} myBox, myBOX, myBoxRec, *myBoxPtr;
+
+typedef struct my_XRegion {
+ long size;
+ long numRects;
+ myBOX *rects;
+ myBOX extents;
+} myREGION;
+
+/* Items in long list of windows that have some part in the grabbed area */
+typedef struct {
+ Window win;
+ Visual *vis;
+ Colormap cmap;
+ int x_rootrel, y_rootrel; /* root relative location of window */
+ int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */
+ int width, height; /* width and height of visible part */
+ int border_width; /* border width of the window */
+ Window parent; /* id of parent (for debugging) */
+} image_win_type;
+
+/* Items in short list of regions that tile the grabbed area. May have
+ multiple windows in the region.
+*/
+typedef struct {
+ Window win; /* lowest window of this visual */
+ Visual *vis;
+ Colormap cmap;
+ int x_rootrel, y_rootrel; /* root relative location of bottom window */
+ int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */
+ int width, height; /* w & h of visible rect of bottom window */
+ int border; /* border width of the window */
+ Region visible_region;
+} image_region_type;
+
+/** ------------------------------------------------------------------------
+ Returns TRUE if the two structs pointed to have the same "vis" &
+ "cmap" fields and s2 lies completely within s1. s1 and s2 can
+ point to structs of image_win_type or image_region_type.
+ ------------------------------------------------------------------------ **/
+#define SAME_REGIONS( s1, s2) \
+ ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap && \
+ (s1)->x_vis <= (s2)->x_vis && \
+ (s1)->y_vis <= (s2)->y_vis && \
+ (s1)->x_vis + (s1)->width >= (s2)->x_vis + (s2)->width && \
+ (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height)
+
+#ifndef MIN
+#define MIN( a, b) ((a) < (b) ? a : b)
+#define MAX( a, b) ((a) > (b) ? a : b)
+#endif
+
+#define RED_SHIFT 16
+#define GREEN_SHIFT 8
+#define BLUE_SHIFT 0
+
+/*
+extern list_ptr new_list();
+extern list_ptr dup_list_head();
+extern void * first_in_list();
+extern void * next_in_list();
+extern int add_to_list();
+extern void zero_list();
+extern void delete_list();
+extern void delete_list_destroying();
+extern unsigned int list_length();
+*/
+
+/* Prototype Declarations for Static Functions */
+static int QueryColorMap(
+#if NeedFunctionPrototypes
+ Display *, Colormap , Visual *,
+ XColor **, int *, int *, int *
+#endif
+ );
+static void TransferImage(
+#if NeedFunctionPrototypes
+ Display *, XImage *,int, int , image_region_type*,
+ XImage *,int ,int
+#endif
+ );
+static XImage * ReadRegionsInList(
+#if NeedFunctionPrototypes
+ Display *, Visual *, int ,int ,int ,
+ int , XRectangle, list_ptr
+#endif
+ );
+
+static list_ptr make_region_list(
+#if NeedFunctionPrototypes
+ Display*, Window, XRectangle*,
+ int*, int, XVisualInfo**, int *
+#endif
+ );
+
+static void destroy_region_list(
+#if NeedFunctionPrototypes
+ list_ptr
+#endif
+ ) ;
+static void subtr_rect_from_image_region(
+#if NeedFunctionPrototypes
+ image_region_type *, int , int , int , int
+#endif
+ );
+static void add_rect_to_image_region(
+#if NeedFunctionPrototypes
+ image_region_type *,
+ int , int , int , int
+#endif
+ );
+static int src_in_region_list(
+#if NeedFunctionPrototypes
+ image_win_type *, list_ptr
+#endif
+ );
+static void add_window_to_list(
+#if NeedFunctionPrototypes
+ list_ptr, Window, int, int ,
+ int , int , int , int, int,
+ Visual*, Colormap, Window
+#endif
+ );
+static int src_in_image(
+#if NeedFunctionPrototypes
+ image_win_type *, int , XVisualInfo**
+#endif
+ );
+static int src_in_overlay(
+#if NeedFunctionPrototypes
+ image_region_type *, int, OverlayInfo *, int*, int*
+#endif
+ );
+
+/* End of Prototype Declarations */
+
+void initFakeVisual(Vis)
+Visual *Vis ;
+{
+ Vis->ext_data=NULL;
+ Vis->class = DirectColor ;
+ Vis->red_mask = 0x00FF0000;
+ Vis->green_mask = 0x0000FF00 ;
+ Vis->blue_mask = 0x000000FF ;
+ Vis->map_entries = 256 ;
+ Vis->bits_per_rgb = 8 ;
+}
+
+static int
+QueryColorMap(disp,src_cmap,src_vis,src_colors,rShift,gShift,bShift)
+Display *disp ;
+Visual *src_vis ;
+Colormap src_cmap ;
+XColor **src_colors ;
+int *rShift, *gShift, *bShift;
+{
+ int ncolors,i ;
+ unsigned long redMask, greenMask, blueMask;
+ int redShift, greenShift, blueShift;
+ XColor *colors ;
+
+ ncolors = src_vis->map_entries ;
+ *src_colors = colors = (XColor *)malloc(ncolors * sizeof(XColor) ) ;
+
+ if(src_vis->class != TrueColor && src_vis->class != DirectColor)
+ {
+ for(i=0 ; i < ncolors ; i++)
+ {
+ colors[i].pixel = i ;
+ colors[i].pad = 0;
+ colors[i].flags = DoRed|DoGreen|DoBlue;
+ }
+ }
+ else /** src is decomposed rgb ***/
+ {
+ /* Get the X colormap */
+ redMask = src_vis->red_mask;
+ greenMask = src_vis->green_mask;
+ blueMask = src_vis->blue_mask;
+ redShift = 0; while (!(redMask&0x1)) {
+ redShift++;
+ redMask = redMask>>1;
+ }
+ greenShift = 0; while (!(greenMask&0x1)) {
+ greenShift++;
+ greenMask = greenMask>>1;
+ }
+ blueShift = 0; while (!(blueMask&0x1)) {
+ blueShift++;
+ blueMask = blueMask>>1;
+ }
+ *rShift = redShift ;
+ *gShift = greenShift ;
+ *bShift = blueShift ;
+ for (i=0; i<ncolors; i++) {
+ if( i <= redMask)colors[i].pixel = (i<<redShift) ;
+ if( i <= greenMask)colors[i].pixel |= (i<<greenShift) ;
+ if( i <= blueMask)colors[i].pixel |= (i<<blueShift) ;
+ /***** example :for gecko's 3-3-2 map, blue index should be <= 3.
+ colors[i].pixel = (i<<redShift)|(i<<greenShift)|(i<<blueShift);
+ *****/
+ colors[i].pad = 0;
+ colors[i].flags = DoRed|DoGreen|DoBlue;
+ }
+ }
+
+
+ XQueryColors(disp, src_cmap, colors, ncolors);
+ return ncolors ;
+}
+
+int
+GetMultiVisualRegions(disp,srcRootWinid, x, y, width, height,
+ transparentOverlays,numVisuals, pVisuals,numOverlayVisuals, pOverlayVisuals,
+ numImageVisuals, pImageVisuals,vis_regions,vis_image_regions,allImage)
+ Display *disp;
+ Window srcRootWinid; /* root win on which grab was done */
+ int x; /* root rel UL corner of bounding box of grab */
+ int y;
+ unsigned int width; /* size of bounding box of grab */
+ unsigned int height;
+ int *transparentOverlays ;
+ int *numVisuals;
+ XVisualInfo **pVisuals;
+ int *numOverlayVisuals;
+ OverlayInfo **pOverlayVisuals;
+ int *numImageVisuals;
+ XVisualInfo ***pImageVisuals;
+ list_ptr *vis_regions; /* list of regions to read from */
+ list_ptr *vis_image_regions ;
+ int *allImage ;
+{
+ int hasNonDefault;
+ XRectangle bbox; /* bounding box of grabbed area */
+
+
+ bbox.x = x; /* init X rect for bounding box */
+ bbox.y = y;
+ bbox.width = width;
+ bbox.height = height;
+
+ GetXVisualInfo(disp,DefaultScreen(disp),
+ transparentOverlays,
+ numVisuals, pVisuals,
+ numOverlayVisuals, pOverlayVisuals,
+ numImageVisuals, pImageVisuals);
+
+ *vis_regions = *vis_image_regions = NULL ;
+ if ((*vis_regions = make_region_list( disp, srcRootWinid, &bbox,
+ &hasNonDefault, *numImageVisuals,
+ *pImageVisuals, allImage)) == NULL)
+ return 0 ;
+
+ if (*transparentOverlays)
+ {
+ *allImage = 1; /* until proven otherwise,
+ this flags that it to be an image only list */
+ *vis_image_regions =
+ make_region_list( disp, srcRootWinid, &bbox, &hasNonDefault,
+ *numImageVisuals, *pImageVisuals, allImage);
+ }
+
+ /* if there is a second region in any of the two lists return 1 **/
+ if ( ( *vis_regions && (*vis_regions)->next && (*vis_regions)->next->next ) ||
+ ( *vis_image_regions && (*vis_image_regions)->next &&
+ (*vis_image_regions)->next->next ) ) return 1 ;
+ else return 0 ;
+
+}
+
+static void TransferImage(disp,reg_image,srcw,srch,reg,
+ target_image,dst_x,dst_y)
+Display *disp;
+XImage *reg_image,*target_image ;
+image_region_type *reg;
+int srcw,srch,dst_x , dst_y ;
+{
+ int ncolors;
+ int i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ;
+ XColor *colors;
+ int rShift,gShift,bShift;
+ int targetBytesPerLine ;
+
+ ncolors = QueryColorMap(disp,reg->cmap,reg->vis,&colors,
+ &rShift,&gShift,&bShift) ;
+
+ targetBytesPerLine = target_image->bytes_per_line;
+
+ switch (reg->vis->class) {
+ case TrueColor :
+ for(i=0 ; i < srch ; i++)
+ {
+ for(j=0 ; j < srcw ; j++)
+ {
+ old_pixel = XGetPixel(reg_image,j,i) ;
+
+ if( reg->vis->map_entries == 16) {
+
+ red_ind = (old_pixel & reg->vis->red_mask) >> rShift ;
+ green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
+ blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ;
+
+ new_pixel = (
+ ((colors[red_ind].red >> 8) << RED_SHIFT)
+ |((colors[green_ind].green >> 8) << GREEN_SHIFT)
+ |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
+ );
+ }
+ else
+ new_pixel = old_pixel;
+
+ XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
+
+ }
+ }
+ break;
+ case DirectColor :
+ for(i=0 ; i < srch ; i++)
+ {
+
+ for(j=0 ; j < srcw ; j++)
+ {
+ old_pixel = XGetPixel(reg_image,j,i) ;
+ red_ind = (old_pixel & reg->vis->red_mask) >> rShift ;
+ green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
+ blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ;
+
+ new_pixel = (
+ ((colors[red_ind].red >> 8) << RED_SHIFT)
+ |((colors[green_ind].green >> 8) << GREEN_SHIFT)
+ |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
+ );
+ XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
+
+ }
+ }
+ break;
+ default :
+ for(i=0 ; i < srch ; i++)
+ {
+ for(j=0 ; j < srcw ; j++)
+ {
+ old_pixel = XGetPixel(reg_image,j,i) ;
+
+ new_pixel = (
+ ((colors[old_pixel].red >> 8) << RED_SHIFT)
+ |((colors[old_pixel].green >> 8) << GREEN_SHIFT)
+ |((colors[old_pixel].blue >> 8) << BLUE_SHIFT)
+ );
+ XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
+
+ }
+ }
+ break;
+ }
+}
+
+static XImage *
+ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions)
+Display *disp ;
+Visual *fakeVis ;
+int depth , width , height ;
+int format ;
+XRectangle bbox; /* bounding box of grabbed area */
+list_ptr regions;/* list of regions to read from */
+{
+ image_region_type *reg;
+ int dst_x, dst_y; /* where in pixmap to write (UL) */
+ int diff;
+
+ XImage *reg_image,*ximage ;
+ int srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
+ int rem ;
+ int bytes_per_line;
+ int bitmap_unit;
+
+ bitmap_unit = sizeof (long);
+ if (format == ZPixmap)
+ bytes_per_line = width*depth/8;
+ else
+ bytes_per_line = width/8;
+
+
+ /* Find out how many more bytes are required for padding so that
+ ** bytes per scan line will be multiples of bitmap_unit bits */
+ if (format == ZPixmap) {
+ rem = (bytes_per_line*8)%bitmap_unit;
+ if (rem)
+ bytes_per_line += (rem/8 + 1);
+ }
+
+ ximage = XCreateImage(disp,fakeVis,depth,format,0,NULL,width,height,
+ 8,0) ;
+ bytes_per_line = ximage->bytes_per_line;
+
+ if (format == ZPixmap)
+ ximage->data = malloc(height*bytes_per_line);
+ else
+ ximage->data = malloc(height*bytes_per_line*depth);
+
+ ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
+
+ for (reg = (image_region_type *) first_in_list( regions); reg;
+ reg = (image_region_type *) next_in_list( regions))
+ {
+ int rect;
+ struct my_XRegion *vis_reg;
+ vis_reg = (struct my_XRegion *)(reg->visible_region);
+ for (rect = 0;
+ rect < vis_reg->numRects;
+ rect++)
+ {
+ /** ------------------------------------------------------------------------
+ Intersect bbox with visible part of region giving src rect & output
+ location. Width is the min right side minus the max left side.
+ Similar for height. Offset src rect so x,y are relative to
+ origin of win, not the root-relative visible rect of win.
+ ------------------------------------------------------------------------ **/
+ srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) -
+ MAX( vis_reg->rects[rect].x1, bbox.x);
+ srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) -
+ MAX( vis_reg->rects[rect].y1, bbox.y);
+ diff = bbox.x - vis_reg->rects[rect].x1;
+ srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
+ dst_x = MAX( 0, -diff) ;
+ diff = bbox.y - vis_reg->rects[rect].y1;
+ srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
+ dst_y = MAX( 0, -diff) ;
+ reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
+ srcRect_width,srcRect_height,AllPlanes,format) ;
+ TransferImage(disp,reg_image,srcRect_width,
+ srcRect_height,reg,ximage,dst_x,dst_y) ;
+ }
+ }
+ return ximage ;
+}
+
+
+/** ------------------------------------------------------------------------
+ ------------------------------------------------------------------------ **/
+
+XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height,
+ numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals,
+ pImageVisuals,vis_regions,vis_image_regions,format,allImage)
+ Display *disp;
+ Window srcRootWinid; /* root win on which grab was done */
+ int x; /* root rel UL corner of bounding box of grab */
+ int y;
+ unsigned int width; /* size of bounding box of grab */
+ unsigned int height;
+ /** int transparentOverlays; ***/
+ int numVisuals;
+ XVisualInfo *pVisuals;
+ int numOverlayVisuals;
+ OverlayInfo *pOverlayVisuals;
+ int numImageVisuals;
+ XVisualInfo **pImageVisuals;
+ list_ptr vis_regions; /* list of regions to read from */
+ list_ptr vis_image_regions ;/* list of regions to read from */
+ int format;
+ int allImage ;
+{
+ image_region_type *reg;
+ XRectangle bbox; /* bounding box of grabbed area */
+ int depth ;
+ XImage *ximage, *ximage_ipm ;
+ Visual fakeVis ;
+ int x1, y1;
+ XImage *image;
+ unsigned char *pmData , *ipmData ;
+ int transparentColor, transparentType;
+ int srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
+ int diff ;
+ int dst_x, dst_y; /* where in pixmap to write (UL) */
+ int pixel;
+
+ bbox.x = x; /* init X rect for bounding box */
+ bbox.y = y;
+ bbox.width = width;
+ bbox.height = height;
+
+
+ initFakeVisual(&fakeVis) ;
+
+ depth = 24 ;
+ ximage = ReadRegionsInList(disp,&fakeVis,depth,format,width,height,
+ bbox,vis_regions) ;
+ pmData = (unsigned char *)ximage -> data ;
+
+/* if transparency possible do it again, but this time for image planes only */
+ if (vis_image_regions && (vis_image_regions->next) && !allImage)
+ {
+ ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format,width,height,
+ bbox,vis_image_regions) ;
+ ipmData = (unsigned char *)ximage_ipm -> data ;
+ }
+/* Now tranverse the overlay visual windows and test for transparency index. */
+/* If you find one, subsitute the value from the matching image plane pixmap. */
+
+ for (reg = (image_region_type *) first_in_list( vis_regions); reg;
+ reg = (image_region_type *) next_in_list( vis_regions))
+ {
+
+ if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals,
+ &transparentColor, &transparentType))
+ {
+ int test = 0 ;
+ srcRect_width = MIN( reg->width + reg->x_vis, bbox.width + bbox.x)
+ - MAX( reg->x_vis, bbox.x);
+ srcRect_height = MIN( reg->height + reg->y_vis, bbox.height
+ + bbox.y) - MAX( reg->y_vis, bbox.y);
+ diff = bbox.x - reg->x_vis;
+ srcRect_x = MAX( 0, diff) + (reg->x_vis - reg->x_rootrel - reg->border);
+ dst_x = MAX( 0, -diff) ;
+ diff = bbox.y - reg->y_vis;
+ srcRect_y = MAX( 0, diff) + (reg->y_vis - reg->y_rootrel - reg->border);
+ dst_y = MAX( 0, -diff) ;
+ /* let's test some pixels for transparency */
+ image = XGetImage(disp, reg->win, srcRect_x, srcRect_y,
+ srcRect_width, srcRect_height, 0xffffffff, ZPixmap);
+
+ /* let's assume byte per pixel for overlay image for now */
+ if ((image->depth == 8) && (transparentType == TransparentPixel))
+ {
+ unsigned char *pixel_ptr;
+ unsigned char *start_of_line = (unsigned char *) image->data;
+
+ for (y1 = 0; y1 < srcRect_height; y1++) {
+ pixel_ptr = start_of_line;
+ for (x1 = 0; x1 < srcRect_width; x1++)
+ {
+ if (*pixel_ptr++ == transparentColor)
+ {
+ /*
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ */
+ pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
+ XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
+
+ if(!test){
+ test = 1 ;
+ }
+ }
+ /*
+ else {
+ pmData +=3;
+ ipmData +=3;
+ }
+ */
+ }
+ start_of_line += image->bytes_per_line;
+ }
+ } else {
+ if (transparentType == TransparentPixel) {
+ for (y1 = 0; y1 < srcRect_height; y1++) {
+ for (x1 = 0; x1 < srcRect_width; x1++)
+ {
+ int pixel_value = XGetPixel(image, x1, y1);
+ if (pixel_value == transparentColor)
+ {
+ /*
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ */
+ pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
+ XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
+ if(!test){
+ test = 1 ;
+ }
+ }
+ /*
+ else {
+ pmData +=3;
+ ipmData +=3;
+ }
+ */
+ }
+ }
+ } else {
+ for (y1 = 0; y1 < srcRect_height; y1++) {
+ for (x1 = 0; x1 < srcRect_width; x1++)
+ {
+ int pixel_value = XGetPixel(image, x1, y1);
+ if (pixel_value & transparentColor)
+ {
+ /*
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ */
+ pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
+ XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
+ if(!test){
+ test = 1 ;
+ }
+ }
+ /*
+ else {
+ pmData +=3;
+ ipmData +=3;
+ }
+ */
+ }
+ }
+ }
+ }
+ XDestroyImage (image);
+ } /* end of src_in_overlay */
+ } /** end transparency **/
+ destroy_region_list( vis_regions);
+ if (vis_image_regions) destroy_region_list( vis_image_regions );
+ FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals);
+ XSync(disp, 0);
+
+ return ximage;
+}
+
+/** ------------------------------------------------------------------------
+ Creates a list of the subwindows of a given window which have a
+ different visual than their parents. The function is recursive.
+ This list is used in make_region_list(), which coalesces the
+ windows with the same visual into a region.
+ image_wins must point to an existing list struct that's already
+ been zeroed (zero_list()).
+ ------------------------------------------------------------------------ **/
+static void make_src_list( disp, image_wins, bbox, curr, x_rootrel, y_rootrel,
+ curr_attrs, pclip)
+ Display *disp;
+ list_ptr image_wins;
+ XRectangle *bbox; /* bnding box of area we want */
+ Window curr;
+ int x_rootrel; /* pos of curr WRT root */
+ int y_rootrel;
+ XWindowAttributes *curr_attrs;
+ XRectangle *pclip; /* visible part of curr, not */
+ /* obscurred by ancestors */
+{
+ XWindowAttributes child_attrs;
+ Window root, parent, *child; /* variables for XQueryTree() */
+ Window *save_child_list; /* variables for XQueryTree() */
+ unsigned int nchild; /* variables for XQueryTree() */
+ XRectangle child_clip; /* vis part of child */
+ int curr_clipX, curr_clipY, curr_clipRt, curr_clipBt;
+
+ /* check that win is mapped & not outside bounding box */
+ if (curr_attrs->map_state == IsViewable &&
+ curr_attrs->class == InputOutput &&
+ !( pclip->x >= (int) (bbox->x + bbox->width) ||
+ pclip->y >= (int) (bbox->y + bbox->height) ||
+ (int) (pclip->x + pclip->width) <= bbox->x ||
+ (int) (pclip->y + pclip->height) <= bbox->y)) {
+
+ XQueryTree( disp, curr, &root, &parent, &child, &nchild );
+ save_child_list = child; /* so we can free list when we're done */
+ add_window_to_list( image_wins, curr, x_rootrel, y_rootrel,
+ pclip->x, pclip->y,
+ pclip->width, pclip->height,
+ curr_attrs->border_width,curr_attrs->visual,
+ curr_attrs->colormap, parent);
+
+
+/** ------------------------------------------------------------------------
+ set RR coords of right (Rt), left (X), bottom (Bt) and top (Y)
+ of rect we clip all children by. This is our own clip rect (pclip)
+ inflicted on us by our parent plus our own borders. Within the
+ child loop, we figure the clip rect for each child by adding in
+ it's rectangle (not taking into account the child's borders).
+ ------------------------------------------------------------------------ **/
+ curr_clipX = MAX( pclip->x, x_rootrel + (int) curr_attrs->border_width);
+ curr_clipY = MAX( pclip->y, y_rootrel + (int) curr_attrs->border_width);
+ curr_clipRt = MIN( pclip->x + (int) pclip->width,
+ x_rootrel + (int) curr_attrs->width +
+ 2 * (int) curr_attrs->border_width);
+ curr_clipBt = MIN( pclip->y + (int) pclip->height,
+ y_rootrel + (int) curr_attrs->height +
+ 2 * (int) curr_attrs->border_width);
+
+ while (nchild--) {
+ int new_width, new_height;
+ int child_xrr, child_yrr; /* root relative x & y of child */
+
+ XGetWindowAttributes( disp, *child, &child_attrs);
+
+ /* intersect parent & child clip rects */
+ child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width;
+ child_clip.x = MAX( curr_clipX, child_xrr);
+ new_width = MIN( curr_clipRt, child_xrr + (int) child_attrs.width
+ + 2 * child_attrs.border_width)
+ - child_clip.x;
+ if (new_width >= 0) {
+ child_clip.width = new_width;
+
+ child_yrr = y_rootrel + child_attrs.y +
+ curr_attrs->border_width;
+ child_clip.y = MAX( curr_clipY, child_yrr);
+ new_height = MIN( curr_clipBt,
+ child_yrr + (int) child_attrs.height +
+ 2 * child_attrs.border_width)
+ - child_clip.y;
+ if (new_height >= 0) {
+ child_clip.height = new_height;
+ make_src_list( disp, image_wins, bbox, *child,
+ child_xrr, child_yrr,
+ &child_attrs, &child_clip);
+ }
+ }
+ child++;
+ }
+ XFree( save_child_list);
+ }
+}
+
+
+/** ------------------------------------------------------------------------
+ This function creates a list of regions which tile a specified
+ window. Each region contains all visible portions of the window
+ which are drawn with the same visual. For example, if the
+ window consists of subwindows of two different visual types,
+ there will be two regions in the list.
+ Returns a pointer to the list.
+ ------------------------------------------------------------------------ **/
+static list_ptr make_region_list( disp, win, bbox, hasNonDefault,
+ numImageVisuals, pImageVisuals, allImage)
+ Display *disp;
+ Window win;
+ XRectangle *bbox;
+ int *hasNonDefault;
+ int numImageVisuals;
+ XVisualInfo **pImageVisuals;
+ int *allImage;
+{
+ XWindowAttributes win_attrs;
+ list image_wins;
+ list_ptr image_regions;
+ list_ptr srcs_left;
+ image_region_type *new_reg;
+ image_win_type *base_src, *src;
+ Region bbox_region = XCreateRegion();
+ XRectangle clip;
+ int image_only;
+
+ int count=0 ;
+
+ *hasNonDefault = False;
+ XUnionRectWithRegion( bbox, bbox_region, bbox_region);
+ XGetWindowAttributes( disp, win, &win_attrs);
+
+ zero_list( &image_wins);
+ clip.x = 0;
+ clip.y = 0;
+ clip.width = win_attrs.width;
+ clip.height = win_attrs.height;
+ make_src_list( disp, &image_wins, bbox, win,
+ 0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip);
+
+ image_regions = new_list();
+ image_only = (*allImage) ? True:False;
+
+ for (base_src = (image_win_type *) first_in_list( &image_wins); base_src;
+ base_src = (image_win_type *) next_in_list( &image_wins))
+ {
+ /* test for image visual */
+ if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals))
+ {
+ /* find a window whose visual hasn't been put in list yet */
+ if (!src_in_region_list( base_src, image_regions))
+ {
+ if (! (new_reg = (image_region_type *)
+ malloc( sizeof( image_region_type)))) {
+ return (list_ptr) NULL;
+ }
+ count++;
+
+ new_reg->visible_region = XCreateRegion();
+ new_reg->win = base_src->win;
+ new_reg->vis = base_src->vis;
+ new_reg->cmap = base_src->cmap;
+ new_reg->x_rootrel = base_src->x_rootrel;
+ new_reg->y_rootrel = base_src->y_rootrel;
+ new_reg->x_vis = base_src->x_vis;
+ new_reg->y_vis = base_src->y_vis;
+ new_reg->width = base_src->width;
+ new_reg->height = base_src->height;
+ new_reg->border = base_src->border_width;
+
+ srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR);
+ for (src = (image_win_type *) first_in_list( srcs_left); src;
+ src = (image_win_type *) next_in_list( srcs_left)) {
+ if (SAME_REGIONS( base_src, src)) {
+ add_rect_to_image_region( new_reg, src->x_vis, src->y_vis,
+ src->width, src->height);
+ }
+ else {
+ if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals))
+ {
+ subtr_rect_from_image_region( new_reg, src->x_vis,
+ src->y_vis, src->width, src->height);
+ }
+ }
+ }
+ XIntersectRegion( bbox_region, new_reg->visible_region,
+ new_reg->visible_region);
+ if (! XEmptyRegion( new_reg->visible_region)) {
+ add_to_list( image_regions, new_reg);
+ if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) ||
+ new_reg->cmap != DefaultColormapOfScreen(
+ win_attrs.screen)) {
+ *hasNonDefault = True;
+ }
+ }
+ else {
+ XDestroyRegion( new_reg->visible_region);
+ free( (void *) new_reg);
+ }
+ }
+ } else *allImage = 0;
+ }
+ delete_list( &image_wins, True);
+ XDestroyRegion( bbox_region);
+ return image_regions;
+}
+/** ------------------------------------------------------------------------
+ Destructor called from destroy_region_list().
+ ------------------------------------------------------------------------ **/
+void destroy_image_region( image_region)
+ image_region_type *image_region;
+{
+ XDestroyRegion( image_region->visible_region);
+ free( (void *) image_region);
+}
+
+/** ------------------------------------------------------------------------
+ Destroys the region list, destroying all the regions contained in it.
+ ------------------------------------------------------------------------ **/
+static void destroy_region_list( rlist)
+ list_ptr rlist;
+{
+ delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region);
+}
+
+
+/** ------------------------------------------------------------------------
+ Subtracts the specified rectangle from the region in image_region.
+ First converts the rectangle to a region of its own, since X
+ only provides a way to subtract one region from another, not a
+ rectangle from a region.
+ ------------------------------------------------------------------------ **/
+static void subtr_rect_from_image_region( image_region, x, y, width, height)
+ image_region_type *image_region;
+ int x;
+ int y;
+ int width;
+ int height;
+{
+ XRectangle rect;
+ Region rect_region;
+
+ rect_region = XCreateRegion();
+ rect.x = x;
+ rect.y = y;
+ rect.width = width;
+ rect.height = height;
+ XUnionRectWithRegion( &rect, rect_region, rect_region);
+ XSubtractRegion( image_region->visible_region, rect_region,
+ image_region->visible_region);
+ XDestroyRegion( rect_region);
+}
+
+
+/** ------------------------------------------------------------------------
+ Adds the specified rectangle to the region in image_region.
+ ------------------------------------------------------------------------ **/
+static void add_rect_to_image_region( image_region, x, y, width, height)
+ image_region_type *image_region;
+ int x;
+ int y;
+ int width;
+ int height;
+{
+ XRectangle rect;
+
+ rect.x = x;
+ rect.y = y;
+ rect.width = width;
+ rect.height = height;
+ XUnionRectWithRegion( &rect, image_region->visible_region,
+ image_region->visible_region);
+}
+
+
+/** ------------------------------------------------------------------------
+ Returns TRUE if the given src's visual is already represented in
+ the image_regions list, FALSE otherwise.
+ ------------------------------------------------------------------------ **/
+static int src_in_region_list( src, image_regions)
+ image_win_type *src;
+ list_ptr image_regions;
+{
+ image_region_type *ir;
+
+ for (ir = (image_region_type *) first_in_list( image_regions); ir;
+ ir = (image_region_type *) next_in_list( image_regions)) {
+ if (SAME_REGIONS( ir, src)) {
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+/** ------------------------------------------------------------------------
+ Makes a new entry in image_wins with the given fields filled in.
+ ------------------------------------------------------------------------ **/
+static void add_window_to_list( image_wins, w, xrr, yrr, x_vis, y_vis,
+ width, height, border_width,vis, cmap, parent)
+ list_ptr image_wins;
+ Window w;
+ int xrr;
+ int yrr;
+ int x_vis;
+ int y_vis;
+ int width;
+ int height;
+ Visual *vis;
+ Colormap cmap;
+ Window parent;
+{
+ image_win_type *new_src;
+
+ if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL)
+
+ return;
+
+ new_src->win = w;
+ new_src->x_rootrel = xrr;
+ new_src->y_rootrel = yrr;
+ new_src->x_vis = x_vis;
+ new_src->y_vis = y_vis;
+ new_src->width = width;
+ new_src->height = height;
+ new_src->border_width = border_width;
+ new_src->vis = vis;
+ new_src->cmap = cmap;
+ new_src->parent = parent;
+ add_to_list( image_wins, new_src);
+}
+
+/** ------------------------------------------------------------------------
+ Returns TRUE if the given src's visual is in the image planes,
+ FALSE otherwise.
+ ------------------------------------------------------------------------ **/
+static int src_in_image( src, numImageVisuals, pImageVisuals)
+ image_win_type *src;
+ int numImageVisuals;
+ XVisualInfo **pImageVisuals;
+{
+ int i;
+
+ for (i = 0 ; i < numImageVisuals ; i++)
+ {
+ if (pImageVisuals[i]->visual == src->vis)
+ return 1;
+ }
+ return 0;
+}
+
+
+/** ------------------------------------------------------------------------
+ Returns TRUE if the given src's visual is in the overlay planes
+ and transparency is possible, FALSE otherwise.
+ ------------------------------------------------------------------------ **/
+static int src_in_overlay( src, numOverlayVisuals, pOverlayVisuals,
+ transparentColor, transparentType)
+ image_region_type *src;
+ int numOverlayVisuals;
+ OverlayInfo *pOverlayVisuals;
+ int *transparentColor;
+ int *transparentType;
+{
+ int i;
+
+ for (i = 0 ; i < numOverlayVisuals ; i++)
+ {
+ if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis)
+ && (pOverlayVisuals[i].transparentType != None))
+ {
+ *transparentColor = pOverlayVisuals[i].value;
+ *transparentType = pOverlayVisuals[i].transparentType;
+ return 1;
+ }
+
+ else {
+ }
+
+ }
+ return 0;
+}
+
+
+/********************** from wsutils.c ******************************/
+
+/******************************************************************************
+ *
+ * This file contains a set of example utility procedures; procedures that can
+ * help a "window-smart" Starbase or PHIGS program determine information about
+ * a device, and create image and overlay plane windows. To use these
+ * utilities, #include "wsutils.h" and compile this file and link the results
+ * with your program.
+ *
+ ******************************************************************************/
+
+
+
+#define STATIC_GRAY 0x01
+#define GRAY_SCALE 0x02
+#define PSEUDO_COLOR 0x04
+#define TRUE_COLOR 0x10
+#define DIRECT_COLOR 0x11
+
+
+static int weCreateServerOverlayVisualsProperty = False;
+
+
+/******************************************************************************
+ *
+ * GetXVisualInfo()
+ *
+ * This routine takes an X11 Display, screen number, and returns whether the
+ * screen supports transparent overlays and three arrays:
+ *
+ * 1) All of the XVisualInfo struct's for the screen.
+ * 2) All of the OverlayInfo struct's for the screen.
+ * 3) An array of pointers to the screen's image plane XVisualInfo
+ * structs.
+ *
+ * The code below obtains the array of all the screen's visuals, and obtains
+ * the array of all the screen's overlay visual information. It then processes
+ * the array of the screen's visuals, determining whether the visual is an
+ * overlay or image visual.
+ *
+ * If the routine sucessfully obtained the visual information, it returns zero.
+ * If the routine didn't obtain the visual information, it returns non-zero.
+ *
+ ******************************************************************************/
+
+int GetXVisualInfo(display, screen, transparentOverlays,
+ numVisuals, pVisuals,
+ numOverlayVisuals, pOverlayVisuals,
+ numImageVisuals, pImageVisuals)
+
+ Display *display; /* Which X server (aka "display"). */
+ int screen; /* Which screen of the "display". */
+ int *transparentOverlays; /* Non-zero if there's at least one
+ * overlay visual and if at least one
+ * of those supports a transparent
+ * pixel. */
+ int *numVisuals; /* Number of XVisualInfo struct's
+ * pointed to to by pVisuals. */
+ XVisualInfo **pVisuals; /* All of the device's visuals. */
+ int *numOverlayVisuals; /* Number of OverlayInfo's pointed
+ * to by pOverlayVisuals. If this
+ * number is zero, the device does
+ * not have overlay planes. */
+ OverlayInfo **pOverlayVisuals; /* The device's overlay plane visual
+ * information. */
+ int *numImageVisuals; /* Number of XVisualInfo's pointed
+ * to by pImageVisuals. */
+ XVisualInfo ***pImageVisuals; /* The device's image visuals. */
+{
+ XVisualInfo getVisInfo; /* Paramters of XGetVisualInfo */
+ int mask;
+ XVisualInfo *pVis, **pIVis; /* Faster, local copies */
+ OverlayInfo *pOVis;
+ OverlayVisualPropertyRec *pOOldVis;
+ int nVisuals, nOVisuals;
+ Atom overlayVisualsAtom; /* Parameters for XGetWindowProperty */
+ Atom actualType;
+ unsigned long numLongs, bytesAfter;
+ int actualFormat;
+ int nImageVisualsAlloced; /* Values to process the XVisualInfo */
+ int imageVisual; /* array */
+
+
+ /* First, get the list of visuals for this screen. */
+ getVisInfo.screen = screen;
+ mask = VisualScreenMask;
+
+ *pVisuals = XGetVisualInfo(display, mask, &getVisInfo, numVisuals);
+ if ((nVisuals = *numVisuals) <= 0)
+ {
+ /* Return that the information wasn't sucessfully obtained: */
+ return(1);
+ }
+ pVis = *pVisuals;
+
+
+ /* Now, get the overlay visual information for this screen. To obtain
+ * this information, get the SERVER_OVERLAY_VISUALS property.
+ */
+ overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True);
+ if (overlayVisualsAtom != None)
+ {
+ /* Since the Atom exists, we can request the property's contents. The
+ * do-while loop makes sure we get the entire list from the X server.
+ */
+ bytesAfter = 0;
+ numLongs = sizeof(OverlayVisualPropertyRec) / 4;
+ do
+ {
+ numLongs += bytesAfter * 4;
+ XGetWindowProperty(display, RootWindow(display, screen),
+ overlayVisualsAtom, 0, numLongs, False,
+ overlayVisualsAtom, &actualType, &actualFormat,
+ &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals);
+ } while (bytesAfter > 0);
+
+
+ /* Calculate the number of overlay visuals in the list. */
+ *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4);
+ }
+ else
+ {
+ /* This screen doesn't have overlay planes. */
+ *numOverlayVisuals = 0;
+ *pOverlayVisuals = NULL;
+ *transparentOverlays = 0;
+ }
+
+
+ /* Process the pVisuals array. */
+ *numImageVisuals = 0;
+ nImageVisualsAlloced = 1;
+ pIVis = *pImageVisuals = (XVisualInfo **) malloc(sizeof(XVisualInfo *));
+ while (--nVisuals >= 0)
+ {
+ nOVisuals = *numOverlayVisuals;
+ pOVis = *pOverlayVisuals;
+ imageVisual = True;
+ while (--nOVisuals >= 0)
+ {
+ pOOldVis = (OverlayVisualPropertyRec *) pOVis;
+ if (pVis->visualid == pOOldVis->visualID)
+ {
+ imageVisual = False;
+ pOVis->pOverlayVisualInfo = pVis;
+ if (pOVis->transparentType == TransparentPixel)
+ *transparentOverlays = 1;
+ }
+ pOVis++;
+ }
+ if (imageVisual)
+ {
+ if ((*numImageVisuals += 1) > nImageVisualsAlloced)
+ {
+ nImageVisualsAlloced++;
+ *pImageVisuals = (XVisualInfo **)
+ realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *)));
+ pIVis = *pImageVisuals + (*numImageVisuals - 1);
+ }
+ *pIVis++ = pVis;
+ }
+ pVis++;
+ }
+
+
+ /* Return that the information was sucessfully obtained: */
+ return(0);
+
+} /* GetXVisualInfo() */
+
+
+/******************************************************************************
+ *
+ * FreeXVisualInfo()
+ *
+ * This routine frees the data that was allocated by GetXVisualInfo().
+ *
+ ******************************************************************************/
+
+void FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals)
+
+ XVisualInfo *pVisuals;
+ OverlayInfo *pOverlayVisuals;
+ XVisualInfo **pImageVisuals;
+{
+ XFree(pVisuals);
+ if (weCreateServerOverlayVisualsProperty)
+ free(pOverlayVisuals);
+ else
+ XFree(pOverlayVisuals);
+ free(pImageVisuals);
+
+} /* FreeXVisualInfo() */
diff --git a/multiVis.h b/multiVis.h
new file mode 100644
index 0000000..a11137c
--- /dev/null
+++ b/multiVis.h
@@ -0,0 +1,60 @@
+/* $Xorg: multiVis.h,v 1.4 2001/02/09 02:06:03 xorgcvs Exp $ */
+/** ------------------------------------------------------------------------
+ This file contains routines for manipulating generic lists.
+ Lists are implemented with a "harness". In other words, each
+ node in the list consists of two pointers, one to the data item
+ and one to the next node in the list. The head of the list is
+ the same struct as each node, but the "item" ptr is used to point
+ to the current member of the list (used by the first_in_list and
+ next_in_list functions).
+
+Copyright 1994 Hewlett-Packard Co.
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+ ------------------------------------------------------------------------ **/
+
+extern int GetMultiVisualRegions(
+#if NeedFunctionPrototypes
+ Display *, Window, int, int, unsigned int,
+ unsigned int, int *, int *, XVisualInfo **, int *,
+ OverlayInfo **, int *, XVisualInfo ***, list_ptr *,
+ list_ptr *, int *
+#endif
+);
+
+extern XImage *ReadAreaToImage(
+#if NeedFunctionPrototypes
+ Display *, Window, int, int, unsigned int,
+ unsigned int, int, XVisualInfo *, int,
+ OverlayInfo *, int, XVisualInfo **, list_ptr,
+ list_ptr, int, int
+#endif
+);
+
+extern void initFakeVisual(
+#if NeedFunctionPrototypes
+ Visual *
+#endif
+);
diff --git a/wsutils.h b/wsutils.h
new file mode 100644
index 0000000..df03815
--- /dev/null
+++ b/wsutils.h
@@ -0,0 +1,350 @@
+/* $Xorg: wsutils.h,v 1.4 2001/02/09 02:06:03 xorgcvs Exp $ */
+/** ------------------------------------------------------------------------
+ This file contains routines for manipulating generic lists.
+ Lists are implemented with a "harness". In other words, each
+ node in the list consists of two pointers, one to the data item
+ and one to the next node in the list. The head of the list is
+ the same struct as each node, but the "item" ptr is used to point
+ to the current member of the list (used by the first_in_list and
+ next_in_list functions).
+
+Copyright 1994 Hewlett-Packard Co.
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+ ------------------------------------------------------------------------ **/
+/******************************************************************************
+ *
+ * This file contains various typedef's, macros and procedure declarations for
+ * a set of example utility procedures contained in the file "wsutils.c".
+ *
+ ******************************************************************************/
+
+/* This is the actual structure returned by the X server describing the
+ * SERVER_OVERLAY_VISUAL property.
+ */
+typedef struct
+{
+ VisualID visualID; /* The VisualID of the overlay visual */
+ int transparentType; /* Can be None, TransparentPixel or
+ * TransparentMask */
+ int value; /* Pixel value */
+ int layer; /* Overlay planes will always be in
+ * layer 1 */
+} OverlayVisualPropertyRec;
+
+
+/* This is structure also describes the SERVER_OVERLAY_VISUAL property, but
+ * should be more useful than the one actually returned by the X server
+ * because it actually points to the visual's XVisualInfo struct rather than
+ * refering to the visual's ID.
+ */
+typedef struct
+{
+ XVisualInfo *pOverlayVisualInfo; /* Pointer to the XVisualInfo struct */
+ int transparentType; /* Can be None, TransparentPixel or
+ * TransparentMask */
+ int value; /* Pixel value */
+ int layer; /* Overlay planes will always be in
+ * layer 1 */
+} OverlayInfo;
+
+
+/* These macros are the values of the "transparentType" above: */
+#ifndef None
+#define None 0
+#endif
+#ifndef TransparentPixel
+#define TransparentPixel 1
+#endif
+
+
+/* These macros define how flexible a program is when it requests a window's
+ * creation with either the CreateImagePlanesWindow() or
+ * CreateOverlayPlanesWindow():
+ */
+#ifndef NOT_FLEXIBLE
+#define NOT_FLEXIBLE 0
+#define FLEXIBLE 1
+#endif
+
+
+/* These macros define the values of the "sbCmapHint" parameter of the
+ * CreateImagePlanesWindow():
+ */
+#ifndef SB_CMAP_TYPE_NORMAL
+#define SB_CMAP_TYPE_NORMAL 1
+#endif
+
+#ifndef SB_CMAP_TYPE_MONOTONIC
+#define SB_CMAP_TYPE_MONOTONIC 2
+#endif
+
+#ifndef SB_CMAP_TYPE_FULL
+#define SB_CMAP_TYPE_FULL 4
+#endif
+
+
+/******************************************************************************
+ *
+ * GetXVisualInfo()
+ *
+ * This routine takes an X11 Display, screen number, and returns whether the
+ * screen supports transparent overlays and three arrays:
+ *
+ * 1) All of the XVisualInfo struct's for the screen.
+ * 2) All of the OverlayInfo struct's for the screen.
+ * 3) An array of pointers to the screen's image plane XVisualInfo
+ * structs.
+ *
+ * The code below obtains the array of all the screen's visuals, and obtains
+ * the array of all the screen's overlay visual information. It then processes
+ * the array of the screen's visuals, determining whether the visual is an
+ * overlay or image visual.
+ *
+ * If the routine sucessfully obtained the visual information, it returns zero.
+ * If the routine didn't obtain the visual information, it returns non-zero.
+ *
+ ******************************************************************************/
+
+extern int GetXVisualInfo(
+#if NeedFunctionPrototypes
+ Display *display, /* Which X server (aka "display"). */
+ int screen, /* Which screen of the "display". */
+ int *transparentOverlays, /* Non-zero if there's at least one
+ * overlay visual and if at least one
+ * of those supports a transparent
+ * pixel. */
+ int *numVisuals, /* Number of XVisualInfo struct's
+ * pointed to to by pVisuals. */
+ XVisualInfo **pVisuals, /* All of the device's visuals. */
+ int *numOverlayVisuals, /* Number of OverlayInfo's pointed
+ * to by pOverlayVisuals. If this
+ * number is zero, the device does
+ * not have overlay planes. */
+ OverlayInfo **pOverlayVisuals, /* The device's overlay plane visual
+ * information. */
+ int *numImageVisuals, /* Number of XVisualInfo's pointed
+ * to by pImageVisuals. */
+ XVisualInfo ***pImageVisuals /* The device's image visuals. */
+#endif
+ );
+
+
+/******************************************************************************
+ *
+ * FreeXVisualInfo()
+ *
+ * This routine frees the data that was allocated by GetXVisualInfo().
+ *
+ ******************************************************************************/
+
+extern void FreeXVisualInfo(
+#if NeedFunctionPrototypes
+ XVisualInfo *pVisuals,
+ OverlayInfo *pOverlayVisuals,
+ XVisualInfo **pImageVisuals
+#endif
+ );
+
+
+/******************************************************************************
+ *
+ * FindImagePlanesVisual()
+ *
+ * This routine attempts to find a visual to use to create an image planes
+ * window based upon the information passed in.
+ *
+ * The "Hint" values give guides to the routine as to what the program wants.
+ * The "depthFlexibility" value tells the routine how much the program wants
+ * the actual "depthHint" specified. If the program can't live with the
+ * screen's image planes visuals, the routine returns non-zero, and the
+ * "depthObtained" and "pImageVisualToUse" return parameters are NOT valid.
+ * Otherwise, the "depthObtained" and "pImageVisualToUse" return parameters
+ * are valid and the routine returns zero.
+ *
+ * NOTE: This is just an example of what can be done. It may or may not be
+ * useful for any specific application.
+ *
+ ******************************************************************************/
+
+extern int FindImagePlanesVisual(
+#if NeedFunctionPrototypes
+ Display *display, /* Which X server (aka "display"). */
+ int screen, /* Which screen of the "display". */
+ int numImageVisuals, /* Number of XVisualInfo's pointed
+ * to by pImageVisuals. */
+ XVisualInfo **pImageVisuals, /* The device's image visuals. */
+ int sbCmapHint, /* What Starbase cmap modes will be
+ * used with the visual. NOTE: This
+ * is a mask of the possible values. */
+ int depthHint, /* Desired depth. */
+ int depthFlexibility, /* How much the actual value in
+ * "depthHint" is desired. */
+ Visual **pImageVisualToUse, /* The screen's image visual to use. */
+ int *depthObtained /* Actual depth of the visual. */
+#endif
+ );
+
+
+/******************************************************************************
+ *
+ * FindOverlayPlanesVisual()
+ *
+ * This routine attempts to find a visual to use to create an overlay planes
+ * window based upon the information passed in.
+ *
+ * While the CreateImagePlanesWindow() routine took a sbCmapHint, this
+ * routine doesn't. Starbase's CMAP_FULL shouldn't be used in overlay planes
+ * windows. This is partially because this functionality is better suited in
+ * the image planes where there are generally more planes, and partially
+ * because the overlay planes generally have PseudoColor visuals with one
+ * color being transparent (the transparent normally being the "white" color
+ * for CMAP_FULL).
+ *
+ * The "depthHint" values give guides to the routine as to what depth the
+ * program wants the window to be. The "depthFlexibility" value tells the
+ * routine how much the program wants the actual "depthHint" specified. If
+ * the program can't live with the screen's overlay planes visuals, the
+ * routine returns non-zero, and the "depthObtained" and "pOverlayVisualToUse"
+ * return parameters are NOT valid. Otherwise, the "depthObtained" and
+ * "pOverlayVisualToUse" return parameters are valid and the routine returns
+ * zero.
+ *
+ * NOTE: This is just an example of what can be done. It may or may not be
+ * useful for any specific application.
+ *
+ ******************************************************************************/
+
+extern int FindOverlayPlanesVisual(
+#if NeedFunctionPrototypes
+ Display *display, /* Which X server (aka "display"). */
+ int screen, /* Which screen of the "display". */
+ int numOverlayVisuals, /* Number of OverlayInfo's pointed
+ * to by pOverlayVisuals. */
+ OverlayInfo *pOverlayVisuals, /* The device's overlay plane visual
+ * information. */
+ int depthHint, /* Desired depth. */
+ int depthFlexibility, /* How much the actual value in
+ * "depthHint" is desired. */
+ int transparentBackground, /* Non-zero if the visual must have
+ * a transparent color. */
+ Visual **pOverlayVisualToUse, /* The screen's overlay visual to
+ * use. */
+ int *depthObtained, /* Actual depth of the visual. */
+ int *transparentColor /* The transparent color the program
+ * can use with the visual. */
+#endif
+ );
+
+
+/******************************************************************************
+ *
+ * CreateImagePlanesWindow()
+ *
+ * This routine creates an image planes window, potentially creates a colormap
+ * for the window to use, and sets the window's standard properties, based
+ * upon the information passed in to the routine. While "created," the window
+ * has not been mapped.
+ *
+ * If the routine suceeds, it returns zero and the return parameters
+ * "imageWindow", "imageColormap" and "mustFreeImageColormap" are valid.
+ * Otherwise, the routine returns non-zero and the return parameters are
+ * NOT valid.
+ *
+ * NOTE: This is just an example of what can be done. It may or may not be
+ * useful for any specific application.
+ *
+ ******************************************************************************/
+
+extern int CreateImagePlanesWindow(
+#if NeedFunctionPrototypes
+ Display *display, /* Which X server (aka "display"). */
+ int screen, /* Which screen of the "display". */
+ Window parentWindow, /* Window ID of the parent window for
+ * the created window. */
+ int windowX, /* Desired X coord. of the window. */
+ int windowY, /* Desired Y coord of the window. */
+ int windowWidth, /* Desired width of the window. */
+ int windowHeight, /* Desired height of the window. */
+ int windowDepth, /* Desired depth of the window. */
+ Visual *pImageVisualToUse, /* The window's image planes visual. */
+ int argc, /* Program's argc parameter. */
+ char *argv[], /* Program's argv parameter. */
+ char *windowName, /* Name to put on window's border. */
+ char *iconName, /* Name to put on window's icon. */
+ Window *imageWindow, /* Window ID of the created window. */
+ Colormap *imageColormap, /* The window's colormap. */
+ int *mustFreeImageColormap /* Non-zero if the program must call
+ * XFreeColormap() for imageColormap. */
+#endif
+ );
+
+
+/******************************************************************************
+ *
+ * CreateOverlayPlanesWindow()
+ *
+ * This routine creates an overlay planes window, potentially creates a colormap
+ * for the window to use, and sets the window's standard properties, based
+ * upon the information passed in to the routine. While "created," the window
+ * has not been mapped.
+ *
+ * If the routine suceeds, it returns zero and the return parameters
+ * "overlayWindow", "overlayColormap" and "mustFreeOverlayColormap" are valid.
+ * Otherwise, the routine returns non-zero and the return parameters are
+ * NOT valid.
+ *
+ * NOTE: This is just an example of what can be done. It may or may not be
+ * useful for any specific application.
+ *
+ ******************************************************************************/
+
+int CreateOverlayPlanesWindow(
+#if NeedFunctionPrototypes
+ Display *display, /* Which X server (aka "display"). */
+ int screen, /* Which screen of the "display". */
+ Window parentWindow, /* Window ID of the parent window for
+ * the created window. */
+ int windowX, /* Desired X coord. of the window. */
+ int windowY, /* Desired Y coord of the window. */
+ int windowWidth, /* Desired width of the window. */
+ int windowHeight, /* Desired height of the window. */
+ int windowDepth, /* Desired depth of the window. */
+ Visual *pOverlayVisualToUse, /* The window's overlay planes visual.*/
+ int argc, /* Program's argc parameter. */
+ char *argv[], /* Program's argv parameter. */
+ char *windowName, /* Name to put on window's border. */
+ char *iconName, /* Name to put on window's icon. */
+ int transparentBackground, /* Non-zero if the window's background
+ * should be a transparent color. */
+ int *transparentColor, /* The transparent color to use as the
+ * window's background. */
+ Window *overlayWindow, /* Window ID of the created window. */
+ Colormap *overlayColormap, /* The window's colormap. */
+ int *mustFreeOverlayColormap/* Non-zero if the program must call
+ * XFreeColormap() for
+ * overlayColormap. */
+#endif
+ );
diff --git a/xwd.c b/xwd.c
new file mode 100644
index 0000000..810ff57
--- /dev/null
+++ b/xwd.c
@@ -0,0 +1,664 @@
+/* $Xorg: xwd.c,v 1.5 2001/02/09 02:06:03 xorgcvs Exp $ */
+
+/*
+
+Copyright 1987, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+/*
+ * xwd.c MIT Project Athena, X Window system window raster image dumper.
+ *
+ * This program will dump a raster image of the contents of a window into a
+ * file for output on graphics printers or for other uses.
+ *
+ * Author: Tony Della Fera, DEC
+ * 17-Jun-85
+ *
+ * Modification history:
+ *
+ * 11/14/86 Bill Wyatt, Smithsonian Astrophysical Observatory
+ * - Removed Z format option, changing it to an XY option. Monochrome
+ * windows will always dump in XY format. Color windows will dump
+ * in Z format by default, but can be dumped in XY format with the
+ * -xy option.
+ *
+ * 11/18/86 Bill Wyatt
+ * - VERSION 6 is same as version 5 for monchrome. For colors, the
+ * appropriate number of Color structs are dumped after the header,
+ * which has the number of colors (=0 for monochrome) in place of the
+ * V5 padding at the end. Up to 16-bit displays are supported. I
+ * don't yet know how 24- to 32-bit displays will be handled under
+ * the Version 11 protocol.
+ *
+ * 6/15/87 David Krikorian, MIT Project Athena
+ * - VERSION 7 runs under the X Version 11 servers, while the previous
+ * versions of xwd were are for X Version 10. This version is based
+ * on xwd version 6, and should eventually have the same color
+ * abilities. (Xwd V7 has yet to be tested on a color machine, so
+ * all color-related code is commented out until color support
+ * becomes practical.)
+ */
+
+/*%
+ *% This is the format for commenting out color-related code until
+ *% color can be supported.
+%*/
+
+#include <stdio.h>
+#include <errno.h>
+#include <X11/Xos.h>
+
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <X11/Xmu/WinUtil.h>
+typedef unsigned long Pixel;
+#include "X11/XWDFile.h"
+
+#define FEEP_VOLUME 0
+
+/* Include routines to do parsing */
+#include "dsimple.h"
+#include "list.h"
+#include "wsutils.h"
+#include "multiVis.h"
+
+#ifdef XKB
+#include <X11/extensions/XKBbells.h>
+#endif
+
+/* Setable Options */
+
+int format = ZPixmap;
+Bool nobdrs = False;
+Bool on_root = False;
+Bool standard_out = True;
+Bool debug = False;
+Bool silent = False;
+Bool use_installed = False;
+long add_pixel_value = 0;
+
+extern int (*_XErrorFunction)();
+extern int _XDefaultError();
+
+static long parse_long (s)
+ char *s;
+{
+ char *fmt = "%lu";
+ long retval = 0L;
+ int thesign = 1;
+
+ if (s && s[0]) {
+ if (s[0] == '-') s++, thesign = -1;
+ if (s[0] == '0') s++, fmt = "%lo";
+ if (s[0] == 'x' || s[0] == 'X') s++, fmt = "%lx";
+ (void) sscanf (s, fmt, &retval);
+ }
+ return (thesign * retval);
+}
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ register i;
+ Window target_win;
+ FILE *out_file = stdout;
+ Bool frame_only = False;
+
+ INIT_NAME;
+
+ Setup_Display_And_Screen(&argc, argv);
+
+ /* Get window select on command line, if any */
+ target_win = Select_Window_Args(&argc, argv);
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-nobdrs")) {
+ nobdrs = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-debug")) {
+ debug = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-help"))
+ usage();
+ if (!strcmp(argv[i], "-out")) {
+ if (++i >= argc) usage();
+ if (!(out_file = fopen(argv[i], "wb")))
+ Error("Can't open output file as specified.");
+ standard_out = False;
+ continue;
+ }
+ if (!strcmp(argv[i], "-xy")) {
+ format = XYPixmap;
+ continue;
+ }
+ if (!strcmp(argv[i], "-screen")) {
+ on_root = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-icmap")) {
+ use_installed = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-add")) {
+ if (++i >= argc) usage();
+ add_pixel_value = parse_long (argv[i]);
+ continue;
+ }
+ if (!strcmp(argv[i], "-frame")) {
+ frame_only = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-silent")) {
+ silent = True;
+ continue;
+ }
+ usage();
+ }
+#ifdef WIN32
+ if (standard_out)
+ _setmode(fileno(out_file), _O_BINARY);
+#endif
+
+ /*
+ * Let the user select the target window.
+ */
+ if (!target_win) {
+ target_win = Select_Window(dpy);
+ if (target_win != None && !frame_only) {
+ Window root;
+ int dummyi;
+ unsigned int dummy;
+
+ if (XGetGeometry (dpy, target_win, &root, &dummyi, &dummyi,
+ &dummy, &dummy, &dummy, &dummy) &&
+ target_win != root)
+ target_win = XmuClientWindow (dpy, target_win);
+ }
+ }
+
+
+ /*
+ * Dump it!
+ */
+ Window_Dump(target_win, out_file);
+
+ XCloseDisplay(dpy);
+ if (fclose(out_file)) {
+ perror("xwd");
+ exit(1);
+ }
+ exit(0);
+}
+
+static int
+Get24bitDirectColors(colors)
+XColor **colors ;
+{
+ int i , ncolors = 256 ;
+ XColor *tcol ;
+
+ *colors = tcol = (XColor *)malloc(sizeof(XColor) * ncolors) ;
+
+ for(i=0 ; i < ncolors ; i++)
+ {
+ tcol[i].pixel = i << 16 | i << 8 | i ;
+ tcol[i].red = tcol[i].green = tcol[i].blue = i << 8 | i ;
+ }
+
+ return ncolors ;
+}
+
+
+/*
+ * Window_Dump: dump a window to a file which must already be open for
+ * writting.
+ */
+
+char *calloc();
+
+Window_Dump(window, out)
+ Window window;
+ FILE *out;
+{
+ unsigned long swaptest = 1;
+ XColor *colors;
+ unsigned buffer_size;
+ int win_name_size;
+ int header_size;
+ int ncolors, i;
+ char *win_name;
+ Bool got_win_name;
+ XWindowAttributes win_info;
+ XImage *image;
+ int absx, absy, x, y;
+ unsigned width, height;
+ int dwidth, dheight;
+ int bw;
+ Window dummywin;
+ XWDFileHeader header;
+ XWDColor xwdcolor;
+
+ int transparentOverlays , multiVis;
+ int numVisuals;
+ XVisualInfo *pVisuals;
+ int numOverlayVisuals;
+ OverlayInfo *pOverlayVisuals;
+ int numImageVisuals;
+ XVisualInfo **pImageVisuals;
+ list_ptr vis_regions; /* list of regions to read from */
+ list_ptr vis_image_regions ;
+ Visual vis_h,*vis ;
+ int allImage = 0 ;
+
+ /*
+ * Inform the user not to alter the screen.
+ */
+ if (!silent) {
+#ifdef XKB
+ XkbStdBell(dpy,None,50,XkbBI_Wait);
+#else
+ XBell(dpy,FEEP_VOLUME);
+#endif
+ XFlush(dpy);
+ }
+
+ /*
+ * Get the parameters of the window being dumped.
+ */
+ if (debug) outl("xwd: Getting target window information.\n");
+ if(!XGetWindowAttributes(dpy, window, &win_info))
+ Fatal_Error("Can't get target window attributes.");
+
+ /* handle any frame window */
+ if (!XTranslateCoordinates (dpy, window, RootWindow (dpy, screen), 0, 0,
+ &absx, &absy, &dummywin)) {
+ fprintf (stderr,
+ "%s: unable to translate window coordinates (%d,%d)\n",
+ program_name, absx, absy);
+ exit (1);
+ }
+ win_info.x = absx;
+ win_info.y = absy;
+ width = win_info.width;
+ height = win_info.height;
+ bw = 0;
+
+ if (!nobdrs) {
+ absx -= win_info.border_width;
+ absy -= win_info.border_width;
+ bw = win_info.border_width;
+ width += (2 * bw);
+ height += (2 * bw);
+ }
+ dwidth = DisplayWidth (dpy, screen);
+ dheight = DisplayHeight (dpy, screen);
+
+
+ /* clip to window */
+ if (absx < 0) width += absx, absx = 0;
+ if (absy < 0) height += absy, absy = 0;
+ if (absx + width > dwidth) width = dwidth - absx;
+ if (absy + height > dheight) height = dheight - absy;
+
+ XFetchName(dpy, window, &win_name);
+ if (!win_name || !win_name[0]) {
+ win_name = "xwdump";
+ got_win_name = False;
+ } else {
+ got_win_name = True;
+ }
+
+ /* sizeof(char) is included for the null string terminator. */
+ win_name_size = strlen(win_name) + sizeof(char);
+
+ /*
+ * Snarf the pixmap with XGetImage.
+ */
+
+ x = absx - win_info.x;
+ y = absy - win_info.y;
+
+ multiVis = GetMultiVisualRegions(dpy,RootWindow(dpy, screen),
+ absx, absy,
+ width, height,&transparentOverlays,&numVisuals, &pVisuals,
+ &numOverlayVisuals,&pOverlayVisuals,&numImageVisuals,
+ &pImageVisuals,&vis_regions,&vis_image_regions,&allImage) ;
+ if (on_root || multiVis)
+ {
+ if(!multiVis)
+ image = XGetImage (dpy, RootWindow(dpy, screen), absx, absy,
+ width, height, AllPlanes, format);
+ else
+ image = ReadAreaToImage(dpy, RootWindow(dpy, screen), absx, absy,
+ width, height,
+ numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,
+ numImageVisuals, pImageVisuals,vis_regions,
+ vis_image_regions,format,allImage);
+ }
+ else
+ image = XGetImage (dpy, window, x, y, width, height, AllPlanes, format);
+ if (!image) {
+ fprintf (stderr, "%s: unable to get image at %dx%d+%d+%d\n",
+ program_name, width, height, x, y);
+ exit (1);
+ }
+
+ if (add_pixel_value != 0) XAddPixel (image, add_pixel_value);
+
+ /*
+ * Determine the pixmap size.
+ */
+ buffer_size = Image_Size(image);
+
+ if (debug) outl("xwd: Getting Colors.\n");
+
+ if( !multiVis)
+ {
+ ncolors = Get_XColors(&win_info, &colors);
+ vis = win_info.visual ;
+ }
+ else
+ {
+ ncolors = Get24bitDirectColors(&colors) ;
+ initFakeVisual(&vis_h) ;
+ vis = &vis_h ;
+ }
+ /*
+ * Inform the user that the image has been retrieved.
+ */
+ if (!silent) {
+#ifdef XKB
+ XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_Proceed);
+ XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_RepeatingLastBell);
+#else
+ XBell(dpy, FEEP_VOLUME);
+ XBell(dpy, FEEP_VOLUME);
+#endif
+ XFlush(dpy);
+ }
+
+ /*
+ * Calculate header size.
+ */
+ if (debug) outl("xwd: Calculating header size.\n");
+ header_size = SIZEOF(XWDheader) + win_name_size;
+
+ /*
+ * Write out header information.
+ */
+ if (debug) outl("xwd: Constructing and dumping file header.\n");
+ header.header_size = (CARD32) header_size;
+ header.file_version = (CARD32) XWD_FILE_VERSION;
+ header.pixmap_format = (CARD32) format;
+ header.pixmap_depth = (CARD32) image->depth;
+ header.pixmap_width = (CARD32) image->width;
+ header.pixmap_height = (CARD32) image->height;
+ header.xoffset = (CARD32) image->xoffset;
+ header.byte_order = (CARD32) image->byte_order;
+ header.bitmap_unit = (CARD32) image->bitmap_unit;
+ header.bitmap_bit_order = (CARD32) image->bitmap_bit_order;
+ header.bitmap_pad = (CARD32) image->bitmap_pad;
+ header.bits_per_pixel = (CARD32) image->bits_per_pixel;
+ header.bytes_per_line = (CARD32) image->bytes_per_line;
+ /****
+ header.visual_class = (CARD32) win_info.visual->class;
+ header.red_mask = (CARD32) win_info.visual->red_mask;
+ header.green_mask = (CARD32) win_info.visual->green_mask;
+ header.blue_mask = (CARD32) win_info.visual->blue_mask;
+ header.bits_per_rgb = (CARD32) win_info.visual->bits_per_rgb;
+ header.colormap_entries = (CARD32) win_info.visual->map_entries;
+ *****/
+ header.visual_class = (CARD32) vis->class;
+ header.red_mask = (CARD32) vis->red_mask;
+ header.green_mask = (CARD32) vis->green_mask;
+ header.blue_mask = (CARD32) vis->blue_mask;
+ header.bits_per_rgb = (CARD32) vis->bits_per_rgb;
+ header.colormap_entries = (CARD32) vis->map_entries;
+
+ header.ncolors = ncolors;
+ header.window_width = (CARD32) win_info.width;
+ header.window_height = (CARD32) win_info.height;
+ header.window_x = absx;
+ header.window_y = absy;
+ header.window_bdrwidth = (CARD32) win_info.border_width;
+
+ if (*(char *) &swaptest) {
+ _swaplong((char *) &header, sizeof(header));
+ for (i = 0; i < ncolors; i++) {
+ _swaplong((char *) &colors[i].pixel, sizeof(long));
+ _swapshort((char *) &colors[i].red, 3 * sizeof(short));
+ }
+ }
+
+ if (fwrite((char *)&header, SIZEOF(XWDheader), 1, out) != 1 ||
+ fwrite(win_name, win_name_size, 1, out) != 1) {
+ perror("xwd");
+ exit(1);
+ }
+
+ /*
+ * Write out the color maps, if any
+ */
+
+ if (debug) outl("xwd: Dumping %d colors.\n", ncolors);
+ for (i = 0; i < ncolors; i++) {
+ xwdcolor.pixel = colors[i].pixel;
+ xwdcolor.red = colors[i].red;
+ xwdcolor.green = colors[i].green;
+ xwdcolor.blue = colors[i].blue;
+ xwdcolor.flags = colors[i].flags;
+ if (fwrite((char *) &xwdcolor, SIZEOF(XWDColor), 1, out) != 1) {
+ perror("xwd");
+ exit(1);
+ }
+ }
+
+ /*
+ * Write out the buffer.
+ */
+ if (debug) outl("xwd: Dumping pixmap. bufsize=%d\n",buffer_size);
+
+ /*
+ * This copying of the bit stream (data) to a file is to be replaced
+ * by an Xlib call which hasn't been written yet. It is not clear
+ * what other functions of xwd will be taken over by this (as yet)
+ * non-existant X function.
+ */
+ if (fwrite(image->data, (int) buffer_size, 1, out) != 1) {
+ perror("xwd");
+ exit(1);
+ }
+
+ /*
+ * free the color buffer.
+ */
+
+ if(debug && ncolors > 0) outl("xwd: Freeing colors.\n");
+ if(ncolors > 0) free(colors);
+
+ /*
+ * Free window name string.
+ */
+ if (debug) outl("xwd: Freeing window name string.\n");
+ if (got_win_name) XFree(win_name);
+
+ /*
+ * Free image
+ */
+ XDestroyImage(image);
+}
+
+/*
+ * Report the syntax for calling xwd.
+ */
+usage()
+{
+ fprintf (stderr,
+"usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] [-out <file>]",
+ program_name, SELECT_USAGE);
+ fprintf (stderr, " [-xy] [-add value] [-frame]\n");
+ exit(1);
+}
+
+
+/*
+ * Error - Fatal xwd error.
+ */
+
+Error(string)
+ char *string; /* Error description string. */
+{
+ outl("\nxwd: Error => %s\n", string);
+ if (errno != 0) {
+ perror("xwd");
+ outl("\n");
+ }
+
+ exit(1);
+}
+
+
+/*
+ * Determine the pixmap size.
+ */
+
+int Image_Size(image)
+ XImage *image;
+{
+ if (image->format != ZPixmap)
+ return(image->bytes_per_line * image->height * image->depth);
+
+ return(image->bytes_per_line * image->height);
+}
+
+#define lowbit(x) ((x) & (~(x) + 1))
+
+static int
+ReadColors(vis,cmap,colors)
+Visual *vis ;
+Colormap cmap ;
+XColor **colors ;
+{
+ int i,ncolors ;
+
+ ncolors = vis->map_entries;
+
+ if (!(*colors = (XColor *) malloc (sizeof(XColor) * ncolors)))
+ Fatal_Error("Out of memory!");
+
+ if (vis->class == DirectColor ||
+ vis->class == TrueColor) {
+ Pixel red, green, blue, red1, green1, blue1;
+
+ red = green = blue = 0;
+ red1 = lowbit(vis->red_mask);
+ green1 = lowbit(vis->green_mask);
+ blue1 = lowbit(vis->blue_mask);
+ for (i=0; i<ncolors; i++) {
+ (*colors)[i].pixel = red|green|blue;
+ (*colors)[i].pad = 0;
+ red += red1;
+ if (red > vis->red_mask)
+ red = 0;
+ green += green1;
+ if (green > vis->green_mask)
+ green = 0;
+ blue += blue1;
+ if (blue > vis->blue_mask)
+ blue = 0;
+ }
+ } else {
+ for (i=0; i<ncolors; i++) {
+ (*colors)[i].pixel = i;
+ (*colors)[i].pad = 0;
+ }
+ }
+
+ XQueryColors(dpy, cmap, *colors, ncolors);
+
+ return(ncolors);
+}
+
+/*
+ * Get the XColors of all pixels in image - returns # of colors
+ */
+int Get_XColors(win_info, colors)
+ XWindowAttributes *win_info;
+ XColor **colors;
+{
+ int i, ncolors;
+ Colormap cmap = win_info->colormap;
+
+ if (use_installed)
+ /* assume the visual will be OK ... */
+ cmap = XListInstalledColormaps(dpy, win_info->root, &i)[0];
+ if (!cmap)
+ return(0);
+ ncolors = ReadColors(win_info->visual,cmap,colors) ;
+ return ncolors ;
+}
+
+_swapshort (bp, n)
+ register char *bp;
+ register unsigned n;
+{
+ register char c;
+ register char *ep = bp + n;
+
+ while (bp < ep) {
+ c = *bp;
+ *bp = *(bp + 1);
+ bp++;
+ *bp++ = c;
+ }
+}
+
+_swaplong (bp, n)
+ register char *bp;
+ register unsigned n;
+{
+ register char c;
+ register char *ep = bp + n;
+ register char *sp;
+
+ while (bp < ep) {
+ sp = bp + 3;
+ c = *sp;
+ *sp = *bp;
+ *bp++ = c;
+ sp = bp + 1;
+ c = *sp;
+ *sp = *bp;
+ *bp++ = c;
+ bp += 2;
+ }
+}
diff --git a/xwd.man b/xwd.man
new file mode 100644
index 0000000..26898d6
--- /dev/null
+++ b/xwd.man
@@ -0,0 +1,130 @@
+.\" $Xorg: xwd.man,v 1.4 2001/02/09 02:06:03 xorgcvs Exp $
+.\" Copyright 1988, 1994, 1998 The Open Group
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that
+.\" copyright notice and this permission notice appear in supporting
+.\" documentation.
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of The Open Group shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from The Open Group.
+.TH XWD 1 "Release 6.4" "X Version 11"
+.SH NAME
+xwd - dump an image of an X window
+.SH SYNOPSIS
+.B "xwd"
+[-debug] [-help] [-nobdrs] [-out \fIfile\fP] [-xy] [-frame] [-add \fIvalue\fP]
+[-root | -id \fIid\fP | -name \fIname\fP ] [-icmap] [-screen]
+[-display \fIdisplay\fP]
+.SH DESCRIPTION
+.PP
+.I Xwd
+is an X Window System window dumping utility.
+.I Xwd
+allows X users to store window images in a specially formatted dump
+file. This file can then be read by various other X utilities for
+redisplay, printing, editing, formatting, archiving, image processing, etc.
+The target window is selected by clicking the pointer in the desired window.
+The keyboard bell is rung once at the beginning of the dump and twice when
+the dump is completed.
+.SH OPTIONS
+.PP
+.TP 8
+.B "-display \fIdisplay\fP"
+This argument allows you to specify the server to connect to; see \fIX(1)\fP.
+.PP
+.TP 8
+.B "-help"
+Print out the `Usage:' command syntax summary.
+.PP
+.TP 8
+.B "-nobdrs"
+This argument specifies that the window dump should not include the
+pixels that compose the X window border. This is useful in situations
+where you may wish to include the window contents in a document
+as an illustration.
+.PP
+.TP 8
+.B "-out \fIfile\fP"
+This argument allows the user to explicitly specify the output
+file on the command line. The default is to output to standard out.
+.PP
+.TP 8
+.B "-xy"
+This option applies to color displays only. It selects `XY' format dumping
+instead of the default `Z' format.
+.PP
+.TP 8
+.B "-add \fIvalue\fP"
+This option specifies an signed value to be added to every pixel.
+.PP
+.TP 8
+.B "-frame"
+This option indicates that the window manager frame should be included when
+manually selecting a window.
+.PP
+.TP 8
+.B "-root"
+This option indicates that the root window should be selected for the
+window dump, without requiring the user to select a window with the pointer.
+.PP
+.TP 8
+.B "-id \fIid\fP"
+This option indicates that the window with the specified resource id
+should be selected for the window dump, without requiring the user to
+select a window with the pointer.
+.PP
+.TP 8
+.B "-name \fIname\fP"
+This option indicates that the window with the specified WM_NAME property
+should be selected for the window dump, without requiring the user to
+select a window with the pointer.
+.PP
+.TP 8
+.B "-icmap"
+Normally the colormap of the chosen window is used to obtain RGB values.
+This option forces the first installed colormap of the screen to be used
+instead.
+.PP
+.TP 8
+.B "-screen"
+This option indicates that the GetImage request used to obtain the image
+should be done on the root window, rather than directly on the specified
+window. In this way, you can obtain pieces of other windows that overlap
+the specified window, and more importantly, you can capture menus or other
+popups that are independent windows but appear over the specified window.
+.PP
+.TP 8
+.B "-silent"
+Operate silently, i.e. don't ring any bells before and after dumping
+the window.
+.SH ENVIRONMENT
+.PP
+.TP 8
+.B DISPLAY
+To get default host and display number.
+.SH FILES
+.PP
+.TP 8
+.B XWDFile.h
+X Window Dump File format definition file.
+.SH SEE ALSO
+xwud(1), xpr(1), X(1)
+.SH AUTHORS
+Tony Della Fera, Digital Equipment Corp., MIT Project Athena
+.br
+William F. Wyatt, Smithsonian Astrophysical Observatory