示例#1
1
int
main (int argc, char **argv)
{
  GtkStatusIcon *icon;

  gtk_init (&argc, &argv);

  icon = gtk_status_icon_new ();

  g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
  g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
  g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
  g_signal_connect (icon, "notify::screen", G_CALLBACK (screen_changed_cb), NULL);
  g_print ("icon size %d\n", gtk_status_icon_get_size (icon));

  g_signal_connect (icon, "activate",
                    G_CALLBACK (icon_activated), NULL);

  g_signal_connect (icon, "popup-menu",
                    G_CALLBACK (popup_menu), NULL);

  icons = g_slist_append (icons, icon);

  update_icon ();

  timeout = gdk_threads_add_timeout (2000, timeout_handler, icon);

  gtk_main ();

  return 0;
}
示例#2
0
文件: tray.c 项目: Explorer09/hime
void load_tray_icon()
{
  if (!hime_status_tray)
    return;
  if (!tray_icon) {
    create_tray(NULL);
    return;
  }
  // wrong width & height if it is not embedded-ready
  if (!gtk_status_icon_is_embedded(tray_icon))
    return;
  iw = gtk_status_icon_get_size(tray_icon), ih = gtk_status_icon_get_size(tray_icon);
  if (!pixbuf) {
    char icon_fname[128];
    get_icon_path(HIME_TRAY_PNG, icon_fname);
    pixbuf = gdk_pixbuf_new_from_file_at_size(icon_fname, iw, ih, NULL);
  }
  char *iconame = HIME_TRAY_PNG;
//  if (current_CS && current_CS->in_method && inmd)
// Workaround due to issue #161
  if (current_CS && current_CS->im_state != HIME_STATE_DISABLED && current_CS->im_state != HIME_STATE_ENG_FULL)
    iconame = inmd[current_CS->in_method].icon;
  char fname[512];
  if (iconame)
    get_icon_path(iconame, fname);
  if (strcmp(pixbuf_ch_fname, fname) && pixbuf_ch) {
    g_object_unref(pixbuf_ch); pixbuf_ch = NULL;
  }
  if (!pixbuf_ch) {
    strcpy(pixbuf_ch_fname, fname);
    pixbuf_ch = gdk_pixbuf_new_from_file_at_size(fname, iw, ih, NULL);
  }
  draw_icon();
  iconame = NULL;
}
示例#3
0
文件: tray.c 项目: Explorer09/hime
static void draw_icon()
{
  gboolean tsin_pho_mode();

  if (!tray_icon)
    return;

  GdkPixbuf *pix =  ((! current_CS) ||
                     (current_CS->im_state != HIME_STATE_CHINESE)) ?
                    pixbuf : pixbuf_ch;

  int w = 0, h = 0;
  iw = gtk_status_icon_get_size(tray_icon), ih = gtk_status_icon_get_size(tray_icon);

  cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, iw, ih);
  cr = cairo_create (cst);
  gdk_cairo_set_source_color (cr, &red_color_fg);

  if (pix) {
    gdk_cairo_set_source_pixbuf (cr, pix, 0, 0);
    cairo_paint (cr);
  } else {
    get_text_w_h(inmd[current_CS->in_method].cname, &w, &h);
    cairo_move_to (cr, 0, 0);
    pango_cairo_show_layout (cr, pango);
  }

  if (current_CS) {
    gdk_cairo_set_source_color (cr, &red_color_fg);
    if (current_shape_mode()) {
      get_text_w_h(full,  &w, &h);
      cairo_move_to (cr, iw - w, ih - h);
      pango_cairo_show_layout (cr, pango);
    }
    if (current_CS->im_state == HIME_STATE_CHINESE && !tsin_pho_mode()) {
      gdk_cairo_set_source_color (cr, &blue_color_fg);
      get_text_w_h(engst,  &w, &h);
      cairo_move_to (cr, 0, 0);
      pango_cairo_show_layout (cr, pango);
    }
  }

  if (gb_output) {
    gdk_cairo_set_source_color (cr, &red_color_fg);
    get_text_w_h(sim,  &w, &h);
    cairo_move_to (cr, 0, ih - h);
    pango_cairo_show_layout (cr, pango);
  }
  cairo_destroy(cr); cr = NULL;
  GdkPixbuf *icon_pixbuf_output = gdk_pixbuf_get_from_surface(cst, 0, 0, iw, ih);
  cairo_surface_destroy(cst); cst = NULL;
  gtk_status_icon_set_from_pixbuf(tray_icon, icon_pixbuf_output);
  g_object_unref(icon_pixbuf_output); icon_pixbuf_output = NULL;
  pix = NULL;
}
示例#4
0
文件: main.c 项目: eaglexmw/pnmixer
/**
 * Returns the size of the tray icon.
 *
 * @return size of the tray icon or 48 if there is none
 */
gint
tray_icon_size(void)
{
	// gtk_status_icon_is_embedded returns false until the prefs
	// window is opened on gtk3
	if (tray_icon && GTK_IS_STATUS_ICON(tray_icon))
		return gtk_status_icon_get_size(tray_icon);
	return 48;
}
示例#5
0
int
main (int argc, char **argv)
{
  GdkDisplay *display;
  guint n_screens, i;

  gtk_init (&argc, &argv);

  display = gdk_display_get_default ();

  n_screens = gdk_display_get_n_screens (display);

  for (i = 0; i < n_screens; i++)
    {
      GtkStatusIcon *icon;

      icon = gtk_status_icon_new ();
      gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
      update_icons ();

      g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
      g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
      g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
      g_signal_connect (icon, "notify::screen", G_CALLBACK (screen_changed_cb), NULL);
      g_print ("icon size %d\n", gtk_status_icon_get_size (icon));

      g_signal_connect (icon, "activate",
                        G_CALLBACK (icon_activated), NULL);

      g_signal_connect (icon, "popup-menu",
                        G_CALLBACK (popup_menu), NULL);

      icons = g_slist_append (icons, icon);
 
      update_icons ();

      timeout = gdk_threads_add_timeout (2000, timeout_handler, icon);
    }

  gtk_main ();

  return 0;
}