awesome-wm-widgets/email-widget/email.lua

45 lines
1.4 KiB
Lua
Raw Normal View History

2017-01-31 03:38:50 +01:00
local wibox = require("wibox")
local awful = require("awful")
local naughty = require("naughty")
local watch = require("awful.widget.watch")
2017-02-02 03:45:15 +01:00
local path_to_icons = "/usr/share/icons/Arc/actions/22/"
2017-01-31 03:38:50 +01:00
2020-12-06 20:47:40 +01:00
local email_widget = wibox.widget.textbox()
2017-01-31 03:38:50 +01:00
email_widget:set_font('Play 9')
2020-12-06 20:47:40 +01:00
local email_icon = wibox.widget.imagebox()
2017-01-31 03:38:50 +01:00
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
watch(
2017-02-02 04:00:45 +01:00
"python /home/<username>/.config/awesome/email-widget/count_unread_emails.py", 20,
2020-12-06 20:47:40 +01:00
function(_, stdout)
2017-02-04 16:38:46 +01:00
local unread_emails_num = tonumber(stdout) or 0
2017-01-31 03:38:50 +01:00
if (unread_emails_num > 0) then
2020-12-06 20:47:40 +01:00
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
2017-01-31 03:38:50 +01:00
email_widget:set_text(stdout)
elseif (unread_emails_num == 0) then
2020-12-06 20:47:40 +01:00
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
email_widget:set_text("")
end
2017-01-31 03:38:50 +01:00
end
)
2020-12-06 20:47:40 +01:00
local function show_emails()
2017-02-02 04:00:45 +01:00
awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email-widget/read_unread_emails.py']],
2020-12-06 20:47:40 +01:00
function(stdout)
2017-01-31 03:38:50 +01:00
naughty.notify{
text = stdout,
title = "Unread Emails",
timeout = 5, hover_timeout = 0.5,
width = 400,
}
end
)
end
2017-02-04 16:38:46 +01:00
email_icon:connect_signal("mouse::enter", function() show_emails() end)
return email_widget, email_icon