diff options
author | Denis Gorodnichev <[email protected]> | 2014-02-27 17:16:51 +0400 |
---|---|---|
committer | Denis Gorodnichev <[email protected]> | 2014-02-27 17:16:51 +0400 |
commit | e95d24559060365eb4fee8154ad82434bf3c8a0a (patch) | |
tree | 1c62646abdff4ae1c191fc4f4f86cfb3933c1ad5 /libmate-desktop/mate-rr-labeler.c | |
parent | 0e7cc64581b44f4f80fa392ee9bff0a139f06785 (diff) | |
download | mate-desktop-e95d24559060365eb4fee8154ad82434bf3c8a0a.tar.bz2 mate-desktop-e95d24559060365eb4fee8154ad82434bf3c8a0a.tar.xz |
gtk3: GdkRGBA support
Diffstat (limited to 'libmate-desktop/mate-rr-labeler.c')
-rw-r--r-- | libmate-desktop/mate-rr-labeler.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/libmate-desktop/mate-rr-labeler.c b/libmate-desktop/mate-rr-labeler.c index 2b33526..c490ed2 100644 --- a/libmate-desktop/mate-rr-labeler.c +++ b/libmate-desktop/mate-rr-labeler.c @@ -45,7 +45,11 @@ struct _MateRRLabeler { int num_outputs; +#if GTK_CHECK_VERSION(3, 0, 0) + GdkRGBA *palette; +#else GdkColor *palette; +#endif GtkWidget **windows; GdkScreen *screen; @@ -225,7 +229,11 @@ make_palette (MateRRLabeler *labeler) g_assert (labeler->num_outputs > 0); +#if GTK_CHECK_VERSION(3, 0, 0) + labeler->palette = g_new (GdkRGBA, labeler->num_outputs); +#else labeler->palette = g_new (GdkColor, labeler->num_outputs); +#endif start_hue = 0.0; /* red */ end_hue = 2.0/3; /* blue */ @@ -240,9 +248,16 @@ make_palette (MateRRLabeler *labeler) gtk_hsv_to_rgb (h, s, v, &r, &g, &b); +#if GTK_CHECK_VERSION(3, 0, 0) + labeler->palette[i].red = r; + labeler->palette[i].green = g; + labeler->palette[i].blue = b; + labeler->palette[i].alpha = 1.0; +#else labeler->palette[i].red = (int) (65535 * r + 0.5); labeler->palette[i].green = (int) (65535 * g + 0.5); labeler->palette[i].blue = (int) (65535 * b + 0.5); +#endif } } @@ -256,7 +271,11 @@ label_window_draw_event_cb (GtkWidget *widget, cairo_t *cr, gpointer data) label_window_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) #endif { +#if GTK_CHECK_VERSION(3, 0, 0) + GdkRGBA *color; +#else GdkColor *color; +#endif GtkAllocation allocation; color = g_object_get_data (G_OBJECT (widget), "color"); @@ -279,7 +298,11 @@ label_window_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer /* fill */ +#if GTK_CHECK_VERSION(3, 0, 0) + gdk_cairo_set_source_rgba (cr, color); +#else gdk_cairo_set_source_color (cr, color); +#endif cairo_rectangle (cr, LABEL_WINDOW_EDGE_THICKNESS, LABEL_WINDOW_EDGE_THICKNESS, @@ -315,13 +338,21 @@ position_window (MateRRLabeler *labeler, } static GtkWidget * +#if GTK_CHECK_VERSION(3, 0, 0) +create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkRGBA *color) +#else create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *color) +#endif { GtkWidget *window; GtkWidget *widget; char *str; const char *display_name; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; +#else GdkColor black = { 0, 0, 0, 0 }; +#endif window = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_app_paintable (window, TRUE); @@ -363,7 +394,11 @@ create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *c * theme's colors, since the label is always shown against a light * pastel background. See bgo#556050 */ +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_override_color( widget, gtk_widget_get_state_flags (widget), &black); +#else gtk_widget_modify_fg (widget, gtk_widget_get_state (widget), &black); +#endif gtk_container_add (GTK_CONTAINER (window), widget); @@ -441,8 +476,9 @@ mate_rr_labeler_hide (MateRRLabeler *labeler) } +#if GTK_CHECK_VERSION (3, 0, 0) void -mate_rr_labeler_get_color_for_output (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *color_out) +mate_rr_labeler_get_rgba_for_output (MateRRLabeler *labeler, MateOutputInfo *output, GdkRGBA *color_out) { int i; @@ -458,6 +494,38 @@ mate_rr_labeler_get_color_for_output (MateRRLabeler *labeler, MateOutputInfo *ou g_warning ("trying to get the color for unknown MateOutputInfo %p; returning magenta!", output); + color_out->red = 1.0; + color_out->green = 0; + color_out->blue = 1.0; + color_out->alpha = 1.0; +} +#endif + +void +mate_rr_labeler_get_color_for_output (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *color_out) +{ + int i; + + g_return_if_fail (MATE_IS_RR_LABELER (labeler)); + g_return_if_fail (output != NULL); + g_return_if_fail (color_out != NULL); + + for (i = 0; i < labeler->num_outputs; i++) + if (labeler->config->outputs[i] == output) { +#if GTK_CHECK_VERSION (3, 0, 0) + color_out->red = labeler->palette[i].red * 0xffff; + color_out->green = labeler->palette[i].green * 0xffff; + color_out->blue = labeler->palette[i].blue * 0xffff; +#else + color_out->red = labeler->palette[i].red; + color_out->green = labeler->palette[i].green; + color_out->blue = labeler->palette[i].blue; +#endif + return; + } + + g_warning ("trying to get the color for unknown MateOutputInfo %p; returning magenta!", output); + color_out->red = 0xffff; color_out->green = 0; color_out->blue = 0xffff; |