2013-04-13 15:17:09 +00:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local vicious = require("vicious")
|
2017-02-16 08:51:01 +00:00
|
|
|
local naughty = require("naughty")
|
2013-04-13 15:17:09 +00:00
|
|
|
local modkey = conf.modkey or "Mod4"
|
2014-08-28 08:58:03 +00:00
|
|
|
local awful = require("awful")
|
2015-05-28 13:21:42 +00:00
|
|
|
local tag = require("awful.tag")
|
2017-01-10 16:45:32 +00:00
|
|
|
local beautiful = require("beautiful")
|
2013-04-13 15:17:09 +00:00
|
|
|
local widgets = { add = {} }
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- table declarations {{{
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local wlist = {}
|
|
|
|
local bars = {}
|
2017-01-10 16:45:32 +00:00
|
|
|
local leftwibar = {}
|
|
|
|
local rightwibar = {}
|
2013-04-13 15:17:09 +00:00
|
|
|
|
|
|
|
local mytaglist = {}
|
|
|
|
mytaglist.buttons = awful.util.table.join(
|
|
|
|
awful.button({ }, 1, awful.tag.viewonly),
|
|
|
|
awful.button({ modkey }, 1, awful.client.movetotag),
|
|
|
|
awful.button({ }, 3, awful.tag.viewtoggle),
|
|
|
|
awful.button({ modkey }, 3, awful.client.toggletag),
|
|
|
|
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
|
|
|
|
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
|
|
|
|
)
|
|
|
|
-- }}}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- setup {{{
|
|
|
|
--------------------------------------------------------------------------------
|
2017-01-10 16:45:32 +00:00
|
|
|
local function setup()
|
2017-02-16 08:51:01 +00:00
|
|
|
for s in screen do
|
2013-04-13 15:17:09 +00:00
|
|
|
wlist[s]={}
|
|
|
|
bars[s]={}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
-- Create the wibar
|
|
|
|
leftwibar[s] = awful.wibar({
|
2013-04-13 15:17:09 +00:00
|
|
|
position = "left",
|
|
|
|
screen = s,
|
|
|
|
width = 18
|
|
|
|
})
|
2017-01-10 16:45:32 +00:00
|
|
|
rightwibar[s] = awful.wibar({
|
2013-04-13 15:17:09 +00:00
|
|
|
position = "right",
|
|
|
|
screen = s,
|
|
|
|
width = 18
|
|
|
|
})
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
-- {{{ create containers
|
|
|
|
local left_bottom_container = wibox.layout.fixed.horizontal()
|
|
|
|
local left_top_container = wibox.layout.fixed.horizontal()
|
2013-04-13 15:17:09 +00:00
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
local left_container = wibox.layout.align.horizontal()
|
|
|
|
left_container:set_left(left_bottom_container)
|
|
|
|
left_container:set_right(left_top_container)
|
2013-04-13 15:17:09 +00:00
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
local right_bottom_container = wibox.layout.fixed.horizontal()
|
|
|
|
local right_top_container = wibox.layout.fixed.horizontal()
|
2013-04-13 15:17:09 +00:00
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
local right_container = wibox.layout.align.horizontal()
|
|
|
|
right_container:set_left(right_top_container)
|
|
|
|
right_container:set_right(right_bottom_container)
|
2013-04-13 15:17:09 +00:00
|
|
|
--}}}
|
|
|
|
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
-- {{{ rotate containers and add to wibox
|
|
|
|
local leftrotate = wibox.container.rotate()
|
2013-04-13 15:17:09 +00:00
|
|
|
leftrotate:set_direction('east')
|
2017-01-10 16:45:32 +00:00
|
|
|
leftrotate:set_widget(left_container)
|
|
|
|
leftwibar[s]:set_widget(leftrotate)
|
2013-04-13 15:17:09 +00:00
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
local rightrotate = wibox.container.rotate()
|
2013-04-13 15:17:09 +00:00
|
|
|
rightrotate:set_direction('west')
|
2017-01-10 16:45:32 +00:00
|
|
|
rightrotate:set_widget(right_container)
|
|
|
|
rightwibar[s]:set_widget(rightrotate)
|
2013-04-13 15:17:09 +00:00
|
|
|
--}}}
|
|
|
|
|
|
|
|
|
|
|
|
bars[s] = {}
|
|
|
|
bars[s].left = {}
|
2017-01-10 16:45:32 +00:00
|
|
|
bars[s].left.bottom = left_bottom_container
|
|
|
|
bars[s].left.top = left_top_container
|
2013-04-13 15:17:09 +00:00
|
|
|
bars[s].right = {}
|
2017-01-10 16:45:32 +00:00
|
|
|
bars[s].right.bottom = right_bottom_container
|
|
|
|
bars[s].right.top = right_top_container
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
2017-01-10 16:45:32 +00:00
|
|
|
end
|
2013-04-13 15:17:09 +00:00
|
|
|
|
|
|
|
-- }}}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Utility {{{
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- force update of a widget
|
2017-01-10 16:45:32 +00:00
|
|
|
local function update(widgetname, index)
|
2017-02-16 08:51:01 +00:00
|
|
|
for s in screen do
|
2013-04-13 15:17:09 +00:00
|
|
|
if wlist[s] ~= nil and wlist[s][widgetname] ~= nil then
|
|
|
|
if index ~= nil then
|
|
|
|
vicious.force({ wlist[s][widgetname][index] })
|
|
|
|
else
|
|
|
|
vicious.force({ wlist[s][widgetname] })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--}}}
|
|
|
|
widgets.update = update
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
-- get container for adding widgets
|
|
|
|
local function get_container(screen, bar, align)
|
2013-04-13 15:17:09 +00:00
|
|
|
if bars[screen][bar] == nil then return nil end
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
return {screen = screen, container = bars[screen][bar][align]}
|
|
|
|
end
|
|
|
|
widgets.container = get_container
|
2013-04-13 15:17:09 +00:00
|
|
|
|
|
|
|
-- }}}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- widget creators {{{
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2015-05-28 13:21:42 +00:00
|
|
|
local show = function(self)
|
|
|
|
self:set_widget(self.widget)
|
|
|
|
end
|
|
|
|
|
|
|
|
local hide = function(self)
|
|
|
|
self:set_widget(nil)
|
|
|
|
end
|
|
|
|
|
2015-06-13 22:00:56 +00:00
|
|
|
local function wrap_and_add(name, parent, widget, callback_widget)
|
2017-01-10 16:45:32 +00:00
|
|
|
local container = wibox.container.margin(widget)
|
2015-05-28 13:21:42 +00:00
|
|
|
container.widget = widget
|
|
|
|
container.show = show
|
|
|
|
container.hide = hide
|
|
|
|
|
2015-06-13 22:00:56 +00:00
|
|
|
wlist[parent.screen][name] = callback_widget == nil and widget or callback_widget
|
2017-01-10 16:45:32 +00:00
|
|
|
parent.container:add(container)
|
2015-05-28 13:21:42 +00:00
|
|
|
return container
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-04-13 15:17:09 +00:00
|
|
|
-- mail widget
|
2017-01-10 16:45:32 +00:00
|
|
|
local function mailwidget(name, parent, mailboxes, notify_pos, title)
|
2013-04-13 15:17:09 +00:00
|
|
|
local widget = wibox.widget.textbox()
|
2017-01-10 16:45:32 +00:00
|
|
|
local bg = wibox.container.background()
|
2013-04-13 15:17:09 +00:00
|
|
|
bg:set_widget(widget)
|
2015-05-28 13:21:42 +00:00
|
|
|
|
2015-06-13 22:00:56 +00:00
|
|
|
local container = wrap_and_add(name, parent, bg, widget)
|
2015-08-02 13:24:30 +00:00
|
|
|
vicious.register(widget, vicious.widgets.mdir, function(widget, args)
|
2013-04-13 15:17:09 +00:00
|
|
|
if args[1] > 0 then
|
|
|
|
naughty.notify({
|
2015-05-28 13:21:42 +00:00
|
|
|
title = "New mail arrived in box " .. title,
|
2015-06-13 22:00:56 +00:00
|
|
|
text = title .. " " ..args[2].." / "..args[1],
|
2014-04-25 13:15:11 +00:00
|
|
|
position = notify_pos or "top_left"
|
2013-04-13 15:17:09 +00:00
|
|
|
|
|
|
|
})
|
2017-01-10 16:45:32 +00:00
|
|
|
bg:set_bg(beautiful.bg_urgent)
|
|
|
|
bg:set_fg(beautiful.fg_urgent)
|
2015-05-28 13:21:42 +00:00
|
|
|
container:show()
|
2013-04-13 15:17:09 +00:00
|
|
|
elseif args[2] > 0 then
|
2017-01-10 16:45:32 +00:00
|
|
|
bg:set_bg(beautiful.bg_focus)
|
|
|
|
bg:set_fg(beautiful.fg_focus)
|
2015-05-28 13:21:42 +00:00
|
|
|
container:show()
|
2013-04-13 15:17:09 +00:00
|
|
|
else
|
2017-01-10 16:45:32 +00:00
|
|
|
bg:set_bg(beautiful.bg_normal)
|
|
|
|
bg:set_fg(beautiful.fg_normal)
|
2015-05-28 13:21:42 +00:00
|
|
|
container:hide()
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
|
|
|
return "⬓⬓ Unread "..args[2].." / New "..args[1].. " "
|
|
|
|
end, 0, mailboxes)
|
2013-04-15 12:30:23 +00:00
|
|
|
widgets.update(name)
|
2015-05-28 13:21:42 +00:00
|
|
|
return container
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
|
|
|
--}}}
|
|
|
|
widgets.add.mail = mailwidget
|
|
|
|
|
|
|
|
-- text clock
|
2017-01-10 16:45:32 +00:00
|
|
|
local function clockwidget(name, parent)
|
|
|
|
return wrap_and_add(name, parent, wibox.widget.textclock())
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
|
|
|
--}}}
|
|
|
|
widgets.add.clock = clockwidget
|
|
|
|
|
2017-01-10 16:45:32 +00:00
|
|
|
-- containerbox
|
|
|
|
local function layoutwidget(parent)
|
|
|
|
local mylayoutbox = awful.widget.layoutbox(s)
|
|
|
|
|
|
|
|
mylayoutbox:buttons(awful.util.table.join(
|
|
|
|
awful.button({ }, 1, function () awful.layout.inc( 1) end),
|
|
|
|
awful.button({ }, 3, function () awful.layout.inc(-1) end),
|
|
|
|
awful.button({ }, 4, function () awful.layout.inc( 1) end),
|
|
|
|
awful.button({ }, 5, function () awful.layout.inc(-1) end)
|
|
|
|
))
|
|
|
|
return wrap_and_add("layout", parent, mylayoutbox);
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
|
|
|
--}}}
|
2015-05-28 13:21:42 +00:00
|
|
|
widgets.add.layout_indicator = layoutwidget
|
2013-04-13 15:17:09 +00:00
|
|
|
|
|
|
|
-- taglist
|
2017-01-10 16:45:32 +00:00
|
|
|
local function taglistwidget(name, parent)
|
2015-05-28 13:21:42 +00:00
|
|
|
local filter_urgentonly = function(t, args)
|
|
|
|
for k, c in pairs(t:clients()) do
|
|
|
|
if c.urgent then return true end
|
|
|
|
end
|
|
|
|
return t.selected
|
|
|
|
end
|
2013-04-13 15:17:09 +00:00
|
|
|
-- Create a taglist widget
|
2015-05-28 13:21:42 +00:00
|
|
|
return wrap_and_add(name, parent,
|
2017-01-10 16:45:32 +00:00
|
|
|
awful.widget.taglist(parent.screen, awful.widget.taglist.filter.noempty, mytaglist.buttons)
|
2015-05-28 13:21:42 +00:00
|
|
|
)
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.taglist = taglistwidget
|
|
|
|
|
|
|
|
-- system tray
|
2013-04-15 12:30:23 +00:00
|
|
|
-- not using a name argument, because only one systray is allowed
|
2017-01-10 16:45:32 +00:00
|
|
|
local function systraywidget(parent)
|
2013-04-13 15:17:09 +00:00
|
|
|
if (wlist["systray"] ~= nil) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
wlist["systray"] = wibox.widget.systray()
|
2017-01-10 16:45:32 +00:00
|
|
|
parent.container:add(wlist["systray"])
|
2015-05-28 13:21:42 +00:00
|
|
|
return wlist["systray"]
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.systray = systraywidget
|
|
|
|
|
|
|
|
-- cpu usage
|
2017-01-10 16:45:32 +00:00
|
|
|
local function cpuwidget(name, parent)
|
2015-05-28 13:21:42 +00:00
|
|
|
local cpu = wrap_and_add(name, parent, wibox.widget.textbox())
|
2015-03-01 20:18:54 +00:00
|
|
|
vicious.register(wlist[parent.screen][name], vicious.widgets.cpu, "CPU: $1%")
|
2015-05-28 13:21:42 +00:00
|
|
|
return cpu
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.cpu = cpuwidget
|
|
|
|
|
|
|
|
-- battery
|
2017-01-10 16:45:32 +00:00
|
|
|
local function batterywidget(name, parent, batname)
|
2013-04-15 12:30:23 +00:00
|
|
|
local widget = wibox.widget.textbox()
|
2017-01-10 16:45:32 +00:00
|
|
|
local bg = wibox.container.background()
|
2013-04-15 12:30:23 +00:00
|
|
|
bg:set_widget(widget)
|
|
|
|
vicious.register(widget, vicious.widgets.bat, function (widget, args)
|
2013-04-13 15:17:09 +00:00
|
|
|
if args[2] == 0 then return ""
|
|
|
|
else
|
|
|
|
if args[2] < 15 then
|
2017-01-10 16:45:32 +00:00
|
|
|
bg:set_bg(beautiful.bg_urgent)
|
|
|
|
bg:set_fg(beautiful.fg_urgent)
|
2013-04-13 15:17:09 +00:00
|
|
|
else
|
2017-01-10 16:45:32 +00:00
|
|
|
bg:set_bg(beautiful.bg_normal)
|
|
|
|
bg:set_fg(beautiful.fg_normal)
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
2013-04-15 12:30:23 +00:00
|
|
|
return name .. ": " ..
|
2017-01-10 16:45:32 +00:00
|
|
|
args[1]..args[2].."% - "..args[3]
|
2013-04-13 15:17:09 +00:00
|
|
|
end
|
|
|
|
end, 61, batname)
|
2013-04-15 12:30:23 +00:00
|
|
|
widgets.update(name)
|
2015-05-28 13:21:42 +00:00
|
|
|
return wrap_and_add(name, parent, bg)
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.battery = batterywidget
|
|
|
|
|
|
|
|
-- wireless status
|
2017-01-10 16:45:32 +00:00
|
|
|
local function wifiwidget(name, parent, interface)
|
2015-05-28 13:21:42 +00:00
|
|
|
local wifi = wrap_and_add(name, parent, wibox.widget.textbox())
|
2015-03-01 20:18:54 +00:00
|
|
|
vicious.register(wlist[parent.screen][name], vicious.widgets.wifi,
|
2015-05-15 19:06:07 +00:00
|
|
|
"WLAN ${ssid} @ ${sign}dBm, Q:${link}/70", 31, interface)
|
2015-05-28 13:21:42 +00:00
|
|
|
return wifi
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.wifi = wifiwidget
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- spacers {{{
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local spacer = wibox.widget.textbox()
|
|
|
|
spacer:set_text(" ")
|
|
|
|
|
|
|
|
-- manual spacing between widgets
|
2017-01-10 16:45:32 +00:00
|
|
|
local function spacerwidget(parent)
|
|
|
|
parent.container:add(spacer)
|
2013-04-13 15:17:09 +00:00
|
|
|
end --}}}
|
|
|
|
widgets.add.spacer = spacerwidget
|
|
|
|
|
2019-12-10 13:49:28 +00:00
|
|
|
-- manual spacing between widgets
|
|
|
|
local function textwidget(text, parent)
|
|
|
|
local newtext = wibox.widget.textbox()
|
|
|
|
newtext:set_text(text)
|
|
|
|
parent.container:add(newtext)
|
|
|
|
end --}}}
|
|
|
|
widgets.add.text = textwidget
|
|
|
|
|
2013-04-13 15:17:09 +00:00
|
|
|
-- change appearance of spacers
|
2017-01-10 16:45:32 +00:00
|
|
|
local function spacertext(text)
|
2013-04-13 15:17:09 +00:00
|
|
|
spacer:set_text(text)
|
|
|
|
end --}}}
|
|
|
|
widgets.set_spacer_text = spacertext
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2015-03-01 20:18:54 +00:00
|
|
|
setup()
|
|
|
|
|
2013-04-13 15:17:09 +00:00
|
|
|
return widgets
|
|
|
|
|
|
|
|
-- vim:foldmethod=marker
|