2019-06-07 16:21:32 +02:00
|
|
|
local awful = require("awful")
|
2019-06-21 18:11:00 +02:00
|
|
|
local gtable = require("gears.table")
|
2020-02-28 13:15:09 +01:00
|
|
|
local naughty = require("naughty")
|
|
|
|
local wibox = require("wibox")
|
2019-02-16 22:06:02 +01:00
|
|
|
|
|
|
|
local lain = require("lain")
|
2019-06-07 16:21:32 +02:00
|
|
|
local helpers = require("lain.helpers")
|
2019-02-16 22:06:02 +01:00
|
|
|
local markup = lain.util.markup
|
|
|
|
|
|
|
|
local theme = require("theme")
|
2019-06-14 18:09:32 +02:00
|
|
|
local utils = require("utils")
|
2019-02-16 22:06:02 +01:00
|
|
|
|
|
|
|
local gfs = require("gears.filesystem")
|
|
|
|
local iconsdir = gfs.get_configuration_dir() .. "icons/"
|
|
|
|
|
2019-03-27 20:17:26 +01:00
|
|
|
local network_interfaces = {"enp0s25", "wlp3s0"}
|
|
|
|
|
2019-02-16 22:06:02 +01:00
|
|
|
local widgets = {}
|
|
|
|
|
|
|
|
widgets.netdown_icon = wibox.widget.imagebox(iconsdir .. "down.png")
|
|
|
|
widgets.netdown = lain.widget.net({
|
2019-02-16 22:16:41 +01:00
|
|
|
units = 1024^2,
|
2019-03-27 20:17:26 +01:00
|
|
|
iface = network_interfaces,
|
2019-06-06 22:22:59 +02:00
|
|
|
notify = "off",
|
2019-02-16 22:06:02 +01:00
|
|
|
settings = function()
|
2019-02-16 22:16:41 +01:00
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.colors.green, net_now.received .. "MiB/s "))
|
2019-02-16 22:06:02 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
widgets.netup_icon = wibox.widget.imagebox(iconsdir .. "up.png")
|
|
|
|
widgets.netup = lain.widget.net({
|
2019-02-16 22:16:41 +01:00
|
|
|
units = 1024^2,
|
2019-03-27 20:17:26 +01:00
|
|
|
iface = network_interfaces,
|
2019-06-06 22:22:59 +02:00
|
|
|
notify = "off",
|
2019-02-16 22:06:02 +01:00
|
|
|
settings = function()
|
2019-02-16 22:16:41 +01:00
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.colors.red, net_now.sent .. "MiB/s "))
|
2019-02-16 22:06:02 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
widgets.mem_icon = wibox.widget.imagebox(iconsdir .. "mem.png")
|
|
|
|
widgets.mem = lain.widget.mem({
|
|
|
|
settings = function()
|
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.colors.yellow, mem_now.perc .. "% "))
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
widgets.cpu_icon = wibox.widget.imagebox(iconsdir .. "cpu.png")
|
|
|
|
widgets.cpu = lain.widget.cpu({
|
|
|
|
settings = function()
|
2019-02-16 22:16:41 +01:00
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.colors.cyan, string.format("%02d", cpu_now.usage) .. "% "))
|
2019-02-16 22:06:02 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
widgets.temp_icon = wibox.widget.imagebox(iconsdir .. "temp.png")
|
|
|
|
widgets.temp = lain.widget.temp({
|
|
|
|
settings = function()
|
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.colors.magenta, math.floor(coretemp_now) .. "°C "))
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
widgets.bat_icon = wibox.widget.imagebox(iconsdir .. "bat.png")
|
|
|
|
widgets.bat = lain.widget.bat({
|
2019-06-06 22:22:59 +02:00
|
|
|
notify = "off",
|
2019-02-16 22:06:02 +01:00
|
|
|
settings = function()
|
|
|
|
state = bat_now.ac_status == 0 and "D" or "C"
|
|
|
|
widget:set_markup(markup.fontfg(theme.font, theme.fg_normal, state .. bat_now.perc))
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2019-06-21 18:10:53 +02:00
|
|
|
widgets.vpn = {}
|
|
|
|
widgets.vpn.icon = wibox.widget.imagebox(iconsdir .. "vpn.png")
|
|
|
|
widgets.vpn.widget = wibox.widget.textbox()
|
|
|
|
widgets.vpn.update = function()
|
|
|
|
helpers.async({ "/bin/ip", "link" }, function(output)
|
|
|
|
connected = false
|
|
|
|
for line in output:gmatch("[^\r\n]+") do
|
2019-07-30 16:57:00 +02:00
|
|
|
vpn_server = string.match(line, "^%d+: mullvad%-(%g+):")
|
2019-06-21 18:10:53 +02:00
|
|
|
if vpn_server then
|
|
|
|
widgets.vpn.widget:set_markup(markup.fontfg(theme.font, theme.colors.blue, vpn_server .. " "))
|
|
|
|
connected = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if connected then
|
|
|
|
widgets.vpn.icon.visible = true
|
|
|
|
else
|
|
|
|
widgets.vpn.widget:set_markup(markup.fontfg(theme.font, theme.colors.blue, ""))
|
|
|
|
widgets.vpn.icon.visible = false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
helpers.newtimer("vpn", 5, widgets.vpn.update)
|
|
|
|
|
2019-06-07 16:21:32 +02:00
|
|
|
widgets.bluetooth = wibox.widget.imagebox(iconsdir .. "bluetooth-on.png")
|
|
|
|
widgets.bluetooth.pass_state = function(callback)
|
|
|
|
helpers.async_with_shell("/sbin/rfkill -n -o SOFT list bluetooth|uniq", function(state)
|
|
|
|
callback(state:gsub("^%s*(.-)%s*$", "%1"))
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
widgets.bluetooth.update = function()
|
|
|
|
widgets.bluetooth.pass_state(function(state)
|
|
|
|
if state == "blocked" then
|
|
|
|
widgets.bluetooth:set_image(iconsdir .. "bluetooth-off.png")
|
|
|
|
else
|
|
|
|
helpers.async_with_shell("for device in $(bluetoothctl devices|cut -d' ' -f 2);do bluetoothctl info $device|grep 'Connected: yes';done|wc -l", function(connected_devices)
|
|
|
|
if tonumber(connected_devices) > 0 then
|
|
|
|
widgets.bluetooth:set_image(iconsdir .. "bluetooth-active.png")
|
|
|
|
else
|
|
|
|
widgets.bluetooth:set_image(iconsdir .. "bluetooth-on.png")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
widgets.bluetooth.toggle = function()
|
|
|
|
widgets.bluetooth.pass_state(function(state)
|
|
|
|
if state == "blocked" then
|
|
|
|
awful.spawn.spawn({ "/sbin/rfkill", "unblock", "bluetooth" })
|
|
|
|
else
|
|
|
|
awful.spawn.spawn({ "/sbin/rfkill", "block", "bluetooth" })
|
|
|
|
end
|
|
|
|
widgets.bluetooth.update()
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
widgets.bluetooth:buttons(
|
2019-06-21 18:11:00 +02:00
|
|
|
gtable.join(
|
2019-06-07 16:21:32 +02:00
|
|
|
awful.button({ }, 1, widgets.bluetooth.toggle),
|
|
|
|
awful.button({ }, 3, function()
|
2019-06-07 22:41:48 +02:00
|
|
|
awful.spawn.with_shell("blueman-manager; pkill blueman-applet")
|
2019-06-07 16:21:32 +02:00
|
|
|
end)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
helpers.newtimer("bluetooth", 10, widgets.bluetooth.update)
|
|
|
|
|
2019-06-07 16:55:07 +02:00
|
|
|
widgets.redshift = wibox.widget.imagebox(iconsdir .. "redshift-on.png")
|
|
|
|
widgets.redshift.pid = nil
|
2019-06-14 18:09:32 +02:00
|
|
|
utils.handle_pid("redshift", function(pid)
|
2019-06-07 16:55:07 +02:00
|
|
|
if pid and #pid > 0 then
|
|
|
|
widgets.redshift.pid = tonumber(pid)
|
|
|
|
else
|
|
|
|
widgets.redshift.pid = awful.spawn.spawn({ "redshift" })
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
widgets.redshift.active = true
|
|
|
|
|
|
|
|
widgets.redshift.toggle = function()
|
|
|
|
awful.spawn.spawn({ "kill", "-SIGUSR1", tostring(widgets.redshift.pid) })
|
|
|
|
widgets.redshift.active = not widgets.redshift.active
|
|
|
|
|
|
|
|
if widgets.redshift.active == true then
|
|
|
|
widgets.redshift:set_image(iconsdir .. "redshift-on.png")
|
|
|
|
else
|
|
|
|
widgets.redshift:set_image(iconsdir .. "redshift-off.png")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
widgets.redshift:buttons(
|
2019-06-21 18:11:00 +02:00
|
|
|
gtable.join(
|
2019-06-07 16:55:07 +02:00
|
|
|
awful.button({ }, 1, widgets.redshift.toggle)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2019-06-14 18:09:32 +02:00
|
|
|
widgets.tearstop = wibox.widget.imagebox(iconsdir .. "tearstop-off.png")
|
|
|
|
utils.handle_pid("compton --backend=glx", function(pid)
|
|
|
|
if pid and #pid > 0 then
|
|
|
|
widgets.tearstop.pid = tonumber(pid)
|
|
|
|
widgets.tearstop:set_image(iconsdir .. "tearstop-on.png")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
widgets.tearstop.pid = nil
|
|
|
|
|
|
|
|
widgets.tearstop:buttons(
|
2019-06-21 18:11:00 +02:00
|
|
|
gtable.join(
|
2019-06-14 18:09:32 +02:00
|
|
|
awful.button({ }, 1, function()
|
|
|
|
if widgets.tearstop.pid == nil then
|
|
|
|
widgets.tearstop.pid = awful.spawn.spawn({ "compton", "--backend=glx" })
|
|
|
|
widgets.tearstop:set_image(iconsdir .. "tearstop-on.png")
|
|
|
|
else
|
|
|
|
awful.spawn.spawn({ "kill", tostring(widgets.tearstop.pid) })
|
|
|
|
widgets.tearstop.pid = nil
|
|
|
|
widgets.tearstop:set_image(iconsdir .. "tearstop-off.png")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
)
|
2020-04-18 04:52:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
widgets.notifications = wibox.widget.imagebox(iconsdir .. "notifications-on.png")
|
|
|
|
|
|
|
|
widgets.notifications:buttons(
|
|
|
|
gtable.join(
|
|
|
|
awful.button({ }, 1, function()
|
|
|
|
if naughty.is_suspended() then
|
|
|
|
naughty.resume()
|
|
|
|
widgets.notifications:set_image(iconsdir .. "notifications-on.png")
|
|
|
|
else
|
|
|
|
naughty.suspend()
|
|
|
|
widgets.notifications:set_image(iconsdir .. "notifications-off.png")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
)
|
2019-06-14 18:09:32 +02:00
|
|
|
)
|
|
|
|
|
2020-02-28 13:15:09 +01:00
|
|
|
widgets.cal = {}
|
|
|
|
|
|
|
|
widgets.cal.show = function()
|
|
|
|
widgets.cal.hide()
|
|
|
|
|
2020-02-29 13:49:52 +01:00
|
|
|
widgets.cal.notification_processing = true
|
|
|
|
|
2020-02-28 13:15:09 +01:00
|
|
|
helpers.async({ "khal", "calendar" }, function(output)
|
|
|
|
widgets.cal.notification = naughty.notify{
|
|
|
|
screen = awful.screen.focused(),
|
|
|
|
text = output:gsub("\n$", ""),
|
|
|
|
timeout = 0,
|
|
|
|
}
|
2020-02-29 13:49:52 +01:00
|
|
|
|
|
|
|
widgets.cal.notification_processing = false
|
|
|
|
|
|
|
|
if widgets.cal.trigger_hide then
|
|
|
|
widgets.cal.hide()
|
|
|
|
widgets.cal.trigger_hide = false
|
|
|
|
end
|
2020-02-28 13:15:09 +01:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
widgets.cal.hide = function()
|
2020-02-29 13:49:52 +01:00
|
|
|
if widgets.cal.notification_processing then
|
|
|
|
widgets.cal.trigger_hide = true
|
|
|
|
else
|
|
|
|
if not widgets.cal.notification then return end
|
|
|
|
naughty.destroy(widgets.cal.notification)
|
|
|
|
widgets.cal.notification = nil
|
|
|
|
end
|
2020-02-28 13:15:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
widgets.cal.attach = function(parent)
|
|
|
|
parent:connect_signal("mouse::enter", widgets.cal.show)
|
|
|
|
parent:connect_signal("mouse::leave", widgets.cal.hide)
|
|
|
|
end
|
|
|
|
|
2019-02-16 22:06:02 +01:00
|
|
|
return widgets
|