令人惊叹的淘气通知

我正在为 Awesome 创建一个基于 playerctl 的小部件。 当我使用 awesomeclient 进行测试时它工作得很好。

awesome-client '

local stdout = "Playing;Eurythmics;Miracle of Love;file:///home/mgaber/Workbench/awesome/stags1.7/testing/173308_26.png"

local words = {}
for w in stdout:gmatch("([^;]*)") do
    print(w)
    table.insert(words, w)
end

mpdstatus = words[1]
current_song = words[2]
artist = words[3]
song_art = words[4]

a,b,c = 1, 2, 3

local song_art = string.sub( song_art,8, -1)

local awful = require("awful");
local gears = require("gears")
local naughty= require("naughty");
local bubble =function(cr, w, h)
        return gears.shape.infobubble(cr, w, h, 20, 10, w/2 - 30)
    end
naughty.notification(
{
margin = 15,
position = "top_left",
width = 640,
height = 160,
title = mpdstatus,
text=current_song .. " By " .. artist .. a .. c,
image = song_art});

'

然而,当我把代码放到 rc.lua 中时,图标没有出现,我进行了测试,我的代码按预期工作,图像文件被传递给了 naughty.notification..

    local function show_MPD_status()
        spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _)
            -- notification = naughty.notification {
            naughty.notification {
                margin = 10,
                timeout = 5,
                hover_timeout = 0.5,
                width = auto,
                height = auto,
                title = mpdstatus,
                text = current_song .. " by " .. artist,
                image = artUr
            }
        end)
    end

Awesome 版本

$ awesome --version
awesome v4.3-895-g538586c17-dirty (太长)
 • 编译Lua 5.3.6(运行Lua 5.3)
 • API级别:4
 • D-Bus支持:有
 • xcb-errors支持:有
 • execinfo支持:有
 • xcb-randr版本:1.6
 • LGI版本:0.9.2
 • 透明度启用:有
 • 自定义搜索路径:无

我得到了一个显示“状态”、“歌曲”和“艺术家”的通知,但没有图像或图标。

感谢

点赞
用户3342050
用户3342050

我认为这是 Lua 版本的问题。我不知道具体情况,但它在 Lua 5.3 和 5.4 上运行良好,但在 LuaJIT、Lua 5.1 和 5.2 中你提到的缺少歌手和歌曲的艺术品相同。你是否知道你的 AwesomeWM 编译使用的 Lua 版本是什么?

#! /usr/bin/env lua
print(_VERSION)

local stdout = 'Playing;Eurythmics;Miracle of Love;file:///home/mgaber/Workbench/awesome/stags1.7/testing/173308_26.png'

local words = {}
for w in stdout:gmatch('([^;]*)') do
    if #w > 0 then
        print(w)
        words[#words +1] = w
    end
end

local mpdstatus = words[1]; print(mpdstatus)
local current_song = words[2]; print(current_song)
local artist = words[3]; print(artist)
local song_art = words[4]:sub(8); print(song_art)

local awful = require('awful')
local gears = require('gears')
local naughty = require('naughty')

local bubble = function(cr, w, h)
    return gears.shape.infobubble(cr, w, h, 20, 10, w/2 - 30)
end

naughty.notification({
    margin = 15,
    position = 'top_left',
    width = 640,
    height = 160,
    title = mpdstatus,
    text = current_song ..' By ' .. artist,
    image = song_art
})

编辑:

它在单词列表中放入了比预期更多的条目。过滤掉空条目。

2020-11-23 21:40:30
用户10700322
用户10700322

我终于成功解决了这个问题。

问题是由于告知形状的小部件模板被错误配置所引起的,移除该模板后问题得到了修复。

2020-11-25 21:09:29