Use app_name instead of title to determine notification icon

This commit is contained in:
elenapan 2020-03-11 00:20:40 +02:00
parent c2776a5b39
commit d580f2f63c
6 changed files with 43 additions and 46 deletions

View file

@ -69,11 +69,8 @@ local night_mode_notif
apps.night_mode = function ()
local cmd = "pgrep redshift > /dev/null && (pkill redshift && echo 'OFF') || (echo 'ON' && redshift -l 0:0 -t 3700:3700 -r &>/dev/null &)"
awful.spawn.easy_async_with_shell(cmd, function(out)
if out:match('ON') then
night_mode_notif = notifications.notify_dwim({ title = "Night mode", message = "Activated!" }, night_mode_notif)
else
night_mode_notif = notifications.notify_dwim({ title = "Night mode", message = "Deactivated!" }, night_mode_notif)
end
local message = out:match('ON') and "Activated!" or "Deactivated!"
night_mode_notif = notifications.notify_dwim({ title = "Night mode", message = message, app_name = "night_mode", icon = icons.redshift }, night_mode_notif)
end)
end

View file

@ -303,6 +303,7 @@ end
-- TODO: notification action buttons
-- https://github.com/awesomeWM/awesome/issues/3017
local capture_notif = nil
local screenshot_notification_app_name = "screenshot"
function helpers.screenshot(action, delay)
local cmd
local timestamp = os.date("%Y.%m.%d-%H.%M.%S")
@ -321,14 +322,14 @@ function helpers.screenshot(action, delay)
if action == "full" then
cmd = prefix.."maim "..maim_args.." "..filename
awful.spawn.easy_async_with_shell(cmd, function()
naughty.notification({ title = "Screenshot", message = "Screenshot taken", icon = icon })
naughty.notification({ title = "Screenshot", message = "Screenshot taken", icon = icon, app_name = screenshot_notification_app_name })
end)
elseif action == "selection" then
cmd = "maim "..maim_args.." -s "..filename
capture_notif = naughty.notification({ title = "Screenshot", message = "Select area to capture.", icon = icon, timeout = 1 })
awful.spawn.easy_async_with_shell(cmd, function(_, __, ___, exit_code)
if exit_code == 0 then
capture_notif = notifications.notify_dwim({ title = "Screenshot", message = "Selection captured", icon = icon }, capture_notif)
capture_notif = notifications.notify_dwim({ title = "Screenshot", message = "Selection captured", icon = icon, app_name = screenshot_notification_app_name }, capture_notif)
else
naughty.destroy(capture_notif)
end
@ -338,7 +339,7 @@ function helpers.screenshot(action, delay)
cmd = "maim "..maim_args.." -s /tmp/maim_clipboard && xclip -selection clipboard -t image/png /tmp/maim_clipboard &>/dev/null && rm /tmp/maim_clipboard"
awful.spawn.easy_async_with_shell(cmd, function(_, __, ___, exit_code)
if exit_code == 0 then
capture_notif = notifications.notify_dwim({ title = "Screenshot", message = "Copied selection to clipboard", icon = icon }, capture_notif)
capture_notif = notifications.notify_dwim({ title = "Screenshot", message = "Copied selection to clipboard", icon = icon, app_name = screenshot_notification_app_name }, capture_notif)
else
naughty.destroy(capture_notif)
end
@ -347,7 +348,7 @@ function helpers.screenshot(action, delay)
awful.spawn.with_shell("cd "..user.screenshot_dir.." && feh $(ls -t)")
elseif action == "gimp" then
awful.spawn.with_shell("cd "..user.screenshot_dir.." && gimp $(ls -t | head -n1)")
naughty.notification({ message = "Opening last screenshot with GIMP", icon = icon })
naughty.notification({ message = "Opening last screenshot with GIMP", icon = icon, app_name = screenshot_notification_app_name})
end
end

View file

@ -38,7 +38,7 @@ awesome.connect_signal("evil::battery", function(battery)
-- If message has been initialized, then we need to send a notification
if message then
notif = notifications.notify_dwim({title = "Battery", message = message, icon = icon, timeout = timeout}, notif)
notif = notifications.notify_dwim({ title = "Battery", message = message, icon = icon, timeout = timeout, app_name = "battery" }, notif)
end
end)
@ -64,6 +64,6 @@ awesome.connect_signal("evil::charger", function(plugged)
if charger_first_time then
charger_first_time = false
else
notif = notifications.notify_dwim({title = "Charger", message = message, icon = icon, timeout = 3}, notif)
notif = notifications.notify_dwim({ title = "Charger", message = message, icon = icon, timeout = 3, app_name = "charger" }, notif)
end
end)

View file

@ -16,7 +16,7 @@ awesome.connect_signal("evil::brightness", function (percentage)
end
else
-- Send notification
notif = notifications.notify_dwim({ title = "Brightness", message = tostring(percentage), icon = icons.redshift, timeout = timeout }, notif)
notif = notifications.notify_dwim({ title = "Brightness", message = tostring(percentage), icon = icons.redshift, timeout = timeout, app_name = "brightness" }, notif)
end
end
end)

View file

@ -30,9 +30,24 @@ local rainbow_stripe = wibox.widget {
local notification_bg = beautiful.notification_bg
beautiful.notification_bg = "#00000000"
local default_symbol = ""
local default_icon = ""
local default_color = x.foreground
-- Custom text icons according to the notification's app_name
-- (This will be removed when notification rules are released)
-- Using icomoon font
local text_icons = {
['battery'] = "",
['charger'] = "",
['volume'] = "",
['brightness'] = "",
['screenshot'] = "",
['Telegram Desktop'] = "",
['night_mode'] = "",
['NetworkManager'] = "",
['youtube'] = "",
}
-- Template
-- ===================================================================
naughty.connect_signal("request::display", function(n)
@ -40,6 +55,7 @@ naughty.connect_signal("request::display", function(n)
-- Debugging
-- print('n.title = '..n.title)
-- print('n.message = '..n.message)
-- print('n.app_name = '..n.app_name)
-- Custom icon widget
-- It can be used instead of naughty.widget.icon if you prefer your icon to be
@ -54,35 +70,13 @@ naughty.connect_signal("request::display", function(n)
widget = wibox.widget.textbox
}
local symbol = default_symbol
local icon
local color = default_color
-- Try to detect the notification source and change the symbol and/or color ccordingly
if n.title == "Telegram" then
symbol = ""
elseif n.title == "Volume" then
symbol = ""
n.title = ""
elseif n.title == "Screenshot" then
-- symbol = ""
symbol = ""
n.title = ""
elseif n.title == "Performance mode" then
symbol = ""
elseif n.title == "Night mode" then
symbol = ""
elseif n.title:match('Connection') then
symbol = ""
elseif n.title == "Battery" then
-- symbol = ""
symbol = ""
elseif n.title == "Charger" then
symbol = ""
n.title = ""
elseif n.title:match('YouTube') then
-- symbol = ""
-- symbol = ""
symbol = ""
-- Set icon according to app_name
if text_icons[n.app_name] then
icon = text_icons[n.app_name]
else
icon = default_icon
end
naughty.layout.box {
@ -103,7 +97,7 @@ naughty.connect_signal("request::display", function(n)
{
{
{
markup = helpers.colorize_text(symbol, color),
markup = helpers.colorize_text(icon, color),
widget = custom_notification_icon,
},
margins = beautiful.notification_margin,
@ -127,8 +121,8 @@ naughty.connect_signal("request::display", function(n)
{
{
align = "center",
-- Only show title if no symbol has been set
visible = symbol == default_symbol,
-- Only show title if no icon has been set
visible = icon == default_icon,
widget = naughty.widget.title,
},
{

View file

@ -15,11 +15,16 @@ awesome.connect_signal("evil::volume", function (percentage, muted)
end
else
-- Send notification
local message, icon
if muted then
notif = notifications.notify_dwim({ title = "Volume", message = "muted", icon = icons.muted, timeout = timeout }, notif)
message = "muted"
icon = icons.muted
else
notif = notifications.notify_dwim({ title = "Volume", message = tostring(percentage), icon = icons.volume, timeout = timeout }, notif)
message = tostring(percentage)
icon = icons.volume
end
notif = notifications.notify_dwim({ title = "Volume", message = message, icon = icon, timeout = timeout, app_name = "volume" }, notif)
end
end
end)