2

I am configuring the widgets in awesome wm (v3.5.5-1) using vicious (v2.1.3-1). I want to show the time in a widget. And then show the date in the tooltip when I hover over the time widget.

The following code using vicious in my rc.lua file works fine:

myclock = wibox.widget.textbox()
vicious.register(myclock, vicious.widgets.date, " <span color='#ffffff'>%H:%M</span> ") 
myclock_tooltip =  awful.tooltip ({ objects = { myclock } })
vicious.register(myclock_tooltip, vicious.widgets.date, " %a %d %b ", 60)

However, when I try to combine the two vicious.register statements (based on the Format functions section of the vicious readme file):

myclock = wibox.widget.textbox()
myclock_tooltip =  awful.tooltip ({ objects = { myclock } })
vicious.register(myclock, vicious.widgets.date, 
    function (widget, args)
        myclock_tooltip.set_text(" %a %d %b ")
        return " <span color='#ffffff'>%H:%M</span> "
    end)

I get the following error:

/usr/share/lua/5.2/vicious/widgets/date.lua:23: bad argument #1 to 'date' (string expected, got function)

Any suggestions where I'm going wrong?

maninashed
  • 23
  • 3

2 Answers2

2

Why do you need that format function at all? Doesn't the following work?

myclock = wibox.widget.textbox()
myclock_tooltip =  awful.tooltip ({ objects = { myclock } })
vicious.register(myclock, vicious.widgets.date, " <span color='#fffff'>%H:%M</span> ")
myclock_tooltip_timer = timer({ timeout = 3600 })
myclock_tooltip_timer:connect_signal("timeout", function()
    myclock_tooltip:set_text(os.date(" %a %d %b "))
end)
myclock_tooltip_timer:start()
myclock_tooltip_timer:emit_signal("timeout")

This uses the "normal" vicious stuff for the widget and updates your tooltip with a seperate timer which fires once per hour.

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39
  • Thanks for the sample code. I'd started looking into using timers and this gives me a good start. However, this code just sets the tooltip to the string " %a %d %b ". Also, it doesn't initialise the tooltip and it needs to be `myclock_tooltip:set_text`. – maninashed Sep 24 '14 at 23:32
  • The following line can be used to initialise the tooltip and update it: `myclock_tooltip:set_text(os.date(" %a %d %b "))`. – maninashed Sep 24 '14 at 23:45
  • Whoops & thanks. Added the missing `os.date` call, switched to `:set_text` and added a new `:emit_signal()` at the end to initialy set the text of the tooltip. – Uli Schlachter Sep 25 '14 at 08:15
1

I don't believe you are doing anything wrong from a technical perspective. I think (and a quick look at the source confirms) that that widget just doesn't accept a function format.

It looks like some widgets take format strings (to be used by the widget function) and some accept format functions (to be called with the result of the widget function) but I don't see any clear indication from that README which are which.

Compare the worker function in date.lua against the worker function in uptime.lua for example.

The date.lua function uses the format argument in a call to os.date (which is what is generating the error you are getting, try calling os.date(function()end) locally).

The uptime.lua function does not use the format argument at all (presumably it gets called by vicious internally on the return value from that function.

It is probably worth asking to get the documentation updated to make this clearer (or fixing the documentation up yourself and submitting a patch for it).

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148