コード例 #1
0
ファイル: volume_change.c プロジェクト: wor/avolt
/* Sets new volume, expects new_vol to be within [0,100] range. */
bool set_new_volume(
        struct sound_profile* sp,
        long int new_vol,
        bool relative_inc,
        bool set_default_vol,
        bool toggle_vol,
        bool use_semaphore,
        enum Volume_type volume_type)
{
    /* XXX: Checking new_vol limits */
    if (relative_inc) {
        if (new_vol < 0 || new_vol > 100) {
            fprintf(stderr, "Cannot set volume which is not in range [0,100]: %li\n", new_vol);
            return false;
        }
    } else if ((new_vol < -100 || new_vol > 100) && !set_default_vol && !toggle_vol) {
        fprintf(stderr, "Cannot set volume which is not in range [-100,100]: %li\n", new_vol);
        return false;
    }
    /* **************************** */

    sem_t *sem = NULL; /* Semaphore which is used if USE_SEMAPHORE is true */
    if (use_semaphore && !check_semaphore(&sem)) return false;

    /* Change new volume to native range */
    PD_M("set_new_volume: new vol [-100,100], relative or toggling: %li\n", new_vol);

    if (set_default_vol) {
        // Set default volume
        PD_M("set_new_volume: setting default vol..\n");
        set_vol(sp->volume_cntrl_mixer_element, sp->volume_type, sp->default_volume, 0);
    } else if (toggle_vol) {
        // toggle volume
        PD_M("set_new_volume: toggling..\n");
        toggle_volume(sp, new_vol, volume_type);
    } else {
        /* Change absolute and relative volumes */

        /* First check if relative volume */
        if (relative_inc || new_vol < 0) {
            if (new_vol != 0) {
                PD_M("set_new_volume: Relative vol change...\n");
                long int current_vol = 0;
                // Change volume relative to current volume
                get_vol(sp->volume_cntrl_mixer_element, volume_type, &current_vol);
                // By setting the round direction we always guarantee that
                // some change happens.
                int round_direction = new_vol < 0 ? -1 : 1;
                set_vol(sp->volume_cntrl_mixer_element, volume_type, current_vol + new_vol, round_direction);
            }
        } else {
            // Change absolute volume
            PD_M("set_new_volume: Changing absolute volume: %li\n", new_vol);
            set_vol(sp->volume_cntrl_mixer_element, volume_type, new_vol, 0);
        }
    }

    if (use_semaphore && !check_semaphore(&sem)) return false;
    return true;
}
コード例 #2
0
ファイル: trayicon.c プロジェクト: cecylia/vampiria
static void
mute_menuitem_toggled_cb (GtkCheckMenuItem *checkmenuitem,
                          gpointer user_data)
{
	toggle_volume ();
}