~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to docs/tools/shooter.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <gdk/gdk.h>
 
2
#include <gtk/gtk.h>
 
3
#include <gdkx.h>
 
4
#include <stdio.h>
 
5
#include <errno.h>
 
6
#include <sys/wait.h>
 
7
#include <unistd.h>
 
8
#include <X11/extensions/shape.h>
 
9
 
 
10
#include <gdk-pixbuf/gdk-pixbuf.h>
 
11
#include <sys/types.h>
 
12
#include <sys/stat.h>
 
13
#include <sys/wait.h>
 
14
#include <signal.h>
 
15
#include <unistd.h>
 
16
#include <stdlib.h>
 
17
#include <fcntl.h>
 
18
#include <errno.h>
 
19
#include <locale.h>
 
20
#include "widgets.h"
 
21
#include "shadow.h"
 
22
 
 
23
#define MAXIMUM_WM_REPARENTING_DEPTH 4
 
24
#ifndef _
 
25
#define _(x) (x)
 
26
#endif
 
27
 
 
28
static Window
 
29
find_toplevel_window (Window xid)
 
30
{
 
31
  Window root, parent, *children;
 
32
  int nchildren;
 
33
 
 
34
  do
 
35
    {
 
36
      if (XQueryTree (GDK_DISPLAY (), xid, &root,
 
37
                      &parent, &children, &nchildren) == 0)
 
38
        {
 
39
          g_warning ("Couldn't find window manager window");
 
40
          return 0;
 
41
        }
 
42
 
 
43
      if (root == parent)
 
44
        return xid;
 
45
 
 
46
      xid = parent;
 
47
    }
 
48
  while (TRUE);
 
49
}
 
50
 
 
51
static GdkPixbuf *
 
52
add_border_to_shot (GdkPixbuf *pixbuf)
 
53
{
 
54
  GdkPixbuf *retval;
 
55
 
 
56
  retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
 
57
                           gdk_pixbuf_get_width (pixbuf) + 2,
 
58
                           gdk_pixbuf_get_height (pixbuf) + 2);
 
59
 
 
60
  /* Fill with solid black */
 
61
  gdk_pixbuf_fill (retval, 0xFF);
 
62
  gdk_pixbuf_copy_area (pixbuf,
 
63
                        0, 0,
 
64
                        gdk_pixbuf_get_width (pixbuf),
 
65
                        gdk_pixbuf_get_height (pixbuf),
 
66
                        retval, 1, 1);
 
67
 
 
68
  return retval;
 
69
}
 
70
 
 
71
static GdkPixbuf *
 
72
remove_shaped_area (GdkPixbuf *pixbuf,
 
73
                    Window     window)
 
74
{
 
75
  GdkPixbuf *retval;
 
76
  XRectangle *rectangles;
 
77
  int rectangle_count, rectangle_order;
 
78
  int i;
 
79
 
 
80
  retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
 
81
                           gdk_pixbuf_get_width (pixbuf),
 
82
                           gdk_pixbuf_get_height (pixbuf));
 
83
  
 
84
  gdk_pixbuf_fill (retval, 0);
 
85
  rectangles = XShapeGetRectangles (GDK_DISPLAY (), window,
 
86
                                    ShapeBounding, &rectangle_count, &rectangle_order);
 
87
 
 
88
  for (i = 0; i < rectangle_count; i++)
 
89
    {
 
90
      int y, x;
 
91
 
 
92
      for (y = rectangles[i].y; y < rectangles[i].y + rectangles[i].height; y++)
 
93
        {
 
94
          guchar *src_pixels, *dest_pixels;
 
95
 
 
96
          src_pixels = gdk_pixbuf_get_pixels (pixbuf) +
 
97
            y * gdk_pixbuf_get_rowstride (pixbuf) +
 
98
            rectangles[i].x * (gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3);
 
99
          dest_pixels = gdk_pixbuf_get_pixels (retval) +
 
100
            y * gdk_pixbuf_get_rowstride (retval) +
 
101
            rectangles[i].x * 4;
 
102
 
 
103
          for (x = rectangles[i].x; x < rectangles[i].x + rectangles[i].width; x++)
 
104
            {
 
105
              *dest_pixels++ = *src_pixels ++;
 
106
              *dest_pixels++ = *src_pixels ++;
 
107
              *dest_pixels++ = *src_pixels ++;
 
108
              *dest_pixels++ = 255;
 
109
 
 
110
              if (gdk_pixbuf_get_has_alpha (pixbuf))
 
111
                src_pixels++;
 
112
            }
 
113
        }
 
114
    }
 
115
 
 
116
  return retval;
 
117
}
 
118
 
 
119
static GdkPixbuf *
 
120
take_window_shot (Window   child,
 
121
                  gboolean include_decoration)
 
122
{
 
123
  GdkWindow *window;
 
124
  Display *disp;
 
125
  Window w, xid;
 
126
  gint x_orig, y_orig;
 
127
  gint x = 0, y = 0;
 
128
  gint width, height;
 
129
 
 
130
  GdkPixbuf *tmp, *tmp2;
 
131
  GdkPixbuf *retval;
 
132
 
 
133
  disp = GDK_DISPLAY ();
 
134
  w = GDK_ROOT_WINDOW ();
 
135
 
 
136
  if (include_decoration)
 
137
    xid = find_toplevel_window (child);
 
138
  else
 
139
    xid = child;
 
140
 
 
141
  window = gdk_window_foreign_new (xid);
 
142
 
 
143
  gdk_drawable_get_size (window, &width, &height);
 
144
  gdk_window_get_origin (window, &x_orig, &y_orig);
 
145
 
 
146
  if (x_orig < 0)
 
147
    {
 
148
      x = - x_orig;
 
149
      width = width + x_orig;
 
150
      x_orig = 0;
 
151
    }
 
152
 
 
153
  if (y_orig < 0)
 
154
    {
 
155
      y = - y_orig;
 
156
      height = height + y_orig;
 
157
      y_orig = 0;
 
158
    }
 
159
 
 
160
  if (x_orig + width > gdk_screen_width ())
 
161
    width = gdk_screen_width () - x_orig;
 
162
 
 
163
  if (y_orig + height > gdk_screen_height ())
 
164
    height = gdk_screen_height () - y_orig;
 
165
 
 
166
  tmp = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
 
167
                                      x, y, 0, 0, width, height);
 
168
 
 
169
  if (include_decoration)
 
170
    tmp2 = remove_shaped_area (tmp, xid);
 
171
  else
 
172
    tmp2 = add_border_to_shot (tmp);
 
173
 
 
174
  retval = create_shadowed_pixbuf (tmp2);
 
175
  g_object_unref (tmp);
 
176
  g_object_unref (tmp2);
 
177
 
 
178
  return retval;
 
179
}
 
180
 
 
181
int main (int argc, char **argv)
 
182
{
 
183
  GList *toplevels;
 
184
  GdkPixbuf *screenshot = NULL;
 
185
  GList *node;
 
186
 
 
187
  /* If there's no DISPLAY, we silently error out.  We don't want to break
 
188
   * headless builds. */
 
189
  if (! gtk_init_check (&argc, &argv))
 
190
    return 0;
 
191
 
 
192
  toplevels = get_all_widgets ();
 
193
 
 
194
  for (node = toplevels; node; node = g_list_next (node))
 
195
    {
 
196
      GdkWindow *window;
 
197
      WidgetInfo *info;
 
198
      XID id;
 
199
      char *filename;
 
200
 
 
201
      info = node->data;
 
202
 
 
203
      gtk_widget_show (info->window);
 
204
 
 
205
      window = info->window->window;
 
206
 
 
207
      gtk_widget_show_now (info->window);
 
208
      gtk_widget_draw (info->window, &(info->window->allocation));
 
209
 
 
210
      while (gtk_events_pending ())
 
211
        {
 
212
          gtk_main_iteration ();
 
213
        }
 
214
      sleep (1);
 
215
 
 
216
      while (gtk_events_pending ())
 
217
        {
 
218
          gtk_main_iteration ();
 
219
        }
 
220
 
 
221
      id = gdk_x11_drawable_get_xid (GDK_DRAWABLE (window));
 
222
      screenshot = take_window_shot (id, info->include_decorations);
 
223
      filename = g_strdup_printf ("./%s.png", info->name);
 
224
      gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
 
225
      g_free(filename);
 
226
      gtk_widget_hide (info->window);
 
227
    }
 
228
 
 
229
  return 0;
 
230
}