~dbarth/compiz/reworked-fix-744104

« back to all changes in this revision

Viewing changes to unity/unity_window_decorator/src/gdk.c

  • Committer: David Barth
  • Date: 2011-04-05 20:20:54 UTC
  • Revision ID: david.barth@canonical.com-20110405202054-fnh0y5t2s228mf4k
re-integrate the unity-window-decorator, for real this time

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gtk-window-decorator.h"
 
2
 
 
3
GdkPixmap *
 
4
pixmap_new_from_pixbuf (GdkPixbuf *pixbuf, int depth)
 
5
{
 
6
    GdkPixmap *pixmap;
 
7
    guint     width, height;
 
8
    cairo_t   *cr;
 
9
 
 
10
    width  = gdk_pixbuf_get_width (pixbuf);
 
11
    height = gdk_pixbuf_get_height (pixbuf);
 
12
 
 
13
    pixmap = create_pixmap (width, height, depth);
 
14
    if (!pixmap)
 
15
        return NULL;
 
16
 
 
17
    cr = (cairo_t *) gdk_cairo_create (GDK_DRAWABLE (pixmap));
 
18
    gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
 
19
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
20
    cairo_paint (cr);
 
21
    cairo_destroy (cr);
 
22
 
 
23
    return pixmap;
 
24
}
 
25
 
 
26
 
 
27
void
 
28
gdk_cairo_set_source_color_alpha (cairo_t  *cr,
 
29
                                  GdkColor *color,
 
30
                                  double   alpha)
 
31
{
 
32
    cairo_set_source_rgba (cr,
 
33
                           color->red   / 65535.0,
 
34
                           color->green / 65535.0,
 
35
                           color->blue  / 65535.0,
 
36
                           alpha);
 
37
}
 
38
 
 
39
inline GdkWindow *
 
40
create_gdk_window (Window xframe)
 
41
{
 
42
    GdkDisplay  *display = gdk_display_get_default ();
 
43
    GdkScreen   *screen  = gdk_display_get_default_screen (display);
 
44
    GdkWindow   *window  = gdk_window_foreign_new (xframe);
 
45
    GdkColormap *cmap    = gdk_screen_get_rgb_colormap (screen);
 
46
 
 
47
    gdk_drawable_set_colormap (GDK_DRAWABLE (window), cmap);
 
48
 
 
49
    return window;
 
50
}
 
51
 
 
52
GdkColormap *
 
53
get_colormap_for_drawable (GdkDrawable *d)
 
54
{
 
55
    GdkDisplay *display = gdk_display_get_default ();
 
56
    GdkScreen  *screen  = gdk_display_get_default_screen (display);
 
57
 
 
58
    if (gdk_drawable_get_depth (d) == 32)
 
59
        return gdk_screen_get_rgba_colormap (screen);
 
60
 
 
61
    return gdk_screen_get_rgb_colormap (screen);
 
62
}
 
63
 
 
64
XRenderPictFormat *
 
65
get_format_for_drawable (decor_t *d, GdkDrawable *drawable)
 
66
{
 
67
    if (!d->frame_window || gdk_drawable_get_depth (drawable) == 32)
 
68
        return xformat_rgba;
 
69
 
 
70
    return xformat_rgb;
 
71
}
 
72
 
 
73
GdkPixmap *
 
74
create_pixmap (int w,
 
75
               int h,
 
76
               int depth)
 
77
{
 
78
    GtkWidget *widget;
 
79
    GdkWindow *window;
 
80
 
 
81
    if (w == 0 || h == 0)
 
82
        abort ();
 
83
 
 
84
    widget = (depth > 24) ? style_window_rgba : style_window_rgb;
 
85
    window = gtk_widget_get_window (widget);
 
86
    return gdk_pixmap_new (GDK_DRAWABLE (window), w, h, depth);
 
87
}
 
 
b'\\ No newline at end of file'