Exemplo n.º 1
0
/**
 * Updates all status icons for the different volume states like
 * muted, low, medium, high as well as the volume meter. This
 * is triggered either by apply_prefs() in the preferences subsystem,
 * do_alsa_reinit() or tray_icon_resized().
 */
void update_status_icons() {
  int i,icon_width;
  GdkPixbuf* old_icons[4];
  int size = tray_icon_size();
  for(i=0;i<4;i++)
    old_icons[i] = status_icons[i];
  if (g_key_file_has_key(keyFile,"PNMixer","IconTheme",NULL)) {
    status_icons[0] = get_stock_pixbuf("audio-volume-muted",size);
    status_icons[1] = get_stock_pixbuf("audio-volume-low",size);
    status_icons[2] = get_stock_pixbuf("audio-volume-medium",size);
    status_icons[3] = get_stock_pixbuf("audio-volume-high",size);
  } else {
    status_icons[0] = create_pixbuf("pnmixer-muted.png");
    status_icons[1] = create_pixbuf("pnmixer-low.png");
    status_icons[2] = create_pixbuf("pnmixer-medium.png");
    status_icons[3] = create_pixbuf("pnmixer-high.png");
  }
  icon_width = gdk_pixbuf_get_height(status_icons[0]);
  vol_div_factor = ((gdk_pixbuf_get_height(status_icons[0])-10)/100.0);
  vol_meter_width = 1.25*icon_width;
  if (vol_meter_width%4 != 0)
    vol_meter_width -= (vol_meter_width%4);
  if (!vol_meter_row &&  g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) {
    int lim = vol_meter_width/4;
    vol_meter_row = g_malloc(vol_meter_width*sizeof(guchar));
    for(i=0;i<lim;i++) {
      vol_meter_row[i*4]   = vol_meter_red;
      vol_meter_row[i*4+1] = vol_meter_green;
      vol_meter_row[i*4+2] = vol_meter_blue;
      vol_meter_row[i*4+3] = 255;
    }
  } else if (vol_meter_row && !g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) {
    free(vol_meter_row);
    vol_meter_row = NULL;
    if (icon_copy)
      g_object_unref(icon_copy);
    icon_copy = NULL;
  }
  draw_offset = g_key_file_get_integer(keyFile,"PNMixer","VolMeterPos",NULL);
  if (tray_icon)
    get_mute_state(TRUE);
  for(i = 0;i < 4;i++)
    if(old_icons[i])
      g_object_unref(old_icons[i]);
}
Exemplo n.º 2
0
/**
 * Updates all status icons for the different volume states like
 * muted, low, medium, high as well as the volume meter. This
 * is triggered either by apply_prefs() in the preferences subsystem,
 * do_alsa_reinit() or tray_icon_resized().
 */
void
update_status_icons(void)
{
	int i, icon_width;
	GdkPixbuf *old_icons[N_VOLUME_ICONS];
	int size = tray_icon_size();

	for (i = 0; i < N_VOLUME_ICONS; i++)
		old_icons[i] = status_icons[i];

	/* Handle icons depending on the theme */
	if (prefs_get_boolean("SystemTheme", FALSE)) {
		status_icons[VOLUME_MUTED] = get_stock_pixbuf("audio-volume-muted",
					     size);
		status_icons[VOLUME_OFF] = get_stock_pixbuf("audio-volume-off", size);
		status_icons[VOLUME_LOW] = get_stock_pixbuf("audio-volume-low", size);
		status_icons[VOLUME_MEDIUM] = get_stock_pixbuf("audio-volume-medium",
					      size);
		status_icons[VOLUME_HIGH] = get_stock_pixbuf("audio-volume-high",
					    size);
		/* 'audio-volume-off' is not available in every icon set. More info at:
		 * http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
		 */
		if (status_icons[VOLUME_OFF] == NULL)
			status_icons[VOLUME_OFF] = get_stock_pixbuf("audio-volume-low",
						   size);
	} else {
		status_icons[VOLUME_MUTED] = create_pixbuf("pnmixer-muted.png");
		status_icons[VOLUME_OFF] = create_pixbuf("pnmixer-off.png");
		status_icons[VOLUME_LOW] = create_pixbuf("pnmixer-low.png");
		status_icons[VOLUME_MEDIUM] = create_pixbuf("pnmixer-medium.png");
		status_icons[VOLUME_HIGH] = create_pixbuf("pnmixer-high.png");
	}

	/* Handle volume meter */
	icon_width = gdk_pixbuf_get_height(status_icons[0]);
	vol_div_factor = ((gdk_pixbuf_get_height(status_icons[0]) - 10) / 100.0);
	vol_meter_width = 1.25 * icon_width;
	if (vol_meter_width % 4 != 0)
		vol_meter_width -= (vol_meter_width % 4);

	if (prefs_get_boolean("DrawVolMeter", FALSE)) {
		int lim;

		if (vol_meter_row)
			g_free(vol_meter_row);
		vol_meter_row = g_malloc(vol_meter_width * sizeof(guchar));

		lim = vol_meter_width / 4;
		for (i = 0; i < lim; i++) {
			vol_meter_row[i * 4] = vol_meter_red;
			vol_meter_row[i * 4 + 1] = vol_meter_green;
			vol_meter_row[i * 4 + 2] = vol_meter_blue;
			vol_meter_row[i * 4 + 3] = 255;
		}
	} else {
		if (vol_meter_row)
			g_free(vol_meter_row);
		vol_meter_row = NULL;
		if (icon_copy)
			g_object_unref(icon_copy);
		icon_copy = NULL;
	}

	draw_offset = prefs_get_integer("VolMeterPos", 0);

	if (tray_icon)
		on_volume_has_changed();

	for (i = 0; i < N_VOLUME_ICONS; i++)
		if (old_icons[i])
			g_object_unref(old_icons[i]);
}