static gboolean
xfce_panel_image_load (gpointer data)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (data)->priv;
  GdkPixbuf             *pixbuf;
  GdkScreen             *screen;
  GtkIconTheme          *icon_theme = NULL;
  gint                   dest_w, dest_h;

  GDK_THREADS_ENTER ();

  dest_w = priv->width;
  dest_h = priv->height;

  if (G_UNLIKELY (priv->force_icon_sizes
      && dest_w < 32
      && dest_w == dest_h))
    {
      /* we use some hardcoded values here for convienence,
       * above 32 pixels svg icons will kick in */
      if (dest_w > 16 && dest_w < 22)
        dest_w = 16;
      else if (dest_w > 22 && dest_w < 24)
        dest_w = 22;
      else if (dest_w > 24 && dest_w < 32)
        dest_w = 24;

      dest_h = dest_w;
    }

  if (priv->pixbuf != NULL)
    {
      /* use the pixbuf set by the user */
      pixbuf = g_object_ref (G_OBJECT (priv->pixbuf));

      if (G_LIKELY (pixbuf != NULL))
        {
          /* scale the icon to the correct size */
          priv->cache = xfce_panel_image_scale_pixbuf (pixbuf, dest_w, dest_h);
          g_object_unref (G_OBJECT (pixbuf));
        }
    }
  else
    {
      screen = gtk_widget_get_screen (GTK_WIDGET (data));
      if (G_LIKELY (screen != NULL))
        icon_theme = gtk_icon_theme_get_for_screen (screen);

      priv->cache = xfce_panel_pixbuf_from_source_at_size (priv->source, icon_theme, dest_w, dest_h);
    }

  if (G_LIKELY (priv->cache != NULL))
    gtk_widget_queue_draw (GTK_WIDGET (data));

  GDK_THREADS_LEAVE ();

  return FALSE;
}
static gboolean
xfce_panel_image_expose_event (GtkWidget      *widget,
                               GdkEventExpose *event)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
  gint                   source_width, source_height;
  gint                   dest_x, dest_y;
  GtkIconSource         *source;
  GdkPixbuf             *rendered = NULL;
  GdkPixbuf             *pixbuf = priv->cache;
  cairo_t               *cr;

  if (G_LIKELY (pixbuf != NULL))
    {
      /* get the size of the cache pixbuf */
      source_width = gdk_pixbuf_get_width (pixbuf);
      source_height = gdk_pixbuf_get_height (pixbuf);

      /* position */
      dest_x = widget->allocation.x + (priv->width - source_width) / 2;
      dest_y = widget->allocation.y + (priv->height - source_height) / 2;

      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
        {
          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);

          rendered = gtk_style_render_icon (widget->style,
                                            source,
                                            gtk_widget_get_direction (widget),
                                            GTK_WIDGET_STATE (widget),
                                            -1, widget, "xfce-panel-image");
          gtk_icon_source_free (source);

          if (G_LIKELY (rendered != NULL))
            pixbuf = rendered;
        }

      /* draw the pixbuf */
      cr = gdk_cairo_create (gtk_widget_get_window (widget));
      if (G_LIKELY (cr != NULL))
        {
          gdk_cairo_set_source_pixbuf (cr, pixbuf, dest_x, dest_y);
          cairo_paint (cr);
          cairo_destroy (cr);
        }

      if (rendered != NULL)
        g_object_unref (G_OBJECT (rendered));
    }

  return FALSE;
}
Esempio n. 3
0
static gboolean
xfce_panel_image_draw (GtkWidget *widget,
                       cairo_t   *cr)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
  gint                   source_width, source_height;
  gint                   dest_x, dest_y;
  GtkIconSource         *source;
  GdkPixbuf             *rendered = NULL;
  GdkPixbuf             *pixbuf = priv->cache;
  GtkStyleContext       *context;

  if (G_LIKELY (pixbuf != NULL))
    {
      /* get the size of the cache pixbuf */
      source_width = gdk_pixbuf_get_width (pixbuf);
      source_height = gdk_pixbuf_get_height (pixbuf);

      /* position */
      dest_x = (priv->width - source_width) / 2;
      dest_y = (priv->height - source_height) / 2;

      context = gtk_widget_get_style_context (widget);

      if (!gtk_widget_is_sensitive (widget))
        {
          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);
          rendered = gtk_render_icon_pixbuf (context, source, -1);
          gtk_icon_source_free (source);

          if (G_LIKELY (rendered != NULL))
            pixbuf = rendered;
        }

      /* draw the icon */
      gtk_render_icon (context, cr, pixbuf, dest_x, dest_y);

      if (rendered != NULL)
        g_object_unref (G_OBJECT (rendered));
    }

  return FALSE;
}
void
exitbutton_save(XfcePanelPlugin *plugin, ExitbuttonPlugin *exitbutton) {

  if (exo_str_is_empty(exitbutton->icon_name))
    {
      return;
    }

  // Update the icon
  xfce_panel_image_set_from_source(XFCE_PANEL_IMAGE(exitbutton->icon), exitbutton->icon_name);

  /********************************************************
   * Save the properties
   ********************************************************/
  XfceRc *rc;
  gchar *file;

  /* get the config file location */
  file = xfce_panel_plugin_save_location(plugin, TRUE);

  if (G_UNLIKELY (file == NULL))
    {
      DBG("Failed to open config file");
      return;
    }

  /* open the config file, read/write */
  rc = xfce_rc_simple_open(file, FALSE);
  g_free(file);

  if (G_LIKELY (rc != NULL))
    {
      /* save the settings */
      DBG(".");
      if (exitbutton->icon_name)
        xfce_rc_write_entry(rc, "icon_name", exitbutton->icon_name);

      /* close the rc file */
      xfce_rc_close(rc);
    }
}
static void
xfce_panel_image_size_request (GtkWidget      *widget,
                               GtkRequisition *requisition)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;

  if (priv->size > 0)
    {
      requisition->width = priv->size;
      requisition->height = priv->size;
    }
  else if (priv->pixbuf != NULL)
    {
      requisition->width = gdk_pixbuf_get_width (priv->pixbuf);
      requisition->height = gdk_pixbuf_get_height (priv->pixbuf);
    }
  else
    {
      requisition->width = widget->allocation.width;
      requisition->height = widget->allocation.height;
    }
}
/**
 * xfce_panel_image_clear:
 * @image : an #XfcePanelImage.
 *
 * Resets the image to be empty.
 *
 * Since: 4.8
 **/
