Hi,

I was playing around with naughty for the first time, and I have a
problem using naughty.destroy - I am not sure, if it is a bug or if I am
doing it wrong.

I wrote this volume control with naughty notification:

    function get_volume()
        local fh = io.popen('sleep 0.1 ; amixer sget PCM | grep "Front Left:" | 
sed -e \'s/^.*\\[\\([0-9]\\+%\\)\\].*$/\\1/\'')
        output = fh:read("*a")
        fh:close()
        return output
    end

    vol_notify = nil 
    function change_volume(value, up) 
        local sign, notify_text
        if up then
            sign = "+" 
            notify_text = "up"
        else
            sign = "-" 
            notify_text = "down"
        end 
        -- get the volume
        awful.util.spawn("amixer -q set PCM '"..value.."%"..sign.."'")
        -- delete old notification
        if vol_notify then
            awful.hooks.timer.unregister(vol_notify.die)
            naughty.destroy(vol_notify)
        end 
        -- display new notification
        output = get_volume()
        vol_notify = naughty.notify({ title = "Volume "..notify_text, text = 
output, timeout = 5 })
        -- update the volume widget
        volumewidget_reg.update()
    end

    keybinding({ modkey            }, "F9",     function () change_volume(8, 
false) end):add()
    keybinding({ modkey, "Control" }, "F9",     function () change_volume(2, 
false) end):add()
    keybinding({ modkey            }, "F10",    function () change_volume(8, 
true) end):add()
    keybinding({ modkey, "Control" }, "F10",    function () change_volume(2, 
true) end):add()


This works quite fine most of the time, but sometimes (when pressing one of the
keybindings in short order), I get this error:

    W: awesome: luaA_dofunction:323: error running function:
    /usr/share/awesome/lib/naughty.lua:144: attempt to index field '?' (a
    nil value)

My guess is that there is a race condition between the timer hook that
calls destroy for the notification after the timeout, and my own call to
destroy. I thought I could avoid this by calling

    awful.hooks.timer.unregister(vol_notify.die)

but that did not help.

I really want to delete the old notification before showing a new one,
because I don't like a bunch of popups cluttering my screen when I do
repeated key presses. Only one of those "volume up/down" notifications
should be visible at one point of time.

What am I doing wrong, or is there a more elegant way to achieve this?


Greetings,
Frank

-- 
Frank Blendinger | fb(at)intoxicatedmind.net | GPG: 0x0BF2FE7A
Fingerprint: BB64 F2B8 DFD8 BF90 0F2E 892B 72CF 7A41 0BF2 FE7A
  "Just because I don't care doesn't mean I don't understand."
                                               (Homer Simpson)

Attachment: signature.asc
Description: Digital signature

Reply via email to