summaryrefslogtreecommitdiff
path: root/experiments/volume/volume.lua
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/volume/volume.lua')
-rw-r--r--experiments/volume/volume.lua94
1 files changed, 63 insertions, 31 deletions
diff --git a/experiments/volume/volume.lua b/experiments/volume/volume.lua
index beaa119..9110a45 100644
--- a/experiments/volume/volume.lua
+++ b/experiments/volume/volume.lua
@@ -12,39 +12,26 @@ local wibox = require("wibox")
local spawn = require("awful.spawn")
local gears = require("gears")
local beautiful = require("beautiful")
+local watch = require("awful.widget.watch")
local utils = require("awesome-wm-widgets.experiments.volume.utils")
-local HOME_DIR = os.getenv("HOME")
-local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/experiments/volume'
local LIST_DEVICES_CMD = [[sh -c "pacmd list-sinks; pacmd list-sources"]]
+local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
+local INC_VOLUME_CMD = 'amixer -q -D pulse sset Master 5%+'
+local DEC_VOLUME_CMD = 'amixer -q -D pulse sset Master 5%-'
+local TOG_VOLUME_CMD = 'amixer -q -D pulse sset Master toggle'
-local rows = { layout = wibox.layout.fixed.vertical }
-local volume_widget = wibox.widget {
- {
- {
- id = "icon",
- image = WIDGET_DIR .. '/volume-2.svg',
- widget = wibox.widget.imagebox
- },
- id = "margin",
- margins = 4,
- layout = wibox.container.margin
- },
- {
- id = "txt",
- widget = wibox.widget.textbox
- },
- layout = wibox.layout.fixed.horizontal,
- set_text = function(self, new_value)
- self.txt.text = new_value
- end,
- set_icon = function(self, new_value)
- self.margin.icon.image = new_value
- end
+local widget_types = {
+ icon_and_text = require("awesome-wm-widgets.experiments.volume.widgets.icon-and-text-widget"),
+ icon = require("awesome-wm-widgets.experiments.volume.widgets.icon-widget"),
+ arc = require("awesome-wm-widgets.experiments.volume.widgets.arc-widget")
}
+local volume_widget = wibox.widget{}
+
+local rows = { layout = wibox.layout.fixed.vertical }
local popup = awful.popup{
bg = beautiful.bg_normal,
@@ -60,7 +47,7 @@ local popup = awful.popup{
local function build_main_line(device)
if device.active_port ~= nil and device.ports[device.active_port] ~= nil then
- return device.properties.device_description .. ' - ' .. device.ports[device.active_port]
+ return device.properties.device_description .. ' ยท ' .. device.ports[device.active_port]
else
return device.properties.device_description
end
@@ -82,7 +69,6 @@ local function build_rows(devices, on_checkbox_click, device_type)
}
checkbox:connect_signal("button::press", function(c)
- print(string.format([[sh -c 'pacmd set-default-%s "%s"']], device_type, device.name))
spawn.easy_async(string.format([[sh -c 'pacmd set-default-%s "%s"']], device_type, device.name), function()
on_checkbox_click()
end)
@@ -108,13 +94,35 @@ local function build_rows(devices, on_checkbox_click, device_type)
spacing = 8,
layout = wibox.layout.align.horizontal
},
- margins = 8,
+ margins = 4,
layout = wibox.container.margin
},
bg = beautiful.bg_normal,
widget = wibox.container.background
}
+ row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)
+ row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end)
+
+ local old_cursor, old_wibox
+ row:connect_signal("mouse::enter", function(c)
+ local wb = mouse.current_wibox
+ old_cursor, old_wibox = wb.cursor, wb
+ wb.cursor = "hand1"
+ end)
+ row:connect_signal("mouse::leave", function(c)
+ if old_wibox then
+ old_wibox.cursor = old_cursor
+ old_wibox = nil
+ end
+ end)
+
+ row:connect_signal("button::press", function(c)
+ spawn.easy_async(string.format([[sh -c 'pacmd set-default-%s "%s"']], device_type, device.name), function()
+ on_checkbox_click()
+ end)
+ end)
+
table.insert(device_rows, row)
end
@@ -147,25 +155,49 @@ local function rebuild_popup()
popup:setup(rows)
end)
-
end
local function worker(args)
+ local args = args or {}
+
+ local widget_type = args.widget_type
+
+ if widget_types[widget_type] == nil then
+ volume_widget = widget_types['icon_and_text'].get_widget()
+ else
+ volume_widget = widget_types[widget_type].get_widget()
+ end
+
volume_widget:buttons(
awful.util.table.join(
- awful.button({}, 1, function()
+ awful.button({}, 3, function()
if popup.visible then
popup.visible = not popup.visible
else
rebuild_popup()
popup:move_next_to(mouse.current_widget_geometry)
end
- end)
+ end),
+ awful.button({}, 4, function() awful.spawn(INC_VOLUME_CMD, false) end),
+ awful.button({}, 5, function() awful.spawn(DEC_VOLUME_CMD, false) end),
+ awful.button({}, 1, function() awful.spawn(TOG_VOLUME_CMD, false) end)
)
)
+ local function update_graphic(widget, stdout)
+ local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
+ if mute == 'off' then volume_widget:mute()
+ elseif mute == 'on' then volume_widget:unmute()
+ end
+ local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
+ volume = string.format("% 3d", volume)
+ widget:set_volume_level(volume)
+ end
+
+ watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
+
return volume_widget
end