diff --git a/config/awesome/apps.lua b/config/awesome/apps.lua index 7746da0..5cc1e8c 100644 --- a/config/awesome/apps.lua +++ b/config/awesome/apps.lua @@ -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 diff --git a/config/awesome/helpers.lua b/config/awesome/helpers.lua index 4ca5949..b560119 100644 --- a/config/awesome/helpers.lua +++ b/config/awesome/helpers.lua @@ -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 diff --git a/config/awesome/notifications/battery.lua b/config/awesome/notifications/battery.lua index aedddf2..773f7aa 100644 --- a/config/awesome/notifications/battery.lua +++ b/config/awesome/notifications/battery.lua @@ -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) diff --git a/config/awesome/notifications/brightness.lua b/config/awesome/notifications/brightness.lua index bd82ec7..bf16b4d 100644 --- a/config/awesome/notifications/brightness.lua +++ b/config/awesome/notifications/brightness.lua @@ -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) diff --git a/config/awesome/notifications/themes/ephemeral.lua b/config/awesome/notifications/themes/ephemeral.lua index 9656028..6365b35 100644 --- a/config/awesome/notifications/themes/ephemeral.lua +++ b/config/awesome/notifications/themes/ephemeral.lua @@ -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, }, { diff --git a/config/awesome/notifications/volume.lua b/config/awesome/notifications/volume.lua index 01d5f7f..1aad905 100644 --- a/config/awesome/notifications/volume.lua +++ b/config/awesome/notifications/volume.lua @@ -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)