diff options
author | Sorokin Alexei <[email protected]> | 2016-06-18 23:48:12 +0300 |
---|---|---|
committer | Sorokin Alexei <[email protected]> | 2016-06-18 23:48:12 +0300 |
commit | 051d9df1ca81e586f43d1d95a1ac3159452d4f17 (patch) | |
tree | 025200ea2e9a76d70fc6f862bef99e240510fa92 /savers | |
parent | 156f1b626cdd4e22beea0fbdba5869e2f693020a (diff) | |
download | mate-screensaver-051d9df1ca81e586f43d1d95a1ac3159452d4f17.tar.bz2 mate-screensaver-051d9df1ca81e586f43d1d95a1ac3159452d4f17.tar.xz |
Gtk3: fix several deprecations
Diffstat (limited to 'savers')
-rw-r--r-- | savers/floaters.c | 41 | ||||
-rw-r--r-- | savers/gs-theme-window.c | 11 | ||||
-rw-r--r-- | savers/gste-popsquares.c | 131 |
3 files changed, 126 insertions, 57 deletions
diff --git a/savers/floaters.c b/savers/floaters.c index dd0d85e..d565d63 100644 --- a/savers/floaters.c +++ b/savers/floaters.c @@ -265,7 +265,7 @@ static CachedSource *cached_source_new (cairo_pattern_t *pattern, gint height); static void cached_source_free (CachedSource *source); -static ScreenSaver *screen_saver_new (GtkDrawingArea *drawing_area, +static ScreenSaver *screen_saver_new (GtkWidget *drawing_area, const gchar *filename, gint max_floater_count, gboolean should_do_rotations, @@ -841,7 +841,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, } static ScreenSaver * -screen_saver_new (GtkDrawingArea *drawing_area, +screen_saver_new (GtkWidget *drawing_area, const gchar *filename, gint max_floater_count, gboolean should_do_rotations, @@ -851,7 +851,7 @@ screen_saver_new (GtkDrawingArea *drawing_area, screen_saver = g_new (ScreenSaver, 1); screen_saver->filename = g_strdup (filename); - screen_saver->drawing_area = GTK_WIDGET (drawing_area); + screen_saver->drawing_area = drawing_area; screen_saver->cached_sources = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) cached_source_free); @@ -1216,15 +1216,13 @@ int main (int argc, char *argv[]) { - ScreenSaver *screen_saver; - GtkWidget *window; - GtkWidget *drawing_area; -#if GTK_CHECK_VERSION (3, 0, 0) - GdkRGBA bg; - GdkRGBA fg; -#else - GtkStyle *style; - GtkStateType state; + ScreenSaver *screen_saver; + GtkWidget *window; + GtkWidget *drawing_area; +#if !GTK_CHECK_VERSION (3, 0, 0) + GtkStyle *style; + GtkStateType state; + GdkColor black = { 0, 0x0000, 0x0000, 0x0000 }; #endif GError *error; @@ -1264,25 +1262,14 @@ main (int argc, g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); - drawing_area = gtk_drawing_area_new (); + drawing_area = GTK_WIDGET (gtk_drawing_area_new ()); -#if GTK_CHECK_VERSION (3, 0, 0) - bg.red = 0; - bg.green = 0; - bg.blue = 0; - bg.alpha = 1.0; - fg.red = 0.8; - fg.green = 0.8; - fg.blue = 0.8; - fg.alpha = 1.0; - gtk_widget_override_background_color (drawing_area, 0, &bg); - gtk_widget_override_color (drawing_area, 0, &fg); -#else +#if !GTK_CHECK_VERSION (3, 0, 0) style = gtk_widget_get_style (drawing_area); state = (GtkStateType) 0; while (state < (GtkStateType) G_N_ELEMENTS (style->bg)) { - gtk_widget_modify_bg (drawing_area, state, &style->mid[state]); + gtk_widget_modify_bg (drawing_area, state, &black); state++; } #endif @@ -1290,7 +1277,7 @@ main (int argc, gtk_widget_show (drawing_area); gtk_container_add (GTK_CONTAINER (window), drawing_area); - screen_saver = screen_saver_new (GTK_DRAWING_AREA (drawing_area), + screen_saver = screen_saver_new (drawing_area, filenames[0], max_floater_count, should_do_rotations, should_show_paths); g_strfreev (filenames); diff --git a/savers/gs-theme-window.c b/savers/gs-theme-window.c index 0741aad..47c731e 100644 --- a/savers/gs-theme-window.c +++ b/savers/gs-theme-window.c @@ -62,6 +62,7 @@ gs_theme_window_class_init (GSThemeWindowClass *klass) widget_class->realize = gs_theme_window_real_realize; } +#if !GTK_CHECK_VERSION (3, 0, 0) static void force_no_pixmap_background (GtkWidget *widget) { @@ -90,11 +91,16 @@ force_no_pixmap_background (GtkWidget *widget) gtk_widget_set_name (widget, "gs-window"); } +#endif static void gs_theme_window_init (GSThemeWindow *window) { +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); +#else force_no_pixmap_background (GTK_WIDGET (window)); +#endif } static void @@ -177,9 +183,14 @@ gs_theme_window_real_realize (GtkWidget *widget) return; } +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_style_context_set_background (gtk_widget_get_style_context (widget), + window); +#else gtk_style_set_background (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL); +#endif gdk_window_set_decorations (window, (GdkWMDecoration) 0); gdk_window_set_events (window, gdk_window_get_events (window) | event_mask); diff --git a/savers/gste-popsquares.c b/savers/gste-popsquares.c index 837bb2c..44caa48 100644 --- a/savers/gste-popsquares.c +++ b/savers/gste-popsquares.c @@ -51,7 +51,11 @@ struct GSTEPopsquaresPrivate int ncolors; int subdivision; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *colors; +#else GdkColor *colors; +#endif square *squares; }; @@ -63,12 +67,12 @@ static GObjectClass *parent_class = NULL; G_DEFINE_TYPE (GSTEPopsquares, gste_popsquares, GS_TYPE_THEME_ENGINE) static void -hsv_to_rgb (int h, - double s, - double v, - unsigned short *r, - unsigned short *g, - unsigned short *b) +hsv_to_rgb (int h, + double s, + double v, + double *r, + double *g, + double *b) { double H, S, V, R, G, B; double p1, p2, p3; @@ -138,27 +142,27 @@ hsv_to_rgb (int h, B = p2; } - *r = R * 65535; - *g = G * 65535; - *b = B * 65535; + *r = R; + *g = G; + *b = B; } static void -rgb_to_hsv (unsigned short r, - unsigned short g, - unsigned short b, - int *h, - double *s, - double *v) +rgb_to_hsv (double r, + double g, + double b, + int *h, + double *s, + double *v) { double R, G, B, H, S, V; double cmax, cmin; double cmm; int imax; - R = ((double) r) / 65535.0; - G = ((double) g) / 65535.0; - B = ((double) b) / 65535.0; + R = r; + G = g; + B = b; cmax = R; cmin = G; imax = 1; @@ -226,11 +230,13 @@ make_color_ramp (GdkColormap *colormap, int h2, double s2, double v2, - GdkColor *colors, - int n_colors, #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *colors, + int n_colors, gboolean closed) #else + GdkColor *colors, + int n_colors, gboolean closed, gboolean allocate, gboolean writable) @@ -267,13 +273,25 @@ make_color_ramp (GdkColormap *colormap, for (i = 0; i < ncolors; i++) { +#if !GTK_CHECK_VERSION (3, 0, 0) + double red, green, blue; + +#endif hsv_to_rgb ((int) (h1 + (i * dh)), (s1 + (i * ds)), (v1 + (i * dv)), +#if GTK_CHECK_VERSION (3, 0, 0) &colors [i].red, &colors [i].green, &colors [i].blue); -#if !GTK_CHECK_VERSION (3, 0, 0) + colors [i].alpha = 1.0; +#else + &red, &green, &blue); + + colors [i].red = (guint16) (red * 65535.0); + colors [i].green = (guint16) (green * 65535.0); + colors [i].blue = (guint16) (blue * 65535.0); + if (allocate) { gdk_colormap_alloc_color (colormap, @@ -310,25 +328,55 @@ randomize_square_colors (square *squares, } } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +set_colors (GtkWidget *widget, + GdkRGBA *fg, + GdkRGBA *bg) +{ + GtkStyleContext *style; + + style = gtk_widget_get_style_context (widget); + + gtk_style_context_save (style); + gtk_style_context_set_state (style, GTK_STATE_FLAG_SELECTED); + gtk_style_context_get_background_color (style, + gtk_style_context_get_state (style), + bg); + if (bg->alpha == 0.0) + gtk_style_context_get_color (style, + gtk_style_context_get_state (style), + bg); + gtk_style_context_restore (style); + + fg->red = bg->red * 0.7; + fg->green = bg->green * 0.7; + fg->blue = bg->blue * 0.7; + fg->alpha = bg->alpha; +} +#else static void -set_colors (GdkWindow *window, +set_colors (GtkWidget *widget, GdkColor *fg, GdkColor *bg) { - GtkWidget *widget; + GtkWidget *style_widget; + GtkStyle *style; GdkColor color; - widget = gtk_invisible_new (); + style_widget = gtk_invisible_new (); + style = gtk_widget_get_style (style_widget); - color = gtk_widget_get_style (widget)->dark [GTK_STATE_SELECTED]; + color = style->dark [GTK_STATE_SELECTED]; fg->red = color.red; fg->green = color.green; fg->blue = color.blue; - color = gtk_widget_get_style (widget)->bg [GTK_STATE_SELECTED]; + color = style->bg [GTK_STATE_SELECTED]; bg->red = color.red; bg->green = color.green; bg->blue = color.blue; } +#endif static void gste_popsquares_set_property (GObject *object, @@ -413,8 +461,13 @@ setup_colors (GSTEPopsquares *pop) double s1, v1, s2, v2 = 0; int h1, h2 = 0; int nsquares; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA fg; + GdkRGBA bg; +#else GdkColor fg; GdkColor bg; +#endif GdkWindow *window; window = gs_theme_engine_get_window (GS_THEME_ENGINE (pop)); @@ -424,24 +477,37 @@ setup_colors (GSTEPopsquares *pop) return; } - set_colors (window, &fg, &bg); + set_colors (GTK_WIDGET (pop), &fg, &bg); if (pop->priv->colors) { g_free (pop->priv->colors); } +#if GTK_CHECK_VERSION (3, 0, 0) + pop->priv->colors = g_new0 (GdkRGBA, pop->priv->ncolors); +#else pop->priv->colors = g_new0 (GdkColor, pop->priv->ncolors); +#endif +#if GTK_CHECK_VERSION (3, 0, 0) rgb_to_hsv (fg.red, fg.green, fg.blue, &h1, &s1, &v1); rgb_to_hsv (bg.red, bg.green, bg.blue, &h2, &s2, &v2); -#if GTK_CHECK_VERSION (3, 0, 0) make_color_ramp (h1, s1, v1, h2, s2, v2, pop->priv->colors, pop->priv->ncolors, TRUE); #else + rgb_to_hsv ((double) (fg.red / 65535.0), + (double) (fg.green / 65535.0), + (double) (fg.blue / 65535.0), + &h1, &s1, &v1); + rgb_to_hsv ((double) (bg.red / 65535.0), + (double) (bg.green / 65535.0), + (double) (bg.blue / 65535.0), + &h2, &s2, &v2); + make_color_ramp (gtk_widget_get_colormap (GTK_WIDGET (pop)), h1, s1, v1, h2, s2, v2, @@ -484,10 +550,12 @@ gste_popsquares_real_draw (GtkWidget *widget, gste_popsquares_real_expose (GtkWidget *widget, GdkEventExpose *event) { + cairo_t *cr; + if (GTK_WIDGET_CLASS (parent_class)->expose_event) { GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); } - cairo_t *cr = gdk_cairo_create (event->window); + cr = gdk_cairo_create (event->window); #endif draw_frame (GSTE_POPSQUARES (widget), cr); @@ -545,7 +613,6 @@ gste_popsquares_class_init (GSTEPopsquaresClass *klass) g_type_class_add_private (klass, sizeof (GSTEPopsquaresPrivate)); } - static void draw_frame (GSTEPopsquares *pop, cairo_t *cr) @@ -580,7 +647,11 @@ draw_frame (GSTEPopsquares *pop, { square *s = (square *) &pop->priv->squares [gw * y + x]; +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &(pop->priv->colors [s->color])); +#else gdk_cairo_set_source_color (cr, &(pop->priv->colors [s->color])); +#endif cairo_rectangle (cr, s->x, s->y, border ? s->w - border : s->w, border ? s->h - border : s->h); |