void
xfce_panel_image_clear (XfcePanelImage *image)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (image)->priv;

  g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));

  if (priv->idle_load_id != 0)
    g_source_remove (priv->idle_load_id);

  if (priv->source != NULL)
    {
     g_free (priv->source);
     priv->source = NULL;
    }

  xfce_panel_image_unref_null (priv->pixbuf);
  xfce_panel_image_unref_null (priv->cache);

  /* reset values */
  priv->width = -1;
  priv->height = -1;
}
static void
xfce_panel_image_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;


  widget->allocation = *allocation;

  /* check if the available size changed */
  if ((priv->pixbuf != NULL || priv->source != NULL)
      && allocation->width > 0
      && allocation->height > 0
      && (allocation->width != priv->width
      || allocation->height != priv->height))
    {
      /* store the new size */
      priv->width = allocation->width;
      priv->height = allocation->height;

      /* free cache */
      xfce_panel_image_unref_null (priv->cache);

      if (priv->pixbuf == NULL)
        {
          /* delay icon loading */
          priv->idle_load_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, xfce_panel_image_load,
                                                widget, xfce_panel_image_load_destroy);
        }
      else
        {
          /* directly render pixbufs */
          xfce_panel_image_load (widget);
        }
    }
}
static void
xfce_panel_image_load_destroy (gpointer data)
{
  XFCE_PANEL_IMAGE (data)->priv->idle_load_id = 0;
}