Skip to content

Commit cf8ef78

Browse files
committed
{alsa,pulse}bar: code lightened
1 parent be69daf commit cf8ef78

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

widget/alsabar.lua

+11-28
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
77
--]]
88

9-
local helpers = require("lain.helpers")
10-
local awful = require("awful")
11-
local naughty = require("naughty")
12-
local wibox = require("wibox")
13-
local math = { modf = math.modf }
14-
local string = { format = string.format,
15-
match = string.match,
16-
rep = string.rep }
17-
local type, tonumber = type, tonumber
9+
local helpers = require("lain.helpers")
10+
local awful = require("awful")
11+
local naughty = require("naughty")
12+
local wibox = require("wibox")
13+
14+
local math, string, type, tonumber = math, string type, tonumber
1815

1916
-- ALSA volume bar
2017
-- lain.widget.alsabar
@@ -36,11 +33,8 @@ local function factory(args)
3633
local settings = args.settings or function() end
3734
local width = args.width or 63
3835
local height = args.height or 1
39-
local margins = args.margins or 1
40-
local paddings = args.paddings or 1
4136
local ticks = args.ticks or false
4237
local ticks_size = args.ticks_size or 7
43-
local step = args.step or '5%'
4438

4539
alsabar.cmd = args.cmd or "amixer"
4640
alsabar.channel = args.channel or "Master"
@@ -54,13 +48,10 @@ local function factory(args)
5448
alsabar.notification_preset.font = "Monospace 10"
5549
end
5650

57-
local format_get_cmd = string.format("%s get %s", alsabar.cmd, alsabar.channel)
58-
local format_inc_cmd = string.format("%s sset %s %s+", alsabar.cmd, alsabar.channel, step)
59-
local format_dec_cmd = string.format("%s sset %s %s-" , alsabar.cmd, alsabar.channel, step)
60-
local format_tog_cmd = string.format("%s sset %s toggle", alsabar.cmd, alsabar.channel)
51+
local format_cmd = string.format("%s get %s", alsabar.cmd, alsabar.channel)
6152

6253
if alsabar.togglechannel then
63-
format_get_cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s",
54+
format_cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s",
6455
alsabar.cmd, alsabar.channel, alsabar.cmd, alsabar.togglechannel) }
6556
end
6657

@@ -69,8 +60,8 @@ local function factory(args)
6960
forced_width = width,
7061
color = alsabar.colors.unmute,
7162
background_color = alsabar.colors.background,
72-
margins = margins,
73-
paddings = paddings,
63+
margins = 1,
64+
paddings = 1,
7465
ticks = ticks,
7566
ticks_size = ticks_size,
7667
widget = wibox.widget.progressbar
@@ -79,7 +70,7 @@ local function factory(args)
7970
alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
8071

8172
function alsabar.update(callback)
82-
helpers.async(format_get_cmd, function(mixer)
73+
helpers.async(format_cmd, function(mixer)
8374
local vol, playback = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
8475

8576
if not vol or not playback then return end
@@ -152,14 +143,6 @@ local function factory(args)
152143

153144
helpers.newtimer(string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel), timeout, alsabar.update)
154145

155-
alsabar.bar:connect_signal("button::press", function(_,_,_,button)
156-
if (button == 4) then awful.spawn(format_inc_cmd)
157-
elseif (button == 5) then awful.spawn(format_dec_cmd)
158-
elseif (button == 1) then awful.spawn(format_tog_cmd)
159-
end
160-
alsabar.update()
161-
end)
162-
163146
return alsabar
164147
end
165148

widget/pulsebar.lua

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
77
--]]
88

9-
local helpers = require("lain.helpers")
10-
local awful = require("awful")
11-
local naughty = require("naughty")
12-
local wibox = require("wibox")
13-
local math = { modf = math.modf }
14-
local string = { format = string.format,
15-
match = string.match,
16-
gmatch = string.gmatch,
17-
rep = string.rep }
18-
local type, tonumber = type, tonumber
9+
local helpers = require("lain.helpers")
10+
local awful = require("awful")
11+
local naughty = require("naughty")
12+
local wibox = require("wibox")
13+
14+
local math, string, type, tonumber = math, string type, tonumber
1915

2016
-- PulseAudio volume bar
2117
-- lain.widget.pulsebar
@@ -38,6 +34,8 @@ local function factory(args)
3834
local settings = args.settings or function() end
3935
local width = args.width or 63
4036
local height = args.heigth or 1
37+
local margins = args.margins or 1
38+
local paddings = args.paddings or 1
4139
local ticks = args.ticks or false
4240
local ticks_size = args.ticks_size or 7
4341

@@ -58,8 +56,8 @@ local function factory(args)
5856
forced_width = width,
5957
color = pulsebar.colors.unmute,
6058
background_color = pulsebar.colors.background,
61-
margins = 1,
62-
paddings = 1,
59+
margins = margins,
60+
paddings = paddings,
6361
ticks = ticks,
6462
ticks_size = ticks_size,
6563
widget = wibox.widget.progressbar,

wiki

Submodule wiki updated from 1acb69e to e611812

0 commit comments

Comments
 (0)