summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Sorokin <[email protected]>2017-03-12 15:07:16 +0300
committerAlexei Sorokin <[email protected]>2017-03-12 15:07:16 +0300
commitdc510d875ae166dd814cebc060186b4042b0ef30 (patch)
tree7d4b5b9e8bb16e561d4425a1a01923c6dfbe2bad
parentf8e542223bdd305ac69ed0380b05b9a0c99ad3ab (diff)
downloadcaja-dc510d875ae166dd814cebc060186b4042b0ef30.tar.bz2
caja-dc510d875ae166dd814cebc060186b4042b0ef30.tar.xz
eel: Avoid deprecated gdk_window_set_background functions
-rw-r--r--eel/eel-background-box.c19
-rw-r--r--eel/eel-background.c229
-rw-r--r--eel/eel-background.h5
-rw-r--r--libcaja-private/caja-directory-background.c3
-rw-r--r--libcaja-private/caja-icon-container.c56
-rw-r--r--src/caja-desktop-window.c15
6 files changed, 214 insertions, 113 deletions
diff --git a/eel/eel-background-box.c b/eel/eel-background-box.c
index d0b80c4e..cb1a771e 100644
--- a/eel/eel-background-box.c
+++ b/eel/eel-background-box.c
@@ -30,23 +30,30 @@
G_DEFINE_TYPE (EelBackgroundBox, eel_background_box, GTK_TYPE_EVENT_BOX)
static gboolean
-eel_background_box_draw (GtkWidget *widget,
#if GTK_CHECK_VERSION (3, 0, 0)
+eel_background_box_draw (GtkWidget *widget,
cairo_t *cr)
#else
- GdkEventExpose *event)
+eel_background_box_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
#endif
{
-#if GTK_CHECK_VERSION (3, 0, 0)
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr = gdk_cairo_create (event->window);
+
+ gdk_cairo_rectangle (cr, &event->area);
+ cairo_clip (cr);
+#endif
eel_background_draw (widget, cr);
+#if GTK_CHECK_VERSION (3, 0, 0)
gtk_container_propagate_draw (GTK_CONTAINER (widget),
gtk_bin_get_child (GTK_BIN (widget)),
cr);
#else
- eel_background_draw (widget, event);
gtk_container_propagate_expose (GTK_CONTAINER (widget),
gtk_bin_get_child (GTK_BIN (widget)),
event);
+ cairo_destroy (cr);
#endif
return TRUE;
}
@@ -60,12 +67,12 @@ static void
eel_background_box_class_init (EelBackgroundBoxClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
#if GTK_CHECK_VERSION (3, 0, 0)
widget_class->draw = eel_background_box_draw;
#else
- widget_class->expose_event = eel_background_box_draw;
+ widget_class->expose_event = eel_background_box_expose_event;
#endif
+
}
GtkWidget*
diff --git a/eel/eel-background.c b/eel/eel-background.c
index 1966a85a..98b26176 100644
--- a/eel/eel-background.c
+++ b/eel/eel-background.c
@@ -68,6 +68,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
struct EelBackgroundDetails
{
GtkWidget *widget;
+ GtkWidget *front_widget;
MateBG *bg;
char *color;
@@ -99,6 +100,10 @@ struct EelBackgroundDetails
gboolean is_active;
};
+#if GTK_CHECK_VERSION (3, 22, 0)
+static GList *desktop_bg_objects = NULL;
+#endif
+
static void
free_fade (EelBackground *self)
{
@@ -144,9 +149,16 @@ eel_background_finalize (GObject *object)
}
free_background_surface (self);
-
free_fade (self);
+#if GTK_CHECK_VERSION (3, 22, 0)
+ if (self->details->is_desktop)
+ {
+ desktop_bg_objects = g_list_remove (desktop_bg_objects,
+ G_OBJECT (self));
+ }
+
+#endif
G_OBJECT_CLASS (eel_background_parent_class)->finalize (object);
}
@@ -468,46 +480,21 @@ eel_background_ensure_realized (EelBackground *self)
void
eel_background_draw (GtkWidget *widget,
-# if GTK_CHECK_VERSION (3, 0, 0)
cairo_t *cr)
{
- int width, height;
- GdkWindow *window = gtk_widget_get_window (widget);
- GdkRGBA color;
-
EelBackground *self = eel_get_widget_background (widget);
-
- drawable_get_adjusted_size (self, &width, &height);
-
- eel_background_ensure_realized (self);
- color = self->details->default_color;
- make_color_inactive (self, &color);
-
- cairo_save (cr);
-
- if (self->details->bg_surface != NULL) {
- cairo_set_source_surface (cr, self->details->bg_surface, 0, 0);
- cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
- } else {
- gdk_cairo_set_source_rgba (cr, &color);
- }
-
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_fill (cr);
-
- cairo_restore (cr);
-}
-# else
- GdkEventExpose *event)
-{
- int width, height;
- GdkWindow *window = gtk_widget_get_window (widget);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA color;
+#else
GdkColor color;
+#endif
+ int width, height;
- if (event->window != window)
+ if (self->details->fade != NULL &&
+ mate_bg_crossfade_is_started (self->details->fade))
+ {
return;
-
- EelBackground *self = eel_get_widget_background (widget);
+ }
drawable_get_adjusted_size (self, &width, &height);
@@ -515,24 +502,25 @@ eel_background_draw (GtkWidget *widget,
color = self->details->default_color;
make_color_inactive (self, &color);
- cairo_t *cr = gdk_cairo_create (window);
+ cairo_save (cr);
- if (self->details->bg_surface != NULL) {
+ if (self->details->bg_surface != NULL)
+ {
cairo_set_source_surface (cr, self->details->bg_surface, 0, 0);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
} else {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_cairo_set_source_rgba (cr, &color);
+#else
gdk_cairo_set_source_color (cr, &color);
+#endif
}
- gdk_cairo_rectangle (cr, &event->area);
- cairo_clip (cr);
-
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
- cairo_destroy (cr);
+ cairo_restore (cr);
}
-# endif
static void
set_root_surface (EelBackground *self,
@@ -617,7 +605,7 @@ on_fade_finished (MateBGCrossfade *fade,
static gboolean
fade_to_surface (EelBackground *self,
- GdkWindow *window,
+ GtkWidget *widget,
cairo_surface_t *surface)
{
if (self->details->fade == NULL ||
@@ -628,7 +616,22 @@ fade_to_surface (EelBackground *self,
if (!mate_bg_crossfade_is_started (self->details->fade))
{
+#if GTK_CHECK_VERSION (3, 22, 0)
+ mate_bg_crossfade_start_widget (self->details->fade, widget);
+#else
+ GdkWindow *window;
+
+ if (EEL_IS_CANVAS (widget))
+ {
+ window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
+ }
+ else
+ {
+ window = gtk_widget_get_window (widget);
+ }
+
mate_bg_crossfade_start (self->details->fade, window);
+#endif
if (self->details->is_desktop)
{
g_signal_connect (self->details->fade,
@@ -643,63 +646,66 @@ fade_to_surface (EelBackground *self,
static void
eel_background_set_up_widget (EelBackground *self)
{
- GdkWindow *window;
GtkWidget *widget = self->details->widget;
-# if GTK_CHECK_VERSION (3, 0, 0)
- GdkRGBA color;
-#else
- GdkColor color;
-#endif
gboolean in_fade = FALSE;
if (!gtk_widget_get_realized (widget))
return;
eel_background_ensure_realized (self);
- color = self->details->default_color;
- make_color_inactive (self, &color);
if (self->details->bg_surface == NULL)
return;
- if (EEL_IS_CANVAS (widget)) {
- window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
- } else {
- window = gtk_widget_get_window (widget);
- }
+ gtk_widget_queue_draw (widget);
if (self->details->fade != NULL)
- in_fade = fade_to_surface (self, window, self->details->bg_surface);
+ in_fade = fade_to_surface (self, widget, self->details->bg_surface);
if (!in_fade)
{
-# if GTK_CHECK_VERSION (3, 0, 0)
- cairo_pattern_t *pattern;
- pattern = cairo_pattern_create_for_surface (self->details->bg_surface);
- gdk_window_set_background_pattern (window, pattern);
- cairo_pattern_destroy (pattern);
-# endif
+ GdkWindow *window;
- if (self->details->is_desktop)
+ if (EEL_IS_CANVAS (widget))
{
-# if !GTK_CHECK_VERSION (3, 0, 0)
- gdk_window_set_back_pixmap (window, self->details->bg_surface, FALSE);
-# endif
- set_root_surface (self, window, gtk_widget_get_screen (widget));
+ window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
}
else
{
+ window = gtk_widget_get_window (widget);
+ }
+
+ if (self->details->is_desktop)
+ {
+#if !GTK_CHECK_VERSION (3, 22, 0)
+ if (self->details->bg_surface != NULL)
+ {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_pattern_t *pattern =
+ cairo_pattern_create_for_surface (self->details->bg_surface);
+ gdk_window_set_background_pattern (window, pattern);
+ cairo_pattern_destroy (pattern);
+#else
+ gdk_window_set_back_pixmap (window,
+ self->details->bg_surface, FALSE);
+#endif
+ }
+ else
+ {
#if GTK_CHECK_VERSION (3, 0, 0)
- gdk_window_set_background_rgba (window, &color);
+ GdkRGBA color = self->details->default_color;
+ make_color_inactive (self, &color);
+ gdk_window_set_background_rgba (window, &color);
#else
- gdk_window_set_background (window, &color);
+ GdkColor color = self->details->default_color;
+ make_color_inactive (self, &color);
+ gdk_window_set_background (window, &color);
#endif
-# if !GTK_CHECK_VERSION (3, 0, 0)
- gdk_window_set_back_pixmap (window, self->details->bg_surface, FALSE);
-# endif
+ }
+ gdk_window_invalidate_rect (window, NULL, TRUE);
+#endif
+ set_root_surface (self, window, gtk_widget_get_screen (widget));
}
-
- gdk_window_invalidate_rect (window, NULL, TRUE);
}
}
@@ -714,8 +720,6 @@ background_changed_cb (EelBackground *self)
eel_background_unrealize (self);
eel_background_set_up_widget (self);
- gtk_widget_queue_draw (self->details->widget);
-
return FALSE;
}
@@ -738,6 +742,13 @@ widget_queue_background_change (GtkWidget *widget,
* EelBackgroundStyle so that it will match the chosen GTK+ theme.
*/
static void
+#if GTK_CHECK_VERSION (3, 0, 0)
+widget_style_updated_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ widget_queue_background_change (widget, user_data);
+}
+#else
widget_style_set_cb (GtkWidget *widget,
GtkStyle *previous_style,
gpointer user_data)
@@ -745,6 +756,7 @@ widget_style_set_cb (GtkWidget *widget,
if (previous_style != NULL)
widget_queue_background_change (widget, user_data);
}
+#endif
static void
eel_background_changed (MateBG *bg,
@@ -853,7 +865,9 @@ on_widget_destroyed (GtkWidget *widget,
}
free_fade (self);
+
self->details->widget = NULL;
+ self->details->front_widget = NULL;
}
/* Gets the background attached to a widget.
@@ -862,9 +876,9 @@ on_widget_destroyed (GtkWidget *widget,
this will create one. To change the widget's background, you can
just call eel_background methods on the widget.
- If the widget is a canvas, nothing more needs to be done. For
- normal widgets, you need to call eel_background_draw() from your
- draw/expose handler to draw the background.
+ If the widget is a desktop window, nothing more needs to be done, otherwise
+ you need to call eel_background_draw() from your draw/expose event handler
+ to draw the background.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
@@ -873,22 +887,41 @@ on_widget_destroyed (GtkWidget *widget,
EelBackground *
eel_get_widget_background (GtkWidget *widget)
{
+ EelBackground *self;
+ gpointer data;
+#if GTK_CHECK_VERSION (3, 22, 0)
+ GList *l;
+#endif
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
/* Check for an existing background. */
- gpointer data = g_object_get_data (G_OBJECT (widget), "eel_background");
+ data = g_object_get_data (G_OBJECT (widget), "eel_background");
if (data != NULL)
{
g_assert (EEL_IS_BACKGROUND (data));
return data;
}
+#if GTK_CHECK_VERSION (3, 22, 0)
+ /* Check for an existing desktop window background. */
+ for (l = desktop_bg_objects; l != NULL; l = l->next)
+ {
+ g_assert (EEL_IS_BACKGROUND (l->data));
+ self = EEL_BACKGROUND (l->data);
+ if (widget == self->details->widget)
+ {
+ return self;
+ }
+ }
+#endif
+
+ self = eel_background_new ();
+ self->details->widget = widget;
+ self->details->front_widget = widget;
/* Store the background in the widget's data. */
- EelBackground *self = eel_background_new ();
g_object_set_data_full (G_OBJECT (widget), "eel_background",
self, g_object_unref);
- self->details->widget = widget;
g_signal_connect_object (widget, "destroy",
G_CALLBACK (on_widget_destroyed), self, 0);
@@ -897,8 +930,13 @@ eel_get_widget_background (GtkWidget *widget)
g_signal_connect_object (widget, "unrealize",
G_CALLBACK (widget_unrealize_cb), self, 0);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect_object (widget, "style-updated",
+ G_CALLBACK (widget_style_updated_cb), self, 0);
+#else
g_signal_connect_object (widget, "style_set",
G_CALLBACK (widget_style_set_cb), self, 0);
+#endif
/* Arrange to get the signal whenever the background changes. */
g_signal_connect_object (self, "appearance_changed",
@@ -995,14 +1033,32 @@ eel_background_reset (EelBackground *self)
void
eel_background_set_desktop (EelBackground *self,
- GtkWidget *widget,
gboolean is_desktop)
{
self->details->is_desktop = is_desktop;
- if (gtk_widget_get_realized (widget) && is_desktop)
+ if (is_desktop)
{
- widget_realized_setup (widget, self);
+#if GTK_CHECK_VERSION (3, 22, 0)
+ self->details->widget =
+ gtk_widget_get_toplevel (self->details->front_widget);
+
+ desktop_bg_objects = g_list_prepend (desktop_bg_objects,
+ G_OBJECT (self));
+
+#endif
+ if (gtk_widget_get_realized (self->details->widget))
+ {
+ widget_realized_setup (self->details->widget, self);
+ }
+ }
+ else
+ {
+#if GTK_CHECK_VERSION (3, 22, 0)
+ desktop_bg_objects = g_list_remove (desktop_bg_objects,
+ G_OBJECT (self));
+ self->details->widget = self->details->front_widget;
+#endif
}
}
@@ -1020,6 +1076,7 @@ eel_background_set_active (EelBackground *self,
{
self->details->is_active = is_active;
set_image_properties (self);
+ gtk_widget_queue_draw (self->details->widget);
}
}
diff --git a/eel/eel-background.h b/eel/eel-background.h
index 9303835e..3820e21d 100644
--- a/eel/eel-background.h
+++ b/eel/eel-background.h
@@ -83,7 +83,6 @@ void eel_bg_set_placement (EelBackground
/* Should be TRUE for desktop background */
gboolean eel_background_is_desktop (EelBackground *self);
void eel_background_set_desktop (EelBackground *self,
- GtkWidget *widget,
gboolean is_desktop);
/* Calls to interrogate the current state of a background. */
@@ -95,11 +94,7 @@ gboolean eel_background_is_set (EelBackground
/* Helper function for widgets using EelBackground */
void eel_background_draw (GtkWidget *widget,
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_t *cr);
-#else
- GdkEventExpose *event);
-#endif
/* Handles a dragged color being dropped on a widget to change the background color. */
void eel_background_set_dropped_color (EelBackground *self,
diff --git a/libcaja-private/caja-directory-background.c b/libcaja-private/caja-directory-background.c
index 4ad9be0e..000012fb 100644
--- a/libcaja-private/caja-directory-background.c
+++ b/libcaja-private/caja-directory-background.c
@@ -382,8 +382,7 @@ caja_connect_desktop_background_to_settings (CajaIconContainer *icon_container)
background = eel_get_widget_background (GTK_WIDGET (icon_container));
- eel_background_set_desktop (background,
- GTK_WIDGET (icon_container), TRUE);
+ eel_background_set_desktop (background, TRUE);
g_signal_connect_object (background, "settings_changed",
G_CALLBACK (desktop_background_changed_cb), NULL, 0);
diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c
index 385d88c2..dfdca59f 100644
--- a/libcaja-private/caja-icon-container.c
+++ b/libcaja-private/caja-icon-container.c
@@ -220,8 +220,10 @@ static void end_renaming_mode (CajaIconCon
gboolean commit);
static CajaIcon *get_icon_being_renamed (CajaIconContainer *container);
static void finish_adding_new_icons (CajaIconContainer *container);
+#if !GTK_CHECK_VERSION(3,0,0)
static void update_label_color (EelBackground *background,
CajaIconContainer *icon_container);
+#endif
static inline void icon_get_bounding_box (CajaIcon *icon,
int *x1_return,
int *y1_return,
@@ -4698,6 +4700,39 @@ size_allocate (GtkWidget *widget,
}
}
+static gboolean
+#if GTK_CHECK_VERSION (3, 0, 0)
+draw (GtkWidget *widget, cairo_t *cr)
+#else
+expose_event (GtkWidget *widget, GdkEventExpose *event)
+#endif
+{
+ if (!CAJA_ICON_CONTAINER (widget)->details->is_desktop)
+ {
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr = gdk_cairo_create (event->window);
+
+ gdk_cairo_rectangle (cr, &event->area);
+ cairo_clip (cr);
+
+#endif
+ eel_background_draw (widget, cr);
+#if !GTK_CHECK_VERSION (3, 0, 0)
+
+ cairo_destroy (cr);
+#endif
+ }
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ return GTK_WIDGET_CLASS (caja_icon_container_parent_class)->draw (widget,
+ cr);
+#else
+ return
+ GTK_WIDGET_CLASS (caja_icon_container_parent_class)->expose_event (widget,
+ event);
+#endif
+}
+
static void
realize (GtkWidget *widget)
{
@@ -4707,6 +4742,7 @@ realize (GtkWidget *widget)
GTK_WIDGET_CLASS (caja_icon_container_parent_class)->realize (widget);
container = CAJA_ICON_CONTAINER (widget);
+#if !GTK_CHECK_VERSION (3, 22, 0)
/* Ensure that the desktop window is native so the background
set on it is drawn by X. */
if (container->details->is_desktop)
@@ -4717,6 +4753,7 @@ realize (GtkWidget *widget)
gdk_x11_drawable_get_xid (gtk_layout_get_bin_window (GTK_LAYOUT (widget)));
#endif
}
+#endif
/* Set up DnD. */
caja_icon_dnd_init (container);
@@ -6294,20 +6331,6 @@ draw_canvas_background (EelCanvas *canvas,
}
-#if !GTK_CHECK_VERSION(3,0,0)
-static gboolean
-expose_event (GtkWidget *widget,
- GdkEventExpose *event)
-{
- /* g_warning ("Expose Icon Container %p '%d,%d: %d,%d'",
- widget,
- event->area.x, event->area.y,
- event->area.width, event->area.height); */
-
- return GTK_WIDGET_CLASS (caja_icon_container_parent_class)->expose_event (widget, event);
-}
-#endif
-
#if !GTK_CHECK_VERSION(3, 0, 0)
static AtkObject *
get_accessible (GtkWidget *widget)
@@ -6761,6 +6784,11 @@ caja_icon_container_class_init (CajaIconContainerClass *class)
widget_class = GTK_WIDGET_CLASS (class);
widget_class->size_allocate = size_allocate;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ widget_class->draw = draw;
+#else
+ widget_class->expose_event = expose_event;
+#endif
widget_class->realize = realize;
widget_class->unrealize = unrealize;
widget_class->button_press_event = button_press_event;
diff --git a/src/caja-desktop-window.c b/src/caja-desktop-window.c
index f843d718..ce11d328 100644
--- a/src/caja-desktop-window.c
+++ b/src/caja-desktop-window.c
@@ -30,6 +30,7 @@
#include <X11/Xatom.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
+#include <eel/eel-background.h>
#include <eel/eel-vfs-extensions.h>
#include <libcaja-private/caja-file-utilities.h>
#include <libcaja-private/caja-icon-names.h>
@@ -255,6 +256,17 @@ realize (GtkWidget *widget)
G_CALLBACK (caja_desktop_window_screen_size_changed), window);
}
+#if GTK_CHECK_VERSION (3, 22, 0)
+static gboolean
+draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ eel_background_draw (widget, cr);
+
+ return GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->draw (widget, cr);
+}
+#endif
+
static char *
real_get_title (CajaWindow *window)
{
@@ -277,6 +289,9 @@ caja_desktop_window_class_init (CajaDesktopWindowClass *klass)
wclass->realize = realize;
wclass->unrealize = unrealize;
wclass->map = map;
+#if GTK_CHECK_VERSION (3, 22, 0)
+ wclass->draw = draw;
+#endif
nclass->window_type = CAJA_WINDOW_DESKTOP;
nclass->get_title = real_get_title;
nclass->get_icon = real_get_icon;