/** * Handles 'button-release-event' signal on the GtkStatusIcon. * Only used for middle-click, which runs the middle click action. * * @param status_icon the object which received the signal. * @param event the GdkEventButton which triggered this signal. * @param icon TrayIcon instance set when the signal handler was connected. * @return TRUE to stop other handlers from being invoked for the event. * FALSE to propagate the event further. */ static gboolean on_button_release_event(G_GNUC_UNUSED GtkStatusIcon *status_icon, GdkEventButton *event, G_GNUC_UNUSED TrayIcon *icon) { int middle_click_action; if (event->button != 2) return FALSE; middle_click_action = prefs_get_integer("MiddleClickAction", 0); switch (middle_click_action) { case 0: audio_toggle_mute(icon->audio, AUDIO_USER_TRAY_ICON); break; case 1: run_prefs_dialog(); break; case 2: run_mixer_command(); break; case 3: run_custom_command(); break; default: { } // nothing } return FALSE; }
/** * Updates the alignment of the volume text which is shown on the * volume popup_window (left click) around the scroll bar. */ void update_vol_text(void) { gboolean show; show = prefs_get_boolean("DisplayTextVolume", TRUE); if (show) { gint pi; GtkPositionType pos; pi = prefs_get_integer("TextVolumePosition", 0); pos = pi == 0 ? GTK_POS_TOP : pi == 1 ? GTK_POS_BOTTOM : pi == 2 ? GTK_POS_LEFT : GTK_POS_RIGHT; gtk_scale_set_draw_value(GTK_SCALE(vol_scale), TRUE); gtk_scale_set_value_pos(GTK_SCALE(vol_scale), pos); } else gtk_scale_set_draw_value(GTK_SCALE(vol_scale), FALSE); }
/** * Handles button-release-event' signal on the tray_icon, currently * only used for middle-click. * * @param status_icon the object which received the signal * @param event the GdkEventButton which triggered this signal * @param user_data user data set when the signal handler was * connected */ void tray_icon_button(G_GNUC_UNUSED GtkStatusIcon *status_icon, GdkEventButton *event, G_GNUC_UNUSED gpointer user_data) { gint action; if (event->button != 2) return; action = prefs_get_integer("MiddleClickAction", 0); switch (action) { case 0: // mute/unmute setmute(mouse_noti); on_volume_has_changed(); break; case 1: do_prefs(); break; case 2: on_mixer(); break; case 3: { gchar *cmd; cmd = prefs_get_string("CustomCommand", NULL); if (cmd) { run_command(cmd); g_free(cmd); } else report_error(_("You have not specified a custom command to run, " "please specify one in preferences.")); break; } default: { } // nothing } }
/* Configure the appearance of the text that is shown around the volume slider, * according to the current preferences. */ static void configure_vol_text(GtkScale *vol_scale) { gboolean enabled; gint position; GtkPositionType gtk_position; enabled = prefs_get_boolean("DisplayTextVolume", TRUE); position = prefs_get_integer("TextVolumePosition", 0); gtk_position = position == 0 ? GTK_POS_TOP : position == 1 ? GTK_POS_BOTTOM : position == 2 ? GTK_POS_LEFT : GTK_POS_RIGHT; if (enabled) { gtk_scale_set_draw_value(vol_scale, TRUE); gtk_scale_set_value_pos(vol_scale, gtk_position); } else { gtk_scale_set_draw_value(vol_scale, FALSE); } }
/* Returns a new VolMeter instance. Returns NULL if VolMeter is disabled. */ static VolMeter * vol_meter_new(void) { VolMeter *vol_meter; gboolean vol_meter_enabled; gdouble *vol_meter_clrs; vol_meter_enabled = prefs_get_boolean("DrawVolMeter", FALSE); if (vol_meter_enabled == FALSE) return NULL; vol_meter = g_new0(VolMeter, 1); vol_meter->x_offset_pct = prefs_get_integer("VolMeterPos", 0); vol_meter->y_offset_pct = 10; vol_meter_clrs = prefs_get_double_list("VolMeterColor", NULL); vol_meter->red = vol_meter_clrs[0] * 255; vol_meter->green = vol_meter_clrs[1] * 255; vol_meter->blue = vol_meter_clrs[2] * 255; g_free(vol_meter_clrs); return vol_meter; }
/** * 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]); }