13
#include <X11/extensions/shape.h>
15
#include "libgimpbase/gimpbase.h"
16
#include "libgimpconfig/gimpconfig.h"
17
#include "libgimpmodule/gimpmodule.h"
18
#include "libgimpwidgets/gimpwidgets.h"
19
#include "libgimpwidgets/gimpwidgets-private.h"
27
find_toplevel_window (Display *display,
30
Window root, parent, *children;
35
if (XQueryTree (display, xid,
36
&root, &parent, &children, &nchildren) == 0)
38
g_warning ("Couldn't find window manager window");
51
add_border_to_shot (GdkPixbuf *pixbuf)
55
retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
56
gdk_pixbuf_get_width (pixbuf) + 2,
57
gdk_pixbuf_get_height (pixbuf) + 2);
59
/* Fill with solid black */
60
gdk_pixbuf_fill (retval, 0x000000FF);
62
gdk_pixbuf_copy_area (pixbuf,
64
gdk_pixbuf_get_width (pixbuf),
65
gdk_pixbuf_get_height (pixbuf),
72
remove_shaped_area (GdkPixbuf *pixbuf,
77
XRectangle *rectangles;
78
gint rectangle_count, rectangle_order;
81
retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
82
gdk_pixbuf_get_width (pixbuf),
83
gdk_pixbuf_get_height (pixbuf));
85
gdk_pixbuf_fill (retval, 0);
87
display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
89
rectangles = XShapeGetRectangles (display, window, ShapeBounding,
90
&rectangle_count, &rectangle_order);
92
for (i = 0; i < rectangle_count; i++)
96
for (y = rectangles[i].y;
97
y < rectangles[i].y + rectangles[i].height;
100
const guchar *src_pixels;
103
src_pixels = gdk_pixbuf_get_pixels (pixbuf) +
104
y * gdk_pixbuf_get_rowstride (pixbuf) +
105
rectangles[i].x * (gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3);
107
dest_pixels = gdk_pixbuf_get_pixels (retval) +
108
y * gdk_pixbuf_get_rowstride (retval) +
111
for (x = rectangles[i].x;
112
x < rectangles[i].x + rectangles[i].width;
115
*dest_pixels++ = *src_pixels ++;
116
*dest_pixels++ = *src_pixels ++;
117
*dest_pixels++ = *src_pixels ++;
118
*dest_pixels++ = 255;
120
if (gdk_pixbuf_get_has_alpha (pixbuf))
130
take_window_shot (Window child,
131
gboolean include_decoration)
140
GdkPixbuf *tmp, *tmp2;
143
display = gdk_display_get_default ();
144
screen = gdk_screen_get_default ();
146
if (include_decoration)
147
xid = find_toplevel_window (gdk_x11_display_get_xdisplay (display), child);
151
window = gdk_window_foreign_new_for_display (display, xid);
153
gdk_drawable_get_size (window, &width, &height);
154
gdk_window_get_origin (window, &x_orig, &y_orig);
159
width = width + x_orig;
166
height = height + y_orig;
170
if (x_orig + width > gdk_screen_get_width (screen))
171
width = gdk_screen_get_width (screen) - x_orig;
173
if (y_orig + height > gdk_screen_get_height (screen))
174
height = gdk_screen_get_height (screen) - y_orig;
176
tmp = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
177
x, y, 0, 0, width, height);
179
if (include_decoration)
180
tmp2 = remove_shaped_area (tmp, xid);
182
tmp2 = add_border_to_shot (tmp);
184
retval = create_shadowed_pixbuf (tmp2);
186
g_object_unref (tmp);
187
g_object_unref (tmp2);
193
shooter_get_foreground (GimpRGB *color)
195
color->r = color->g = color->b = 0.0;
201
shooter_get_background (GimpRGB *color)
203
color->r = color->g = color->b = 1.0;
209
shooter_standard_help (const gchar *help_id,
215
shooter_ensure_modules (void)
217
static GimpModuleDB *module_db = NULL;
221
gchar *config = gimp_config_build_plug_in_path ("modules");
222
gchar *path = gimp_config_path_expand (config, TRUE, NULL);
224
module_db = gimp_module_db_new (FALSE);
225
gimp_module_db_load (module_db, path);
233
main (int argc, char **argv)
235
GdkPixbuf *screenshot = NULL;
239
g_set_application_name ("GIMP documention shooter");
241
/* If there's no DISPLAY, we silently error out.
242
* We don't want to break headless builds.
244
if (! gtk_init_check (&argc, &argv))
247
gtk_rc_add_default_file (gimp_gtkrc ());
251
gimp_widgets_init (shooter_standard_help,
252
shooter_get_foreground,
253
shooter_get_background,
254
shooter_ensure_modules);
256
toplevels = get_all_widgets ();
258
for (node = toplevels; node; node = g_list_next (node))
267
gtk_widget_show (info->window);
269
window = info->window->window;
271
gtk_widget_show_now (info->window);
272
gtk_widget_queue_draw (info->window);
274
while (gtk_events_pending ())
276
gtk_main_iteration ();
280
while (gtk_events_pending ())
282
gtk_main_iteration ();
285
xid = gdk_x11_drawable_get_xid (GDK_DRAWABLE (window));
286
screenshot = take_window_shot (xid, info->include_decorations);
288
filename = g_strdup_printf ("%s.png", info->name);
289
gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
292
gtk_widget_hide (info->window);