Coder Social home page Coder Social logo

awesomewm-basic-patcl-volume-widget's Introduction

Awesome WM v4 Basic Volume Widget using pactl

Background

After installing Awesome for my window manager, I was having trouble finding a volume control widget for Awesome version 4 that would use pactl, have mouse controls on the widget, and would update with the volume slider on my keyboard. This script addresses all of those issues.

Install

Add the volume_widget.lua file to your awesome config directory. It should be ~/.config/awesome

Determine the speaker you're using

Run the command pactl list sinks in a terminal and find the speaker device you are going to control. In my case it is "Built-in Audio Analog Stereo". After determining the device, modify the grep command under the update_volume_widget() function in the volume_widge.lua. It should look like the following:

-- Update volume widget
local function update_volume_widget()
    -- Run "pactl list sinks" and determine the device you're using, then modify the line bellow with your device
    awful.spawn.easy_async_with_shell('pactl list sinks | grep -A 100 "Your Audio Device"', function(stdout)

Modify the rc.lua file

Add near the top of the file:

-- Load the volume widget
local volume_widget = require('volume_widget')

Under the wibar section, add setup_volume_widget(),

-- {{{ Wibar
...
    -- Add widgets to the wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            mylauncher,
            s.mytaglist,
            s.mypromptbox,
        },
        s.mytasklist, -- Middle widget
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
            setup_volume_widget(),
            mykeyboardlayout,
            wibox.widget.systray(),
            mytextclock,
            s.mylayoutbox,
        },
    }
end)
-- }}}

Add the following key bindings.

-- {{{ Key bindings
globalkeys = gears.table.join(
...
    -- Volume Keys
    awful.key({ }, "XF86AudioRaiseVolume",
        function ()
            awful.spawn("pactl set-sink-volume @DEFAULT_SINK@ +5%", false)
            awesome.emit_signal('volume_change')
        end,
        {description = "volume up", group = "audio"}),
    awful.key({ }, "XF86AudioLowerVolume",
        function ()
            awful.spawn("pactl set-sink-volume @DEFAULT_SINK@ -5%", false)
            awesome.emit_signal('volume_change')
        end,
        {description = "volume down", group = "audio"}),
    awful.key({ }, "XF86AudioMute",
        function ()
            awful.spawn("pactl set-sink-mute @DEFAULT_SINK@ toggle", false)
            awesome.emit_signal('volume_change')
        end,
        {description = "toggle mute", group = "audio"}),
...

Post-install

Now restart awesome, and there should be a widget in the top-right corner showing a percentage or "MUTE" if your speakers are muted. If this is not updating correctly, make sure to check the device that is being used in your volume_widget.lua file on line 8. pactl list sinks | grep -A 100 "Built-in Audio Analog Stereo" is what I use to find my speaker. The following lines of code search for the volume and check if the speaker is muted.

Usage

If everything is working correctly, you should now be able to hover the mouse over the volume widget in the top-right corner and use the mouse wheel to change the volume. Left click will mute. The keys you have mapped to XF86AudioRaiseVolume, XF86AudioLowerVolume, and XF86AudioMute on your keyboard should work as well. In my case, these are mapped to the volume wheel on my Razer Blackwidow Elite keyboard by default.

awesomewm-basic-patcl-volume-widget's People

Contributors

sreggopjb avatar

Watchers

 avatar

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.