~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to gnome-panel/panel-background-monitor.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.3.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: james.westby@ubuntu.com-20110530110449-ut1tc5t61rpvf9e3
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <gdk/gdkx.h>
31
31
#include <X11/Xlib.h>
32
32
#include <X11/Xatom.h>
 
33
#include <cairo-xlib.h>
 
34
 
 
35
#include <libgnome-desktop/gnome-bg.h>
33
36
 
34
37
#include "panel-background-monitor.h"
35
38
#include "panel-util.h"
61
64
        Atom       xatom;
62
65
        GdkAtom    gdkatom;
63
66
 
64
 
        GdkPixmap *gdkpixmap;
65
 
        GdkPixbuf *gdkpixbuf;
 
67
        cairo_surface_t *surface;
 
68
        GdkPixbuf *gdkpixbuf;
66
69
 
67
70
        int        width;
68
71
        int        height;
88
91
        g_signal_handlers_disconnect_by_func (monitor->screen, 
89
92
                panel_background_monitor_changed, monitor);
90
93
 
91
 
        if (monitor->gdkpixmap)
92
 
                g_object_unref (monitor->gdkpixmap);
93
 
        monitor->gdkpixmap = NULL;
 
94
        if (monitor->surface)
 
95
                cairo_surface_destroy (monitor->surface);
 
96
        monitor->surface= NULL;
94
97
 
95
98
        if (monitor->gdkpixbuf)
96
99
                g_object_unref (monitor->gdkpixbuf);
127
130
        monitor->gdkatom = gdk_atom_intern_static_string ("_XROOTPMAP_ID");
128
131
        monitor->xatom   = gdk_x11_atom_to_xatom (monitor->gdkatom);
129
132
 
130
 
        monitor->gdkpixmap = NULL;
 
133
        monitor->surface = NULL;
131
134
        monitor->gdkpixbuf = NULL;
132
135
 
133
136
        monitor->display_grabbed = FALSE;
148
151
            G_CALLBACK (panel_background_monitor_changed), monitor);
149
152
 
150
153
        monitor->gdkwindow = gdk_screen_get_root_window (screen);
151
 
        monitor->xwindow   = gdk_x11_drawable_get_xid (monitor->gdkwindow);
 
154
        monitor->xwindow   = GDK_WINDOW_XID (monitor->gdkwindow);
152
155
 
153
156
        gdk_window_add_filter (
154
157
                monitor->gdkwindow, panel_background_monitor_xevent_filter, monitor);
202
205
static void
203
206
panel_background_monitor_changed (PanelBackgroundMonitor *monitor)
204
207
{
205
 
        if (monitor->gdkpixmap)
206
 
                g_object_unref (monitor->gdkpixmap);
207
 
        monitor->gdkpixmap = NULL;
 
208
        if (monitor->surface)
 
209
                cairo_surface_destroy (monitor->surface);
 
210
        monitor->surface = NULL;
208
211
 
209
212
        if (monitor->gdkpixbuf)
210
213
                g_object_unref (monitor->gdkpixbuf);
234
237
        return GDK_FILTER_CONTINUE;
235
238
}
236
239
 
237
 
static void
238
 
panel_background_monitor_setup_pixmap (PanelBackgroundMonitor *monitor)
239
 
{
240
 
        Pixmap  *prop_data = NULL;
241
 
        GdkAtom  prop_type;
242
 
 
243
 
        g_assert (monitor->display_grabbed);
244
 
 
245
 
        if (!gdk_property_get (
246
 
                monitor->gdkwindow, monitor->gdkatom,
247
 
                gdk_x11_xatom_to_atom (XA_PIXMAP), 0, 10, 
248
 
                FALSE, &prop_type, NULL, NULL, (gpointer) &prop_data))
249
 
                return;
250
 
 
251
 
        if ((prop_type == GDK_TARGET_PIXMAP) && prop_data && prop_data [0]) {
252
 
                GdkDisplay *display;
253
 
 
254
 
                g_assert (monitor->gdkpixmap == NULL);
255
 
 
256
 
                display = gdk_screen_get_display (monitor->screen);
257
 
 
258
 
                monitor->gdkpixmap = gdk_pixmap_foreign_new_for_display (display,
259
 
                                                                         prop_data [0]);
260
 
 
261
 
                if (!monitor->gdkpixmap)
262
 
                        g_warning ("couldn't get background pixmap\n");
263
 
        }
264
 
 
265
 
        g_free (prop_data);
266
 
}
267
 
 
268
240
static GdkPixbuf *
269
241
panel_background_monitor_tile_background (PanelBackgroundMonitor *monitor,
270
242
                                          int                     width,
333
305
static void 
334
306
panel_background_monitor_setup_pixbuf (PanelBackgroundMonitor *monitor)
335
307
{
336
 
        GdkColormap *colormap = NULL;
337
308
        GdkDisplay  *display;
338
309
        int          rwidth, rheight;
339
310
        int          pwidth, pheight;
343
314
        gdk_x11_display_grab (display);
344
315
        monitor->display_grabbed = TRUE;
345
316
 
346
 
        if (!monitor->gdkpixmap)
347
 
                panel_background_monitor_setup_pixmap (monitor);
 
317
        if (!monitor->surface)
 
318
              monitor->surface = gnome_bg_get_surface_from_root (monitor->screen);
348
319
 
349
 
        if (!monitor->gdkpixmap) {
 
320
        if (!monitor->surface) {
 
321
                g_warning ("couldn't get background pixmap\n");
350
322
                gdk_x11_display_ungrab (display);
351
323
                monitor->display_grabbed = FALSE;
352
324
                return;
353
325
        }
354
326
 
355
 
        gdk_drawable_get_size (
356
 
                GDK_DRAWABLE (monitor->gdkpixmap), &pwidth, &pheight);
 
327
        pwidth = cairo_xlib_surface_get_width (monitor->surface);
 
328
        pheight = cairo_xlib_surface_get_height (monitor->surface);
357
329
 
358
330
        gdk_window_get_geometry (monitor->gdkwindow,
359
 
                                 NULL, NULL, &rwidth, &rheight, NULL);
 
331
                                 NULL, NULL, &rwidth, &rheight);
360
332
 
361
333
        monitor->width  = MIN (pwidth,  rwidth);
362
334
        monitor->height = MIN (pheight, rheight);
363
335
 
364
 
        colormap = gdk_drawable_get_colormap (monitor->gdkwindow);
365
 
 
366
336
        g_assert (monitor->gdkpixbuf == NULL);
367
 
        monitor->gdkpixbuf = gdk_pixbuf_get_from_drawable (
368
 
                                        NULL, monitor->gdkpixmap, colormap,
369
 
                                        0, 0, 0, 0, 
370
 
                                        monitor->width, monitor->height);
 
337
        monitor->gdkpixbuf = gdk_pixbuf_get_from_surface (monitor->surface,
 
338
                                                          0, 0, monitor->width, monitor->height);
371
339
 
372
340
        gdk_x11_display_ungrab (display);
373
341
        monitor->display_grabbed = FALSE;