--- Begin Message ---
Package: scrot
Version: 0.8-6
Severity: wishlist
Please find attached a patch to add a --focused option which causes
scrot to take a snapshot of the window with the active input focus.
(I needed this while trying to use the xautomation package. An xwd pipe
conversion to png was considerably slower than scrot, yet scrot could
not be given a window id or name, requiring the use of xte to simulate a
click, which was unreliable due to timing. xte could fire the XTest
click before scrot had grabbed the event stream.)
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.2-mppe
Locale: LANG=C, LC_CTYPE=C
Versions of packages scrot depends on:
ii giblib1 1.2.3-3 wrapper library for imlib2, and ot
ii libc6 2.3.2.ds1-11 GNU C Library: Shared libraries an
ii libfreetype6 2.1.7-2 FreeType 2 font engine, shared lib
ii libimlib2 1.1.0-12 Powerful image loading and renderi
ii libx11-6 4.3.0-7 X Window System protocol client li
ii libxext6 4.3.0-7 X Window System miscellaneous exte
ii xlibs 4.3.0-7 X Window System client libraries m
ii zlib1g 1:1.2.1-5 compression library - runtime
-- no debconf information
--
James Cameron
HP Software Security Response Team
Asia Pacific
--- ChangeLog.orig 2003-06-23 22:05:45.000000000 +1000
+++ ChangeLog 2004-04-21 22:00:14.000000000 +1000
@@ -1,3 +1,13 @@
+Wed Apr 21 21:53:26 2004 James Cameron <[email protected]>
+
+ * src/options.c (scrot_parse_option_array): add --focused option.
+
+ * src/main.c (scrot_get_geometry, scrot_nice_clip): new functions
+ for common code used by both selected and focused screenshot.
+
+ * src/main.c (scrot_grab_focused): new function to grab currently
+ focused window after specified delay.
+
Wed Mar 12 13:20:11 GMT 2003 Tom Gilbert <[email protected]>
* Patch from Claes Nasten <[email protected]>
diff -u -r src.orig/options.h src/options.h
--- src.orig/options.h 2004-04-21 21:15:24.000000000 +1000
+++ src/options.h 2004-04-21 22:00:47.000000000 +1000
@@ -32,6 +32,7 @@
int delay;
int countdown;
int select;
+ int focused;
int quality;
int border;
int multidisp;
diff -u -r src.orig/options.c src/options.c
--- src.orig/options.c 2004-04-21 21:15:24.000000000 +1000
+++ src/options.c 2004-04-21 22:00:32.000000000 +1000
@@ -44,13 +44,15 @@
static void
scrot_parse_option_array(int argc, char **argv)
{
- static char stropts[] = "bcd:e:hmq:st:v+:";
+ static char stropts[] = "bcd:e:hmq:st:uv+:";
static struct option lopts[] = {
/* actions */
{"help", 0, 0, 'h'}, /* okay */
{"version", 0, 0, 'v'}, /* okay */
{"count", 0, 0, 'c'},
{"select", 0, 0, 's'},
+ {"focused", 0, 0, 'u'},
+ {"focussed", 0, 0, 'u'}, /* macquarie dictionary has both spellings */
{"border", 0, 0, 'b'},
{"multidisp", 0, 0, 'm'},
/* toggles */
@@ -95,6 +97,9 @@
case 's':
opt.select = 1;
break;
+ case 'u':
+ opt.focused = 1;
+ break;
case '+':
opt.debug_level = atoi(optarg);
break;
@@ -231,6 +236,7 @@
" and join them together.\n"
" -s, --select interactively choose a window or
rectangle\n"
" with the mouse\n"
+ " -u, --focused use the currently focused window\n"
" -t, --thumb NUM generate thumbnail too. NUM is the
percentage\n"
" of the original size for the thumbnail
to be,\n"
" or the geometry in percent, e.g. 50x60
or 80x20.\n"
diff -u -r src.orig/scrot.h src/scrot.h
--- src.orig/scrot.h 2004-04-21 21:15:24.000000000 +1000
+++ src/scrot.h 2004-04-21 22:00:42.000000000 +1000
@@ -72,7 +72,10 @@
char *filename_im, char *filename_thumb);
void scrot_do_delay(void);
Imlib_Image scrot_sel_and_grab_image(void);
+Imlib_Image scrot_grab_focused(void);
void scrot_sel_area(int *x, int *y, int *w, int *h);
+void scrot_nice_clip(int *rx, int *ry, int *rw, int *rh);
+int scrot_get_geometry(Window target, int *rx, int *ry, int *rw, int *rh);
Window scrot_get_window(Display *display,Window window,int x,int y);
Window scrot_get_client_window(Display * display, Window target);
Window scrot_find_window_by_property(Display * display, const Window window,
diff -u -r src.orig/main.c src/main.c
--- src.orig/main.c 2004-04-21 21:15:24.000000000 +1000
+++ src/main.c 2004-04-21 22:01:27.000000000 +1000
@@ -48,7 +48,9 @@
}
- if (opt.select)
+ if (opt.focused)
+ image = scrot_grab_focused();
+ else if (opt.select)
image = scrot_sel_and_grab_image();
else {
scrot_do_delay();
@@ -171,6 +173,22 @@
}
Imlib_Image
+scrot_grab_focused(void)
+{
+ Imlib_Image im = NULL;
+ int rx = 0, ry = 0, rw = 0, rh = 0;
+ Window target = None;
+ int ignored;
+
+ scrot_do_delay();
+ XGetInputFocus(disp, &target, &ignored);
+ if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL;
+ scrot_nice_clip(&rx, &ry, &rw, &rh);
+ im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);
+ return im;
+}
+
+Imlib_Image
scrot_sel_and_grab_image(void)
{
Imlib_Image im = NULL;
@@ -313,57 +331,10 @@
rh = 0 - rh;
}
} else {
- Window child;
- XWindowAttributes attr;
- int stat;
-
/* else it's a window click */
- /* get geometry of window and use that */
- /* get windowmanager frame of window */
- if (target != root) {
- unsigned int d, x;
- int status;
-
- status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
- if (status != 0) {
- Window rt, *children, parent;
-
- for (;;) {
- /* Find window manager frame. */
- status = XQueryTree(disp, target, &rt, &parent, &children, &d);
- if (status && (children != None))
- XFree((char *) children);
- if (!status || (parent == None) || (parent == rt))
- break;
- target = parent;
- }
- /* Get client window. */
- if (!opt.border)
- target = scrot_get_client_window(disp, target);
- XRaiseWindow(disp, target);
- }
- }
- stat = XGetWindowAttributes(disp, target, &attr);
- if ((stat == False) || (attr.map_state != IsViewable))
- return NULL;
- rw = attr.width;
- rh = attr.height;
- XTranslateCoordinates(disp, target, root, 0, 0, &rx, &ry, &child);
+ if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL;
}
-
- /* clip rectangle nicely */
- if (rx < 0) {
- rw += rx;
- rx = 0;
- }
- if (ry < 0) {
- rh += ry;
- ry = 0;
- }
- if ((rx + rw) > scr->width)
- rw = scr->width - rx;
- if ((ry + rh) > scr->height)
- rh = scr->height - ry;
+ scrot_nice_clip(&rx, &ry, &rw, &rh);
XBell(disp, 0);
im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);
@@ -371,6 +342,72 @@
return im;
}
+/* clip rectangle nicely */
+void
+scrot_nice_clip(int *rx,
+ int *ry,
+ int *rw,
+ int *rh)
+{
+ if (*rx < 0) {
+ *rw += *rx;
+ *rx = 0;
+ }
+ if (*ry < 0) {
+ *rh += *ry;
+ *ry = 0;
+ }
+ if ((*rx + *rw) > scr->width)
+ *rw = scr->width - *rx;
+ if ((*ry + *rh) > scr->height)
+ *rh = scr->height - *ry;
+}
+
+/* get geometry of window and use that */
+int
+scrot_get_geometry(Window target,
+ int *rx,
+ int *ry,
+ int *rw,
+ int *rh)
+{
+ Window child;
+ XWindowAttributes attr;
+ int stat;
+
+ /* get windowmanager frame of window */
+ if (target != root) {
+ unsigned int d, x;
+ int status;
+
+ status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
+ if (status != 0) {
+ Window rt, *children, parent;
+
+ for (;;) {
+ /* Find window manager frame. */
+ status = XQueryTree(disp, target, &rt, &parent, &children, &d);
+ if (status && (children != None))
+ XFree((char *) children);
+ if (!status || (parent == None) || (parent == rt))
+ break;
+ target = parent;
+ }
+ /* Get client window. */
+ if (!opt.border)
+ target = scrot_get_client_window(disp, target);
+ XRaiseWindow(disp, target);
+ }
+ }
+ stat = XGetWindowAttributes(disp, target, &attr);
+ if ((stat == False) || (attr.map_state != IsViewable))
+ return 0;
+ *rw = attr.width;
+ *rh = attr.height;
+ XTranslateCoordinates(disp, target, root, 0, 0, rx, ry, &child);
+ return 1;
+}
+
Window
scrot_get_window(Display * display,
Window window,
--- End Message ---