You are not logged in.

#1 2010-06-15 00:18:52

epsilon
Member
Registered: 2009-04-02
Posts: 75

[Solved] Icon changing with Vicious, based on widget value (AwesomeWM)

Ideally, I want to be able to use Vicious (or some other suitable library, but Vicious seems to be the best) to allow the icons I set for widgets to change colors upon certain states. I achieved this with conky + dzen2: for example, my widget icon plus text would change from blue to red when I receive a new message, battery charge went to a certain level, etc.

So, the Vicious README establishes that widgets can use functions to shape output based on the returned values. This would be sufficient, except I wish to also change the icon, either the color or if it appears at all.

For that latter point, I bring you to the problem at hand. I am trying to write an MPD vicious widget that will, if nothing is playing, output nothing (including no icon);  if it is playing, it will initialize the imagebox widget of the icon, and also output the now playing text. As one could observe, I have just followed the Vicious README when doing this, modifying it to also (ideally) create an imagebox when something is playing.

However, nothing is output to the wibox, whether something is playing or not.

I am very new to Lua, so perhaps I am making some trivial error, I would just like to find some way to make this happen.

You can find my entire rc.lua here, but here is the widgets/wibox portion:

-- {{{ Widgets

-- Containers
topbar = {}
bottombar = {}

-- Generic widgets
clock = awful.widget.textclock({align = "right"}, "%a %b %d, %I:%M %p")
mysystray = widget({ type = "systray" })
seperator = widget({ type = "textbox" })
seperator.text = " | "
spacer = widget({ type = "textbox" })
spacer.width = 6

-- Set all the icons needed
cpuicon = widget ({ type = "textbox" })
cpuicon.bg_image = image(beautiful.widget_cpu)
cpuicon.bg_align = "middle"
cpuicon.width = 8
tempicon = widget ({ type = "textbox" })
tempicon.bg_image = image(beautiful.widget_temp)
tempicon.bg_align = "middle"
tempicon.width = 8
-- They continue in this format

-- Create some widgets...
cpuinfo = widget ({ type = "textbox" })
cputemp = widget ({ type = "textbox" })
meminfo = widget ({ type = "textbox" })
spkrinfo = widget ({ type = "textbox" })
headinfo = widget ({ type = "textbox" })
netdowninfo = widget ({ type = "textbox" })
netupinfo = widget ({ type = "textbox" })
mailinfo = widget ({ type = "textbox" })
pacinfo = widget ({ type = "textbox" })
battinfo = widget ({ type = "textbox" })
mpdinfo = widget ({ type = "textbox" })

-- ... And register them
vicious.register(cpuinfo, vicious.widgets.cpu, "$1% / $2%")
vicious.register(cputemp, vicious.widgets.thermal, "$1 C", 19, "thermal_zone0")
vicious.cache(vicious.widgets.mem)
vicious.register(meminfo, vicious.widgets.mem, "$1% ($2Mb)", 5)
vicious.cache(vicious.widgets.volume)
vicious.register(spkrinfo, vicious.widgets.volume, "$1", 11, "Speaker")
vicious.register(headinfo, vicious.widgets.volume, "$1", 11, "Headphone")
vicious.cache(vicious.widgets.net)
vicious.register(netdowninfo, vicious.widgets.net, "${wlan0 down_kb}", 3)
vicious.register(netupinfo, vicious.widgets.net, "${wlan0 up_kb}", 3)
vicious.register(mailinfo, vicious.widgets.gmail, "${count}", 61)
vicious.register(pacinfo, vicious.widgets.pkg, "$1", 301, "Arch")
vicious.register(battinfo, vicious.widgets.bat, "$2%", 59, "BAT0")


-- Here is my MPD widget that is troublesome:
vicious.register(mpdinfo, vicious.widgets.mpd,
  function (widget, args)
    if args["{state}"] == "Stop" then return ""
    else
      mpdicon = widget ({ type = "textbox" })
      mpdicon.bg_image = image(beautiful.widget_mpd)
      mpdicon.bg_align = "middle"
      mpdicon.width = 8
      return "MPD: " .. args["{Artist}"] .. ' - ' .. args["{Title}"]
    end
  end)
  

-- Create a wibox for each screen and add it
mylayoutbox = {}
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, awful.tag.viewnext),
                    awful.button({ }, 5, awful.tag.viewprev)
                    )
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
                     awful.button({ }, 1, function (c)
                                              if not c:isvisible() then
                                                  awful.tag.viewonly(c:tags()[1])
                                              end
                                              client.focus = c
                                              c:raise()
                                          end),
                     awful.button({ }, 3, function ()
                                              if instance then
                                                  instance:hide()
                                                  instance = nil
                                              else
                                                  instance = awful.menu.clients({ width=250 })
                                              end
                                          end),
                     awful.button({ }, 4, function ()
                                              awful.client.focus.byidx(1)
                                              if client.focus then client.focus:raise() end
                                          end),
                     awful.button({ }, 5, function ()
                                              awful.client.focus.byidx(-1)
                                              if client.focus then client.focus:raise() end
                                          end))

