summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-09-23 10:28:07 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-09-23 10:28:07 -0700
commit68dc9400f0047b10eebd77d60353fb96ccf4914d (patch)
tree0b43fddd113c2837017014a4d0cb265a8850d42b
parent8026ace54250eba699ad9979586e78d27a7745dc (diff)
Adopt standard X.Org coding style
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--clientwin.c2
-rw-r--r--dsimple.c330
-rw-r--r--dsimple.h13
-rw-r--r--list.c110
-rw-r--r--list.h52
-rw-r--r--multiVis.c1415
-rw-r--r--multiVis.h29
-rw-r--r--xwd.c496
8 files changed, 1221 insertions, 1226 deletions
diff --git a/clientwin.c b/clientwin.c
index afb06f8..14050d0 100644
--- a/clientwin.c
+++ b/clientwin.c
@@ -107,7 +107,7 @@ Find_Client_In_Children(Display * dpy, Window win)
break;
}
- done:
+ done:
XFree(children);
return win;
diff --git a/dsimple.c b/dsimple.c
index 4fb1a81..972a72e 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -33,6 +33,7 @@ from The Open Group.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+
/*
* Other_stuff.h: Definitions of routines in other_stuff.
*
@@ -63,31 +64,32 @@ int screen = 0;
* 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(
- int *pargc, /* MODIFIED */
- char **argv) /* MODIFIED */
+char *
+Get_Display_Name(int *pargc, /* MODIFIED */
+ char **argv) /* MODIFIED */
{
int argc = *pargc;
- char **pargv = argv+1;
+ 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 ("-display requires an argument");
-
- displayname = argv[i];
- *pargc -= 2;
- continue;
- }
- if (!strcmp(arg,"-")) {
- while (i<argc)
- *pargv++ = argv[i++];
- break;
- }
- *pargv++ = arg;
+ char *arg = argv[i];
+
+ if (!strcmp(arg, "-display") || !strcmp(arg, "-d")) {
+ if (++i >= argc)
+ usage("-display requires an argument");
+
+ displayname = argv[i];
+ *pargc -= 2;
+ continue;
+ }
+ if (!strcmp(arg, "-")) {
+ while (i < argc)
+ *pargv++ = argv[i++];
+ break;
+ }
+ *pargv++ = arg;
}
*pargv = NULL;
@@ -99,18 +101,19 @@ char *Get_Display_Name(
* Open_Display: Routine to open a display with correct error handling.
* Does not require dpy or screen defined on entry.
*/
-Display *Open_Display(const char *display_name)
+Display *
+Open_Display(const char *display_name)
{
- Display *d;
+ Display *d;
- d = XOpenDisplay(display_name);
- if (d == NULL) {
- fprintf (stderr, "%s: unable to open display '%s'\n",
- program_name, XDisplayName (display_name));
- exit(1);
- }
+ d = XOpenDisplay(display_name);
+ if (d == NULL) {
+ fprintf(stderr, "%s: unable to open display '%s'\n",
+ program_name, XDisplayName(display_name));
+ exit(1);
+ }
- return(d);
+ return (d);
}
@@ -121,24 +124,25 @@ Display *Open_Display(const char *display_name)
* for this display is then stored in screen.
* Does not require dpy or screen defined.
*/
-void Setup_Display_And_Screen(
- int *argc, /* MODIFIED */
- char **argv) /* MODIFIED */
+void
+Setup_Display_And_Screen(int *argc, /* MODIFIED */
+ char **argv) /* MODIFIED */
{
- char *displayname = NULL;
+ char *displayname = NULL;
- displayname = Get_Display_Name(argc, argv);
- dpy = Open_Display (displayname);
- screen = XDefaultScreen(dpy);
+ displayname = Get_Display_Name(argc, argv);
+ dpy = Open_Display(displayname);
+ screen = XDefaultScreen(dpy);
}
/*
* Close_Display: Close display
*/
-void Close_Display(void)
+void
+Close_Display(void)
{
if (dpy == NULL)
- return;
+ return;
XCloseDisplay(dpy);
dpy = NULL;
@@ -167,56 +171,56 @@ void Close_Display(void)
* all command line arguments, and other setup is done.
* For examples of usage, see xwininfo, xwd, or xprop.
*/
-Window Select_Window_Args(
- int *rargc,
- char **argv)
+Window
+Select_Window_Args(int *rargc, char **argv)
#define ARGC (*rargc)
{
- int nargc=1;
- int argc;
- char **nargv;
- Window w=0;
+ int nargc = 1;
+ int argc;
+ char **nargv;
+ Window w = 0;
+
+ nargv = argv + 1;
+ argc = ARGC;
- nargv = argv+1; argc = ARGC;
#define OPTION argv[0]
#define NXTOPTP ++argv, --argc>0
#define NXTOPT(arg) if (++argv, --argc==0) usage(arg " requires an argument")
#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("-name");
- 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("-id");
- w=0;
- sscanf(OPTION, "0x%lx", &w);
- if (!w)
- sscanf(OPTION, "%lu", &w);
- if (!w)
- Fatal_Error("Invalid window id format: %s.", OPTION);
- continue;
- }
- COPYOPT;
- }
- ARGC = nargc;
-
- return(w);
+ while (NXTOPTP) {
+ if (!strcmp(OPTION, "-")) {
+ COPYOPT;
+ while (NXTOPTP)
+ COPYOPT;
+ break;
+ }
+ if (!strcmp(OPTION, "-root")) {
+ w = RootWindow(dpy, screen);
+ continue;
+ }
+ if (!strcmp(OPTION, "-name")) {
+ NXTOPT("-name");
+ 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("-id");
+ w = 0;
+ sscanf(OPTION, "0x%lx", &w);
+ if (!w)
+ sscanf(OPTION, "%lu", &w);
+ if (!w)
+ Fatal_Error("Invalid window id format: %s.", OPTION);
+ continue;
+ }
+ COPYOPT;
+ }
+ ARGC = nargc;
+
+ return (w);
}
/*
@@ -230,51 +234,54 @@ Window Select_Window_Args(
* Routine to let user select a window using the mouse
*/
-Window Select_Window(Display *disp, int descend)
+Window
+Select_Window(Display *disp, int descend)
{
- int status;
- Cursor cursor;
- XEvent event;
- Window target_win = None, root = RootWindow(disp,screen);
- int buttons = 0;
-
- /* Make the target cursor */
- cursor = XCreateFontCursor(disp, XC_crosshair);
-
- /* Grab the pointer using target cursor, letting it room all over */
- status = XGrabPointer(disp, 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(disp, SyncPointer, CurrentTime);
- XWindowEvent(disp, 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;
+ int status;
+ Cursor cursor;
+ XEvent event;
+ Window target_win = None, root = RootWindow(disp, screen);
+ int buttons = 0;
+
+ /* Make the target cursor */
+ cursor = XCreateFontCursor(disp, XC_crosshair);
+
+ /* Grab the pointer using target cursor, letting it room all over */
+ status = XGrabPointer(disp, 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(disp, SyncPointer, CurrentTime);
+ XWindowEvent(disp, 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(disp, CurrentTime); /* Done with pointer */
+ XUngrabPointer(disp, CurrentTime); /* Done with pointer */
- if (!descend || (target_win == root))
- return(target_win);
+ if (!descend || (target_win == root))
+ return (target_win);
- target_win = Find_Client(disp, root, target_win);
+ target_win = Find_Client(disp, root, target_win);
- return(target_win);
+ return (target_win);
}
@@ -285,30 +292,31 @@ Window Select_Window(Display *disp, int descend)
* one found will be returned. Only top and its subwindows
* are looked at. Normally, top should be the RootWindow.
*/
-Window Window_With_Name(
- Display *disp,
- Window top,
- const char *name)
+Window
+Window_With_Name(Display *disp, Window top, const char *name)
{
- Window *children, dummy;
- unsigned int nchildren;
- unsigned int i;
- Window w=0;
- char *window_name;
-
- if (XFetchName(disp, top, &window_name) && !strcmp(window_name, name))
- return(top);
-
- if (!XQueryTree(disp, top, &dummy, &dummy, &children, &nchildren))
- return(0);
-
- for (i=0; i<nchildren; i++) {
- w = Window_With_Name(disp, children[i], name);
- if (w)
- break;
- }
- if (children) XFree ((char *)children);
- return(w);
+ Window *children, dummy;
+ unsigned int nchildren;
+ unsigned int i;
+ Window w = 0;
+ char *window_name;
+
+ if (XFetchName(disp, top, &window_name) && !strcmp(window_name, name))
+ return (top);
+
+ if (!XQueryTree(disp, top, &dummy, &dummy, &children, &nchildren))
+ return (0);
+
+ for (i = 0; i < nchildren; i++) {
+ w = Window_With_Name(disp, children[i], name);
+ if (w)
+ break;
+ }
+
+ if (children)
+ XFree((char *) children);
+
+ return (w);
}
/*
@@ -319,30 +327,32 @@ Window Window_With_Name(
void
outl(const char *msg, ...)
{
- va_list args;
- fflush(stdout);
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
- fprintf(stderr, "\n");
- fflush(stderr);
+ va_list args;
+
+ fflush(stdout);
+ va_start(args, msg);
+ vfprintf(stderr, msg, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ fflush(stderr);
}
-
/*
* Standard fatal error routine - call like printf.
* Does not require dpy or screen defined.
*/
-void Fatal_Error(const char *msg, ...)
+void
+Fatal_Error(const char *msg, ...)
{
- va_list args;
- fflush(stdout);
- fflush(stderr);
- fprintf(stderr, "%s: error: ", program_name);
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
- fprintf(stderr, "\n");
- Close_Display();
- exit(EXIT_FAILURE);
+ va_list args;
+
+ fflush(stdout);
+ fflush(stderr);
+ fprintf(stderr, "%s: error: ", program_name);
+ va_start(args, msg);
+ vfprintf(stderr, msg, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ Close_Display();
+ exit(EXIT_FAILURE);
}
diff --git a/dsimple.h b/dsimple.h
index 18679b8..416e96a 100644
--- a/dsimple.h
+++ b/dsimple.h
@@ -51,10 +51,10 @@ extern const char *program_name; /* Name of this program */
extern Display *dpy; /* The current display */
extern int screen; /* The current screen */
-#define INIT_NAME program_name=argv[0] /* use this in main to setup
- program_name */
+#define INIT_NAME program_name=argv[0] /* use this in main to setup
+ program_name */
- /* Declaritions for functions in just_display.c */
+ /* Declarations for functions in just_display.c */
char *Get_Display_Name(int *, char **);
Display *Open_Display(const char *);
@@ -63,8 +63,8 @@ void Close_Display(void);
Window Select_Window_Args(int *, char **);
void usage(const char *errmsg) _X_NORETURN _X_COLD;
-#define X_USAGE "[host:display]" /* X arguments handled by
- Get_Display_Name */
+#define X_USAGE "[host:display]" /* X arguments handled by
+ Get_Display_Name */
/*
* Other_stuff.h: Definitions of routines in other_stuff.
@@ -76,5 +76,6 @@ void usage(const char *errmsg) _X_NORETURN _X_COLD;
Window Select_Window(Display *, int);
Window Window_With_Name(Display *, Window, const char *);
-void Fatal_Error(const char *, ...) _X_NORETURN _X_ATTRIBUTE_PRINTF(1, 2) _X_COLD;
+void Fatal_Error(const char *, ...) _X_NORETURN _X_ATTRIBUTE_PRINTF(1, 2)
+ _X_COLD;
void outl(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
diff --git a/list.c b/list.c
index 6e9a7a4..4a50fc0 100644
--- a/list.c
+++ b/list.c
@@ -43,13 +43,13 @@ from The Open Group.
/** ------------------------------------------------------------------------
Sets the pointers of the specified list to NULL.
--------------------------------------------------------------------- **/
-void zero_list(list_ptr lp)
+void
+zero_list(list_ptr lp)
{
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.
@@ -57,14 +57,15 @@ void zero_list(list_ptr lp)
and the next pointer in the new node is set to NULL.
Returns 1 if successful, 0 if the malloc failed.
-------------------------------------------------------------------- **/
-int add_to_list(list_ptr lp, void *item)
+int
+add_to_list(list_ptr lp, void *item)
{
while (lp->next) {
- lp = lp->next;
+ lp = lp->next;
}
- if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
+ if ((lp->next = (list_ptr) malloc(sizeof(list_item))) == NULL) {
- return 0;
+ return 0;
}
lp->next->ptr.item = item;
lp->next->next = NULL;
@@ -77,13 +78,14 @@ int add_to_list(list_ptr lp, void *item)
Creates a new list and sets its pointers to NULL.
Returns a pointer to the new list.
-------------------------------------------------------------------- **/
-list_ptr new_list (void)
+list_ptr
+new_list(void)
{
list_ptr lp;
- if ((lp = (list_ptr) malloc( sizeof( list_item)))) {
- lp->next = NULL;
- lp->ptr.item = NULL;
+ if ((lp = (list_ptr) malloc(sizeof(list_item)))) {
+ lp->next = NULL;
+ lp->ptr.item = NULL;
}
return lp;
@@ -99,13 +101,14 @@ list_ptr new_list (void)
curr pointer in the new list is the same as in the old list.
Returns a pointer to the new list head.
-------------------------------------------------------------------- **/
-list_ptr dup_list_head(list_ptr lp, int start_at_curr)
+list_ptr
+dup_list_head(list_ptr lp, int start_at_curr)
{
list_ptr new_listp;
- if ((new_listp = (list_ptr) malloc( sizeof( list_item))) == NULL) {
+ if ((new_listp = (list_ptr) malloc(sizeof(list_item))) == NULL) {
- return (list_ptr)NULL;
+ return (list_ptr) NULL;
}
new_listp->next = start_at_curr ? lp->ptr.curr : lp->next;
new_listp->ptr.curr = lp->ptr.curr;
@@ -117,13 +120,14 @@ list_ptr dup_list_head(list_ptr lp, int start_at_curr)
/** ------------------------------------------------------------------------
Returns the number of items in the list.
-------------------------------------------------------------------- **/
-unsigned int list_length(list_ptr lp)
+unsigned int
+list_length(list_ptr lp)
{
unsigned int count = 0;
while (lp->next) {
- count++;
- lp = lp->next;
+ count++;
+ lp = lp->next;
}
return count;
@@ -139,19 +143,20 @@ unsigned int list_length(list_ptr lp)
Returns a pointer to the item, so the caller can free it if it
so desires. If a match is not found, returns NULL.
-------------------------------------------------------------------- **/
-void *delete_from_list(list_ptr lp, void *item)
+void *
+delete_from_list(list_ptr lp, void *item)
{
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;
+ 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;
@@ -164,35 +169,38 @@ void *delete_from_list(list_ptr lp, void *item)
with new_list(). If free_items is true, each item pointed to
from the node is freed, in addition to the node itself.
-------------------------------------------------------------------- **/
-void delete_list(list_ptr lp, int free_items)
+void
+delete_list(list_ptr lp, int free_items)
{
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);
- }
+ del_node = lp->next;
+ item = del_node->ptr.item;
+ lp->next = del_node->next;
+ free(del_node);
+ if (free_items) {
+ free(item);
+ }
}
}
-void delete_list_destroying(list_ptr lp, void destructor(void *item))
+void
+delete_list_destroying(list_ptr lp, void destructor(void *item))
{
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);
- }
+ del_node = lp->next;
+ item = del_node->ptr.item;
+ lp->next = del_node->next;
+ free(del_node);
+ if (destructor) {
+ destructor(item);
+ }
}
}
@@ -202,11 +210,12 @@ void delete_list_destroying(list_ptr lp, void destructor(void *item))
Sets the list head node's curr ptr to the first node in the list.
Returns NULL if the list is empty.
-------------------------------------------------------------------- **/
-void * first_in_list(list_ptr lp)
+void *
+first_in_list(list_ptr lp)
{
- if (! lp) {
+ if (!lp) {
- return NULL;
+ return NULL;
}
lp->ptr.curr = lp->next;
@@ -219,21 +228,22 @@ void * first_in_list(list_ptr lp)
first_in_list must have been called prior.
Returns NULL if no next item.
-------------------------------------------------------------------- **/
-void * next_in_list(list_ptr lp)
+void *
+next_in_list(list_ptr lp)
{
- if (! lp) {
+ if (!lp) {
- return NULL;
+ return NULL;
}
if (lp->ptr.curr) {
- lp->ptr.curr = lp->ptr.curr->next;
+ lp->ptr.curr = lp->ptr.curr->next;
}
return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
}
-int list_is_empty(list_ptr lp)
+int
+list_is_empty(list_ptr lp)
{
return (lp == NULL || lp->next == NULL);
}
-
diff --git a/list.h b/list.h
index 664075d..23f36f2 100644
--- a/list.h
+++ b/list.h
@@ -47,47 +47,23 @@ from The Open Group.
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 */
+ 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)(
-void *
-);
+typedef void (*DESTRUCT_FUNC_PTR) (void *);
-void zero_list(
- list_ptr
- );
-int add_to_list (
- list_ptr , void *
- );
-list_ptr new_list (
- void
- );
-list_ptr dup_list_head (
- list_ptr , int
- );
-unsigned int list_length(
- list_ptr
- );
-void *delete_from_list (
- list_ptr , void *
- );
-void delete_list(
- list_ptr , int
- );
-void delete_list_destroying (
- list_ptr , DESTRUCT_FUNC_PTR
- );
-void *first_in_list (
- list_ptr
- );
-void *next_in_list (
- list_ptr
- );
-int list_is_empty (
- list_ptr
- );
+void zero_list(list_ptr);
+int add_to_list(list_ptr, void *);
+list_ptr new_list(void);
+list_ptr dup_list_head(list_ptr, int);
+unsigned int list_length(list_ptr);
+void *delete_from_list(list_ptr, void *);
+void delete_list(list_ptr, int);
+void delete_list_destroying(list_ptr, DESTRUCT_FUNC_PTR);
+void *first_in_list(list_ptr);
+void *next_in_list(list_ptr);
+int list_is_empty(list_ptr);
#endif
diff --git a/multiVis.c b/multiVis.c
index 9794ebd..da07fc2 100644
--- a/multiVis.c
+++ b/multiVis.c
@@ -61,24 +61,24 @@ 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) */
+ 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 */
+ 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 */
+ 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;
@@ -116,499 +116,489 @@ extern unsigned int list_length();
*/
/* Prototype Declarations for Static Functions */
-static void QueryColorMap(
- Display *, Colormap , Visual *,
- XColor **, int *, int *, int *
- );
-static void TransferImage(
- Display *, XImage *,int, int , image_region_type*,
- XImage *,int ,int
- );
-static XImage * ReadRegionsInList(
- Display *, Visual *, int, int, unsigned int,
- unsigned int, XRectangle, list_ptr
- );
-
-static list_ptr make_region_list(
- Display*, Window, XRectangle*,
- int*, int, XVisualInfo**, int *
- );
-
-static void destroy_region_list(
- list_ptr
- ) ;
-static void subtr_rect_from_image_region(
- image_region_type *, int , int , int , int
- );
-static void add_rect_to_image_region(
- image_region_type *,
- int , int , int , int
- );
-static int src_in_region_list(
- image_win_type *, list_ptr
- );
-static void add_window_to_list(
- list_ptr, Window, int, int ,
- int , int , int , int, int,
- Visual*, Colormap, Window
- );
-static int src_in_image(
- image_win_type *, int , XVisualInfo**
- );
-static int src_in_overlay(
- image_region_type *, int, OverlayInfo *, int*, int*
- );
-static void make_src_list(
- Display *, list_ptr, XRectangle *, Window,
- int, int, XWindowAttributes *, XRectangle *
-);
-static void destroy_image_region(
- image_region_type *
-);
+static void QueryColorMap(Display *, Colormap, Visual *,
+ XColor **, int *, int *, int *);
+static void TransferImage(Display *, XImage *, int, int, image_region_type *,
+ XImage *, int, int);
+static XImage *ReadRegionsInList(Display *, Visual *, int, int, unsigned int,
+ unsigned int, XRectangle, list_ptr);
+
+static list_ptr make_region_list(Display *, Window, XRectangle *,
+ int *, int, XVisualInfo **, int *);
+static void destroy_region_list(list_ptr);
+static void subtr_rect_from_image_region(image_region_type *,
+ int, int, int, int);
+static void add_rect_to_image_region(image_region_type *,
+ int, int, int, int);
+static int src_in_region_list(image_win_type *, list_ptr);
+static void add_window_to_list(list_ptr, Window, int, int,
+ int, int, int, int, int,
+ Visual *, Colormap, Window);
+static int src_in_image(image_win_type *, int, XVisualInfo **);
+static int src_in_overlay(image_region_type *, int, OverlayInfo *, int *,
+ int *);
+static void make_src_list(Display *, list_ptr, XRectangle *, Window, int, int,
+ XWindowAttributes *, XRectangle *);
+static void destroy_image_region(image_region_type *);
/* End of Prototype Declarations */
-void initFakeVisual(Visual *Vis)
+void
+initFakeVisual(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 ;
+ 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 void
QueryColorMap(Display *disp, Colormap src_cmap, Visual *src_vis,
- XColor **src_colors, int *rShift, int *gShift, int *bShift)
+ XColor **src_colors, int *rShift, int *gShift, int *bShift)
{
- unsigned int ncolors,i ;
- unsigned long redMask, greenMask, blueMask;
- int redShift, greenShift, blueShift;
- XColor *colors ;
-
- ncolors = (unsigned) src_vis->map_entries ;
- *src_colors = colors = calloc(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 ***/
- {
+ unsigned int ncolors, i;
+ unsigned long redMask, greenMask, blueMask;
+ int redShift, greenShift, blueShift;
+ XColor *colors;
+
+ ncolors = (unsigned) src_vis->map_entries;
+ *src_colors = colors = calloc(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;
+ redShift = 0;
+ while (!(redMask & 0x1)) {
+ redShift++;
+ redMask = redMask >> 1;
}
- greenShift = 0; while (!(greenMask&0x1)) {
- greenShift++;
- greenMask = greenMask>>1;
+ greenShift = 0;
+ while (!(greenMask & 0x1)) {
+ greenShift++;
+ greenMask = greenMask >> 1;
}
- blueShift = 0; while (!(blueMask&0x1)) {
- blueShift++;
- blueMask = blueMask>>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.
+ *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;
+ *****/
+ colors[i].pad = 0;
+ colors[i].flags = DoRed | DoGreen | DoBlue;
}
- }
+ }
- XQueryColors(disp, src_cmap, colors, (int) ncolors);
+ XQueryColors(disp, src_cmap, colors, (int) ncolors);
}
int
GetMultiVisualRegions(Display *disp,
- /* root win on which grab was done */
- Window srcRootWinid,
- /* root rel UL corner of bounding box of grab */
- int x, int y,
- /* size of bounding box of grab */
- unsigned int width, unsigned int height,
- int *transparentOverlays, int *numVisuals,
- XVisualInfo **pVisuals, int *numOverlayVisuals,
- OverlayInfo **pOverlayVisuals,
- int *numImageVisuals, XVisualInfo ***pImageVisuals,
- /* list of regions to read from */
- list_ptr *vis_regions,
- list_ptr *vis_image_regions, int *allImage)
+ /* root win on which grab was done */
+ Window srcRootWinid,
+ /* root rel UL corner of bounding box of grab */
+ int x, int y,
+ /* size of bounding box of grab */
+ unsigned int width, unsigned int height,
+ int *transparentOverlays, int *numVisuals,
+ XVisualInfo **pVisuals, int *numOverlayVisuals,
+ OverlayInfo **pOverlayVisuals,
+ int *numImageVisuals, XVisualInfo ***pImageVisuals,
+ /* list of regions to read from */
+ list_ptr *vis_regions,
+ list_ptr *vis_image_regions, int *allImage)
{
- int hasNonDefault;
- XRectangle bbox; /* bounding box of grabbed area */
-
+ 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);
+ 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,
+ *vis_regions = *vis_image_regions = NULL;
+ if ((*vis_regions = make_region_list(disp, srcRootWinid, &bbox,
&hasNonDefault, *numImageVisuals,
*pImageVisuals, allImage)) == NULL)
- return 0 ;
+ return 0;
- if (*transparentOverlays)
- {
- *allImage = 1; /* until proven otherwise,
- this flags that it to be an image only list */
+ 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);
+ 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 ;
+ /* 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(Display *disp, XImage *reg_image,
- int srcw, int srch,
- image_region_type *reg, XImage *target_image,
- int dst_x, int dst_y)
+static void
+TransferImage(Display *disp, XImage *reg_image,
+ int srcw, int srch,
+ image_region_type *reg, XImage *target_image,
+ int dst_x, int dst_y)
{
- int i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ;
+ int i, j, old_pixel, new_pixel, red_ind, green_ind, blue_ind;
XColor *colors;
int rShift = 0, gShift = 0, bShift = 0;
- QueryColorMap(disp,reg->cmap,reg->vis,&colors,
- &rShift,&gShift,&bShift) ;
+ QueryColorMap(disp, reg->cmap, reg->vis, &colors,
+ &rShift, &gShift, &bShift);
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;
+ 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(Display *disp, Visual *fakeVis, int depth, int format,
- unsigned int width, unsigned int height,
- XRectangle bbox, /* bounding box of grabbed area */
- list_ptr regions) /* list of regions to read from */
+ unsigned int width, unsigned int height,
+ 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;
+ 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 bytes_per_line;
+ XImage *reg_image, *ximage;
+ int srcRect_x, srcRect_y, srcRect_width, srcRect_height;
+ int bytes_per_line;
- ximage = XCreateImage(disp,fakeVis,depth,format,0,NULL,width,height,
- 8,0) ;
+ 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);
+ ximage->data = malloc(height * bytes_per_line);
else
- ximage->data = malloc(height*bytes_per_line*depth);
+ 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) ;
- }
+ 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 ;
+ return ximage;
}
/** ------------------------------------------------------------------------
------------------------------------------------------------------------ **/
-XImage *ReadAreaToImage(Display *disp,
- /* root win on which grab was done */
- Window srcRootWinid,
- /* root rel UL corner of bounding box of grab */
- int x, int y,
- /* size of bounding box of grab */
- unsigned int width, unsigned int height,
- int numVisuals, XVisualInfo *pVisuals,
- int numOverlayVisuals, OverlayInfo *pOverlayVisuals,
- int numImageVisuals, XVisualInfo **pImageVisuals,
- /* list of regions to read from */
- list_ptr vis_regions,
- /* list of regions to read from */
- list_ptr vis_image_regions,
- int format, int allImage)
+XImage *
+ReadAreaToImage(Display *disp,
+ /* root win on which grab was done */
+ Window srcRootWinid,
+ /* root rel UL corner of bounding box of grab */
+ int x, int y,
+ /* size of bounding box of grab */
+ unsigned int width, unsigned int height,
+ int numVisuals, XVisualInfo *pVisuals,
+ int numOverlayVisuals, OverlayInfo *pOverlayVisuals,
+ int numImageVisuals, XVisualInfo **pImageVisuals,
+ /* list of regions to read from */
+ list_ptr vis_regions,
+ /* list of regions to read from */
+ list_ptr vis_image_regions,
+ int format, int allImage)
{
- image_region_type *reg;
- XRectangle bbox; /* bounding box of grabbed area */
- int depth ;
- XImage *ximage, *ximage_ipm = NULL;
- Visual fakeVis ;
- int x1, y1;
- XImage *image;
+ image_region_type *reg;
+ XRectangle bbox; /* bounding box of grabbed area */
+ int depth;
+ XImage *ximage, *ximage_ipm = NULL;
+ Visual fakeVis;
+ int x1, y1;
+ XImage *image;
+
#if 0
- unsigned char *pmData , *ipmData ;
+ unsigned char *pmData, *ipmData;
#endif
- 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;
+ 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.x = x; /* init X rect for bounding box */
bbox.y = y;
bbox.width = width;
bbox.height = height;
+ initFakeVisual(&fakeVis);
- initFakeVisual(&fakeVis) ;
-
- depth = 24 ;
- ximage = ReadRegionsInList(disp,&fakeVis,depth,format,width,height,
- bbox,vis_regions) ;
+ depth = 24;
+ ximage = ReadRegionsInList(disp, &fakeVis, depth, format, width, height,
+ bbox, vis_regions);
#if 0
- pmData = (unsigned char *)ximage -> data ;
+ pmData = (unsigned char *) ximage->data;
#endif
/* 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) ;
+ if (vis_image_regions && (vis_image_regions->next) && !allImage) {
+ ximage_ipm =
+ ReadRegionsInList(disp, &fakeVis, depth, format, width, height,
+ bbox, vis_image_regions);
#if 0
- ipmData = (unsigned char *)ximage_ipm -> data ;
+ ipmData = (unsigned char *) ximage_ipm->data;
#endif
}
/* 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)
- {
+ 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) {
#if 0
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
#endif
- pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
- XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
-
- if(!test){
- test = 1 ;
- }
- }
+ pixel =
+ XGetPixel(ximage_ipm, dst_x + x1, dst_y + y1);
+ XPutPixel(ximage, dst_x + x1, dst_y + y1, pixel);
+
+ if (!test) {
+ test = 1;
+ }
+ }
#if 0
- else {
- pmData +=3;
- ipmData +=3;
- }
+ else {
+ pmData += 3;
+ ipmData += 3;
+ }
#endif
- }
- 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)
- {
+ }
+ 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) {
#if 0
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
#endif
- pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
- XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
- if(!test){
- test = 1 ;
- }
- }
+ pixel =
+ XGetPixel(ximage_ipm, dst_x + x1,
+ dst_y + y1);
+ XPutPixel(ximage, dst_x + x1, dst_y + y1,
+ pixel);
+ if (!test) {
+ test = 1;
+ }
+ }
#if 0
- else {
- pmData +=3;
- ipmData +=3;
- }
+ else {
+ pmData += 3;
+ ipmData += 3;
+ }
#endif
- }
- }
- } 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)
- {
+ }
+ }
+ }
+ 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) {
#if 0
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
- *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
+ *pmData++ = *ipmData++;
#endif
- pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
- XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel);
- if(!test){
- test = 1 ;
- }
- }
+ pixel =
+ XGetPixel(ximage_ipm, dst_x + x1,
+ dst_y + y1);
+ XPutPixel(ximage, dst_x + x1, dst_y + y1,
+ pixel);
+ if (!test) {
+ test = 1;
+ }
+ }
#if 0
- else {
- pmData +=3;
- ipmData +=3;
- }
+ else {
+ pmData += 3;
+ ipmData += 3;
+ }
#endif
- }
- }
- }
- }
- XDestroyImage (image);
- } /* end of src_in_overlay */
+ }
+ }
+ }
+ }
+ XDestroyImage(image);
+ } /* end of src_in_overlay */
} /** end transparency **/
- destroy_region_list( vis_regions);
- if (vis_image_regions) destroy_region_list( vis_image_regions );
+ destroy_region_list(vis_regions);
+ if (vis_image_regions)
+ destroy_region_list(vis_image_regions);
FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals);
XSync(disp, 0);
@@ -623,39 +613,39 @@ XImage *ReadAreaToImage(Display *disp,
image_wins must point to an existing list struct that's already
been zeroed (zero_list()).
------------------------------------------------------------------------ **/
-static void make_src_list(Display *disp, list_ptr image_wins,
- /* bnding box of area we want */
- XRectangle *bbox,
- Window curr,
- /* pos of curr WRT root */
- int x_rootrel, int y_rootrel,
- XWindowAttributes *curr_attrs,
- /* visible part of curr, not obscurred by ancestors */
- XRectangle *pclip)
+static void
+make_src_list(Display *disp, list_ptr image_wins,
+ /* bnding box of area we want */
+ XRectangle *bbox,
+ Window curr,
+ /* pos of curr WRT root */
+ int x_rootrel, int y_rootrel,
+ XWindowAttributes *curr_attrs,
+ /* visible part of curr, not obscurred by ancestors */
+ XRectangle *pclip)
{
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 */
+ 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);
-
+ 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)
@@ -664,47 +654,47 @@ static void make_src_list(Display *disp, list_ptr image_wins,
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);
+ 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);
}
}
@@ -717,126 +707,133 @@ static void make_src_list(Display *disp, list_ptr image_wins,
there will be two regions in the list.
Returns a pointer to the list.
------------------------------------------------------------------------ **/
-static list_ptr make_region_list(Display *disp, Window win, XRectangle *bbox,
- int *hasNonDefault, int numImageVisuals,
- XVisualInfo **pImageVisuals, int *allImage)
+static list_ptr
+make_region_list(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 ;
+ 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);
+ XUnionRectWithRegion(bbox, bbox_region, bbox_region);
+ XGetWindowAttributes(disp, win, &win_attrs);
- zero_list( &image_wins);
+ zero_list(&image_wins);
clip.x = 0;
clip.y = 0;
- clip.width = win_attrs.width;
+ 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);
+ 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;
+ 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);
+ delete_list(&image_wins, True);
+ XDestroyRegion(bbox_region);
return image_regions;
}
+
/** ------------------------------------------------------------------------
Destructor called from destroy_region_list().
------------------------------------------------------------------------ **/
-static void destroy_image_region(image_region_type *image_region)
+static void
+destroy_image_region(image_region_type *image_region)
{
- XDestroyRegion( image_region->visible_region);
- free( (void *) 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(list_ptr rlist)
+static void
+destroy_region_list(list_ptr rlist)
{
- delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region);
+ 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_type *image_region,
- int x, int y, int width, int height)
+static void
+subtr_rect_from_image_region(image_region_type *image_region,
+ int x, int y, int width, int height)
{
XRectangle rect;
Region rect_region;
@@ -846,18 +843,18 @@ static void subtr_rect_from_image_region(image_region_type *image_region,
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);
+ 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_type *image_region,
- int x, int y, int width, int height)
+static void
+add_rect_to_image_region(image_region_type *image_region,
+ int x, int y, int width, int height)
{
XRectangle rect;
@@ -865,44 +862,43 @@ static void add_rect_to_image_region(image_region_type *image_region,
rect.y = y;
rect.width = width;
rect.height = height;
- XUnionRectWithRegion( &rect, image_region->visible_region,
- image_region->visible_region);
+ 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(image_win_type *src, list_ptr image_regions)
+static int
+src_in_region_list(image_win_type *src, list_ptr image_regions)
{
- image_region_type *ir;
+ 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)) {
+ 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 1;
+ }
}
return 0;
}
-
/** ------------------------------------------------------------------------
Makes a new entry in image_wins with the given fields filled in.
------------------------------------------------------------------------ **/
-static void add_window_to_list(list_ptr image_wins, Window w,
- int xrr, int yrr, int x_vis, int y_vis,
- int width, int height, int border_width,
- Visual *vis, Colormap cmap, Window parent)
+static void
+add_window_to_list(list_ptr image_wins, Window w,
+ int xrr, int yrr, int x_vis, int y_vis,
+ int width, int height, int border_width,
+ Visual *vis, Colormap cmap, Window parent)
{
- image_win_type *new_src;
-
- if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL)
+ image_win_type *new_src;
- return;
+ if ((new_src = (image_win_type *) malloc(sizeof(image_win_type))) == NULL)
+ return;
new_src->win = w;
new_src->x_rootrel = xrr;
@@ -915,22 +911,22 @@ static void add_window_to_list(list_ptr image_wins, Window w,
new_src->vis = vis;
new_src->cmap = cmap;
new_src->parent = parent;
- add_to_list( image_wins, new_src);
+ 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(image_win_type *src, int numImageVisuals,
- XVisualInfo **pImageVisuals)
+static int
+src_in_image(image_win_type *src, int numImageVisuals,
+ XVisualInfo **pImageVisuals)
{
- int i;
+ int i;
- for (i = 0 ; i < numImageVisuals ; i++)
- {
- if (pImageVisuals[i]->visual == src->vis)
- return 1;
+ for (i = 0; i < numImageVisuals; i++) {
+ if (pImageVisuals[i]->visual == src->vis)
+ return 1;
}
return 0;
}
@@ -940,24 +936,23 @@ static int src_in_image(image_win_type *src, int numImageVisuals,
Returns TRUE if the given src's visual is in the overlay planes
and transparency is possible, FALSE otherwise.
------------------------------------------------------------------------ **/
-static int src_in_overlay(image_region_type *src, int numOverlayVisuals,
- OverlayInfo *pOverlayVisuals,
- int *transparentColor, int *transparentType)
+static int
+src_in_overlay(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;
- }
+ 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 {
- }
+ else {
+ }
}
return 0;
@@ -977,15 +972,13 @@ static int src_in_overlay(image_region_type *src, int numOverlayVisuals,
******************************************************************************/
-
#define STATIC_GRAY 0x01
#define GRAY_SCALE 0x02
#define PSEUDO_COLOR 0x04
#define TRUE_COLOR 0x10
#define DIRECT_COLOR 0x11
-
-static int weCreateServerOverlayVisualsProperty = False;
+static int weCreateServerOverlayVisualsProperty = False;
/******************************************************************************
@@ -1010,129 +1003,118 @@ static int weCreateServerOverlayVisualsProperty = False;
*
******************************************************************************/
-int GetXVisualInfo(/* Which X server (aka "display"). */
- Display *display,
- /* Which screen of the "display". */
- int screen,
- /* Non-zero if there's at least one overlay visual and
- * if at least one of those supports a transparent pixel. */
- int *transparentOverlays,
- /* Number of XVisualInfo struct's pointed to by pVisuals. */
- int *numVisuals,
- /* All of the device's visuals. */
- XVisualInfo **pVisuals,
- /* Number of OverlayInfo's pointed to by pOverlayVisuals.
- * If this number is zero, the device does not have
- * overlay planes. */
- int *numOverlayVisuals,
- /* The device's overlay plane visual information. */
- OverlayInfo **pOverlayVisuals,
- /* Number of XVisualInfo's pointed to by pImageVisuals. */
- int *numImageVisuals,
- /* The device's image visuals. */
- XVisualInfo ***pImageVisuals)
+int
+GetXVisualInfo( /* Which X server (aka "display"). */
+ Display *display,
+ /* Which screen of the "display". */
+ int screen,
+ /* Non-zero if there's at least one overlay visual and
+ * if at least one of those supports a transparent pixel. */
+ int *transparentOverlays,
+ /* Number of XVisualInfo struct's pointed to by pVisuals. */
+ int *numVisuals,
+ /* All of the device's visuals. */
+ XVisualInfo **pVisuals,
+ /* Number of OverlayInfo's pointed to by pOverlayVisuals.
+ * If this number is zero, the device does not have
+ * overlay planes. */
+ int *numOverlayVisuals,
+ /* The device's overlay plane visual information. */
+ OverlayInfo **pOverlayVisuals,
+ /* Number of XVisualInfo's pointed to by pImageVisuals. */
+ int *numImageVisuals,
+ /* The device's image visuals. */
+ XVisualInfo ***pImageVisuals)
{
- 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;
+ XVisualInfo getVisInfo; /* Parameters 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 */
-
+ 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);
+ 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) / sizeof(long);
- do
- {
- numLongs += bytesAfter * sizeof(long);
- 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) / sizeof(long));
+ 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) / sizeof(long);
+ do {
+ numLongs += bytesAfter * sizeof(long);
+ 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) / sizeof(long));
}
- else
- {
- /* This screen doesn't have overlay planes. */
- *numOverlayVisuals = 0;
- *pOverlayVisuals = NULL;
- *transparentOverlays = 0;
+ 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++;
+ 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() */
+ return (0);
+} /* GetXVisualInfo() */
/******************************************************************************
*
@@ -1142,14 +1124,15 @@ int GetXVisualInfo(/* Which X server (aka "display"). */
*
******************************************************************************/
-void FreeXVisualInfo(XVisualInfo *pVisuals, OverlayInfo *pOverlayVisuals,
- XVisualInfo **pImageVisuals)
+void
+FreeXVisualInfo(XVisualInfo *pVisuals, OverlayInfo *pOverlayVisuals,
+ XVisualInfo **pImageVisuals)
{
XFree(pVisuals);
if (weCreateServerOverlayVisualsProperty)
- free(pOverlayVisuals);
+ free(pOverlayVisuals);
else
- XFree(pOverlayVisuals);
+ XFree(pOverlayVisuals);
free(pImageVisuals);
-} /* FreeXVisualInfo() */
+} /* FreeXVisualInfo() */
diff --git a/multiVis.h b/multiVis.h
index 28b940b..28488b1 100644
--- a/multiVis.h
+++ b/multiVis.h
@@ -34,20 +34,15 @@ from The Open Group.
------------------------------------------------------------------------ **/
-extern int GetMultiVisualRegions(
- Display *, Window, int, int, unsigned int,
- unsigned int, int *, int *, XVisualInfo **, int *,
- OverlayInfo **, int *, XVisualInfo ***, list_ptr *,
- list_ptr *, int *
-);
-
-extern XImage *ReadAreaToImage(
- Display *, Window, int, int, unsigned int,
- unsigned int, int, XVisualInfo *, int,
- OverlayInfo *, int, XVisualInfo **, list_ptr,
- list_ptr, int, int
-);
-
-extern void initFakeVisual(
- Visual *
-);
+extern int GetMultiVisualRegions(Display *, Window, int, int, unsigned int,
+ unsigned int, int *, int *, XVisualInfo **,
+ int *, OverlayInfo **, int *, XVisualInfo ***,
+ list_ptr *, list_ptr *, int *);
+
+extern XImage *ReadAreaToImage(Display *, Window, int, int, unsigned int,
+ unsigned int, int, XVisualInfo *, int,
+ OverlayInfo *, int, XVisualInfo **, list_ptr,
+ list_ptr, int, int
+ );
+
+extern void initFakeVisual(Visual *);
diff --git a/xwd.c b/xwd.c
index fc32288..c3c48e0 100644
--- a/xwd.c
+++ b/xwd.c
@@ -111,29 +111,29 @@ static long parse_long(char *);
static int Get24bitDirectColors(XColor **);
static int ReadColors(Visual *, Colormap, XColor **);
-
-static long parse_long (char *s)
+static long
+parse_long(char *s)
{
long retval = 0L;
int thesign = 1;
if (s && s[0]) {
- switch(s[0]) {
- case '-':
- (void) sscanf (s + 1, "%lu", &retval);
- thesign = -1;
- break;
- case '0':
- (void) sscanf (s + 1, "%lo", &retval);
- break;
- case 'x':
- case 'X':
- (void) sscanf (s + 1, "%lx", &retval);
- break;
- default:
- (void) sscanf (s, "%lu", &retval);
- break;
- }
+ switch (s[0]) {
+ case '-':
+ (void) sscanf(s + 1, "%lu", &retval);
+ thesign = -1;
+ break;
+ case '0':
+ (void) sscanf(s + 1, "%lo", &retval);
+ break;
+ case 'x':
+ case 'X':
+ (void) sscanf(s + 1, "%lx", &retval);
+ break;
+ default:
+ (void) sscanf(s, "%lu", &retval);
+ break;
+ }
}
return (thesign * retval);
}
@@ -154,66 +154,68 @@ main(int argc, char **argv)
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(NULL);
- if (!strcmp(argv[i], "-out")) {
- if (++i >= argc) usage("-out requires an argument");
- if (!(out_file = fopen(argv[i], "wb")))
- Fatal_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 requires an argument");
- 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;
- }
- if (!strcmp(argv[i], "-version")) {
- puts(PACKAGE_STRING);
- exit(0);
- }
- fprintf (stderr, "%s: unrecognized argument '%s'\n",
- program_name, argv[i]);
- usage(NULL);
+ if (!strcmp(argv[i], "-nobdrs")) {
+ nobdrs = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-debug")) {
+ debug = True;
+ continue;
+ }
+ if (!strcmp(argv[i], "-help"))
+ usage(NULL);
+ if (!strcmp(argv[i], "-out")) {
+ if (++i >= argc)
+ usage("-out requires an argument");
+ if (!(out_file = fopen(argv[i], "wb")))
+ Fatal_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 requires an argument");
+ 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;
+ }
+ if (!strcmp(argv[i], "-version")) {
+ puts(PACKAGE_STRING);
+ exit(0);
+ }
+ fprintf(stderr, "%s: unrecognized argument '%s'\n",
+ program_name, argv[i]);
+ usage(NULL);
}
#ifdef WIN32
if (standard_out)
- _setmode(fileno(out_file), _O_BINARY);
+ _setmode(fileno(out_file), _O_BINARY);
#endif
/*
* Let the user select the target window.
*/
if (target_win == None)
- target_win = Select_Window(dpy, !frame_only);
+ target_win = Select_Window(dpy, !frame_only);
/*
* Dump it!
@@ -222,8 +224,8 @@ main(int argc, char **argv)
XCloseDisplay(dpy);
if (fclose(out_file)) {
- perror("xwd");
- exit(1);
+ perror("xwd");
+ exit(1);
}
exit(0);
}
@@ -231,21 +233,19 @@ main(int argc, char **argv)
static int
Get24bitDirectColors(XColor **colors)
{
- int i , ncolors = 256 ;
- XColor *tcol ;
+ int i, ncolors = 256;
+ XColor *tcol;
- *colors = tcol = (XColor *)malloc(sizeof(XColor) * ncolors) ;
+ *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 ;
+ 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 ;
+ return ncolors;
}
-
/*
* Window_Dump: dump a window to a file which must already be open for
* writing.
@@ -272,44 +272,45 @@ Window_Dump(Window window, FILE *out)
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 ;
+ 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);
+ XkbStdBell(dpy, None, 50, XkbBI_Wait);
#else
- XBell(dpy,FEEP_VOLUME);
+ XBell(dpy, FEEP_VOLUME);
#endif
- XFlush(dpy);
+ 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.");
+ 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);
+ 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;
@@ -317,27 +318,31 @@ Window_Dump(Window window, FILE *out)
height = win_info.height;
if (!nobdrs) {
- absx -= win_info.border_width;
- absy -= win_info.border_width;
- width += (2 * win_info.border_width);
- height += (2 * win_info.border_width);
+ absx -= win_info.border_width;
+ absy -= win_info.border_width;
+ width += (2 * win_info.border_width);
+ height += (2 * win_info.border_width);
}
- dwidth = DisplayWidth (dpy, screen);
- dheight = DisplayHeight (dpy, screen);
-
+ 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;
+ 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 = default_win_name;
- got_win_name = False;
- } else {
- got_win_name = True;
+ win_name = default_win_name;
+ got_win_name = False;
+ }
+ else {
+ got_win_name = True;
}
/* sizeof(char) is included for the null string terminator. */
@@ -350,75 +355,81 @@ Window_Dump(Window window, FILE *out)
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);
+ 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);
+ 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);
+ 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);
+ 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 (debug)
+ outl("xwd: Getting Colors.\n");
- if( !multiVis)
- {
- ncolors = Get_XColors(&win_info, &colors);
- vis = win_info.visual ;
+ if (!multiVis) {
+ ncolors = Get_XColors(&win_info, &colors);
+ vis = win_info.visual;
}
- else
- {
- ncolors = Get24bitDirectColors(&colors) ;
- initFakeVisual(&vis_h) ;
- vis = &vis_h ;
+ 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);
+ XkbStdBell(dpy, window, FEEP_VOLUME, XkbBI_Proceed);
+ XkbStdBell(dpy, window, FEEP_VOLUME, XkbBI_RepeatingLastBell);
#else
- XBell(dpy, FEEP_VOLUME);
- XBell(dpy, FEEP_VOLUME);
+ XBell(dpy, FEEP_VOLUME);
+ XBell(dpy, FEEP_VOLUME);
#endif
- XFlush(dpy);
+ XFlush(dpy);
}
/*
* Calculate header size.
*/
- if (debug) outl("xwd: Calculating header size.\n");
+ if (debug)
+ outl("xwd: Calculating header size.\n");
header_size = SIZEOF(XWDheader) + (CARD32) win_name_size;
/*
* Write out header information.
*/
- if (debug) outl("xwd: Constructing and dumping file header.\n");
+ 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;
@@ -455,64 +466,70 @@ Window_Dump(Window window, FILE *out)
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(CARD32));
- _swapshort((char *) &colors[i].red, 3 * sizeof(short));
- }
+ _swaplong((char *) &header, sizeof(header));
+ for (i = 0; i < ncolors; i++) {
+ _swaplong((char *) &colors[i].pixel, sizeof(CARD32));
+ _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);
+ 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);
+ 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);
- }
+ 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);
+ 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
+ * 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);
+ perror("xwd");
+ exit(1);
}
/*
* free the color buffer.
*/
- if(debug && ncolors > 0) outl("xwd: Freeing colors.\n");
- if(ncolors > 0) free(colors);
+ 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);
+ if (debug)
+ outl("xwd: Freeing window name string.\n");
+ if (got_win_name)
+ XFree(win_name);
/*
* Free image
@@ -527,12 +544,15 @@ void
usage(const char *errmsg)
{
if (errmsg != NULL)
- fprintf (stderr, "%s: %s\n", program_name, errmsg);
-
- fprintf(stderr, "Usage: %s [options] [-root| -id <wdid>| -name <wdname>] > mywddump\n", program_name);
- fprintf(stderr, " %s [options] [-root| -id <wdid>| -name <wdname>] -out mywddump\n", program_name);
- fputs("Options:\n"
- " -help Print this message\n"
+ fprintf(stderr, "%s: %s\n", program_name, errmsg);
+
+ fprintf(stderr,
+ "Usage: %s [options] [-root| -id <wdid>| -name <wdname>] > mywddump\n",
+ program_name);
+ fprintf(stderr,
+ " %s [options] [-root| -id <wdid>| -name <wdname>] -out mywddump\n",
+ program_name);
+ fputs("Options:\n" " -help Print this message\n"
" -version Print the program version and exit\n"
" -debug Enable debug mode\n"
" -d, -display <host:dpy> Specify server to connect\n"
@@ -546,22 +566,21 @@ usage(const char *errmsg)
" -name <wdname> Select a window by its WM_NAME property\n"
" -icmap Use the first colormap of the screen\n"
" -screen Send the request against the root window\n"
- " -silent Don't ring any bells\n",
- stderr);
+ " -silent Don't ring any bells\n", stderr);
exit(1);
}
-
/*
* Determine the pixmap size.
*/
-int Image_Size(XImage *image)
+int
+Image_Size(XImage *image)
{
if (image->format != ZPixmap)
- return(image->bytes_per_line * image->height * image->depth);
+ return (image->bytes_per_line * image->height * image->depth);
- return(image->bytes_per_line * image->height);
+ return (image->bytes_per_line * image->height);
}
#define lowbit(x) ((x) & (~(x) + 1))
@@ -569,79 +588,80 @@ int Image_Size(XImage *image)
static int
ReadColors(Visual *vis, Colormap cmap, XColor **colors)
{
- int i,ncolors ;
+ 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;
- }
+ 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);
+ return (ncolors);
}
/*
* Get the XColors of all pixels in image - returns # of colors
*/
-int Get_XColors(XWindowAttributes *win_info, XColor **colors)
+int
+Get_XColors(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];
+ /* 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 ;
+ return (0);
+ ncolors = ReadColors(win_info->visual, cmap, colors);
+ return ncolors;
}
void
-_swapshort (register char *bp, register unsigned n)
+_swapshort(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;
+ c = *bp;
+ *bp = *(bp + 1);
+ bp++;
+ *bp++ = c;
}
}
void
-_swaplong (register char *bp, register unsigned n)
+_swaplong(register char *bp, register unsigned n)
{
register char c;
register char *ep = bp + n;