This repository has been archived on 2021-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/home/.config/awesome/widgets.lua

167 lines
5.3 KiB
Lua

local awful = require("awful")
local wibox = require("wibox")
local table = require("gears.table")
local lain = require("lain")
local helpers = require("lain.helpers")
local markup = lain.util.markup
local theme = require("theme")
local utils = require("utils")
local gfs = require("gears.filesystem")
local iconsdir = gfs.get_configuration_dir() .. "icons/"
local network_interfaces = {"enp0s25", "wlp3s0"}
local widgets = {}
widgets.netdown_icon = wibox.widget.imagebox(iconsdir .. "down.png")
widgets.netdown = lain.widget.net({
units = 1024^2,
iface = network_interfaces,
notify = "off",
settings = function()
widget:set_markup(markup.fontfg(theme.font, theme.colors.green, net_now.received .. "MiB/s "))
end
})
widgets.netup_icon = wibox.widget.imagebox(iconsdir .. "up.png")
widgets.netup = lain.widget.net({
units = 1024^2,
iface = network_interfaces,
notify = "off",
settings = function()
widget:set_markup(markup.fontfg(theme.font, theme.colors.red, net_now.sent .. "MiB/s "))
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()
widget:set_markup(markup.fontfg(theme.font, theme.colors.cyan, string.format("%02d", cpu_now.usage) .. "% "))
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({
notify = "off",
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
})
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(
table.join(
awful.button({ }, 1, widgets.bluetooth.toggle),
awful.button({ }, 3, function()
awful.spawn.with_shell("blueman-manager; pkill blueman-applet")
end)
)
)
helpers.newtimer("bluetooth", 10, widgets.bluetooth.update)
widgets.redshift = wibox.widget.imagebox(iconsdir .. "redshift-on.png")
widgets.redshift.pid = nil
utils.handle_pid("redshift", function(pid)
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(
table.join(
awful.button({ }, 1, widgets.redshift.toggle)
)
)
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(
table.join(
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)
)
)
return widgets