示例#1
0
文件: notify.c 项目: hyuni/pnmixer
/**
 * Send a volume notification. This is mainly called
 * from the alsa subsystem whenever we have volume
 * changes.
 *
 * @param level the playback volume level
 * @param muted whether the playback is muted
 */
void
do_notify_volume(gint level, gboolean muted)
{
	static NotifyNotification *notification = NULL;
	gchar *summary, *icon, *active_card_name;
	const char *active_channel;
	GError *error = NULL;

	active_card_name = (alsa_get_active_card())->name;
	active_channel = alsa_get_active_channel();

	if (notification == NULL) {
		notification = NOTIFICATION_NEW("", NULL, NULL);
		notify_notification_set_timeout(notification, noti_timeout);
		NOTIFICATION_SET_HINT_STRING(notification,
					     "x-canonical-private-synchronous", "");
	}

	if (level < 0)
		level = 0;
	if (level > 100)
		level = 100;

	if (muted)
		summary = g_strdup("Volume muted");
	else
		summary =
			g_strdup_printf("%s (%s)\nVolume: %d%%\n",
					active_card_name, active_channel, level);

	if (muted)
		icon = "audio-volume-muted";
	else if (level == 0)
		icon = "audio-volume-off";
	else if (level < 33)
		icon = "audio-volume-low";
	else if (level < 66)
		icon = "audio-volume-medium";
	else
		icon = "audio-volume-high";

	notify_notification_update(notification, summary, NULL, icon);
	NOTIFICATION_SET_HINT_INT32(notification, "value", level);

	if (!notify_notification_show(notification, &error)) {
		report_error(_("Could not send notification: %s"), error->message);
		g_error_free(error);
	}

	g_free(summary);
}
示例#2
0
文件: main.c 项目: eaglexmw/pnmixer
/**
 * Updates the tray icon. Usually called after volume has been muted
 * or changed.
 */
void
update_tray_icon(void)
{
	int muted;
	int tmpvol = getvol();
	char tooltip[60];
	gchar *active_card_name = (alsa_get_active_card())->name;
	const char *active_channel = alsa_get_active_channel();

	muted = ismuted();

	if (muted == 1) {
		GdkPixbuf *icon;

		if (tmpvol == 0)
			icon = status_icons[VOLUME_OFF];
		else if (tmpvol < 33)
			icon = status_icons[VOLUME_LOW];
		else if (tmpvol < 66)
			icon = status_icons[VOLUME_MEDIUM];
		else
			icon = status_icons[VOLUME_HIGH];
		sprintf(tooltip, _("%s (%s)\nVolume: %d %%"), active_card_name,
			active_channel,
			tmpvol);

		if (vol_meter_row) {
			GdkPixbuf *old_icon = icon_copy;
			icon_copy = gdk_pixbuf_copy(icon);
			draw_vol_meter(icon_copy, draw_offset, 5,
				       (tmpvol * vol_div_factor));
			if (old_icon)
				g_object_unref(old_icon);
			gtk_status_icon_set_from_pixbuf(tray_icon, icon_copy);
		} else
			gtk_status_icon_set_from_pixbuf(tray_icon, icon);
	} else {
		gtk_status_icon_set_from_pixbuf(tray_icon, status_icons[VOLUME_MUTED]);
		sprintf(tooltip, _("%s (%s)\nVolume: %d %%\nMuted"), active_card_name,
			active_channel, tmpvol);
	}
	gtk_status_icon_set_tooltip_text(tray_icon, tooltip);
}