[vte] Clean up vtebg
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] Clean up vtebg
- Date: Sat, 3 Apr 2010 21:47:09 +0000 (UTC)
commit 61e12fa671c2af5766ba28077a788423355bb5c1
Author: Christian Persch <chpe gnome org>
Date: Sat Apr 3 18:59:03 2010 +0200
Clean up vtebg
Fixes build with !GDK_WINDOWING_X11. Bug #614469.
src/vtebg.c | 191 +++++++++++++++++++++++++++++----------------------------
src/vtebg.h | 19 +++---
src/vtedraw.c | 2 +-
src/vtedraw.h | 2 +-
4 files changed, 107 insertions(+), 107 deletions(-)
---
diff --git a/src/vtebg.c b/src/vtebg.c
index 8767ea7..9357020 100644
--- a/src/vtebg.c
+++ b/src/vtebg.c
@@ -17,38 +17,52 @@
*/
#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
-#include <cairo-xlib.h>
#include "debug.h"
#include "marshal.h"
#include "vtebg.h"
#include <glib/gi18n-lib.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#include <cairo-xlib.h>
+#endif
+
G_DEFINE_TYPE(VteBg, vte_bg, G_TYPE_OBJECT)
-struct VteBgPrivate {
+struct _VteBgPrivate {
GList *cache;
+ GdkScreen *screen;
+#ifdef GDK_WINDOWING_X11
+ cairo_surface_t *root_surface;
+ struct {
+ GdkDisplay *display;
+ GdkWindow *window;
+ XID native_window;
+ GdkAtom atom;
+ Atom native_atom;
+ } native;
+#endif
};
-struct VteBgCacheItem {
- enum VteBgSourceType source_type;
+typedef struct {
+ VteBgSourceType source_type;
GdkPixbuf *source_pixbuf;
char *source_file;
PangoColor tint_color;
double saturation;
cairo_surface_t *surface;
-};
-
+} VteBgCacheItem;
-static void vte_bg_cache_item_free(struct VteBgCacheItem *item);
+static void vte_bg_cache_item_free(VteBgCacheItem *item);
static void vte_bg_cache_prune_int(VteBg *bg, gboolean root);
static const cairo_user_data_key_t item_surface_key;
-
#if 0
static const char *
vte_bg_source_name(enum VteBgSourceType type)
@@ -71,35 +85,14 @@ vte_bg_source_name(enum VteBgSourceType type)
}
#endif
-#ifndef X_DISPLAY_MISSING
-
-#include <gdk/gdkx.h>
-
-struct VteBgNative {
- GdkDisplay *display;
- GdkWindow *window;
- XID native_window;
- GdkAtom atom;
- Atom native_atom;
-};
-
-static struct VteBgNative *
-vte_bg_native_new(GdkWindow *window)
-{
- struct VteBgNative *pvt;
- pvt = g_slice_new(struct VteBgNative);
- pvt->window = window;
- pvt->native_window = gdk_x11_drawable_get_xid(window);
- pvt->display = gdk_drawable_get_display(GDK_DRAWABLE(window));
- pvt->native_atom = gdk_x11_get_xatom_by_name_for_display(pvt->display, "_XROOTPMAP_ID");
- pvt->atom = gdk_x11_xatom_to_atom_for_display(pvt->display, pvt->native_atom);
- return pvt;
-}
+#ifdef GDK_WINDOWING_X11
static void
_vte_bg_display_sync(VteBg *bg)
{
- gdk_display_sync(bg->native->display);
+ VteBgPrivate *pvt = bg->pvt;
+
+ gdk_display_sync(pvt->native.display);
}
static gboolean
@@ -117,6 +110,7 @@ _vte_property_get_pixmaps(GdkWindow *window, GdkAtom atom,
static cairo_surface_t *
vte_bg_root_surface(VteBg *bg)
{
+ VteBgPrivate *pvt = bg->pvt;
GdkPixmap *pixmap;
GdkAtom prop_type;
int prop_size;
@@ -131,9 +125,9 @@ vte_bg_root_surface(VteBg *bg)
pixmap = NULL;
pixmaps = NULL;
gdk_error_trap_push();
- if (!_vte_property_get_pixmaps(bg->native->window, bg->native->atom,
- &prop_type, &prop_size,
- &pixmaps))
+ if (!_vte_property_get_pixmaps(pvt->native.window, pvt->native.atom,
+ &prop_type, &prop_size,
+ &pixmaps))
goto out;
if ((prop_type != GDK_TARGET_PIXMAP) ||
@@ -141,13 +135,13 @@ vte_bg_root_surface(VteBg *bg)
(pixmaps == NULL)))
goto out_pixmaps;
- if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (bg->native->display),
+ if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (pvt->native.display),
pixmaps[0], &root,
&x, &y, &width, &height, &border_width, &depth))
goto out_pixmaps;
- display = gdk_x11_display_get_xdisplay (bg->native->display);
- screen = gdk_x11_screen_get_xscreen (bg->screen);
+ display = gdk_x11_display_get_xdisplay (pvt->native.display);
+ screen = gdk_x11_screen_get_xscreen (pvt->screen);
surface = cairo_xlib_surface_create (display,
pixmaps[0],
DefaultVisualOfScreen(screen),
@@ -169,27 +163,30 @@ vte_bg_root_surface(VteBg *bg)
static void
vte_bg_set_root_surface(VteBg *bg, cairo_surface_t *surface)
{
- if (bg->root_surface != NULL) {
- cairo_surface_destroy (bg->root_surface);
+ VteBgPrivate *pvt = bg->pvt;
+
+ if (pvt->root_surface != NULL) {
+ cairo_surface_destroy (pvt->root_surface);
}
- bg->root_surface = surface;
+ pvt->root_surface = surface;
vte_bg_cache_prune_int (bg, TRUE);
g_signal_emit_by_name(bg, "root-pixmap-changed");
}
-
static GdkFilterReturn
vte_bg_root_filter(GdkXEvent *native, GdkEvent *event, gpointer data)
{
XEvent *xevent = (XEvent*) native;
VteBg *bg;
+ VteBgPrivate *pvt;
cairo_surface_t *surface;
switch (xevent->type) {
case PropertyNotify:
bg = VTE_BG(data);
- if ((xevent->xproperty.window == bg->native->native_window) &&
- (xevent->xproperty.atom == bg->native->native_atom)) {
+ pvt = bg->pvt;
+ if ((xevent->xproperty.window == pvt->native.native_window) &&
+ (xevent->xproperty.atom == pvt->native.native_atom)) {
surface = vte_bg_root_surface(bg);
vte_bg_set_root_surface(bg, surface);
}
@@ -200,33 +197,7 @@ vte_bg_root_filter(GdkXEvent *native, GdkEvent *event, gpointer data)
return GDK_FILTER_CONTINUE;
}
-#else
-
-struct VteBgNative {
- guchar filler;
-};
-static struct VteBgNative *
-vte_bg_native_new(GdkWindow *window)
-{
- return NULL;
-}
-static GdkFilterReturn
-vte_bg_root_filter(GdkXEvent *xevent, GdkEvent *event, gpointer data)
-{
- return GDK_FILTER_CONTINUE;
-}
-static void
-_vte_bg_display_sync(VteBg *bg)
-{
-}
-
-static GdkPixmap *
-vte_bg_root_pixmap(VteBg *bg)
-{
- return NULL;
-}
-#endif
-
+#endif /* GDK_WINDOWING_X11 */
static void
vte_bg_finalize (GObject *obj)
@@ -263,13 +234,13 @@ vte_bg_class_init(VteBgClass *klass)
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- g_type_class_add_private(klass, sizeof (struct VteBgPrivate));
+ g_type_class_add_private(klass, sizeof (VteBgPrivate));
}
static void
vte_bg_init(VteBg *bg)
{
- bg->pvt = G_TYPE_INSTANCE_GET_PRIVATE (bg, VTE_TYPE_BG, struct VteBgPrivate);
+ bg->pvt = G_TYPE_INSTANCE_GET_PRIVATE (bg, VTE_TYPE_BG, VteBgPrivate);
}
/**
@@ -284,25 +255,37 @@ vte_bg_init(VteBg *bg)
VteBg *
vte_bg_get_for_screen(GdkScreen *screen)
{
- GdkEventMask events;
- GdkWindow *window;
VteBg *bg;
bg = g_object_get_data(G_OBJECT(screen), "vte-bg");
if (G_UNLIKELY(bg == NULL)) {
+ VteBgPrivate *pvt;
+
bg = g_object_new(VTE_TYPE_BG, NULL);
g_object_set_data_full(G_OBJECT(screen),
"vte-bg", bg, (GDestroyNotify)g_object_unref);
/* connect bg to screen */
- bg->screen = screen;
+ pvt = bg->pvt;
+ pvt->screen = screen;
+#ifdef GDK_WINDOWING_X11
+ {
+ GdkEventMask events;
+ GdkWindow *window;
+
window = gdk_screen_get_root_window(screen);
- bg->native = vte_bg_native_new(window);
- bg->root_surface = vte_bg_root_surface(bg);
+ pvt->native.window = window;
+ pvt->native.native_window = gdk_x11_drawable_get_xid(window);
+ pvt->native.display = gdk_drawable_get_display(GDK_DRAWABLE(window));
+ pvt->native.native_atom = gdk_x11_get_xatom_by_name_for_display(pvt->native.display, "_XROOTPMAP_ID");
+ pvt->native.atom = gdk_x11_xatom_to_atom_for_display(pvt->native.display, pvt->native.native_atom);
+ pvt->root_surface = vte_bg_root_surface(bg);
events = gdk_window_get_events(window);
events |= GDK_PROPERTY_CHANGE_MASK;
gdk_window_set_events(window, events);
gdk_window_add_filter(window, vte_bg_root_filter, bg);
+ }
+#endif /* GDK_WINDOWING_X11 */
}
return bg;
@@ -317,7 +300,7 @@ vte_bg_colors_equal(const PangoColor *a, const PangoColor *b)
}
static void
-vte_bg_cache_item_free(struct VteBgCacheItem *item)
+vte_bg_cache_item_free(VteBgCacheItem *item)
{
/* Clean up whatever is left in the structure. */
if (item->source_pixbuf != NULL) {
@@ -330,7 +313,7 @@ vte_bg_cache_item_free(struct VteBgCacheItem *item)
cairo_surface_set_user_data (item->surface,
&item_surface_key, NULL, NULL);
- g_slice_free(struct VteBgCacheItem, item);
+ g_slice_free(VteBgCacheItem, item);
}
static void
@@ -338,7 +321,7 @@ vte_bg_cache_prune_int(VteBg *bg, gboolean root)
{
GList *i, *next;
for (i = bg->pvt->cache; i != NULL; i = next) {
- struct VteBgCacheItem *item = i->data;
+ VteBgCacheItem *item = i->data;
next = g_list_next (i);
/* Prune the item if either it is a "root pixmap" item and
* we want to prune them, or its surface is NULL because
@@ -359,7 +342,7 @@ vte_bg_cache_prune(VteBg *bg)
static void item_surface_destroy_func(void *data)
{
- struct VteBgCacheItem *item = data;
+ VteBgCacheItem *item = data;
item->surface = NULL;
}
@@ -367,7 +350,7 @@ static void item_surface_destroy_func(void *data)
/* Add an item to the cache, instructing all of the objects therein to clear
the field which holds a pointer to the object upon its destruction. */
static void
-vte_bg_cache_add(VteBg *bg, struct VteBgCacheItem *item)
+vte_bg_cache_add(VteBg *bg, VteBgCacheItem *item)
{
vte_bg_cache_prune(bg);
bg->pvt->cache = g_list_prepend(bg->pvt->cache, item);
@@ -384,7 +367,7 @@ vte_bg_cache_add(VteBg *bg, struct VteBgCacheItem *item)
additional ref. */
static cairo_surface_t *
vte_bg_cache_search(VteBg *bg,
- enum VteBgSourceType source_type,
+ VteBgSourceType source_type,
const GdkPixbuf *source_pixbuf,
const char *source_file,
const PangoColor *tint,
@@ -394,7 +377,7 @@ vte_bg_cache_search(VteBg *bg,
vte_bg_cache_prune(bg);
for (i = bg->pvt->cache; i != NULL; i = g_list_next(i)) {
- struct VteBgCacheItem *item = i->data;
+ VteBgCacheItem *item = i->data;
if (vte_bg_colors_equal(&item->tint_color, tint) &&
(saturation == item->saturation) &&
(source_type == item->source_type)) {
@@ -424,22 +407,31 @@ vte_bg_cache_search(VteBg *bg,
cairo_surface_t *
vte_bg_get_surface(VteBg *bg,
- enum VteBgSourceType source_type,
+ VteBgSourceType source_type,
GdkPixbuf *source_pixbuf,
const char *source_file,
const PangoColor *tint,
double saturation,
cairo_surface_t *other)
{
- struct VteBgCacheItem *item;
+ VteBgPrivate *pvt;
+ VteBgCacheItem *item;
GdkPixbuf *pixbuf;
cairo_surface_t *cached, *source;
cairo_t *cr;
int width, height;
+ g_return_val_if_fail(VTE_IS_BG(bg), NULL);
+ pvt = bg->pvt;
+
if (source_type == VTE_BG_SOURCE_NONE) {
return NULL;
}
+#ifndef GDK_WINDOWING_X11
+ if (source_type == VTE_BG_SOURCE_ROOT) {
+ return NULL;
+ }
+#endif
cached = vte_bg_cache_search(bg, source_type,
source_pixbuf, source_file,
@@ -448,12 +440,13 @@ vte_bg_get_surface(VteBg *bg,
return cached;
}
- item = g_slice_new(struct VteBgCacheItem);
+ item = g_slice_new(VteBgCacheItem);
item->source_type = source_type;
item->source_pixbuf = NULL;
item->source_file = NULL;
item->tint_color = *tint;
item->saturation = saturation;
+ item->surface = NULL;
source = NULL;
pixbuf = NULL;
@@ -465,7 +458,7 @@ vte_bg_get_surface(VteBg *bg,
pixbuf = g_object_ref (source_pixbuf);
break;
case VTE_BG_SOURCE_FILE:
- if ((source_file != NULL) && (strlen(source_file) > 0)) {
+ if (source_file != NULL && source_file[0] != '\0') {
item->source_file = g_strdup(source_file);
pixbuf = gdk_pixbuf_new_from_file(source_file, NULL);
}
@@ -478,10 +471,15 @@ vte_bg_get_surface(VteBg *bg,
if (pixbuf) {
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
- } else {
- width = cairo_xlib_surface_get_width(bg->root_surface);
- height = cairo_xlib_surface_get_height(bg->root_surface);
}
+#ifdef GDK_WINDOWING_X11
+ else if (source_type == VTE_BG_SOURCE_ROOT) {
+ width = cairo_xlib_surface_get_width(pvt->root_surface);
+ height = cairo_xlib_surface_get_height(pvt->root_surface);
+ }
+#endif
+ else
+ goto out;
item->surface =
cairo_surface_create_similar(other, CAIRO_CONTENT_COLOR_ALPHA,
@@ -491,8 +489,10 @@ vte_bg_get_surface(VteBg *bg,
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
if (pixbuf)
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
- else
- cairo_set_source_surface (cr, bg->root_surface, 0, 0);
+#ifdef GDK_WINDOWING_X11
+ else if (source_type == VTE_BG_SOURCE_ROOT)
+ cairo_set_source_surface (cr, pvt->root_surface, 0, 0);
+#endif
cairo_paint (cr);
if (saturation != 1.0) {
@@ -506,6 +506,7 @@ vte_bg_get_surface(VteBg *bg,
}
cairo_destroy (cr);
+ out:
vte_bg_cache_add(bg, item);
if (pixbuf)
diff --git a/src/vtebg.h b/src/vtebg.h
index 19f5391..cc3e8ab 100644
--- a/src/vtebg.h
+++ b/src/vtebg.h
@@ -24,18 +24,17 @@
G_BEGIN_DECLS
-struct VteBgPrivate;
+typedef struct _VteBg VteBg;
+typedef struct _VteBgPrivate VteBgPrivate;
+typedef struct _VteBgClass VteBgClass;
-typedef struct _VteBg VteBg;
struct _VteBg {
GObject parent;
- GdkScreen *screen;
- cairo_surface_t *root_surface;
- struct VteBgNative *native;
- struct VteBgPrivate *pvt;
+
+ /*< private >*/
+ VteBgPrivate *pvt;
};
-typedef struct _VteBgClass VteBgClass;
struct _VteBgClass {
GObjectClass parent_class;
guint root_pixmap_changed;
@@ -52,16 +51,16 @@ GType vte_bg_get_type(void);
VteBg *vte_bg_get_for_screen(GdkScreen *screen);
-enum VteBgSourceType {
+typedef enum {
VTE_BG_SOURCE_NONE,
VTE_BG_SOURCE_ROOT,
VTE_BG_SOURCE_PIXBUF,
VTE_BG_SOURCE_FILE
-};
+} VteBgSourceType;
cairo_surface_t *
vte_bg_get_surface(VteBg *bg,
- enum VteBgSourceType source_type,
+ VteBgSourceType source_type,
GdkPixbuf *source_pixbuf,
const char *source_file,
const PangoColor *tint,
diff --git a/src/vtedraw.c b/src/vtedraw.c
index 038efb7..c6971e4 100644
--- a/src/vtedraw.c
+++ b/src/vtedraw.c
@@ -886,7 +886,7 @@ _vte_draw_set_background_solid(struct _vte_draw *draw,
void
_vte_draw_set_background_image (struct _vte_draw *draw,
- enum VteBgSourceType type,
+ VteBgSourceType type,
GdkPixbuf *pixbuf,
const char *filename,
const PangoColor *color,
diff --git a/src/vtedraw.h b/src/vtedraw.h
index 510184f..8b98f72 100644
--- a/src/vtedraw.h
+++ b/src/vtedraw.h
@@ -74,7 +74,7 @@ void _vte_draw_set_background_solid(struct _vte_draw *draw,
double blue,
double opacity);
void _vte_draw_set_background_image(struct _vte_draw *draw,
- enum VteBgSourceType type,
+ VteBgSourceType type,
GdkPixbuf *pixbuf,
const char *file,
const PangoColor *color,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]