1

I'd like to get help with configuring the lain imap widget in awesome wm. While I actually have 3 email addresses to care about I'd like to configure the lain widget, so that I have only one Mail-icon and three initialized imap widgets, who sum up the widgets mailcount variable, sending that to the widget.

The current state is this:

local mailicon   = wibox.widget.imagebox(theme.widget_mail)
mailicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.spawn(mailclient) end)))
local mail = lain.widget.imap({
    timeout  = 60,
    server   = mailserver,
    mail     = mailaddress,
    password = mailpass,
    is_plain = true,
    settings = function()
        if mailcount > 0 then
            widget:set_text(" " .. mailcount .. " ")
            mailicon:set_image(theme.widget_mail_on)
        else
            widget:set_text("")
            mailicon:set_image(theme.widget_mail)
        end
    end
})

But I thought about something like this:

local mailicon   = wibox.widget.imagebox(theme.widget_mail)
mailicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.spawn(mailclient) end)))
local mail = lain.widget.imap({
    timeout  = 60,
    server   = mailserver,
    mail     = mailaddress,
    password = mailpass,
    is_plain = true,
    settings = function()
    --> local mailsum = mailcount
        if mailsum > 0 then
            widget:set_text(" " .. --> mailsum .. " ")
            mailicon:set_image(theme.widget_mail_on)
        else
            widget:set_text("")
            mailicon:set_image(theme.widget_mail)
        end
    end
})

local mail2 = lain.widget.imap({
    timeout  = 60,
    server   = "SECOND SERVER",
    mail     = "SECOND ADDRESS",
    password = "SECOND PASS",
    is_plain = true,
    settings = function()
    --> local mailsum = mailsum + mailcount
        if mailsum > 0 then
            widget:set_text(" " .. --> mailsum .. " ")
            mailicon:set_image(theme.widget_mail_on)
        else
            widget:set_text("")
            mailicon:set_image(theme.widget_mail)
        end
    end
})

(changes marked with --> ) Where a "mailsum" variable sums up the "mailcount" of every server. But I'm pretty new at lua coding and don't know how.

So the state I want to have in the end is one mail icon, and if I have one unread mail on first server and two on second, there should spawn a "3" behind the icon.

Can you help me?

1 Answers1

0

If I understand you correctly mail2 should sum up the mail count for both mail addresses. The easiest solution would be to declare a variable outside of the widgets. So write something like local mailsum = 0 before declaring local mail. Both following mail widgets have access to the mailsum variable.

ploth
  • 435
  • 8
  • 16