tests: Test the notification rules.
This commit is contained in:
parent
afe58d6cd2
commit
2d477383ee
|
@ -0,0 +1,61 @@
|
||||||
|
--DOC_GEN_IMAGE --DOC_NO_USAGE
|
||||||
|
local parent = ... --DOC_HIDE
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
local wibox = require("wibox") --DOC_HIDE
|
||||||
|
local beautiful = require("beautiful") --DOC_HIDE
|
||||||
|
local def = require("naughty.widget._default") --DOC_HIDE
|
||||||
|
local acommon = require("awful.widget.common") --DOC_HIDE
|
||||||
|
|
||||||
|
beautiful.notification_bg = beautiful.bg_normal --DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function()
|
||||||
|
-- Add a red background for urgent notifications.
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { }, -- Match everything.
|
||||||
|
properties = {
|
||||||
|
append_actions = {
|
||||||
|
naughty.action {
|
||||||
|
name = "Snooze (5m)",
|
||||||
|
},
|
||||||
|
naughty.action {
|
||||||
|
name = "Snooze (15m)",
|
||||||
|
},
|
||||||
|
naughty.action {
|
||||||
|
name = "Snooze (1h)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
-- Create a normal notification.
|
||||||
|
local notif = --DOC_HIDE
|
||||||
|
naughty.notification {
|
||||||
|
title = "A notification",
|
||||||
|
message = "This is very informative",
|
||||||
|
icon = beautiful.awesome_icon,
|
||||||
|
actions = {
|
||||||
|
naughty.action { name = "Existing 1" },
|
||||||
|
naughty.action { name = "Existing 2" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local function show_notification(n) --DOC_HIDE
|
||||||
|
local default = wibox.widget(def) --DOC_HIDE
|
||||||
|
acommon._set_common_property(default, "notification", n) --DOC_HIDE
|
||||||
|
|
||||||
|
local w, h = default:fit({dpi=96}, 9999, 9999) --DOC_HIDE
|
||||||
|
default.forced_width = w + 250 --DOC_HIDE
|
||||||
|
default.forced_height = h --DOC_HIDE
|
||||||
|
parent.forced_width = w + 250 --DOC_HIDE
|
||||||
|
|
||||||
|
parent:add(default) --DOC_HIDE
|
||||||
|
end --DOC_HIDE
|
||||||
|
|
||||||
|
parent.spacing = 10 --DOC_HIDE
|
||||||
|
show_notification(notif) --DOC_HIDE
|
|
@ -0,0 +1,29 @@
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
|
||||||
|
local function get_mpris_actions() end --DOC_HIDE
|
||||||
|
local my_music_widget_template = nil --DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function() --DOC_HIDE
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { has_class = "amarok" },
|
||||||
|
properties = {
|
||||||
|
widget_template = my_music_widget_template,
|
||||||
|
actions = get_mpris_actions(),
|
||||||
|
works = true --DOC_HIDE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end) --DOC_HIDE
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
local c = client.gen_fake { class = "amarok" } --DOC_HIDE
|
||||||
|
client.focus = c --DOC_HIDE
|
||||||
|
assert(client.focus == c) --DOC_HIDE
|
||||||
|
|
||||||
|
local notif = naughty.notification { --DOC_HIDE
|
||||||
|
message = "I am SPAM", --DOC_HIDE
|
||||||
|
clients = {c}, --DOC_HIDE note that this is undocumented
|
||||||
|
} --DOC_HIDE
|
||||||
|
|
||||||
|
assert(notif.works) --DOC_HIDE
|
|
@ -0,0 +1,24 @@
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function() --DOC_HIDE
|
||||||
|
-- Note that the the message is matched as a pattern.
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { message = "I am SPAM", has_focus = true },
|
||||||
|
properties = { ignore = true}
|
||||||
|
}
|
||||||
|
end) --DOC_HIDE
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
local c = client.gen_fake { class = "xchat" } --DOC_HIDE
|
||||||
|
client.focus = c --DOC_HIDE
|
||||||
|
assert(client.focus == c) --DOC_HIDE
|
||||||
|
|
||||||
|
local notif = naughty.notification { --DOC_HIDE
|
||||||
|
message = "I am SPAM", --DOC_HIDE
|
||||||
|
clients = {c}, --DOC_HIDE note that this is undocumented
|
||||||
|
} --DOC_HIDE
|
||||||
|
|
||||||
|
assert(#notif.clients == 1 and notif.clients[1] == client.focus) --DOC_HIDE
|
||||||
|
assert(notif.ignore) --DOC_HIDE
|
|
@ -0,0 +1,30 @@
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
|
||||||
|
local function get_mpris_actions() end --DOC_HIDE
|
||||||
|
local my_music_widget_template = nil --DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function() --DOC_HIDE
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { has_instance = "amarok" },
|
||||||
|
properties = {
|
||||||
|
widget_template = my_music_widget_template,
|
||||||
|
actions = get_mpris_actions(),
|
||||||
|
works = true --DOC_HIDE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end) --DOC_HIDE
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
local c = client.gen_fake { instance = "amarok" } --DOC_HIDE
|
||||||
|
assert(c.instance == "amarok") --DOC_HIDE
|
||||||
|
client.focus = c --DOC_HIDE
|
||||||
|
assert(client.focus == c) --DOC_HIDE
|
||||||
|
|
||||||
|
local notif = naughty.notification { --DOC_HIDE
|
||||||
|
message = "I am SPAM", --DOC_HIDE
|
||||||
|
clients = {c}, --DOC_HIDE note that this is undocumented
|
||||||
|
} --DOC_HIDE
|
||||||
|
|
||||||
|
assert(notif.works) --DOC_HIDE
|
|
@ -0,0 +1,60 @@
|
||||||
|
--DOC_GEN_IMAGE --DOC_NO_USAGE
|
||||||
|
local parent = ... --DOC_HIDE
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
local wibox = require("wibox") --DOC_HIDE
|
||||||
|
local beautiful = require("beautiful") --DOC_HIDE
|
||||||
|
local def = require("naughty.widget._default") --DOC_HIDE
|
||||||
|
local acommon = require("awful.widget.common") --DOC_HIDE
|
||||||
|
|
||||||
|
beautiful.notification_bg = beautiful.bg_normal --DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function()
|
||||||
|
-- Add a red background for urgent notifications.
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { urgency = "critical" },
|
||||||
|
properties = { bg = "#ff0000", fg = "#ffffff", timeout = 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
-- Or green background for normal ones.
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { urgency = "normal" },
|
||||||
|
properties = { bg = "#00ff00", fg = "#000000"}
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
-- Create a normal notification.
|
||||||
|
local notif = --DOC_HIDE
|
||||||
|
naughty.notification {
|
||||||
|
title = "A notification 1",
|
||||||
|
message = "This is very informative",
|
||||||
|
icon = beautiful.awesome_icon,
|
||||||
|
urgency = "normal",
|
||||||
|
}
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
-- Create a normal notification.
|
||||||
|
local notif2 = --DOC_HIDE
|
||||||
|
naughty.notification {
|
||||||
|
title = "A notification 2",
|
||||||
|
message = "This is very informative",
|
||||||
|
icon = beautiful.awesome_icon,
|
||||||
|
urgency = "critical",
|
||||||
|
}
|
||||||
|
|
||||||
|
local function show_notification(n) --DOC_HIDE
|
||||||
|
local default = wibox.widget(def) --DOC_HIDE
|
||||||
|
acommon._set_common_property(default, "notification", n) --DOC_HIDE
|
||||||
|
parent:add(default) --DOC_HIDE
|
||||||
|
end --DOC_HIDE
|
||||||
|
|
||||||
|
parent.spacing = 10 --DOC_HIDE
|
||||||
|
show_notification(notif) --DOC_HIDE
|
||||||
|
show_notification(notif2) --DOC_HIDE
|
|
@ -0,0 +1,91 @@
|
||||||
|
--DOC_GEN_IMAGE --DOC_NO_USAGE
|
||||||
|
local parent = ... --DOC_HIDE
|
||||||
|
local naughty = require("naughty") --DOC_HIDE
|
||||||
|
local ruled = {notification = require("ruled.notification")}--DOC_HIDE
|
||||||
|
local wibox = require("wibox") --DOC_HIDE
|
||||||
|
local beautiful = require("beautiful") --DOC_HIDE
|
||||||
|
|
||||||
|
local box = nil --DOC_HIDE
|
||||||
|
beautiful.notification_bg = beautiful.bg_normal --DOC_HIDE
|
||||||
|
|
||||||
|
ruled.notification.connect_signal("request::rules", function()
|
||||||
|
-- Add a red background for urgent notifications.
|
||||||
|
ruled.notification.append_rule {
|
||||||
|
rule = { app_name = "mdp" },
|
||||||
|
properties = {
|
||||||
|
widget_template = {
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
naughty.widget.icon,
|
||||||
|
forced_height = 48,
|
||||||
|
halign = "center",
|
||||||
|
valign = "center",
|
||||||
|
widget = wibox.container.place
|
||||||
|
},
|
||||||
|
{
|
||||||
|
align = "center",
|
||||||
|
widget = naughty.widget.title,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
align = "center",
|
||||||
|
widget = naughty.widget.message,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
orientation = "horizontal",
|
||||||
|
widget = wibox.widget.separator,
|
||||||
|
forced_height = 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nil,
|
||||||
|
{
|
||||||
|
wibox.widget.textbox "⏪",
|
||||||
|
wibox.widget.textbox "⏸",
|
||||||
|
wibox.widget.textbox "⏩",
|
||||||
|
spacing = 20,
|
||||||
|
layout = wibox.layout.fixed.horizontal,
|
||||||
|
},
|
||||||
|
expand = "outside",
|
||||||
|
nil,
|
||||||
|
layout = wibox.layout.align.horizontal,
|
||||||
|
},
|
||||||
|
spacing = 10,
|
||||||
|
layout = wibox.layout.fixed.vertical,
|
||||||
|
},
|
||||||
|
margins = beautiful.notification_margin,
|
||||||
|
widget = wibox.container.margin,
|
||||||
|
},
|
||||||
|
id = "background_role",
|
||||||
|
widget = naughty.container.background,
|
||||||
|
},
|
||||||
|
strategy = "max",
|
||||||
|
width = 160,
|
||||||
|
widget = wibox.container.constraint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
naughty.connect_signal("request::display", function(n)
|
||||||
|
box = --DOC_HIDE
|
||||||
|
naughty.layout.box { notification = n }
|
||||||
|
end)
|
||||||
|
|
||||||
|
awesome.emit_signal("startup") --DOC_HIDE
|
||||||
|
|
||||||
|
local notif2 = --DOC_HIDE
|
||||||
|
naughty.notification { --DOC_HIDE
|
||||||
|
title = "Daft Punk", --DOC_HIDE
|
||||||
|
message = "Harder, Better, Faster, Stronger", --DOC_HIDE
|
||||||
|
icon = beautiful.awesome_icon,
|
||||||
|
icon_size = 128, --DOC_HIDE
|
||||||
|
app_name = "mdp", --DOC_HIDE
|
||||||
|
} --DOC_HIDE
|
||||||
|
|
||||||
|
assert(notif2.app_name == "mdp") --DOC_HIDE
|
||||||
|
assert(box) --DOC_HIDE
|
||||||
|
|
||||||
|
box.widget.forced_width = 250 --DOC_HIDE
|
||||||
|
|
||||||
|
parent:add(box.widget) --DOC_HIDE
|
Loading…
Reference in New Issue