summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2025-04-16 22:53:53 -0500
committerTim Keller <tjkeller.xyz>2025-04-16 22:53:53 -0500
commitb0d338292565fe3fe932215fd628a7482a29e8f0 (patch)
tree74ac11512ae036b27e4c47973d83c8cc9b1cbd60
parent0db16d56d1a167be71b1b464af8f4fef3d052054 (diff)
downloadawesome-b0d338292565fe3fe932215fd628a7482a29e8f0.tar.xz
awesome-b0d338292565fe3fe932215fd628a7482a29e8f0.zip
volume dropdown overhual functionality make it almost good
-rw-r--r--bar.lua7
-rw-r--r--lib/pavolctld.lua6
-rw-r--r--theme.lua21
-rw-r--r--widgets/pavolctld.lua133
-rw-r--r--widgets/volumedropdown.lua147
5 files changed, 178 insertions, 136 deletions
diff --git a/bar.lua b/bar.lua
index 7e13d72..a3e2e18 100644
--- a/bar.lua
+++ b/bar.lua
@@ -1,7 +1,7 @@
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
-local buttons = require("buttons")
+require("buttons")
-- load widgets
--local mylauncher = require("widgets.button")
@@ -50,7 +50,7 @@ local widgets = {
widget_ram_usage,
wibox.widget.textbox "%",
},
- vol = {
+ vol = wibox.widget {
layout = wibox.layout.fixed.horizontal,
buttons = volume_buttons,
wibox.widget.textbox "VOL: ",
@@ -109,6 +109,9 @@ function widgets.right_widgets(s) return wibox.widget {
local month_calendar = awful.widget.calendar_popup.month()
month_calendar:attach(widgets.textclock, "t", { on_hover = false })
+-- bind volume popup to volume block
+volume_control.dropdown.dropdown:bind_to_widget(widgets.vol)
+
-- create a wibox for each screen and add it
awful.screen.connect_for_each_screen(function (s)
awful.tag({"1", "2", "3", "4", "5", "6", "7", "8", "9"}, s, awful.layout.layouts[1])
diff --git a/lib/pavolctld.lua b/lib/pavolctld.lua
index e14d964..42babbe 100644
--- a/lib/pavolctld.lua
+++ b/lib/pavolctld.lua
@@ -35,7 +35,7 @@ function sinks.get(i)
sinks.sinks[i] = {
vol = 0,
db = 0.0,
- mute = 0,
+ mute = false,
name = "",
desc = "",
}
@@ -44,7 +44,7 @@ function sinks.get(i)
end
-- return table
-local pavolctld = { _cb = {}, sinks = sinks }
+local pavolctld = { _cb = {}, sinks = sinks, max_volume = 150 }
-- callbacks
function pavolctld.set_volume_change_callback(cb) pavolctld._cb['v'] = cb end
@@ -66,7 +66,7 @@ awful.spawn.read_lines(stdout, function(s)
local sink = sinks.get(i)
sink.vol = tonumber(v())
sink.db = tonumber(v())
- sink.mute = tonumber(v())
+ sink.mute = v() == "1"
-- sink description change
elseif cmd == 's' then
local v = parse_csv(s:sub(2))
diff --git a/theme.lua b/theme.lua
index 72400ee..e36d994 100644
--- a/theme.lua
+++ b/theme.lua
@@ -1,5 +1,6 @@
-- theme handling library
local beautiful = require("beautiful")
+local apply_dpi = beautiful.xresources.apply_dpi
local gears = require("gears")
-- colors
@@ -42,20 +43,26 @@ beautiful.hotkeys_modifiers_fg = lightgray
beautiful.hotkeys_label_bg = darkgray -- ???
-- slider
-beautiful.slider_bar_height = 5
+beautiful.slider_bar_height = apply_dpi(2.5)
beautiful.slider_bar_shape = gears.shape.rounded_rect
-beautiful.slider_handle_width = 17.5
+beautiful.slider_bar_color = beautiful.border_color
+beautiful.slider_handle_width = apply_dpi(10)
beautiful.slider_handle_shape = gears.shape.circle
-beautiful.slider_handle_color = beautiful.border_color
-beautiful.slider_handle_border_color = "#333333"
-beautiful.slider_handle_border_width = 1
+--beautiful.slider_handle_color = beautiful.border_color
+--beautiful.slider_handle_border_color = "#333333"
+--beautiful.slider_handle_border_width = 1
-- progressbar
beautiful.progressbar_fg = beautiful.border_focus
-- margins
-beautiful.margin_leftright = beautiful.xresources.apply_dpi(5)
-beautiful.margin_topbottom = beautiful.xresources.apply_dpi(3)
+beautiful.margin_leftright = apply_dpi(5)
+beautiful.margin_topbottom = apply_dpi(3)
+
+-- calendar
+beautiful.calendar_header_bg_color = "#333333"
+beautiful.calendar_header_border_color = "#222222"
+beautiful.calendar_header_border_width = beautiful.border_width
-- set border on clients
client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
diff --git a/widgets/pavolctld.lua b/widgets/pavolctld.lua
index fb3c5e5..1ef523e 100644
--- a/widgets/pavolctld.lua
+++ b/widgets/pavolctld.lua
@@ -1,48 +1,24 @@
local awful = require("awful")
-local gears = require("gears")
local wibox = require("wibox")
-local beautiful = require("beautiful")
-local menubar = require("menubar")
local pavolctld = require("lib.pavolctld")
-local naughty = require("naughty")
+local volume_dropdown = require("widgets.volumedropdown")
-- ensure pavolctld loaded
if not pavolctld then return wibox.widget.textbox("err") end
-- return table
local widget = {}
+
widget.textbox = wibox.widget.textbox()
-widget.dbmeter = wibox.widget.textbox()
-widget.vslider = wibox.widget {
- {
- {
- {
- value = 50,
- max_value = 150,
- shape = beautiful.slider_bar_shape,
- bg = beautiful.slider_handle_color,
- widget = wibox.widget.progressbar,
- },
- height = 5,
- widget = wibox.container.constraint
- },
- halign = "center",
- widget = wibox.container.place,
- },
- {
- bar_height = 0,
- widget = wibox.widget.slider,
- },
- layout = wibox.layout.stack,
-}
-widget.defsink = wibox.widget.textbox()
widget.tooltip = awful.tooltip { objects = {widget.textbox}, delay_show = 1 }
+widget.dropdown = volume_dropdown
-- widget callbacks
pavolctld.set_volume_change_callback(function()
- widget.vslider.value = pavolctld.sinks.default.vol
widget.textbox:set_text(pavolctld.sinks.default.vol)
- widget.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
+ widget.dropdown.set_volume(pavolctld.sinks.default.vol)
+ widget.dropdown.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
+ widget.dropdown.muted.checked = pavolctld.sinks.default.mute
end)
pavolctld.set_sink_change_callback(function()
@@ -50,102 +26,11 @@ pavolctld.set_sink_change_callback(function()
end)
pavolctld.set_default_sink_change_callback(function()
- widget.vslider.value = pavolctld.sinks.default.vol
widget.textbox:set_text(pavolctld.sinks.default.vol)
- widget.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
widget.tooltip:set_text(pavolctld.sinks.default.desc)
- widget.defsink:set_text(pavolctld.sinks.default.desc)
-end)
-
--- slider
-widget.vslider.maximum = 150 -- max in pavolctld
-widget.vslider:buttons(volume_buttons)
-widget.vslider:connect_signal("property::value", function()
- if pavolctld.sinks.default.vol == widget.vslider.value then return end -- help prevent overloading daemon
- pavolctld.volume_set(widget.vslider.value)
-end)
-
--- scrollbox for default sink select
-local default_sink_scrollbox = wibox.widget {
- widget.defsink,
- step_function = wibox.container.scroll.step_functions.linear_increase,
- speed = 25,
- extra_space = 25, -- space between repetition
- pause = true, -- start paused
- widget = wibox.container.scroll.horizontal,
-}
-
--- scroll when hovering
-default_sink_scrollbox:connect_signal("mouse::enter", function()
- default_sink_scrollbox:continue()
+ widget.dropdown.set_volume(pavolctld.sinks.default.vol)
+ widget.dropdown.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
+ widget.dropdown.defsink:set_text(pavolctld.sinks.default.desc)
end)
-default_sink_scrollbox:connect_signal("mouse::leave", function()
- default_sink_scrollbox:pause()
- default_sink_scrollbox:reset_scrolling()
-end)
-
--- widget dropdown
-local volume_dropdown = wibox.widget {
- {
- {
- {
- default_sink_scrollbox,
- margins = 5,
- widget = wibox.container.margin,
- },
- bg = "#333333",
- widget = wibox.container.background,
- },
- margins = beautiful.border_width,
- color = "#222222",
- widget = wibox.container.margin,
- },
- {
- {
- text = "M",
- widget = wibox.widget.textbox,
- },
- {
- widget.vslider,
- left = 10,
- right = 10,
- widget = wibox.container.margin,
- layout = wibox.layout.stack,
- },
- {
- widget.dbmeter,
- forced_width = 125,
- halign = "right",
- widget = wibox.container.place,
- },
- layout = wibox.layout.align.horizontal,
- },
- forced_num_cols = 1,
- forced_num_rows = 2,
- expand = true,
- forced_width = 500,
- forced_height = 100,
- layout = wibox.layout.grid,
-}
-widget.dropdown = awful.popup {
- widget = {
- volume_dropdown,
- margins = 15,
- widget = wibox.container.margin,
- },
- border_color = beautiful.border_focus,
- border_width = beautiful.border_width,
- shape = gears.shape.rounded_rect,
- ontop = true,
- hide_on_right_click = true,
- preferred_positions = "bottom",
- preferred_anchors = 'back',
- visible = false,
- offset = { y = 5 },
-}
-
-widget.dropdown:bind_to_widget(widget.textbox)
-
-
return widget
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