1 Description: src/options.c (scrot_parse_option_array): add --focused option.
2 src/main.c (scrot_get_geometry, scrot_nice_clip): new functions
3 src/main.c (scrot_grab_focused): new function to grab currently
4 Author: James Cameron <quozl@us.netrek.org>
5 Last-Update: 2009-05-19
6 Index: scrot-0.8/src/options.h
7 ===================================================================
8 --- scrot-0.8.orig/src/options.h
9 +++ scrot-0.8/src/options.h
10 @@ -32,6 +32,7 @@ struct __scrotoptions
18 Index: scrot-0.8/src/options.c
19 ===================================================================
20 --- scrot-0.8.orig/src/options.c
21 +++ scrot-0.8/src/options.c
22 @@ -44,13 +44,15 @@ init_parse_options(int argc, char **argv
24 scrot_parse_option_array(int argc, char **argv)
26 - static char stropts[] = "bcd:e:hmq:st:v+:";
27 + static char stropts[] = "bcd:e:hmq:st:uv+:";
28 static struct option lopts[] = {
30 {"help", 0, 0, 'h'}, /* okay */
31 {"version", 0, 0, 'v'}, /* okay */
33 {"select", 0, 0, 's'},
34 + {"focused", 0, 0, 'u'},
35 + {"focussed", 0, 0, 'u'}, /* macquarie dictionary has both spellings */
36 {"border", 0, 0, 'b'},
37 {"multidisp", 0, 0, 'm'},
39 @@ -95,6 +97,9 @@ scrot_parse_option_array(int argc, char
47 opt.debug_level = atoi(optarg);
49 @@ -231,6 +236,7 @@ show_usage(void)
50 " and join them together.\n"
51 " -s, --select interactively choose a window or rectangle\n"
53 + " -u, --focused use the currently focused window\n"
54 " -t, --thumb NUM generate thumbnail too. NUM is the percentage\n"
55 " of the original size for the thumbnail to be,\n"
56 " or the geometry in percent, e.g. 50x60 or 80x20.\n"
57 Index: scrot-0.8/src/scrot.h
58 ===================================================================
59 --- scrot-0.8.orig/src/scrot.h
60 +++ scrot-0.8/src/scrot.h
61 @@ -72,7 +72,10 @@ void scrot_exec_app(Imlib_Image image, s
62 char *filename_im, char *filename_thumb);
63 void scrot_do_delay(void);
64 Imlib_Image scrot_sel_and_grab_image(void);
65 +Imlib_Image scrot_grab_focused(void);
66 void scrot_sel_area(int *x, int *y, int *w, int *h);
67 +void scrot_nice_clip(int *rx, int *ry, int *rw, int *rh);
68 +int scrot_get_geometry(Window target, int *rx, int *ry, int *rw, int *rh);
69 Window scrot_get_window(Display *display,Window window,int x,int y);
70 Window scrot_get_client_window(Display * display, Window target);
71 Window scrot_find_window_by_property(Display * display, const Window window,
72 Index: scrot-0.8/src/main.c
73 ===================================================================
74 --- scrot-0.8.orig/src/main.c
75 +++ scrot-0.8/src/main.c
76 @@ -48,7 +48,9 @@ main(int argc,
82 + image = scrot_grab_focused();
83 + else if (opt.select)
84 image = scrot_sel_and_grab_image();
87 @@ -171,6 +173,22 @@ scrot_exec_app(Imlib_Image image, struct
91 +scrot_grab_focused(void)
93 + Imlib_Image im = NULL;
94 + int rx = 0, ry = 0, rw = 0, rh = 0;
95 + Window target = None;
99 + XGetInputFocus(disp, &target, &ignored);
100 + if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL;
101 + scrot_nice_clip(&rx, &ry, &rw, &rh);
102 + im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);
107 scrot_sel_and_grab_image(void)
109 Imlib_Image im = NULL;
110 @@ -313,57 +331,10 @@ scrot_sel_and_grab_image(void)
115 - XWindowAttributes attr;
118 /* else it's a window click */
119 - /* get geometry of window and use that */
120 - /* get windowmanager frame of window */
121 - if (target != root) {
125 - status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
127 - Window rt, *children, parent;
130 - /* Find window manager frame. */
131 - status = XQueryTree(disp, target, &rt, &parent, &children, &d);
132 - if (status && (children != None))
133 - XFree((char *) children);
134 - if (!status || (parent == None) || (parent == rt))
138 - /* Get client window. */
140 - target = scrot_get_client_window(disp, target);
141 - XRaiseWindow(disp, target);
144 - stat = XGetWindowAttributes(disp, target, &attr);
145 - if ((stat == False) || (attr.map_state != IsViewable))
149 - XTranslateCoordinates(disp, target, root, 0, 0, &rx, &ry, &child);
152 - /* clip rectangle nicely */
156 + if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL;
162 - if ((rx + rw) > scr->width)
163 - rw = scr->width - rx;
164 - if ((ry + rh) > scr->height)
165 - rh = scr->height - ry;
166 + scrot_nice_clip(&rx, &ry, &rw, &rh);
169 im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);
170 @@ -371,6 +342,72 @@ scrot_sel_and_grab_image(void)
174 +/* clip rectangle nicely */
176 +scrot_nice_clip(int *rx,
189 + if ((*rx + *rw) > scr->width)
190 + *rw = scr->width - *rx;
191 + if ((*ry + *rh) > scr->height)
192 + *rh = scr->height - *ry;
195 +/* get geometry of window and use that */
197 +scrot_get_geometry(Window target,
204 + XWindowAttributes attr;
207 + /* get windowmanager frame of window */
208 + if (target != root) {
212 + status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
214 + Window rt, *children, parent;
217 + /* Find window manager frame. */
218 + status = XQueryTree(disp, target, &rt, &parent, &children, &d);
219 + if (status && (children != None))
220 + XFree((char *) children);
221 + if (!status || (parent == None) || (parent == rt))
225 + /* Get client window. */
227 + target = scrot_get_client_window(disp, target);
228 + XRaiseWindow(disp, target);
231 + stat = XGetWindowAttributes(disp, target, &attr);
232 + if ((stat == False) || (attr.map_state != IsViewable))
236 + XTranslateCoordinates(disp, target, root, 0, 0, rx, ry, &child);
241 scrot_get_window(Display * display,