Compare commits

..

No commits in common. "bb27fcfaa04d9d9cf4a3d23fbb10ec8dc8d8bfa0" and "9ca3a7147d0dfe85970acff79fead792bbfec074" have entirely different histories.

5 changed files with 145 additions and 198 deletions

View File

@ -9,7 +9,7 @@ See the [modules](./modules/README.md) README.
## Dependencies ## Dependencies
Some features require extra tools. Tools each module requires are listed below. If a module is disabled, its tool is not needed. Applications required by `core` MUST be installed. Some features require extra tools. Tools each module requires are listed below. If a module is disabled, its tool is not needed. Applications required by `core` MUST be installed.
- Core: `fish`, `sox` (and plugins) - Core: `fish`
- Backlight: `xbacklight` - Backlight: `xbacklight`
- Battery: `upower` - Battery: `upower`
- Ibus: `ibus` - Ibus: `ibus`

View File

@ -8,8 +8,9 @@ return {
init = function () init = function ()
-- Make sure volume is unmuted -- Make sure volume is unmuted
-- Implicitly updates widgets volume.commands:unmute()
volume.commands.unmute() -- Update volume widget at start
volume.commands:get(widget.update)
end, end,
for_each_screen = function (s) for_each_screen = function (s)

View File

@ -75,7 +75,7 @@ return function(s)
bottom = beautiful.dpi(10), bottom = beautiful.dpi(10),
widget = wibox.container.margin widget = wibox.container.margin
}, },
bg ="#000000CC", bg ="#000000AA",
widget = wibox.container.background, widget = wibox.container.background,
ontop = true, ontop = true,
visible = true, visible = true,
@ -94,7 +94,7 @@ return function(s)
screen = s, screen = s,
placement = function(c) placement = function(c)
awful.placement.bottom_right( awful.placement.centered(
c, c,
{ {
honor_workarea = true, honor_workarea = true,
@ -107,14 +107,10 @@ return function(s)
-- Only set corner radius here. -- Only set corner radius here.
shape = function(cr, width, height) shape = function(cr, width, height)
gears.shape.partially_rounded_rect( gears.shape.rounded_rect(
cr, cr,
width, width,
height, height,
true,
false,
false,
false,
beautiful.dpi(20) beautiful.dpi(20)
) )
end end
@ -126,18 +122,10 @@ return function(s)
} }
awesome.connect_signal("module::volume:update", local function update_popup()
function(status) volume.commands:get(function(status)
-- Update slider awesome.emit_signal("widget::volume")
widget.
container.
popup_layout.
icon_bar_layout.
bar_layout.
volume_bar:set_value(status.value)
-- Update text
widget. widget.
container. container.
popup_layout. popup_layout.
@ -145,7 +133,11 @@ return function(s)
label_value_layout. label_value_layout.
value:set_text(status.value .. "%") value:set_text(status.value .. "%")
-- Update icon awesome.emit_signal(
"widget::volume:update",
status.value
)
local icon local icon
if status.mute then if status.mute then
icon = beautiful.icons.volume.mute icon = beautiful.icons.volume.mute
@ -166,8 +158,22 @@ return function(s)
icon_margin1. icon_margin1.
icon_margin2. icon_margin2.
icon:set_image(icon) icon:set_image(icon)
end end)
) end
local update_slider = function()
volume.commands:get(function(status)
widget.
container.
popup_layout.
icon_bar_layout.
bar_layout.
volume_bar:set_value(status.value)
update_popup()
end)
end
update_slider()
local hide_popup_timer = gears.timer { local hide_popup_timer = gears.timer {
timeout = 1, timeout = 1,
@ -177,9 +183,9 @@ return function(s)
end end
} }
awesome.connect_signal("module::volume_popup:show", awesome.connect_signal("module::volume_popup:show",
function() function()
update_slider()
if s == mouse.screen then if s == mouse.screen then
popup_container.visible = true popup_container.visible = true
end end
@ -192,43 +198,11 @@ return function(s)
end end
) )
awesome.connect_signal("module::volume_popup:show_stay",
function()
if s == mouse.screen then
popup_container.visible = true
end
if hide_popup_timer.started then
hide_popup_timer:stop()
end
end
)
popup_container:connect_signal("button::press", popup_container:connect_signal("button::press",
function(_, _, _, button, mods) function()
-- Right-click popup_container.visible = false
if (button == 1) then hide_popup_timer:stop()
volume.toggle_mute()
-- Scroll up
elseif (button == 4) then
volume.volume_up()
-- Scroll down
elseif (button == 5) then
volume.volume_down()
end
end end
) )
popup_container:connect_signal("mouse::enter", function(result)
awesome.emit_signal("module::volume_popup:show_stay")
end)
popup_container:connect_signal("mouse::leave", function(result)
awesome.emit_signal("module::volume_popup:show")
end)
end end

View File

@ -1,5 +1,5 @@
local volume = {} local volume = {}
volume.commands = {}
-- Create pamixer option string -- Create pamixer option string
@ -8,122 +8,82 @@ if (config.volume.pamixer_sink ~= "") then
volume.pamixer_options = volume.pamixer_options .. " --sink " .. config.volume.pamixer_sink volume.pamixer_options = volume.pamixer_options .. " --sink " .. config.volume.pamixer_sink
end end
volume.commands = { function volume.commands:up()
up = function(callback) awful.spawn("pamixer --increase 5" .. volume.pamixer_options, false)
awful.spawn.easy_async( end
"pamixer --increase 5 " .. volume.pamixer_options,
function(stdout, stderr, exitreason, exitcode) function volume.commands:down()
awesome.emit_signal("module::volume:update_read") awful.spawn("pamixer --decrease 5" .. volume.pamixer_options, false)
if (callback ~= nil) then end
callback()
end function volume.commands:set(value)
awful.spawn("pamixer --set_volume" .. tostring(value) .. " " .. volume.pamixer_options, false)
end
function volume.commands:mute()
awful.spawn("pamixer --mute" .. volume.pamixer_options, false)
end
function volume.commands:unmute()
awful.spawn("pamixer --unmute" .. volume.pamixer_options, false)
end
function volume.commands:get(callback)
local muted
local value
awful.spawn.easy_async("pamixer --get-mute --get-volume" .. volume.pamixer_options,
function(stdout, stderr, exitreason, exitcode)
muted = string.match(stdout, "(%w%w%w%w%w?) ") -- "true" or "false"
muted = (muted == "true")
value = string.match(stdout, "(%d?%d?%d)") -- (\d?\d?\d)\%)
if (value == nil) then
value = false
else
value = tonumber(string.format("% 3d", value))
end end
)
end,
down = function(callback) callback({
awful.spawn.easy_async( mute = muted,
"pamixer --decrease 5 " .. volume.pamixer_options, value = value
function(stdout, stderr, exitreason, exitcode) })
awesome.emit_signal("module::volume:update_read") end
if (callback ~= nil) then )
callback() end
end
end
)
end,
set = function(value, callback) function volume.commands:watch(timeout, callback, widget)
awful.spawn.easy_async( awful.widget.watch(
"pamixer --set_volume " .. tostring(value) .. " " .. volume.pamixer_options, "pamixer --get-mute --get-volume " .. volume.pamixer_options,
function(stdout, stderr, exitreason, exitcode) timeout, callback, widget
awesome.emit_signal("module::volume:update_read") )
if (callback ~= nil) then end
callback()
end
end
)
end,
mute = function(callback)
awful.spawn.easy_async(
"pamixer --mute " .. volume.pamixer_options,
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::volume:update_read")
if (callback ~= nil) then
callback()
end
end
)
end,
unmute = function(callback)
awful.spawn.easy_async(
"pamixer --unmute " .. volume.pamixer_options,
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::volume:update_read")
if (callback ~= nil) then
callback()
end
end
)
end,
watch = function(timeout, callback, widget) volume.hooks = {}
awful.widget.watch( volume.add_hook = function(callback)
"pamixer --get-mute --get-volume " .. volume.pamixer_options, volume.hooks[#volume.hooks + 1] = callback
timeout, callback, widget end
)
end,
get = function(callback) volume.exec_hooks = function()
local muted volume.commands:get(function(status)
local value for i=1, #volume.hooks do
volume.hooks[i](status)
awful.spawn.easy_async( end
"pamixer --get-mute --get-volume " .. volume.pamixer_options, end)
function(stdout, stderr, exitreason, exitcode) end
muted = string.match(stdout, "(%w%w%w%w%w?) ") -- "true" or "false"
muted = (muted == "true")
value = string.match(stdout, "(%d?%d?%d)") -- (\d?\d?\d)\%)
if (value == nil) then
value = false
else
value = tonumber(string.format("% 3d", value))
end
callback({
mute = muted,
value = value
})
end
)
end
}
awesome.connect_signal("module::volume:update_read",
function()
volume.commands.get(
function(status)
awesome.emit_signal(
"module::volume:update",
status
)
end
)
end
)
volume.volume_up = function() volume.volume_up = function()
if volume.muted then if volume.muted then
volume.unmute() volume.unmute()
end end
volume.commands.up(function() volume.commands:up()
core.sound.play("volume_up") core.sound.play("volume_up")
end)
volume.exec_hooks()
end end
volume.volume_down = function() volume.volume_down = function()
@ -131,23 +91,28 @@ volume.volume_down = function()
volume.unmute() volume.unmute()
end end
volume.commands.down(function() volume.commands:down()
core.sound.play("volume_down") core.sound.play("volume_down")
end)
volume.exec_hooks()
end end
volume.mute = function() volume.mute = function()
volume.commands:mute()
volume.muted = true volume.muted = true
volume.commands.mute()
volume.exec_hooks()
end end
volume.unmute = function() volume.unmute = function()
volume.commands:unmute()
volume.muted = false volume.muted = false
volume.commands.unmute()
volume.exec_hooks()
end end
volume.toggle_mute = function() volume.toggle_mute = function()
volume.commands.get(function(status) volume.commands:get(function(status)
if status.mute then if status.mute then
volume.unmute() volume.unmute()
else else

View File

@ -23,7 +23,6 @@ widget.arc = wibox.widget {
colors = {"#27D4CC", "#00446B"}, colors = {"#27D4CC", "#00446B"},
bg = "#FFFFFF30", bg = "#FFFFFF30",
paddings = beautiful.dpi(2), paddings = beautiful.dpi(2),
rounded_edge = true,
widget = wibox.container.arcchart widget = wibox.container.arcchart
} }
@ -70,12 +69,10 @@ widget.widget = wibox.widget {
widget.widget:connect_signal("mouse::enter", function(result) widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg widget.widget.bg = beautiful.color.bar.hover_bg
awesome.emit_signal("module::volume_popup:show_stay")
end) end)
widget.widget:connect_signal("mouse::leave", function(result) widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent widget.widget.bg = beautiful.color.transparent
awesome.emit_signal("module::volume_popup:show")
end) end)
widget.widget:connect_signal("button::press", widget.widget:connect_signal("button::press",
@ -93,39 +90,49 @@ widget.widget:connect_signal("button::press",
elseif (button == 5) then elseif (button == 5) then
volume.volume_down() volume.volume_down()
end end
awesome.emit_signal("module::volume_popup:update")
awesome.emit_signal("module::volume_popup:show")
end end
) )
awesome.connect_signal("module::volume:update", widget.update = function(status)
function(status)
if (status.value == false) then
widget.icon.image = beautiful.icons.volume.error
widget.arc.value = 100;
widget.bar.value = 100;
return
end
widget.arc.value = status.value / 100; if (status.value == false) then
widget.bar.value = status.value; widget.icon.image = beautiful.icons.volume.error
widget.arc.value = 100;
widget.bar.value = 100;
return
end
widget.arc.value = status.value / 100;
widget.bar.value = status.value;
if (status.mute) then if (status.mute) then
-- Set muted icon -- Set muted icon
widget.icon.image = beautiful.icons.volume.mute widget.icon.image = beautiful.icons.volume.mute
else else
-- Set icon by value -- Set icon by value
if status.value > 70 then if status.value > 70 then
widget.icon.image = beautiful.icons.volume.high widget.icon.image = beautiful.icons.volume.high
elseif status.value > 40 then elseif status.value > 40 then
widget.icon.image = beautiful.icons.volume.medium widget.icon.image = beautiful.icons.volume.medium
elseif status.value > 0 then elseif status.value > 0 then
widget.icon.image = beautiful.icons.volume.low widget.icon.image = beautiful.icons.volume.low
elseif status.value == 0 then elseif status.value == 0 then
widget.icon.image = beautiful.icons.volume.off widget.icon.image = beautiful.icons.volume.off
end
end end
end end
end
volume.add_hook(widget.update)
volume.commands:watch(
5,
function()
volume.commands:get(widget.update)
end,
widget.widget
) )
return widget return widget