/** * 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(GtkStatusIcon *status_icon, GdkEventButton *event, gpointer user_data) { if (event->button == 2) { gint act = 0; if (g_key_file_has_key(keyFile,"PNMixer","MiddleClickAction",NULL)) act = g_key_file_get_integer(keyFile,"PNMixer","MiddleClickAction",NULL); switch (act) { case 0: // mute/unmute setmute(mouse_noti); get_mute_state(TRUE); break; case 1: do_prefs(); break; case 2: { on_mixer(); break; } case 3: if (g_key_file_has_key(keyFile,"PNMixer","CustomCommand",NULL)) { gchar* cmd = g_key_file_get_string(keyFile,"PNMixer","CustomCommand",NULL); if (cmd) { run_command(cmd); g_free(cmd); } else // This shouldn't ever happen, so let's just write to console g_warning("KeyFile has CustomCommand key, but get_string returned NULL"); } else report_error(_("You have not specified a custom command to run, please specify one in preferences.")); break; default: {} // nothing } } }
static GdkFilterReturn key_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) { int type; unsigned int key,state; XKeyEvent *xevent; //gboolean bResult; xevent = gdk_xevent; type = xevent->type; if (type == KeyPress) { key = ((XKeyEvent *)xevent)->keycode; state = ((XKeyEvent *)xevent)->state; if (key == volMuteKey && state == volMuteMods) { setmute(enable_noti&&hotkey_noti); get_mute_state(TRUE); return GDK_FILTER_CONTINUE; } else { int cv = getvol(); if (key == volUpKey && state == volUpMods) { setvol(cv+volStep,enable_noti&&hotkey_noti); } else if (key == volDownKey && state == volDownMods) { setvol(cv-volStep,enable_noti&&hotkey_noti); } // just ignore unknown hotkeys if (get_mute_state(TRUE) == 0) setmute(enable_noti&&hotkey_noti); // this will set the slider value get_current_levels(); } } return GDK_FILTER_CONTINUE; }
/** * 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]); }
/** * Reinitializes alsa and updates the tray icon. */ void do_alsa_reinit (void) { alsa_init(); update_status_icons(); update_vol_text(); get_mute_state(TRUE); }