mirror of
https://github.com/bertptrs/vimconfig.git
synced 2025-12-25 20:40:32 +01:00
Add sound control widget to awesome.
This commit is contained in:
@@ -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),
|
||||
|
||||
50
awesome/.config/awesome/volume.lua
Normal file
50
awesome/.config/awesome/volume.lua
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user