summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Sorokin <[email protected]>2017-03-12 15:07:16 +0300
committerraveit65 <[email protected]>2017-03-13 10:28:08 +0100
commit4c10ec0fdac58498c8c9616b940ff78990c86c90 (patch)
tree7cd24f21ef9f150fd7a565e255e3ea2e7dafb8c8
parent438682bef1a8fea49b4c6972350bede1bfad69d0 (diff)
downloadcaja-4c10ec0fdac58498c8c9616b940ff78990c86c90.tar.bz2
caja-4c10ec0fdac58498c8c9616b940ff78990c86c90.tar.xz
eel: Avoid deprecated gdk_window_set_background functions
Fixes partially #506, fixes compiz-reloaded/compiz#40.
-rw-r--r--configure.ac2
-rw-r--r--eel/eel-background.c162
-rw-r--r--eel/eel-background.h1
-rw-r--r--libcaja-private/caja-directory-background.c3
-rw-r--r--libcaja-private/caja-icon-container.c17
-rw-r--r--src/caja-desktop-window.c15
6 files changed, 149 insertions, 51 deletions
diff --git a/configure.ac b/configure.ac
index 6dcfce94..780efcb3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@ dnl ===========================================================================
m4_define(glib_minver, 2.36.0)
m4_define(gio_minver, 2.26.0)
-m4_define(mate_desktop_minver, 1.17.0)
+m4_define(mate_desktop_minver, 1.17.3)
m4_define(pango_minver, 1.1.2)
m4_define(gtk_minver, 3.14.0)
m4_define(xml_minver, 2.4.7)
diff --git a/eel/eel-background.c b/eel/eel-background.c
index c1ef5c6c..76f47a69 100644
--- a/eel/eel-background.c
+++ b/eel/eel-background.c
@@ -53,6 +53,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
struct EelBackgroundDetails
{
GtkWidget *widget;
+ GtkWidget *front_widget;
MateBG *bg;
char *color;
@@ -79,6 +80,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)
{
@@ -124,9 +129,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);
}
@@ -358,11 +370,15 @@ void
eel_background_draw (GtkWidget *widget,
cairo_t *cr)
{
- int width, height;
- GdkWindow *window = gtk_widget_get_window (widget);
+ EelBackground *self = eel_get_widget_background (widget);
GdkRGBA color;
+ int width, height;
- EelBackground *self = eel_get_widget_background (widget);
+ if (self->details->fade != NULL &&
+ mate_bg_crossfade_is_started (self->details->fade))
+ {
+ return;
+ }
drawable_get_adjusted_size (self, &width, &height);
@@ -372,7 +388,8 @@ eel_background_draw (GtkWidget *widget,
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 {
@@ -468,7 +485,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 ||
@@ -479,7 +496,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,
@@ -494,9 +526,7 @@ fade_to_surface (EelBackground *self,
static void
eel_background_set_up_widget (EelBackground *self)
{
- GdkWindow *window;
GtkWidget *widget = self->details->widget;
- GdkRGBA color;
gboolean in_fade = FALSE;
@@ -504,41 +534,48 @@ eel_background_set_up_widget (EelBackground *self)
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)
{
- 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);
-
+ GdkWindow *window;
- if (self->details->is_desktop)
+ if (EEL_IS_CANVAS (widget))
{
- set_root_surface (self, window, gtk_widget_get_screen (widget));
+ window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
}
else
{
-
- gdk_window_set_background_rgba (window, &color);
-
+ window = gtk_widget_get_window (widget);
}
- gdk_window_invalidate_rect (window, NULL, TRUE);
+ if (self->details->is_desktop)
+ {
+#if !GTK_CHECK_VERSION (3, 22, 0)
+ if (self->details->bg_surface != NULL)
+ {
+ 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
+ {
+ GdkRGBA color = self->details->default_color;
+ make_color_inactive (self, &color);
+ gdk_window_set_background_rgba (window, &color);
+ }
+ gdk_window_invalidate_rect (window, NULL, TRUE);
+#endif
+ set_root_surface (self, window, gtk_widget_get_screen (widget));
+ }
}
}
@@ -553,8 +590,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;
}
@@ -577,12 +612,10 @@ widget_queue_background_change (GtkWidget *widget,
* EelBackgroundStyle so that it will match the chosen GTK+ theme.
*/
static void
-widget_style_set_cb (GtkWidget *widget,
- GtkStyle *previous_style,
- gpointer user_data)
+widget_style_updated_cb (GtkWidget *widget,
+ gpointer user_data)
{
- if (previous_style != NULL)
- widget_queue_background_change (widget, user_data);
+ widget_queue_background_change (widget, user_data);
}
static void
@@ -692,7 +725,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.
@@ -701,9 +736,8 @@ 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.
+ You need to call eel_background_draw() from your draw 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
@@ -712,22 +746,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);
@@ -736,8 +789,8 @@ eel_get_widget_background (GtkWidget *widget)
g_signal_connect_object (widget, "unrealize",
G_CALLBACK (widget_unrealize_cb), self, 0);
- g_signal_connect_object (widget, "style_set",
- G_CALLBACK (widget_style_set_cb), self, 0);
+ g_signal_connect_object (widget, "style-updated",
+ G_CALLBACK (widget_style_updated_cb), self, 0);
/* Arrange to get the signal whenever the background changes. */
g_signal_connect_object (self, "appearance_changed",
@@ -828,14 +881,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
}
}
@@ -853,6 +924,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 b16fc88b..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. */
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 f6021900..75ecefc0 100644
--- a/libcaja-private/caja-icon-container.c
+++ b/libcaja-private/caja-icon-container.c
@@ -185,8 +185,6 @@ static void end_renaming_mode (CajaIconCon
gboolean commit);
static CajaIcon *get_icon_being_renamed (CajaIconContainer *container);
static void finish_adding_new_icons (CajaIconContainer *container);
-static void update_label_color (EelBackground *background,
- CajaIconContainer *icon_container);
static inline void icon_get_bounding_box (CajaIcon *icon,
int *x1_return,
int *y1_return,
@@ -4520,6 +4518,18 @@ size_allocate (GtkWidget *widget,
}
}
+static gboolean
+draw (GtkWidget *widget, cairo_t *cr)
+{
+ if (!CAJA_ICON_CONTAINER (widget)->details->is_desktop)
+ {
+ eel_background_draw (widget, cr);
+ }
+
+ return GTK_WIDGET_CLASS (caja_icon_container_parent_class)->draw (widget,
+ cr);
+}
+
static void
realize (GtkWidget *widget)
{
@@ -4529,12 +4539,14 @@ 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)
{
gdk_x11_window_get_xid (gtk_layout_get_bin_window (GTK_LAYOUT (widget)));
}
+#endif
/* Set up DnD. */
caja_icon_dnd_init (container);
@@ -6507,6 +6519,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class)
widget_class = GTK_WIDGET_CLASS (class);
widget_class->size_allocate = size_allocate;
+ widget_class->draw = draw;
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 23d6809a..0d2a9f7f 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>
@@ -249,6 +250,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)
{
@@ -271,6 +283,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;