diff --git a/awesome/.config/awesome/rc.lua b/awesome/.config/awesome/rc.lua index 69099be..3f438d0 100644 --- a/awesome/.config/awesome/rc.lua +++ b/awesome/.config/awesome/rc.lua @@ -10,6 +10,7 @@ local beautiful = require("beautiful") -- Notification library local naughty = require("naughty") local menubar = require("menubar") +local volume = require("volume") -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to @@ -191,6 +192,7 @@ for s = 1, screen.count() do local battery = require("battery") right_layout:add(mytextclock) + right_layout:add(volume) right_layout:add(battery) right_layout:add(mylayoutbox[s]) @@ -276,6 +278,11 @@ globalkeys = awful.util.table.join( -- Menubar awful.key({ modkey }, "p", function() menubar.show() end), + -- Volume control + awful.key({ }, "XF86AudioLowerVolume", function () volume.decrease() end), + awful.key({ }, "XF86AudioRaiseVolume", function () volume.increase() end), + awful.key({ }, "XF86AudioMute", function () volume.mute() end), + -- Backlight control awful.key({ }, "XF86MonBrightnessDown", function () awful.util.spawn("xbacklight -dec 15") end), diff --git a/awesome/.config/awesome/volume.lua b/awesome/.config/awesome/volume.lua new file mode 100644 index 0000000..cb29c8a --- /dev/null +++ b/awesome/.config/awesome/volume.lua @@ -0,0 +1,50 @@ +-- Volume widget + +local vicious = require("vicious") +local wibox = require("wibox") +local awful = require("awful") + +module("volume") + +local widget = wibox.widget.textbox() + +local function volume_callback (_, args) + local muted = args[2] + local volume = args[1] + + if muted == "♫" then + return "🔊" .. volume .. "%" + else + return "🔇" + end +end + +local function volume_command (command) + local step = "5%" + local base = "amixer set Master " + + if command == "mute" then + awful.util.spawn(base .. "toggle") + else + awful.util.spawn(base .. step .. command) + end + + vicious.force({widget}) +end + + +widget.increase = function() + volume_command("+") +end + +widget.decrease = function() + volume_command("-") +end + +widget.mute = function() + volume_command("mute") +end + +vicious.register(widget, vicious.widgets.volume, volume_callback, 60, "Master") + +return widget