Git Product home page Git Product logo

i3-volume-ctrl's Introduction

i3-volume-ctrl

Simple volume control for i3

i3-volume-ctrl screenshot

Requirements

  • alsa-utils
  • yad

Installation

  • Clone down this repository somewhere.

  • Install yad

      # arch-linux
      sudo pacman -S yad
    
      # debian / ubuntu
      sudo apt-get install yad
    
  • Install alsa-utils

      # arch-linux
      sudo pacman -S alsa-utils
    
      # debian / ubuntu
      sudo apt-get install alsa-utils
    
  • Keybindings for i3, put this in you i3 config file:

      bindsym $mod+F3 exec <path-to-i3-volume-ctrl>/volume-increase.sh
      bindsym $mod+F2 exec <path-to-i3-volume-ctrl>/volume-decrease.sh
    

<path-top-i3-volume-ctrl> is where you have cloned down this repository.

You should now be able to increase the volume using i3 function-key + f3, and you should be able to decrease the volume using i3 function-key + f2.

i3-volume-ctrl's People

Contributors

jmrr avatar sebbekarlsson avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jmrr

i3-volume-ctrl's Issues

Playback percentage found on the 3rd element of the amixer output line

I realised that on my setup, the playback % for the volume can be found on the 3rd - not 4th - parameter of the output line. This is also the same for other devices:

$ amixer | grep "\[on\]"

  Mono: Playback 52 [41%] [-37.50dB] [on]
  Front Left: Playback 127 [100%] [0.00dB] [on]
  Front Right: Playback 127 [100%] [0.00dB] [on]
  Mono: Playback [on]
  Mono: Playback [on]
  Mono: Playback [on]
  Mono: Playback [on]
  Front Left: Capture 127 [100%] [30.00dB] [on]
  Front Right: Capture 127 [100%] [30.00dB] [on]
  Mono: Capture [on]

Raising a quick PR for this, and thanks for this useful feature on i3!

I'm using amixer version 1.1.3 on Ubuntu 18.04 with zsh.

read volume from alsa C library instead

Parsing the volume from the amixer program output is not very stable.

This could be used:

#include <alsa/asoundlib.h>
#include <alsa/mixer.h>

/**
 * Get volume
 *
 * @return float
 */
float get_volume()
{
    long min, max, v;
    snd_mixer_t *handle;
    snd_mixer_selem_id_t *sid;
    const char *card = "default";
    const char *selem_name = "Master";

    snd_mixer_open(&handle, 0);
    snd_mixer_attach(handle, card);
    snd_mixer_selem_register(handle, NULL, NULL);
    snd_mixer_load(handle);
    snd_mixer_handle_events(handle); 

    snd_mixer_selem_id_alloca(&sid);
    snd_mixer_selem_id_set_index(sid, 0);
    snd_mixer_selem_id_set_name(sid, selem_name);
    snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);

    snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &v);
    snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
    
    float volume = (((float) v) / ((float)max)) * 100.0f;
    
    snd_mixer_close(handle);
    
    return volume;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.