forked from old/legacy-imlib2
Add some options:
-id <drawable> to grab other than root window. -w/width set output image width. -h/height set output image height. -noshape do not use window shape. -help show usage. -v show info about the grabbed drawable. SVN revision: 22718
This commit is contained in:
parent
7f1bc6088f
commit
42d0f19674
|
@ -20,18 +20,87 @@ Colormap cm;
|
|||
int depth;
|
||||
int image_width = 0, image_height = 0;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] [-height <height>] [-noshape] <output file>\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *s;
|
||||
Imlib_Image *im = NULL;
|
||||
char *file = NULL;
|
||||
int no = 1;
|
||||
int verbose;
|
||||
int get_alpha;
|
||||
const char *display_name = getenv("DISPLAY");
|
||||
Drawable draw;
|
||||
int x, y;
|
||||
unsigned int w, h, bw, depth;
|
||||
unsigned int wo, ho;
|
||||
Window rr;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
verbose = 0;
|
||||
get_alpha = 1;
|
||||
draw = None;
|
||||
wo = ho = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc <= 0)
|
||||
break;
|
||||
s = argv[0];
|
||||
if (*s++ != '-')
|
||||
break;
|
||||
if (!strcmp(s, "id"))
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc <= 1)
|
||||
break;
|
||||
draw = strtoul(argv[0], NULL, 0);
|
||||
}
|
||||
else if (!strcmp(s, "w") || !strcmp(s, "width"))
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc <= 1)
|
||||
break;
|
||||
wo = strtoul(argv[0], NULL, 0);
|
||||
}
|
||||
else if (!strcmp(s, "h") || !strcmp(s, "height"))
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc <= 1)
|
||||
break;
|
||||
ho = strtoul(argv[0], NULL, 0);
|
||||
}
|
||||
else if (!strcmp(s, "noshape"))
|
||||
{
|
||||
get_alpha = 0;
|
||||
}
|
||||
else if (!strcmp(s, "v"))
|
||||
{
|
||||
verbose = 1;
|
||||
}
|
||||
else if (!strcmp(s, "help"))
|
||||
{
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (argc <= 0)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = argv[0];
|
||||
|
||||
file = argv[no];
|
||||
if (display_name == NULL)
|
||||
display_name = ":0";
|
||||
disp = XOpenDisplay(display_name);
|
||||
|
@ -40,26 +109,44 @@ main(int argc, char **argv)
|
|||
fprintf(stderr, "Can't open display %s\n", display_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
vis = DefaultVisual(disp, DefaultScreen(disp));
|
||||
depth = DefaultDepth(disp, DefaultScreen(disp));
|
||||
cm = DefaultColormap(disp, DefaultScreen(disp));
|
||||
imlib_context_set_display(disp);
|
||||
imlib_context_set_visual(vis);
|
||||
imlib_context_set_colormap(cm);
|
||||
imlib_context_set_drawable(DefaultRootWindow(disp));
|
||||
im = imlib_create_image_from_drawable(0, 0, 0,
|
||||
DisplayWidth(disp, DefaultScreen(disp)),
|
||||
DisplayHeight(disp, DefaultScreen(disp)),
|
||||
1);
|
||||
|
||||
if (draw == None)
|
||||
draw = DefaultRootWindow(disp);
|
||||
imlib_context_set_drawable(draw);
|
||||
|
||||
XGetGeometry(disp, draw, &rr, &x, &y, &w, &h, &bw, &depth);
|
||||
if (wo == 0)
|
||||
wo = w;
|
||||
if (ho == 0)
|
||||
ho = h;
|
||||
if (verbose)
|
||||
{
|
||||
printf("Drawable: %#lx: x,y: %d,%d wxh=%ux%u bw=%u depth=%u\n",
|
||||
draw, x, y, w, h, bw, depth);
|
||||
if ((wo != w) || (ho != h))
|
||||
printf("Output : wxh=%ux%u\n", wo, ho);
|
||||
}
|
||||
|
||||
if ((wo != w) || (ho != h))
|
||||
im = imlib_create_scaled_image_from_drawable(None, 0, 0, w, h, wo, ho, 1,
|
||||
(get_alpha) ? 1 : 0);
|
||||
else
|
||||
im = imlib_create_image_from_drawable((get_alpha) ? 1 : 0, 0, 0, w, h, 1);
|
||||
if (!im)
|
||||
{
|
||||
fprintf(stderr, "Cannot grab image!\n");
|
||||
exit(0);
|
||||
}
|
||||
if (argc > 1)
|
||||
{
|
||||
imlib_context_set_image(im);
|
||||
imlib_save_image(argv[1]);
|
||||
}
|
||||
|
||||
imlib_context_set_image(im);
|
||||
imlib_save_image(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue