diff options
Diffstat (limited to 'widgets/volumedropdown.lua')
-rw-r--r-- | widgets/volumedropdown.lua | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/widgets/volumedropdown.lua b/widgets/volumedropdown.lua new file mode 100644 index 0000000..c2e3fbc --- /dev/null +++ b/widgets/volumedropdown.lua @@ -0,0 +1,147 @@ +local awful = require("awful") +local wibox = require("wibox") +local beautiful = require("beautiful") +local apply_dpi = beautiful.xresources.apply_dpi +local pavolctld = require("lib.pavolctld") + +-- return table +local widget = {} + +widget.dbmeter = wibox.widget.textbox() +local slider = wibox.widget { + bar_height = 0, + widget = wibox.widget.slider, + maximum = pavolctld.max_volume, +} +local progressbar = wibox.widget { + max_value = pavolctld.max_volume, + shape = beautiful.slider_bar_shape, + bg = beautiful.slider_handle_color, + widget = wibox.widget.progressbar, +} +widget.vslider = wibox.widget { + { + { + progressbar, + height = apply_dpi(3), + widget = wibox.container.constraint + }, + halign = "center", + widget = wibox.container.place, + }, + slider, + layout = wibox.layout.stack, +} + +-- scrollbox for default sink select +widget.defsink = wibox.widget.textbox() +local default_sink_scrollbox = wibox.widget { + widget.defsink, + step_function = wibox.container.scroll.step_functions.linear_increase, + speed = apply_dpi(15), + extra_space = apply_dpi(25), -- space between repetition + pause = true, -- start paused + widget = wibox.container.scroll.horizontal, +} + +widget.muted = wibox.widget { + color = "#222222", + check_color = beautiful.border_focus, + widget = wibox.widget.checkbox, +} + +-- widget dropdown +local volume_dropdown = wibox.widget { + { + { + { + default_sink_scrollbox, + margins = beautiful.margin_topbottom, + widget = wibox.container.margin, + }, + bg = "#333333", + widget = wibox.container.background, + }, + margins = beautiful.border_width, + color = "#222222", + widget = wibox.container.margin, + }, + { + { + { + text = "Mute:", + widget = wibox.widget.textbox, + }, + left = apply_dpi(10), + right = apply_dpi(5), + widget = wibox.container.margin, + }, + { + widget.muted, + fill_vertical = true, + widget = wibox.container.place, + }, + forced_width = apply_dpi(80), + layout = wibox.layout.align.horizontal, + }, + widget.vslider, + { + widget.dbmeter, + forced_width = apply_dpi(80), + halign = "right", + widget = wibox.container.place, + }, + forced_num_cols = 2, + forced_num_rows = 2, + homogeneous = false, + expand = true, + forced_width = apply_dpi(300), + forced_height = apply_dpi(60), + layout = wibox.layout.grid, +} +widget.dropdown = awful.popup { + widget = { + volume_dropdown, + left = beautiful.margin_leftright, + right = beautiful.margin_leftright, + top = beautiful.margin_topbottom, + bottom = beautiful.margin_topbottom, + widget = wibox.container.margin, + }, + border_color = beautiful.border_normal, + border_width = beautiful.border_width, + ontop = true, + hide_on_right_click = true, + preferred_positions = "bottom", + preferred_anchors = "back", + visible = false, +} + +-- slider +slider:buttons(volume_buttons) +slider:connect_signal("property::value", function() + if pavolctld.sinks.default.vol == slider.value then return end + pavolctld.volume_set(slider.value) +end) + +function widget.set_volume(vol) + progressbar:set_value(vol) + if vol == slider.value then return end + slider.value = vol + slider:emit_signal("widget::redraw_needed") +end + +-- scroll when hovering +default_sink_scrollbox:connect_signal("mouse::enter", function() + default_sink_scrollbox:continue() +end) + +default_sink_scrollbox:connect_signal("mouse::leave", function() + default_sink_scrollbox:pause() + default_sink_scrollbox:reset_scrolling() +end) + +-- mute button +widget.muted:connect_signal("button::press", pavolctld.mute_toggle) + +return widget |