static void set_account(GtkListStore *store, GtkTreeIter *iter, PurpleAccount *account) { GdkPixbuf *pixbuf; GdkPixbuf *scale; scale = NULL; pixbuf = pidgin_create_prpl_icon(account, 0.5); if (pixbuf != NULL) { scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); if (purple_account_is_disconnected(account)) gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); } gtk_list_store_set(store, iter, COLUMN_ICON, scale, COLUMN_SCREENNAME, purple_account_get_username(account), COLUMN_ENABLED, ap_account_has_profile_enabled(account), COLUMN_PROTOCOL, purple_account_get_protocol_name(account), COLUMN_DATA, account, -1); if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); if (scale != NULL) g_object_unref(G_OBJECT(scale)); }
gboolean launcher_clicked (GtkWidget *event_box, GdkEventButton *event, t_launcher *launcher) { int size = 1.25 * launcher->quicklauncher->icon_size; if (event->button != 1) return FALSE; if (event->type == GDK_BUTTON_PRESS) { g_assert(launcher->zoomed_img); if(event->x < 0 || event->x > size || event->y < 0 || event->y > size) return FALSE; if (!launcher->clicked_img) { launcher->clicked_img = gdk_pixbuf_copy (launcher->zoomed_img); gdk_pixbuf_saturate_and_pixelate(launcher->zoomed_img, launcher->clicked_img, 5, TRUE); } gtk_image_set_from_pixbuf (GTK_IMAGE(launcher->image), launcher->clicked_img); } else if (event->type == GDK_BUTTON_RELEASE) { //g_assert(launcher->clicked_img); if (event->x > 0 && event->x < size && event->y > 0 && event->y < size) xfce_exec(launcher->command, FALSE, FALSE, NULL); gtk_image_set_from_pixbuf (GTK_IMAGE(launcher->image), launcher->def_img); gtk_container_set_border_width(GTK_CONTAINER (event_box), (int)launcher->quicklauncher->icon_size/8); //gtk_widget_set_size_request(launcher->image, size, size); } return TRUE; }
static void on_icon_changed(WnckWindow *controlwindow, WindowckPlugin *wckp) { GdkPixbuf *pixbuf = NULL; GdkPixbuf *grayscale = NULL; if (!controlwindow) { xfce_panel_image_clear(XFCE_PANEL_IMAGE (wckp->icon->symbol)); } else if (wckp->prefs->show_on_desktop) { gtk_widget_set_sensitive (wckp->icon->symbol, TRUE); if (wnck_window_get_window_type (controlwindow) == WNCK_WINDOW_DESKTOP) { if (!wnck_window_is_active(controlwindow)) gtk_widget_set_sensitive (wckp->icon->symbol, FALSE); xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (wckp->icon->symbol),GTK_STOCK_HOME); } } if (controlwindow && wnck_window_get_window_type (controlwindow) != WNCK_WINDOW_DESKTOP) { /* This only returns a pointer - it SHOULDN'T be unrefed! */ if (XFCE_PANEL_IS_SMALL) pixbuf = wnck_window_get_mini_icon(controlwindow); else pixbuf = wnck_window_get_icon(controlwindow); /* leave when there is no valid pixbuf */ if (G_UNLIKELY (pixbuf == NULL)) { xfce_panel_image_clear (XFCE_PANEL_IMAGE (wckp->icon->symbol)); return; } if (!wnck_window_is_active(controlwindow)) { /* icon color is set to grayscale */ grayscale = gdk_pixbuf_copy(pixbuf); gdk_pixbuf_saturate_and_pixelate(grayscale, grayscale, 0, FALSE); if (G_UNLIKELY (grayscale != NULL)) pixbuf = grayscale; } xfce_panel_image_set_from_pixbuf(XFCE_PANEL_IMAGE (wckp->icon->symbol), pixbuf); } if (grayscale != NULL && grayscale != pixbuf) g_object_unref (G_OBJECT (grayscale)); }
void wibuti_widget_set_icon(WibutiWidget *self, GdkPixbuf *icon) { // TODO: fix memory leak if (self->use_icon) { if (icon == NULL) { gtk_image_clear(self->image_icon); self->icon = NULL; } else { GdkPixbuf *icon_tmp1 = gdk_pixbuf_scale_simple(icon, ICON_WIDTH, ICON_HEIGHT, GDK_INTERP_BILINEAR); self->icon = icon_tmp1; if (!self->is_active) { gdk_pixbuf_saturate_and_pixelate(icon_tmp1, icon_tmp1, 0, FALSE); } GdkPixbuf *icon_tmp2 = gdk_pixbuf_rotate_simple(icon_tmp1, self->angle); gtk_image_set_from_pixbuf(self->image_icon, icon_tmp2); g_object_unref(icon_tmp2); } } }
/** * ar_pixbuf_utils_create_highlight: * @pixbuf: the original pixbuf * @highligh_colour: the colour to use for the highlight * * Creates a highlighted pixbuf from @pixbuf using @highligh_colour. * * Returns: a new #GdkPixbuf, or %NULL if there was an error */ GdkPixbuf * ar_pixbuf_utils_create_highlight (GdkPixbuf *pixbuf, const GdkColor *highligh_colour) { GdkPixbuf *comppixbuf; guint x, y, width, height, rowstride; guint16 red, green, blue; guchar *pixels, *p; if (!pixbuf) return NULL; comppixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_bits_per_sample (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); if (!comppixbuf) return NULL; gdk_pixbuf_saturate_and_pixelate (pixbuf, comppixbuf, 0.0, FALSE); pixels = gdk_pixbuf_get_pixels (comppixbuf); width = gdk_pixbuf_get_width (comppixbuf); height = gdk_pixbuf_get_height (comppixbuf); rowstride = gdk_pixbuf_get_rowstride (comppixbuf); red = highligh_colour->red >> 8; green = highligh_colour->green >> 8; blue = highligh_colour->blue >> 8; /* FIXMEchpe: This could probably use lots of improvements! */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { p = pixels + y * rowstride + x * 4; p[0] += (0xFF - p[0]) * red / 0xFF; p[1] += (0xFF - p[1]) * green / 0xFF; p[2] += (0xFF - p[2]) * blue / 0xFF; } } return comppixbuf; }
static void draw_icon (GtkWidget *widget, GtkIconEntryPosition icon_pos) { GtkIconEntry *entry; GtkIconEntryPrivate *priv; EntryIconInfo *icon_info; GdkPixbuf *pixbuf; gint x, y, width, height; entry = GTK_ICON_ENTRY (widget); priv = GTK_ICON_ENTRY_GET_PRIVATE (entry); icon_info = &priv->icons[icon_pos]; if (icon_info->pixbuf == NULL || !GTK_WIDGET_REALIZED (widget)) return; if ((pixbuf = get_pixbuf_from_icon (entry, icon_pos)) == NULL) return; gdk_drawable_get_size (icon_info->window, &width, &height); if (width == 1 || height == 1) { /* * size_allocate hasn't been called yet. These are the default values. */ return; } if (gdk_pixbuf_get_height (pixbuf) > height) { GdkPixbuf *temp_pixbuf; int scale; scale = height - (2 * ICON_MARGIN); temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = temp_pixbuf; } x = (width - gdk_pixbuf_get_width(pixbuf)) / 2; y = (height - gdk_pixbuf_get_height(pixbuf)) / 2; if (icon_info->insensitive) { GdkPixbuf *temp_pixbuf; temp_pixbuf = gdk_pixbuf_copy (pixbuf); gdk_pixbuf_saturate_and_pixelate (pixbuf, temp_pixbuf, 0.8f, TRUE); g_object_unref (pixbuf); pixbuf = temp_pixbuf; } else if (icon_info->hovered) { GdkPixbuf *temp_pixbuf; temp_pixbuf = gdk_pixbuf_copy (pixbuf); colorshift_pixbuf (temp_pixbuf, pixbuf, 30); g_object_unref (pixbuf); pixbuf = temp_pixbuf; } gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf, 0, 0, x, y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0); g_object_unref (pixbuf); }
static GdkPixbuf * render_icon (GtkStyle *style, const GtkIconSource *source, GtkTextDirection direction, GtkStateType state, GtkIconSize size, GtkWidget *widget, const gchar *detail) { int width = 1; int height = 1; GdkPixbuf *scaled; GdkPixbuf *stated; GdkPixbuf *base_pixbuf; GdkScreen *screen; GtkSettings *settings; /* Oddly, style can be NULL in this function, because * GtkIconSet can be used without a style and if so * it uses this function. */ base_pixbuf = gtk_icon_source_get_pixbuf (source); g_return_val_if_fail (base_pixbuf != NULL, NULL); if (widget && gtk_widget_has_screen (widget)) { screen = gtk_widget_get_screen (widget); settings = gtk_settings_get_for_screen (screen); } else if (style->colormap) { screen = gdk_colormap_get_screen (style->colormap); settings = gtk_settings_get_for_screen (screen); } else { settings = gtk_settings_get_default (); GTK_NOTE (MULTIHEAD, g_warning ("Using the default screen for gtk_default_render_icon()")); } if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height)) { g_warning (G_STRLOC ": invalid icon size '%d'", size); return NULL; } /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise, * leave it alone. */ if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source)) scaled = scale_or_ref (base_pixbuf, width, height); else scaled = g_object_ref (base_pixbuf); /* If the state was wildcarded, then generate a state. */ if (gtk_icon_source_get_state_wildcarded (source)) { if (state == GTK_STATE_INSENSITIVE) { stated = set_transparency (scaled, 0.3); gdk_pixbuf_saturate_and_pixelate (stated, stated, 0.1, FALSE); g_object_unref (scaled); } else if (state == GTK_STATE_PRELIGHT) { stated = gdk_pixbuf_copy (scaled); gdk_pixbuf_saturate_and_pixelate (scaled, stated, 1.2, FALSE); g_object_unref (scaled); } else { stated = scaled; } } else stated = scaled; return stated; }
static void megaphone_applet_update_icon (MegaphoneApplet *applet) { MegaphoneAppletPriv *priv = GET_PRIV (applet); EmpathyAvatar *avatar = NULL; GdkPixbuf *avatar_pixbuf; if (priv->contact) { avatar = empathy_contact_get_avatar (priv->contact); } else { gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); return; } if (!avatar) { gchar *avatar_token; /* Try to take avatar from cache */ avatar_token = panel_applet_gconf_get_string (PANEL_APPLET (applet), "avatar_token", NULL); if (!EMP_STR_EMPTY (avatar_token)) { empathy_contact_load_avatar_cache (priv->contact, avatar_token); avatar = empathy_contact_get_avatar (priv->contact); } g_free (avatar_token); } if (avatar) { avatar_pixbuf = empathy_pixbuf_from_avatar_scaled (avatar, priv->image_size - 2, priv->image_size - 2); } else { GtkIconTheme *icon_theme; /* Load the default icon when no avatar is found */ icon_theme = gtk_icon_theme_get_default (); avatar_pixbuf = gtk_icon_theme_load_icon (icon_theme, "stock_contact", priv->image_size - 2, 0, NULL); } /* Now some desaturation if the contact is offline */ if (!empathy_contact_is_online (priv->contact)) { GdkPixbuf *offline_avatar; offline_avatar = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, gdk_pixbuf_get_height (avatar_pixbuf), gdk_pixbuf_get_width (avatar_pixbuf)); gdk_pixbuf_saturate_and_pixelate (avatar_pixbuf, offline_avatar, 0.0, TRUE); g_object_unref (avatar_pixbuf); avatar_pixbuf = offline_avatar; } gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), avatar_pixbuf); g_object_unref (avatar_pixbuf); }
// Updates the images according to preferences and the window situation // Warning! This function is called very often, so it should only do the most necessary things! void updateTitle(WTApplet *wtapplet) { WnckWindow *controlledwindow; gchar *title_text, *title_color, *title_font; GdkPixbuf *icon_pixbuf; if (wtapplet->prefs->only_maximized) { controlledwindow = wtapplet->umaxedwindow; } else { controlledwindow = wtapplet->activewindow; } if (controlledwindow == NULL) return; if (controlledwindow == wtapplet->rootwindow) { // we're on desktop if (wtapplet->prefs->hide_on_unmaximized) { // hide everything icon_pixbuf = NULL; title_text = ""; } else { // display "custom" icon/title (TODO: customization via preferences?) icon_pixbuf = gtk_widget_render_icon(GTK_WIDGET(wtapplet),GTK_STOCK_HOME,GTK_ICON_SIZE_MENU,NULL); // This has to be unrefed! title_text = ("Desktop"); } } else { icon_pixbuf = wnck_window_get_icon(controlledwindow); // This only returns a pointer - it SHOULDN'T be unrefed! title_text = (gchar*)wnck_window_get_name(controlledwindow); } // TODO: we need the default font to somehow be the same in both modes if (wtapplet->prefs->custom_style) { // custom style if (controlledwindow == wtapplet->activewindow) { // window focused title_color = wtapplet->prefs->title_active_color; title_font = wtapplet->prefs->title_active_font; } else { // window unfocused title_color = wtapplet->prefs->title_inactive_color; title_font = wtapplet->prefs->title_inactive_font; } } else { // automatic (non-custom) style if (controlledwindow == wtapplet->activewindow) { // window focused title_color = wtapplet->panel_color_fg; title_font = ""; } else { // window unfocused title_color = "#808080"; // inactive title color. best fits for any panel regardless of color title_font = ""; } } // Set tooltips if (wtapplet->prefs->show_tooltips) { gtk_widget_set_tooltip_text (GTK_WIDGET(wtapplet->icon), title_text); gtk_widget_set_tooltip_text (GTK_WIDGET(wtapplet->title), title_text); } title_text = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span>", title_font, title_color, title_text); // Apply markup to label widget gtk_label_set_markup(GTK_LABEL(wtapplet->title), title_text); g_free(title_text); if (icon_pixbuf == NULL) { gtk_image_clear(wtapplet->icon); } else { // We're updating window info (Careful! We've had pixbuf memory leaks here) GdkPixbuf *ipb1 = gdk_pixbuf_scale_simple(icon_pixbuf, ICON_WIDTH, ICON_HEIGHT, GDK_INTERP_BILINEAR); if (controlledwindow == wtapplet->rootwindow) g_object_unref(icon_pixbuf); //this is stupid beyond belief, thanks to the retarded GTK framework GdkPixbuf *ipb2 = gdk_pixbuf_rotate_simple(ipb1, wtapplet->angle); g_object_unref(ipb1); // Unref ipb1 to get it cleared from memory (we still need ipb2) // Saturate icon when window is not focused if (controlledwindow != wtapplet->activewindow) gdk_pixbuf_saturate_and_pixelate(ipb2, ipb2, 0, FALSE); // Apply pixbuf to icon widget gtk_image_set_from_pixbuf(wtapplet->icon, ipb2); g_object_unref(ipb2); // Unref ipb2 to get it cleared from memory } }
task_item_expose_event (GtkWidget *widget, GdkEventExpose *event) #endif { #if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr; #endif TaskItem *item; GdkRectangle area; TaskItemPrivate *priv; GdkPixbuf *desat; GdkPixbuf *pbuf; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (TASK_IS_ITEM (widget), FALSE); #if !GTK_CHECK_VERSION (3, 0, 0) g_return_val_if_fail (event != NULL, FALSE); #endif item = TASK_ITEM (widget); priv = item->priv; g_return_val_if_fail (WNCK_IS_WINDOW (priv->window), FALSE); area = priv->area; #if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (event->window); #endif pbuf = priv->pixbuf; desat = NULL; gint size = MIN (area.height, area.width); gboolean active = wnck_window_is_active (priv->window); gboolean attention = wnck_window_or_transient_needs_attention (priv->window); if (GDK_IS_PIXBUF (pbuf) && gdk_pixbuf_get_width (pbuf) != size && gdk_pixbuf_get_height (pbuf) != size) { g_object_unref (pbuf); pbuf = NULL; } if (active) { cairo_rectangle (cr, area.x + .5, area.y - 4, area.width - 1, area.height + 8); cairo_set_source_rgba (cr, .8, .8, .8, .2); cairo_fill_preserve (cr); cairo_set_line_width (cr, 1); cairo_set_source_rgba (cr, .8, .8, .8, .4); cairo_stroke (cr); } if (!pbuf) { pbuf = priv->pixbuf = task_item_sized_pixbuf_for_window (item, priv->window, size); } if (active || priv->mouse_over || attention) { gdk_cairo_set_source_pixbuf (cr, pbuf, (area.x + (area.width - gdk_pixbuf_get_width (pbuf)) / 2), (area.y + (area.height - gdk_pixbuf_get_height (pbuf)) / 2)); } else { desat = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, gdk_pixbuf_get_bits_per_sample (pbuf), gdk_pixbuf_get_width (pbuf), gdk_pixbuf_get_height (pbuf)); if (desat) { gdk_pixbuf_saturate_and_pixelate (pbuf, desat, 0, FALSE); } else /* just paint the colored version as a fallback */ { desat = pbuf; } gdk_cairo_set_source_pixbuf (cr, desat, (area.x + (area.width - gdk_pixbuf_get_width (desat)) / 2), (area.y + (area.height - gdk_pixbuf_get_height (desat)) / 2)); } if (!priv->mouse_over && attention) /* urgent */ { GTimeVal current_time; g_get_current_time (¤t_time); gdouble ms = (current_time.tv_sec - priv->urgent_time.tv_sec) * 1000 + (current_time.tv_usec - priv->urgent_time.tv_usec) / 1000; gdouble alpha = .66 + (cos (3.15 * ms / 600) / 3); cairo_paint_with_alpha (cr, alpha); } else if (priv->mouse_over || active) /* focused */ { cairo_paint (cr); } else /* not focused */ { cairo_paint_with_alpha (cr, .65); } if (GDK_IS_PIXBUF (desat)) g_object_unref (desat); #if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); #endif return FALSE; }