static gboolean
_button_clicked_event (CairoMainIcon *icon, GdkEventButton *event, gpointer null)
{
  g_return_val_if_fail (AWN_IS_CAIRO_MAIN_ICON(icon), FALSE);
  CairoMainIconPrivate * priv = GET_PRIVATE (icon);

  if (event->button == 1)
  {
    awn_icon_popup_gtk_menu (AWN_ICON (icon), priv->menu, event->button, event->time);

    if (!priv->autohide_cookie)
    {
      priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(priv->applet),"CairoMenu" );
    }
    g_object_set(awn_overlayable_get_effects (AWN_OVERLAYABLE(icon)), "depressed", FALSE,NULL);
  }
  else if (event->button == 3)
  {
    GtkWidget * item;

    if (!priv->context_menu)
    {
      priv->context_menu = awn_applet_create_default_menu (AWN_APPLET(priv->applet));
      gtk_menu_set_screen(GTK_MENU(priv->context_menu), NULL);
      item = awn_themed_icon_create_remove_custom_icon_item (AWN_THEMED_ICON(icon),NULL);
      gtk_menu_shell_append (GTK_MENU_SHELL(priv->context_menu), item);
/*      item = gtk_image_menu_item_new_with_label("Applet Preferences");
      gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(item),
                                     gtk_image_new_from_stock (GTK_STOCK_PREFERENCES,GTK_ICON_SIZE_MENU));
      gtk_widget_show(item);
      gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
       */
//      g_signal_connect(G_OBJECT(item), "button-press-event", G_CALLBACK(_show_prefs), NULL);
      item=awn_applet_create_about_item_simple(AWN_APPLET(priv->applet),
                                               "Copyright 2007,2008, 2009 Rodney Cryderman <*****@*****.**>",
                                               AWN_APPLET_LICENSE_GPLV2,
                                               VERSION);
      gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
      g_signal_connect(G_OBJECT(priv->context_menu), "deactivate", G_CALLBACK(_deactivate_event), icon);
    }
    if (!priv->autohide_cookie)
    {
      priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(priv->applet),"CairoMenu" );
    }
    awn_icon_popup_gtk_menu (AWN_ICON (icon), priv->context_menu, event->button, event->time);
    g_object_set(awn_overlayable_get_effects (AWN_OVERLAYABLE(icon)), "depressed", FALSE,NULL);
    awn_utils_show_menu_images (GTK_MENU (priv->context_menu));
  }
  else
  {
    return TRUE;
  }

  awn_icon_set_is_active (AWN_ICON(icon), TRUE);
  return TRUE;
}
static gboolean
on_click (GtkWidget *widget, GdkEventButton *event, AwnIconBox *box)
{
  AwnEffects *fx = awn_overlayable_get_effects (AWN_OVERLAYABLE (widget));
  switch (event->button) {
    /* left click > test progress pie */
    case 1: {
      float progress;
      g_object_get (fx, "progress", &progress, NULL);
      if (progress < 1.0) progress += 0.1; else progress = 0.0;
      if (progress > 1.0) progress = 1.0;
      g_object_set (fx, "progress", progress, NULL);
      break;
    }
    /* middle click > destroy AwnIcon */
    case 2:
      gtk_container_remove(GTK_CONTAINER(box), widget);
      break;
    /* right click > change position */
    case 3:
      position++;
      if (position > GTK_POS_BOTTOM) position = GTK_POS_LEFT;
      awn_icon_box_set_pos_type (box, position);
      break;
  }
  return TRUE;
}
static GtkWidget *
pixbuf_icon (GtkWidget *parent)
{
  GdkPixbuf *pixbuf;
  GtkWidget *icon;

  pixbuf = gdk_pixbuf_new_from_file_at_size (PICTURE_FILE, 50, 50, NULL);

  icon = awn_icon_new ();
  awn_icon_set_from_pixbuf (AWN_ICON (icon), pixbuf);
  awn_icon_set_tooltip_text (AWN_ICON (icon), "Pixbuf Icon");

  /* test the signals */
  AwnEffects *fx = awn_overlayable_get_effects (AWN_OVERLAYABLE (icon));
  g_signal_connect(fx, "animation-start", (GCallback)anim_started, NULL);
  g_signal_connect(fx, "animation-end", (GCallback)anim_ended, NULL);

  gtk_container_add (GTK_CONTAINER (parent), icon);
  gtk_widget_show (icon);

  g_signal_connect (icon, "button-release-event", 
                    G_CALLBACK (on_click), parent); 
  g_object_unref (pixbuf);
  return icon;
}
static AwnEffects*
awn_applet_simple_get_effects (AwnOverlayable *simple)
{
  AwnAppletSimplePrivate *priv = AWN_APPLET_SIMPLE_GET_PRIVATE (simple);

  if (AWN_IS_ICON (priv->icon))
    return awn_overlayable_get_effects (AWN_OVERLAYABLE (priv->icon));

  return NULL;
}
static gboolean
on_signal_click(GtkWidget *widget, gpointer user_data)
{
  AwnIcon *icon = AWN_ICON(icons[0]);

  AwnEffects *fx = awn_overlayable_get_effects (AWN_OVERLAYABLE (icon));
  awn_effects_start_ex(fx, AWN_EFFECT_OPENING, 1, TRUE, TRUE);

  g_object_set(fx, "arrow-png", "/usr/share/gimp/2.0/themes/Default/images/preferences/folders-gradients-22.png", NULL);

  return FALSE;
}
static gboolean
awn_throbber_timeout (gpointer user_data)
{
    AwnThrobberPrivate *priv = AWN_THROBBER_GET_PRIVATE (user_data);

    priv->counter = (priv->counter - 1) % 8 + 8;

    AwnOverlayable *overlayable = AWN_OVERLAYABLE (user_data);
    awn_effects_redraw (awn_overlayable_get_effects (overlayable));

    return TRUE;
}
void
awn_throbber_set_type (AwnThrobber *throbber, AwnThrobberType type)
{
    g_return_if_fail (AWN_IS_THROBBER (throbber));
    gboolean needs_redraw = FALSE;

    AwnThrobberPrivate *priv = throbber->priv;

    if (type != priv->type) needs_redraw = TRUE;

    priv->type = type;
    switch (type)
    {
    case AWN_THROBBER_TYPE_NORMAL:
        if (!priv->timer_id && gtk_widget_get_mapped (GTK_WIDGET (throbber)))
        {
            // we want lower prio than HIGH_IDLE
            priv->timer_id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
                                                 100, awn_throbber_timeout,
                                                 throbber, NULL);
        }
        break;
    case AWN_THROBBER_TYPE_CLOSE_BUTTON:
        g_object_set (awn_overlayable_get_effects (AWN_OVERLAYABLE (throbber)),
                      "make-shadow", TRUE, NULL);
    // no break;
    default:
        if (priv->timer_id)
        {
            g_source_remove (priv->timer_id);
            priv->timer_id = 0;
        }
        break;
    }

    if (needs_redraw)
    {
        gtk_widget_queue_draw (GTK_WIDGET (throbber));
    }
}
static void
awn_throbber_init (AwnThrobber *throbber)
{
    AwnThrobberPrivate *priv;

    priv = throbber->priv = AWN_THROBBER_GET_PRIVATE (throbber);

    priv->size = 50;
    priv->counter = 0;
    priv->type = AWN_THROBBER_TYPE_NORMAL;

    g_object_set (awn_overlayable_get_effects (AWN_OVERLAYABLE (throbber)),
                  "effects", 0,
                  "reflection-visible", FALSE,
                  NULL);

    gtk_widget_add_events (GTK_WIDGET (throbber), GDK_ALL_EVENTS_MASK);

    g_signal_connect (throbber, "show",
                      G_CALLBACK (awn_throbber_show), NULL);
    g_signal_connect (throbber, "hide",
                      G_CALLBACK (awn_throbber_hide), NULL);
}
static gboolean
awn_throbber_expose_event (GtkWidget *widget, GdkEventExpose *event)
{
    AwnThrobberPrivate *priv = AWN_THROBBER (widget)->priv;
    cairo_t *cr;
    gint w, h;
    GtkPositionType pos_type;

    /* clip the drawing region, nvidia likes it */
    AwnEffects *fx = awn_overlayable_get_effects (AWN_OVERLAYABLE (widget));
    cr = awn_effects_cairo_create_clipped (fx, event);

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

    // we'll paint to [0,0] - [1,1], so scale's needed
    g_object_get (G_OBJECT (widget), "icon-width", &w, "icon-height", &h, NULL);
    cairo_scale (cr, w, h);

    switch (priv->type)
    {
    case AWN_THROBBER_TYPE_NORMAL:
    {
        const gdouble RADIUS = 0.0625;
        const gdouble DIST = 0.3;
        const gdouble OTHER = DIST * 0.707106781; /* sqrt(2)/2 */
        const gint COUNT = 8;
        const gint counter = priv->counter;

        cairo_set_line_width (cr, 1. / priv->size);
        cairo_translate (cr, 0.5, 0.5);
        cairo_scale (cr, 1, -1);

#define PAINT_CIRCLE(cr, x, y, cnt) \
    awn_cairo_set_source_color_with_alpha_multiplier (cr, \
        priv->fill_color, ((counter+cnt) % COUNT) / (float)COUNT); \
    cairo_arc (cr, x, y, RADIUS, 0, 2*M_PI); \
    cairo_fill_preserve (cr); \
    awn_cairo_set_source_color_with_alpha_multiplier (cr, \
        priv->outline_color, ((counter+cnt) % COUNT) / (float)COUNT); \
    cairo_stroke (cr);

        PAINT_CIRCLE (cr, 0, DIST, 0);
        PAINT_CIRCLE (cr, OTHER, OTHER, 1);
        PAINT_CIRCLE (cr, DIST, 0, 2);
        PAINT_CIRCLE (cr, OTHER, -OTHER, 3);
        PAINT_CIRCLE (cr, 0, -DIST, 4);
        PAINT_CIRCLE (cr, -OTHER, -OTHER, 5);
        PAINT_CIRCLE (cr, -DIST, 0, 6);
        PAINT_CIRCLE (cr, -OTHER, OTHER, 7);

#undef PAINT_CIRCLE

        break;
    }
    case AWN_THROBBER_TYPE_SAD_FACE:
    {
        cairo_set_line_width (cr, 0.03);

        if (priv->fill_color == NULL)
        {
            GdkColor c;
            double r, g, b;

            c = gtk_widget_get_style (widget)->fg[GTK_STATE_NORMAL];
            r = c.red / 65535.0;
            g = c.green / 65535.0;
            b = c.blue / 65535.0;

            cairo_set_source_rgb (cr, r, g, b);
        }
        else
        {
            awn_cairo_set_source_color_with_alpha_multiplier (cr,
                    priv->fill_color,
                    0.75);
        }

        paint_sad_face (cr);

        break;
    }
    case AWN_THROBBER_TYPE_ARROW_1:
        cairo_rotate (cr, M_PI);
        cairo_translate (cr, -1.0, -1.0);
    // no break
    case AWN_THROBBER_TYPE_ARROW_2:
    {
        pos_type = awn_icon_get_pos_type (AWN_ICON (widget));

        if (pos_type == GTK_POS_LEFT || pos_type == GTK_POS_RIGHT)
        {
            cairo_rotate (cr, 0.5 * M_PI);
            cairo_translate (cr, 0.0, -1.0);
        }

        if (priv->outline_color)
        {
            cairo_set_line_width (cr, 3.5 / priv->size);
            awn_cairo_set_source_color (cr, priv->outline_color);

            cairo_move_to (cr, 0.125, 0.375);
            cairo_line_to (cr, 0.875, 0.5);
            cairo_line_to (cr, 0.125, 0.625);
            cairo_stroke (cr);
        }

        cairo_set_line_width (cr, 1.75 / priv->size);

        if (priv->fill_color == NULL)
        {
            GdkColor c = gtk_widget_get_style (widget)->fg[GTK_STATE_NORMAL];
            double r = c.red / 65535.0;
            double g = c.green / 65535.0;
            double b = c.blue / 65535.0;

            cairo_set_source_rgb (cr, r, g, b);
        }
        else
        {
            awn_cairo_set_source_color (cr, priv->fill_color);
        }

        cairo_move_to (cr, 0.125, 0.375);
        cairo_line_to (cr, 0.875, 0.5);
        cairo_line_to (cr, 0.125, 0.625);
        cairo_stroke (cr);

        break;
    }
    case AWN_THROBBER_TYPE_CLOSE_BUTTON:
    {
        cairo_set_line_width (cr, 1. / priv->size);

        cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.5, 1.0);
        cairo_pattern_add_color_stop_rgb (pat, 0.0, 0.97254, 0.643137, 0.403921);
        //cairo_pattern_add_color_stop_rgb (pat, 0.0, 0.0, 0.0, 0.0); // test
        cairo_pattern_add_color_stop_rgb (pat, 0.7, 0.98823, 0.4, 0.0);
        cairo_pattern_add_color_stop_rgb (pat, 1.0, 0.98823, 0.4, 0.0);

        cairo_set_source (cr, pat);
        //cairo_arc (cr, 0.5, 0.5, 0.4, 0.0, 2 * M_PI);
        awn_cairo_rounded_rect (cr, 0.1, 0.1, 0.8, 0.8, 0.15, ROUND_ALL);
        cairo_fill_preserve (cr);

        cairo_pattern_destroy (pat);

        cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
        cairo_stroke (cr);

        cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
        cairo_set_line_width (cr, 2./priv->size);

        /*  \  starting with the upper point  */
        cairo_move_to (cr, 0.3, 0.25);
        cairo_line_to (cr, 0.7, 0.75);
        cairo_stroke (cr);
        /*  /  starting with the upper point  */
        cairo_move_to (cr, 0.7, 0.25);
        cairo_line_to (cr, 0.3, 0.75);
        cairo_stroke (cr);
        break;
    }
    default:
        break;
    }

    /* let effects know we're finished */
    awn_effects_cairo_destroy (fx);

    return TRUE;
}
Exemple #10
0
static void
awn_CPUicon_constructed (GObject *object)
{
  /*FIXME*/
  AwnCPUiconPrivate * priv;
  
  glibtop_cpu cpu;
  int i = 0;
  AwnApplet * applet;
  
  g_assert (G_OBJECT_CLASS ( awn_CPUicon_parent_class) );
  
  if (G_OBJECT_CLASS ( awn_CPUicon_parent_class)->constructed)
  {
    G_OBJECT_CLASS ( awn_CPUicon_parent_class)->constructed(object);
  }
  
  g_object_get (object,
                "applet",&applet,
                NULL);
  g_assert (applet);
  g_assert (AWN_IS_APPLET (applet));
  
  priv = AWN_CPUICON_GET_PRIVATE (object); 
  /*
   this will choose add_seconds in a relatively conservative manner.  Note that
   the timer is assumed to be incorrect and time elapsed is actually measured 
   accurately when the timer fires.  Area graph can be informed that the 
   measurement contains a partial point and it will average things out.
   */
  priv->dialog = awn_cpu_dialog_new_with_applet(GTK_WIDGET(object),applet);
  gtk_window_set_title (GTK_WINDOW (priv->dialog),_("CPU"));
  g_signal_connect(object, "button-press-event", 
                   G_CALLBACK(_awn_cpu_icon_clicked), 
                   priv->dialog);
  
  
  priv->num_cpus = 0;
  priv->prev_time = get_double_time();
  glibtop_get_cpu(&cpu);

  while (i < GLIBTOP_NCPU && cpu.xcpu_total[i] != 0)
  {
    priv->num_cpus++;
    i++;
  }
  priv->now = 0;
  
  connect_notify (object, "graph-type",
                    G_CALLBACK (_graph_type_change),applet);
  connect_notify (object, "update-timeout",
                    G_CALLBACK (_update_timeout_change),object);
  
  set_timeout (AWN_CPUICON(object));
  priv->text_overlay = AWN_OVERLAY(awn_overlay_text_new());

  g_object_set (priv->text_overlay,
               "align", AWN_OVERLAY_ALIGN_RIGHT,
               "gravity", GDK_GRAVITY_SOUTH,
                "x-adj", 0.3,
                "y-adj", 0.0,
                "text", "0.0",
               NULL);
  awn_overlayable_add_overlay (AWN_OVERLAYABLE(object), priv->text_overlay);

  do_bridge ( applet,object,
             "icon","update_timeout","update-timeout");

}