update volumebar widget
This commit is contained in:
parent
aa6f0363ad
commit
ed8bd0a96a
|
@ -9,18 +9,59 @@ Supports
|
||||||
- scroll down - decrease volume,
|
- scroll down - decrease volume,
|
||||||
- left click - mute/unmute.
|
- left click - mute/unmute.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
volumebar_widget({
|
||||||
|
main_color = '#af13f7',
|
||||||
|
mute_color = '#ff0000',
|
||||||
|
width = 80,
|
||||||
|
shape = 'rounded_bar', -- octogon, hexagon, powerline, etc
|
||||||
|
-- bar's height = wibar's height minus 2x margins
|
||||||
|
margins = 8
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Above config results in following widget:
|
||||||
|
|
||||||
|
![custom](./custom.png)
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Clone repo, include widget and use it in **rc.lua**:
|
1. Clone this repo under **~/.config/awesome/**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Require volumebar widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local volumebar_widget = require("awesome-wm-widgets.volumebar-widget.volumebar")
|
local volumebar_widget = require("awesome-wm-widgets.volumebar-widget.volumebar")
|
||||||
...
|
```
|
||||||
|
|
||||||
|
1. Add widget to the tasklist:
|
||||||
|
|
||||||
|
```lua
|
||||||
s.mytasklist, -- Middle widget
|
s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
volumebar_widget,
|
--[[default]]
|
||||||
|
volumebar_widget(),
|
||||||
|
--[[or customized]]
|
||||||
|
volumebar_widget({
|
||||||
|
main_color = '#af13f7',
|
||||||
|
mute_color = '#ff0000',
|
||||||
|
width = 80,
|
||||||
|
shape = 'rounded_bar', -- octogon, hexagon, powerline, etc
|
||||||
|
-- bar's height = wibar's height minus 2x margins
|
||||||
|
margins = 8
|
||||||
|
}),
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
|
@ -9,6 +9,7 @@
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
|
local beautiful = require("beautiful")
|
||||||
local gears = require("gears")
|
local gears = require("gears")
|
||||||
local spawn = require("awful.spawn")
|
local spawn = require("awful.spawn")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
|
@ -19,41 +20,50 @@ local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
|
||||||
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
|
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
|
||||||
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
||||||
|
|
||||||
local bar_color = "#74aeab"
|
local widget = {}
|
||||||
local mute_color = "#ff0000"
|
|
||||||
local background_color = "#3a3a3a"
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local main_color = args.main_color or beautiful.widget_main_color
|
||||||
|
local mute_color = args.mute_color or beautiful.widget_red
|
||||||
|
local width = args.width or 50
|
||||||
|
local shape = args.shape or 'bar'
|
||||||
|
local margins = args.margins or 10
|
||||||
|
|
||||||
local volumebar_widget = wibox.widget {
|
local volumebar_widget = wibox.widget {
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
forced_width = 50,
|
forced_width = width,
|
||||||
paddings = 0,
|
color = main_color,
|
||||||
border_width = 0.5,
|
background_color = '#ffffff11',
|
||||||
color = bar_color,
|
shape = gears.shape[shape],
|
||||||
background_color = background_color,
|
|
||||||
shape = gears.shape.bar,
|
|
||||||
clip = true,
|
|
||||||
margins = {
|
margins = {
|
||||||
top = 10,
|
top = margins,
|
||||||
bottom = 10,
|
bottom = margins,
|
||||||
},
|
},
|
||||||
widget = wibox.widget.progressbar
|
widget = wibox.widget.progressbar
|
||||||
}
|
}
|
||||||
|
|
||||||
local update_graphic = function(widget, stdout, _, _, _)
|
local update_graphic = function(widget, stdout, _, _, _)
|
||||||
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
|
||||||
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
|
||||||
volume = tonumber(string.format("% 3d", volume))
|
volume = tonumber(string.format("% 3d", volume))
|
||||||
|
|
||||||
widget.value = volume / 100;
|
widget.value = volume / 100;
|
||||||
widget.color = mute == "off" and mute_color
|
widget.color = mute == "off"
|
||||||
or bar_color
|
and mute_color
|
||||||
|
or main_color
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
volumebar_widget:connect_signal("button::press", function(_, _, _, button)
|
volumebar_widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 4) then awful.spawn(INC_VOLUME_CMD)
|
if (button == 4) then
|
||||||
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD)
|
awful.spawn(INC_VOLUME_CMD)
|
||||||
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD)
|
elseif (button == 5) then
|
||||||
|
awful.spawn(DEC_VOLUME_CMD)
|
||||||
|
elseif (button == 1) then
|
||||||
|
awful.spawn(TOG_VOLUME_CMD)
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
||||||
|
@ -64,3 +74,7 @@ end)
|
||||||
watch(GET_VOLUME_CMD, 1, update_graphic, volumebar_widget)
|
watch(GET_VOLUME_CMD, 1, update_graphic, volumebar_widget)
|
||||||
|
|
||||||
return volumebar_widget
|
return volumebar_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue