diff options
author | lukefromdc <[email protected]> | 2016-08-08 02:57:55 -0400 |
---|---|---|
committer | raveit65 <[email protected]> | 2016-08-08 10:17:18 +0200 |
commit | 8c926115c99100a581abfd20dced5dfbe4922792 (patch) | |
tree | 20743e3f2cdc456c6f602e7474a64b562c39f80c | |
parent | 3eb928b92af5be2fb19e6c975d124a289c5c2787 (diff) | |
download | caja-8c926115c99100a581abfd20dced5dfbe4922792.tar.bz2 caja-8c926115c99100a581abfd20dced5dfbe4922792.tar.xz |
Fix background rendering in noncomposited case
Apply Alberts Muktupāvels' https://bugzilla.gnome.org/attachment.cgi?id=332444&action=diff to Caja, it just plain works.
Remove previous fallback background code.
Add GTK 3.21 selectors missed in caja_desktop_window_class_init, clean up a couple tabs
-rw-r--r-- | src/caja-desktop-window.c | 152 | ||||
-rw-r--r-- | src/file-manager/fm-desktop-icon-view.c | 10 |
2 files changed, 126 insertions, 36 deletions
diff --git a/src/caja-desktop-window.c b/src/caja-desktop-window.c index cea694d0..42f4214e 100644 --- a/src/caja-desktop-window.c +++ b/src/caja-desktop-window.c @@ -34,18 +34,110 @@ #include <libcaja-private/caja-file-utilities.h> #include <libcaja-private/caja-icon-names.h> #include <gio/gio.h> -#include <glib/gi18n.h> +#include <glib/gi18n.h> +#if GTK_CHECK_VERSION(3, 21, 0) +#define MATE_DESKTOP_USE_UNSTABLE_API +#include <libmate-desktop/mate-bg.h> +#endif struct CajaDesktopWindowDetails { gulong size_changed_id; gboolean loaded; +#if GTK_CHECK_VERSION(3, 21, 0) + gboolean composited; + cairo_surface_t *surface; +#endif }; G_DEFINE_TYPE (CajaDesktopWindow, caja_desktop_window, CAJA_TYPE_SPATIAL_WINDOW); +#if GTK_CHECK_VERSION(3, 21, 0) + +static void +background_changed (CajaDesktopWindow *window) +{ + GdkScreen *screen = gdk_screen_get_default (); + + if (window->details->surface) { + cairo_surface_destroy (window->details->surface); + } + + window->details->surface = mate_bg_get_surface_from_root (screen); + gtk_widget_queue_draw (GTK_WIDGET (window)); +} + +static GdkFilterReturn +filter_func (GdkXEvent *xevent, + GdkEvent *event, + CajaDesktopWindow *window) +{ + XEvent *xev = (XEvent *) xevent; + GdkAtom gdkatom; + + if (xev->type != PropertyNotify) { + return GDK_FILTER_CONTINUE; + } + + gdkatom = gdk_atom_intern_static_string ("_XROOTPMAP_ID"); + if (xev->xproperty.atom != gdk_x11_atom_to_xatom (gdkatom)) { + return GDK_FILTER_CONTINUE; + } + + background_changed (window); + + return GDK_FILTER_CONTINUE; +} + +static void +caja_desktop_window_composited_changed (GtkWidget *widget) +{ + CajaDesktopWindow *window = CAJA_DESKTOP_WINDOW (widget); + GdkScreen *screen = gdk_screen_get_default (); + gboolean composited = gdk_screen_is_composited (screen); + GdkWindow *root; + + if (window->details->composited == composited) { + return; + } + + window->details->composited = composited; + root = gdk_screen_get_root_window (screen); + + if (composited) { + gdk_window_remove_filter (root, (GdkFilterFunc) filter_func, window); + + if (window->details->surface) { + cairo_surface_destroy (window->details->surface); + window->details->surface = NULL; + } + } else { + gint events = gdk_window_get_events (root); + + gdk_window_set_events (root, events | GDK_PROPERTY_CHANGE_MASK); + gdk_window_add_filter (root, (GdkFilterFunc) filter_func, window); + background_changed (window); + } +} + +static gboolean +caja_desktop_window_draw (GtkWidget *widget, + cairo_t *cr) +{ + CajaDesktopWindow *window = CAJA_DESKTOP_WINDOW (widget); + + if (window->details->surface) { + cairo_set_source_surface (cr, window->details->surface, 0, 0); + cairo_paint (cr); + } + + return GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->draw (widget, cr); +} + +#endif + static void caja_desktop_window_init (CajaDesktopWindow *window) { @@ -62,6 +154,11 @@ caja_desktop_window_init (CajaDesktopWindow *window) gtk_style_context_add_class (context, "caja-desktop-window"); #endif +#if GTK_CHECK_VERSION(3, 21, 0) + window->details->composited = TRUE; + caja_desktop_window_composited_changed (GTK_WIDGET (window)); +#endif + gtk_window_move (GTK_WINDOW (window), 0, 0); /* shouldn't really be needed given our semantic type @@ -84,9 +181,9 @@ caja_desktop_window_init (CajaDesktopWindow *window) /* Set the accessible name so that it doesn't inherit the cryptic desktop URI. */ accessible = gtk_widget_get_accessible (GTK_WIDGET (window)); - if (accessible) { + if (accessible) { atk_object_set_name (accessible, _("Desktop")); - } + } } static gint @@ -180,11 +277,11 @@ static void unrealize (GtkWidget *widget) { CajaDesktopWindow *window; - CajaDesktopWindowDetails *details; + CajaDesktopWindowDetails *details; GdkWindow *root_window; window = CAJA_DESKTOP_WINDOW (widget); - details = window->details; + details = window->details; root_window = gdk_screen_get_root_window ( gtk_window_get_screen (GTK_WINDOW (window))); @@ -192,11 +289,11 @@ unrealize (GtkWidget *widget) gdk_property_delete (root_window, gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", TRUE)); - if (details->size_changed_id != 0) { - g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)), - details->size_changed_id); - details->size_changed_id = 0; - } + if (details->size_changed_id != 0) { + g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)), + details->size_changed_id); + details->size_changed_id = 0; + } GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->unrealize (widget); } @@ -242,12 +339,12 @@ static void realize (GtkWidget *widget) { CajaDesktopWindow *window; - CajaDesktopWindowDetails *details; + CajaDesktopWindowDetails *details; #if GTK_CHECK_VERSION(3, 21, 0) - GdkVisual *visual; + GdkVisual *visual; #endif window = CAJA_DESKTOP_WINDOW (widget); - details = window->details; + details = window->details; /* Make sure we get keyboard events */ gtk_widget_set_events (widget, gtk_widget_get_events (widget) @@ -266,9 +363,9 @@ realize (GtkWidget *widget) set_desktop_window_id (window, gtk_widget_get_window (widget)); - details->size_changed_id = - g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed", - G_CALLBACK (caja_desktop_window_screen_size_changed), window); + details->size_changed_id = + g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed", + G_CALLBACK (caja_desktop_window_screen_size_changed), window); } static char * @@ -287,18 +384,21 @@ real_get_icon (CajaWindow *window, static void caja_desktop_window_class_init (CajaDesktopWindowClass *klass) { - GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass); - CajaWindowClass *nclass = CAJA_WINDOW_CLASS (klass); - - wclass->realize = realize; - wclass->unrealize = unrealize; - wclass->map = map; + GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass); + CajaWindowClass *nclass = CAJA_WINDOW_CLASS (klass); - nclass->window_type = CAJA_WINDOW_DESKTOP; - nclass->get_title = real_get_title; - nclass->get_icon = real_get_icon; + wclass->realize = realize; + wclass->unrealize = unrealize; + wclass->map = map; +#if GTK_CHECK_VERSION(3, 21, 0) + wclass->composited_changed = caja_desktop_window_composited_changed; + wclass->draw = caja_desktop_window_draw; +#endif + nclass->window_type = CAJA_WINDOW_DESKTOP; + nclass->get_title = real_get_title; + nclass->get_icon = real_get_icon; - g_type_class_add_private (klass, sizeof (CajaDesktopWindowDetails)); + g_type_class_add_private (klass, sizeof (CajaDesktopWindowDetails)); } gboolean diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c index 7214926d..1637532c 100644 --- a/src/file-manager/fm-desktop-icon-view.c +++ b/src/file-manager/fm-desktop-icon-view.c @@ -476,16 +476,6 @@ realized_callback (GtkWidget *widget, FMDesktopIconView *desktop_icon_view) desktop_icon_view_property_filter, desktop_icon_view); - /*Set up a fallback background style class for the noncompositing case */ -#if GTK_CHECK_VERSION(3, 21, 0) - gboolean - composited = gtk_widget_is_composited (GTK_WIDGET(desktop_icon_view)); - if (!composited){ - GtkStyleContext *context; - context = gtk_widget_get_style_context (GTK_WIDGET(desktop_icon_view)); - gtk_style_context_add_class(context,"caja-fallback-desktop-background"); - } -#endif } static CajaZoomLevel |