for s = 1, screen.count() do
    -- Set a screen margin, for borders
    awful.screen.padding( screen[s], {top = 1, bottom = 1} )

    -- Create the layout box, taglist, and tasklist widgets
    mylayoutbox[s] = awful.widget.layoutbox(s)
    mylayoutbox[s]:buttons(awful.util.table.join(
                           awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
                           awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
                           awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
                           awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
    mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)

    -- Create the bars
    topbar[s] = awful.wibox({
                position = "top", screen = s, height = 13,
                fg = beautiful.fg_normal, bg = beautiful.bg_normal,
                border_width = beautiful.border_width,
                border_color = beautiful.border_normal,
                cursor = "/usr/share/themes/Human/cursor.theme" 
    })
    bottombar[s] = awful.wibox({
                position = "bottom", screen = s, height = 13,
                fg = beautiful.fg_normal, bg = beautiful.bg_normal,
                border_width = beautiful.border_width,
                border_color = beautiful.border_normal
    })

    -- Create a table of widgets
    right_aligned = { layout = awful.widget.layout.horizontal.rightleft}
    if s == 1 then table.insert(right_aligned, mysystray) end
    table.insert(right_aligned, mylayoutbox[s])
    topbar[s].widgets = {
        mytaglist[s],
        right_aligned,
        mytasklist[s],
        layout = awful.widget.layout.horizontal.leftright,
        height = 13
    }

    --Inserting the MPD widget
    mpd_widget_container = { layout = awful.widget.layout.horizontal.leftright}
    if mpdicon then table.insert( mpd_widget_container, mpdicon) end
    table.insert( mpd_widget_container, mpdinfo )
    bottombar[s].widgets = {
        mpd_widget_container,
        cpuicon, spacer, cpuinfo, seperator, tempicon, spacer, cputemp,
        seperator, memicon, spacer, meminfo, seperator, spkricon, spacer,
        spkrinfo, spacer, headicon, spacer, headinfo, seperator,
        netdownicon, spacer, netdowninfo, spacer, netupicon, spacer,
        netupinfo, seperator, mailicon, spacer, mailinfo, seperator,
        pacicon, spacer, pacinfo, seperator, batticon, spacer,
        battinfo, seperator, clockicon, spacer, clock, spacer,
        layout = awful.widget.layout.horizontal.rightleft,
        height = 13
   }
end
-- }}}

Thanks.

Last edited by epsilon (2010-06-16 02:22:03)


mu @ freenode - Last.fm

Offline

#2 2010-06-15 10:59:32

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [Solved] Icon changing with Vicious, based on widget value (AwesomeWM)

Create an imagebox widget for mpd icon. Where you did all the others. You could then set its .image field to nothing or nil (image(nil)). In the format function of the mpd textbox widget you can then toggle that image to an actual png or back to nil.

Your widgets not showing up at all are probably connected to the mess you made in the wibox section, with the "container" stuff.


You need to install an RTFM interface.

Offline

#3 2010-06-16 02:21:52

epsilon
Member
Registered: 2009-04-02
Posts: 75

Re: [Solved] Icon changing with Vicious, based on widget value (AwesomeWM)

Yep I have this fixed actually (just forgot to close it). Thanks for the help, anrxc!


mu @ freenode - Last.fm

Offline

Board footer

Powered by FluxBB