diff options
Diffstat (limited to 'mate-panel/panel-background.c')
-rw-r--r-- | mate-panel/panel-background.c | 302 |
1 files changed, 24 insertions, 278 deletions
diff --git a/mate-panel/panel-background.c b/mate-panel/panel-background.c index 9b503209..b5c475d7 100644 --- a/mate-panel/panel-background.c +++ b/mate-panel/panel-background.c @@ -2,6 +2,7 @@ * panel-background.c: panel background rendering * * Copyright (C) 2002, 2003 Sun Microsystems, Inc. + * Copyright (C) 2012-2021 MATE Developers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -38,19 +39,9 @@ #include "panel-util.h" - static gboolean panel_background_composite (PanelBackground *background); static void load_background_file (PanelBackground *background); - -static void -set_pixbuf_background (PanelBackground *background) -{ - g_assert (background->composited_pattern != NULL); - - gdk_window_set_background_pattern (background->window, background->composited_pattern); -} - void panel_background_apply_css (PanelBackground *background, GtkWidget *widget) { GtkStyleContext *context; @@ -110,16 +101,14 @@ panel_background_prepare (PanelBackground *background) * backing region is cleared * (gdk_window_clear_backing_region), the correctly * scaled pattern is used */ - cairo_matrix_t m; cairo_surface_t *surface; - double width, height; - surface = NULL; - width = 1.0; - height = 1.0; cairo_pattern_get_surface(background->default_pattern, &surface); /* catch invalid images (e.g. -gtk-gradient) before scaling and rendering */ if (surface != NULL ){ + double width, height; + cairo_matrix_t m; + cairo_surface_reference(surface); width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); @@ -145,21 +134,18 @@ panel_background_prepare (PanelBackground *background) break; case PANEL_BACK_COLOR: -#ifdef HAVE_X11 - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()) && - background->has_alpha && - !gdk_window_check_composited_wm(background->window)) - set_pixbuf_background (background); - else -#endif /* HAVE_X11 */ - { /* Not using X11, or pixbuf background not needed */ - gdk_window_set_background_rgba (background->window, - &background->color); + { + GdkRGBA color = background->color; + if (!gdk_screen_is_composited (gdk_screen_get_default ())) { + color.alpha = 1.; } + gdk_window_set_background_rgba (background->window, &color); break; + } case PANEL_BACK_IMAGE: - set_pixbuf_background (background); + g_assert (background->composited_pattern); + gdk_window_set_background_pattern (background->window, background->composited_pattern); break; default: @@ -197,69 +183,6 @@ free_composited_resources (PanelBackground *background) background->composited_pattern = NULL; } -#ifdef HAVE_X11 - -static void _panel_background_transparency(GdkScreen* screen,PanelBackground* background) -{ - panel_background_composite(background); -} - -static void -background_changed (PanelBackgroundMonitor *monitor, - PanelBackground *background) -{ - GdkPixbuf *tmp; - - g_return_if_fail (GDK_IS_X11_DISPLAY (gdk_display_get_default ())); - - tmp = background->desktop; - - background->desktop = panel_background_monitor_get_region ( - background->monitor, - background->region.x, - background->region.y, - background->region.width, - background->region.height); - - if (tmp) - g_object_unref (tmp); - - panel_background_composite (background); -} - -static GdkPixbuf * -get_desktop_pixbuf (PanelBackground *background) -{ - GdkPixbuf *desktop; - - g_return_val_if_fail (GDK_IS_X11_DISPLAY (gdk_display_get_default ()), NULL); - - if (!background->monitor) { - background->monitor = - panel_background_monitor_get_for_screen ( - gdk_window_get_screen (background->window)); - - background->monitor_signal = - g_signal_connect ( - background->monitor, "changed", - G_CALLBACK (background_changed), background); - } - g_signal_connect(gdk_window_get_screen(background->window), "composited-changed", - G_CALLBACK(_panel_background_transparency), - background); - - desktop = panel_background_monitor_get_region ( - background->monitor, - background->region.x, - background->region.y, - background->region.width, - background->region.height); - - return desktop; -} - -#endif /* HAVE_X11 */ - static cairo_pattern_t * composite_image_onto_desktop (PanelBackground *background) { @@ -281,24 +204,6 @@ composite_image_onto_desktop (PanelBackground *background) cr = cairo_create (surface); -#ifdef HAVE_X11 - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) { - if (!background->desktop) - background->desktop = get_desktop_pixbuf (background); - - if(!gdk_window_check_composited_wm (background->window)){ - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_paint (cr); - - if (background->desktop) { - gdk_cairo_set_source_pixbuf (cr, background->desktop, 0, 0); - cairo_rectangle (cr, 0, 0, width, height); - cairo_fill (cr); - } - } - } -#endif /* HAVE_X11 */ - gdk_cairo_set_source_pixbuf (cr, background->transformed_image, 0, 0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); @@ -313,71 +218,6 @@ composite_image_onto_desktop (PanelBackground *background) return pattern; } -static cairo_pattern_t * -composite_color_onto_desktop (PanelBackground *background) -{ - cairo_surface_t *surface; - cairo_pattern_t *pattern; - cairo_t *cr; - - surface = gdk_window_create_similar_surface (background->window, - CAIRO_CONTENT_COLOR_ALPHA, - background->region.width, - background->region.height); - if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { - cairo_surface_destroy (surface); - return NULL; - } - - cr = cairo_create (surface); - -#ifdef HAVE_X11 - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) { - if (!background->desktop) - background->desktop = get_desktop_pixbuf (background); - - if(!gdk_window_check_composited_wm (background->window)){ - if (background->desktop) { - gdk_cairo_set_source_pixbuf (cr, background->desktop, 0, 0); - cairo_paint (cr); - } - } - } -#endif /* HAVE_X11 */ - - gdk_cairo_set_source_rgba (cr, &background->color); - cairo_paint (cr); - - cairo_destroy (cr); - - pattern = cairo_pattern_create_for_surface (surface); - cairo_surface_destroy (surface); - - return pattern; -} - -static cairo_pattern_t * -get_composited_pattern (PanelBackground *background) -{ - cairo_pattern_t *retval = NULL; - - switch (background->type) { - case PANEL_BACK_NONE: - break; - case PANEL_BACK_COLOR: - retval = composite_color_onto_desktop (background); - break; - case PANEL_BACK_IMAGE: - retval = composite_image_onto_desktop (background); - break; - default: - g_assert_not_reached (); - break; - } - - return retval; -} - static gboolean panel_background_composite (PanelBackground *background) { @@ -388,16 +228,12 @@ panel_background_composite (PanelBackground *background) switch (background->type) { case PANEL_BACK_NONE: - break; case PANEL_BACK_COLOR: - if (background->has_alpha) - background->composited_pattern = - get_composited_pattern (background); break; case PANEL_BACK_IMAGE: if (background->transformed_image) { background->composited_pattern = - get_composited_pattern (background); + composite_image_onto_desktop (background); } break; default: @@ -407,7 +243,6 @@ panel_background_composite (PanelBackground *background) background->composited = TRUE; - panel_background_prepare (background); return TRUE; @@ -570,25 +405,6 @@ panel_background_transform (PanelBackground *background) return TRUE; } -#ifdef HAVE_X11 -static void -disconnect_background_monitor (PanelBackground *background) -{ - g_return_if_fail (GDK_IS_X11_DISPLAY (gdk_display_get_default ())); - if (background->monitor) { - g_signal_handler_disconnect ( - background->monitor, background->monitor_signal); - background->monitor_signal = -1; - g_object_unref (background->monitor); - } - background->monitor = NULL; - - if (background->desktop) - g_object_unref (background->desktop); - background->desktop = NULL; -} -#endif /* HAVE_X11 */ - static void panel_background_update_has_alpha (PanelBackground *background) { @@ -601,14 +417,7 @@ panel_background_update_has_alpha (PanelBackground *background) background->loaded_image) has_alpha = gdk_pixbuf_get_has_alpha (background->loaded_image); - background->has_alpha = has_alpha; - -#ifdef HAVE_X11 - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) { - if (!has_alpha) - disconnect_background_monitor (background); - } -#endif /* HAVE_X11 */ + background->has_alpha = (has_alpha != FALSE); } static void @@ -651,26 +460,6 @@ panel_background_set_type (PanelBackground *background, } static void -panel_background_set_opacity_no_update (PanelBackground *background, - guint16 opacity) -{ - background->color.alpha = opacity / 65535.0; - panel_background_update_has_alpha (background); -} - -void -panel_background_set_opacity (PanelBackground *background, - guint16 opacity) -{ - if (background->color.alpha == (opacity / 65535.0)) - return; - - free_transformed_resources (background); - panel_background_set_opacity_no_update (background, opacity); - panel_background_transform (background); -} - -static void panel_background_set_color_no_update (PanelBackground *background, const GdkRGBA *color) { @@ -701,16 +490,13 @@ static void panel_background_set_image_no_update (PanelBackground *background, const char *image) { - if (background->loaded_image) - g_object_unref (background->loaded_image); - background->loaded_image = NULL; - - if (background->image) - g_free (background->image); - background->image = NULL; + g_clear_object (&background->loaded_image); + g_free (background->image); if (image && image [0]) background->image = g_strdup (image); + else + background->image = NULL; panel_background_update_has_alpha (background); } @@ -812,7 +598,7 @@ panel_background_set (PanelBackground *background, void panel_background_set_default_style (PanelBackground *background, - GdkRGBA *color, + const GdkRGBA *color, cairo_pattern_t *pattern) { g_return_if_fail (color != NULL); @@ -830,7 +616,6 @@ panel_background_set_default_style (PanelBackground *background, panel_background_prepare (background); } - void panel_background_realized (PanelBackground *background, GdkWindow *window) @@ -905,12 +690,6 @@ panel_background_change_region (PanelBackground *background, background->orientation = orientation; -#ifdef HAVE_X11 - if (background->desktop) - g_object_unref (background->desktop); - background->desktop = NULL; -#endif /* HAVE_X11 */ - if (need_to_retransform || ! background->transformed) /* only retransform the background if we have in fact changed size/orientation */ @@ -950,12 +729,6 @@ panel_background_init (PanelBackground *background, background->transformed_image = NULL; background->composited_pattern = NULL; -#ifdef HAVE_X11 - background->monitor = NULL; - background->desktop = NULL; - background->monitor_signal = -1; -#endif /* HAVE_X11 */ - background->window = NULL; background->default_pattern = NULL; @@ -978,31 +751,12 @@ panel_background_init (PanelBackground *background, void panel_background_free (PanelBackground *background) { -#ifdef HAVE_X11 - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) { - disconnect_background_monitor (background); - } -#endif /* HAVE_X11 */ - free_transformed_resources (background); - if (background->image) - g_free (background->image); - background->image = NULL; - - if (background->loaded_image) - g_object_unref (background->loaded_image); - background->loaded_image = NULL; - -#ifdef HAVE_X11 - if (background->monitor) - g_object_unref (background->monitor); - background->monitor = NULL; -#endif /* HAVE_X11 */ + g_clear_pointer (&background->image, g_free); - if (background->window) - g_object_unref (background->window); - background->window = NULL; + g_clear_object (&background->loaded_image); + g_clear_object (&background->window); if (background->default_pattern) cairo_pattern_destroy (background->default_pattern); @@ -1021,13 +775,7 @@ panel_background_make_string (PanelBackground *background, effective_type = panel_background_effective_type (background); -#ifdef HAVE_X11 - if (is_using_x11 () && - (effective_type == PANEL_BACK_IMAGE || - (effective_type == PANEL_BACK_COLOR && - background->has_alpha && - !gdk_window_check_composited_wm(background->window)))) { - + if (effective_type == PANEL_BACK_IMAGE) { cairo_surface_t *surface; if (!background->composited_pattern) @@ -1040,9 +788,7 @@ panel_background_make_string (PanelBackground *background, return NULL; retval = g_strdup_printf ("pixmap:%d,%d,%d", (guint32)cairo_xlib_surface_get_drawable (surface), x, y); - } else -#endif - if (effective_type == PANEL_BACK_COLOR) { + } else if (effective_type == PANEL_BACK_COLOR) { gchar *rgba = gdk_rgba_to_string (&background->color); retval = g_strdup_printf ( "color:%s", |