qi: publish new version (1.0-rc59). Final RC version
[dragora.git] / patches / scrot / 04-focused.patch
blobd0f0b5f42040e63e7f30d67a13a09760429c881c
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
11 int delay;
12 int countdown;
13 int select;
14 + int focused;
15 int quality;
16 int border;
17 int multidisp;
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
23 static void
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[] = {
29 /* actions */
30 {"help", 0, 0, 'h'}, /* okay */
31 {"version", 0, 0, 'v'}, /* okay */
32 {"count", 0, 0, 'c'},
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'},
38 /* toggles */
39 @@ -95,6 +97,9 @@ scrot_parse_option_array(int argc, char
40 case 's':
41 opt.select = 1;
42 break;
43 + case 'u':
44 + opt.focused = 1;
45 + break;
46 case '+':
47 opt.debug_level = atoi(optarg);
48 break;
49 @@ -231,6 +236,7 @@ show_usage(void)
50 " and join them together.\n"
51 " -s, --select interactively choose a window or rectangle\n"
52 " with the mouse\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,
80 - if (opt.select)
81 + if (opt.focused)
82 + image = scrot_grab_focused();
83 + else if (opt.select)
84 image = scrot_sel_and_grab_image();
85 else {
86 scrot_do_delay();
87 @@ -171,6 +173,22 @@ scrot_exec_app(Imlib_Image image, struct
90 Imlib_Image
91 +scrot_grab_focused(void)
93 + Imlib_Image im = NULL;
94 + int rx = 0, ry = 0, rw = 0, rh = 0;
95 + Window target = None;
96 + int ignored;
98 + scrot_do_delay();
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);
103 + return im;
106 +Imlib_Image
107 scrot_sel_and_grab_image(void)
109 Imlib_Image im = NULL;
110 @@ -313,57 +331,10 @@ scrot_sel_and_grab_image(void)
111 rh = 0 - rh;
113 } else {
114 - Window child;
115 - XWindowAttributes attr;
116 - int stat;
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) {
122 - unsigned int d, x;
123 - int status;
125 - status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
126 - if (status != 0) {
127 - Window rt, *children, parent;
129 - for (;;) {
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))
135 - break;
136 - target = parent;
138 - /* Get client window. */
139 - if (!opt.border)
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))
146 - return NULL;
147 - rw = attr.width;
148 - rh = attr.height;
149 - XTranslateCoordinates(disp, target, root, 0, 0, &rx, &ry, &child);
152 - /* clip rectangle nicely */
153 - if (rx < 0) {
154 - rw += rx;
155 - rx = 0;
156 + if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL;
158 - if (ry < 0) {
159 - rh += ry;
160 - ry = 0;
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);
168 XBell(disp, 0);
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)
171 return im;
174 +/* clip rectangle nicely */
175 +void
176 +scrot_nice_clip(int *rx,
177 + int *ry,
178 + int *rw,
179 + int *rh)
181 + if (*rx < 0) {
182 + *rw += *rx;
183 + *rx = 0;
185 + if (*ry < 0) {
186 + *rh += *ry;
187 + *ry = 0;
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 */
196 +int
197 +scrot_get_geometry(Window target,
198 + int *rx,
199 + int *ry,
200 + int *rw,
201 + int *rh)
203 + Window child;
204 + XWindowAttributes attr;
205 + int stat;
207 + /* get windowmanager frame of window */
208 + if (target != root) {
209 + unsigned int d, x;
210 + int status;
212 + status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
213 + if (status != 0) {
214 + Window rt, *children, parent;
216 + for (;;) {
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))
222 + break;
223 + target = parent;
225 + /* Get client window. */
226 + if (!opt.border)
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))
233 + return 0;
234 + *rw = attr.width;
235 + *rh = attr.height;
236 + XTranslateCoordinates(disp, target, root, 0, 0, rx, ry, &child);
237 + return 1;
240 Window
241 scrot_get_window(Display * display,
242 Window window,