Awesome: Help with `naughty.config.notify_callback`

Created on 15 Sep 2017  路  5Comments  路  Source: awesomeWM/awesome

Continuing from #1965, I want to do something similar to what @RomeuG wanted to do:

I use MusicPlayerDaemon/MPD with eonpatapon/mpDris2 and I've managed to setup notifications when a track is changed, paused and stopped etc.

I have one problem though: In the notification, there is almost always an image of the album art with it, and sometimes that image is way too large. I opened an issue on mpDris2: https://github.com/eonpatapon/mpDris2/issues/94 and I added an image showcasing the problem:

desktop 2017 09 10-17 03 29

I want to create a naughty.config.notify_callback function that will set the size of that image to a certain size no matter what's the size the dbus notification daemon wants to use. Another problem that makes this task challenging is the fact that the text and title that come with that notification don't hold consistent a consistent, it's just the name of the album and the name of track. I understand that I need to use args.freedesktop_hints as explained here, but what are the properties of this table? I tried looking at lib/naughty/dbus.lua and I have no idea where to start..

Anyway, I hope someone will be able to help me,
Thanks.

Most helpful comment

OK, I succeeded with the callback function. I only had to change a small parameter in the if statement. This is the final result:

naughty.config.notify_callback = function(args)
    if args.icon then
        args.icon_size = 250
    end
    return args
end

All 5 comments

Why not naughty.config.defaults.icon_size?

It doesn't seem to be documented in the API:
https://awesomewm.org/doc/api/libraries/naughty.html#config.defaults

beautiful.notification_icon_size

naughty.notify({
  text = string, title = string, icon_size = int
})

naughty.preset.normal.icon_size
naughty.defaults.icon_size

Setting naughty.config.defaults.icon_size and naughty.config.presets.normal.icon_size works for notifications from mpdris2. The problem is that it makes also text only notifications appear as if they have an icon with the same size, even when they should have no icon at all.

Just like that:

desktop 2017 09 16-16 36 30

I think that if I'm not willing to compensate, I have to use naughty.config.notify_callback = function(args). In this I should test if there is even supposed to be an icon at all and only if so I need to set the icon's size. This is what I came up with so far:

naughty.config.notify_callback = function(args)
    if args.icon_size then -- tests if there is supposed to be and 
        args.icon_size = 250
    end
    return args
end

But the question is what properties the args table has? Do those properties equivalent to the arguments that a normal naughty.notify function receives? If so, why it won't work?

OK, I succeeded with the callback function. I only had to change a small parameter in the if statement. This is the final result:

naughty.config.notify_callback = function(args)
    if args.icon then
        args.icon_size = 250
    end
    return args
end

Was this page helpful?
0 / 5 - 0 ratings