From 63c9c7616ae1d0741a8ed34507fd9db7cc031178 Mon Sep 17 00:00:00 2001 From: Luca CPZ Date: Sat, 17 Feb 2018 14:28:31 +0100 Subject: [PATCH] {alsa,pulse}bar: fallback for mywibox variable; closes #384 --- widget/alsabar.lua | 17 ++++++++++++----- widget/pulsebar.lua | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/widget/alsabar.lua b/widget/alsabar.lua index b253d4b..557e97b 100644 --- a/widget/alsabar.lua +++ b/widget/alsabar.lua @@ -113,11 +113,18 @@ local function factory(args) preset.title = preset.title .. " Muted" end - local wib = awful.screen.focused().mywibox - - local tot = wib.height - if wib.position == "left" or wib.position == "right" then - tot = wib.width + -- tot is the maximum number of ticks to display in the notification + -- fallback: default horizontal wibox height + local wib, tot = awful.screen.focused().mywibox, 20 + + -- if we can grab mywibox, tot is defined as its height if + -- horizontal, or width otherwise + if wib then + if wib.position == "left" or wib.position == "right" then + tot = wib.width + else + tot = wib.height + end end int = math.modf((alsabar._current_level / 100) * tot) diff --git a/widget/pulsebar.lua b/widget/pulsebar.lua index 30fbb40..158e639 100644 --- a/widget/pulsebar.lua +++ b/widget/pulsebar.lua @@ -123,11 +123,18 @@ local function factory(args) preset.title = preset.title .. " muted" end - local wib = awful.screen.focused().mywibox - - local tot = wib.height - if wib.position == "left" or wib.position == "right" then - tot = wib.width + -- tot is the maximum number of ticks to display in the notification + -- fallback: default horizontal wibox height + local wib, tot = awful.screen.focused().mywibox, 20 + + -- if we can grab mywibox, tot is defined as its height if + -- horizontal, or width otherwise + if wib then + if wib.position == "left" or wib.position == "right" then + tot = wib.width + else + tot = wib.height + end end int = math.modf((pulsebar._current_level / 100) * tot) -- 2.39.2