[PATCH xwd] Translate window by -geometry

Aaron Plattner aplattner at nvidia.com
Thu Nov 29 15:19:50 PST 2012


 From c851a7b1e8c817853210be85beb34c8679a004d1 Mon Sep 17 00:00:00 2001
 > From: Matt Vollrath <matt at endpoint.com>
 > Date: Fri, 2 Nov 2012 17:55:12 +0000
 > Subject: [PATCH xwd] Translate window by -geometry
 >
 > This is intended to allow dumps of arbitrary sections of the root
 > window.
 >
 > Signed-off-by: Matt Vollrath <matt at endpoint.com>
 > ---
 >  xwd.c |   25 +++++++++++++++++++++----
 >  1 file changed, 21 insertions(+), 4 deletions(-)
 >
 > diff --git a/xwd.c b/xwd.c
 > index 5b40121..05b8a7b 100644
 > --- a/xwd.c
 > +++ b/xwd.c
 > @@ -98,11 +98,12 @@ static Bool standard_out = True;
 >  static Bool debug = False;
 >  static Bool silent = False;
 >  static Bool use_installed = False;
 > +static char *geom = NULL;

This is only used in main(), so it would be nice if it were declared 
there instead of globally.

 >  static long add_pixel_value = 0;
 >
 >
 >  extern int main(int, char **);
 > -extern void Window_Dump(Window, FILE *);
 > +extern void Window_Dump(Window, FILE *, char *);
 >  extern int Image_Size(XImage *);
 >  extern int Get_XColors(XWindowAttributes *, XColor **);
 >  extern void _swapshort(register char *, register unsigned);
 > @@ -196,6 +197,11 @@ main(int argc, char **argv)
 >  	    silent = True;
 >  	    continue;
 >  	}
 > +        if (!strcmp(argv[i], "-geometry")) {
 > +             if (++i >= argc) usage();
 > +             geom = argv[i];
 > +             continue;
 > +        }

This add space-indented lines right next to tab-indented ones.  I don't 
*think* my mailer munched this particular whitespace.

 >  	usage();
 >      }
 >  #ifdef WIN32
 > @@ -212,7 +218,7 @@ main(int argc, char **argv)
 >      /*
 >       * Dump it!
 >       */
 > -    Window_Dump(target_win, out_file);
 > +    Window_Dump(target_win, out_file, geom);
 >
 >      XCloseDisplay(dpy);
 >      if (fclose(out_file)) {
 > @@ -246,7 +252,7 @@ Get24bitDirectColors(XColor **colors)
 >   */
 >
 >  void
 > -Window_Dump(Window window, FILE *out)
 > +Window_Dump(Window window, FILE *out, char *geometry)
 >  {
 >      unsigned long swaptest = 1;
 >      XColor *colors;
 > @@ -260,6 +266,8 @@ Window_Dump(Window window, FILE *out)
 >      XImage *image;
 >      int absx, absy, x, y;
 >      unsigned width, height;
 > +    int gbits, gx, gy;
 > +    unsigned gwidth, gheight;
 >      int dwidth, dheight;
 >      Window dummywin;
 >      XWDFileHeader header;
 > @@ -309,6 +317,15 @@ Window_Dump(Window window, FILE *out)
 >      width = win_info.width;
 >      height = win_info.height;
 >
 > +    /* translate geometry if provided */
 > +    if (geometry) {
 > +        gbits = XParseGeometry( geometry, &gx, &gy, &gwidth, &gheight );

gbits isn't needed outside this block, so please declare it here.

 > +        if (gbits & XValue) absx += gx;
 > +        if (gbits & YValue) absy += gy;
 > +        if (gbits & WidthValue) width = gwidth;
 > +        if (gbits & HeightValue) height = gheight;
 > +    }
 > +
 >      if (!nobdrs) {
 >  	absx -= win_info.border_width;
 >  	absy -= win_info.border_width;

The interaction between -geometry and !nobdrs seems wrong.  This code 
will adjust for the border after the code you added selects a rectangle 
within the window, padding your sub-rectangle by the border size even if 
it's nowhere near the border.

-- Aaron

 > @@ -522,7 +539,7 @@ usage(void)
 >      fprintf (stderr,
 >  "usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] [-out 
<file>]",
 >  	   program_name, "[{-root|-id <id>|-name <name>}]");
 > -    fprintf (stderr, " [-xy] [-add value] [-frame]\n");
 > +    fprintf (stderr, " [-xy] [-add value] [-frame] [-geometry 
<geom>]\n");
 >      exit(1);
 >  }
 >
 > --
 > 1.7.9.5
 >


More information about the xorg-devel mailing list