This repository was archived by the owner on Oct 31, 2023. It is now read-only.
forked from material-shell/material-awesome
-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathnotifications.lua
271 lines (252 loc) · 7.02 KB
/
notifications.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
local gears = require('gears')
local wibox = require('wibox')
local awful = require('awful')
local ruled = require('ruled')
local naughty = require('naughty')
local cst = require("naughty.constants");
local menubar = require('menubar')
local beautiful = require('beautiful')
local dpi = beautiful.xresources.apply_dpi
local clickable_container = require('widget.clickable-container')
-- Defaults
naughty.config.defaults.ontop = true
naughty.config.defaults.icon_size = dpi(32)
naughty.config.defaults.timeout = 5
naughty.config.defaults.title = 'System Notification'
naughty.config.defaults.margin = dpi(16)
naughty.config.defaults.border_width = 0
naughty.config.defaults.position = 'top_right'
naughty.config.defaults.shape = function(cr, w, h)
gears.shape.rounded_rect(cr, w, h, dpi(6))
end
-- Apply theme variables
naughty.config.padding = dpi(8)
naughty.config.spacing = dpi(8)
naughty.config.icon_dirs = {
'/usr/share/icons/Tela',
'/usr/share/icons/Tela-blue-dark',
'/usr/share/icons/Papirus/',
'/usr/share/icons/la-capitaine-icon-theme/',
'/usr/share/icons/gnome/',
'/usr/share/icons/hicolor/',
'/usr/share/pixmaps/'
}
naughty.config.icon_formats = { 'svg', 'png', 'jpg', 'gif' }
-- Presets / rules
ruled.notification.connect_signal(
'request::rules',
function()
-- Critical notifs
ruled.notification.append_rule {
rule = { urgency = 'critical' },
properties = {
font = 'Inter Bold 10',
bg = '#ff0000',
fg = '#ffffff',
margin = dpi(16),
position = 'top_right',
implicit_timeout = 0
}
}
-- Normal notifs
ruled.notification.append_rule {
rule = { urgency = 'normal' },
properties = {
font = 'Inter Regular 10',
bg = beautiful.transparent,
fg = beautiful.fg_normal,
margin = dpi(16),
position = 'top_right',
implicit_timeout = 5
}
}
-- Low notifs
ruled.notification.append_rule {
rule = { urgency = 'low' },
properties = {
font = 'Inter Regular 10',
bg = beautiful.transparent,
fg = beautiful.fg_normal,
margin = dpi(16),
position = 'top_right',
implicit_timeout = 5
}
}
end
)
-- Potential fix to raise windows that made the notification?
-- see bug https://github.com/awesomeWM/awesome/issues/3182
--naughty.connect_signal('destroyed', function(n, reason)
--if not n.clients then return end
--if reason == cst.notification_closed_reason.dismissed_by_user then
--for _, cli in ipairs(n.clients) do
--cli.urgent = true
--cli:emit_signal("request::activate", {raise=true})
--end
--end
--end
--)
-- Error handling
naughty.connect_signal(
'request::display_error',
function(message, startup)
naughty.notification {
urgency = 'critical',
title = 'Oops, an error happened'..(startup and ' during startup!' or '!'),
message = message,
app_name = 'System Notification',
icon = beautiful.awesome_icon
}
end
)
-- XDG icon lookup
naughty.connect_signal(
'request::icon',
function(n, context, hints)
if context ~= 'app_icon' then return end
local path = menubar.utils.lookup_icon(hints.app_icon) or
menubar.utils.lookup_icon(hints.app_icon:lower())
if path then
n.icon = path
end
end
)
-- Connect to naughty on display signal
naughty.connect_signal(
'request::display',
function(n)
-- Actions Blueprint
local actions_template = wibox.widget {
notification = n,
base_layout = wibox.widget {
spacing = dpi(0),
layout = wibox.layout.flex.horizontal
},
widget_template = {
{
{
{
{
id = 'text_role',
font = 'Inter Regular 10',
widget = wibox.widget.textbox
},
widget = wibox.container.place
},
widget = clickable_container
},
bg = beautiful.groups_bg,
shape = gears.shape.rounded_rect,
forced_height = dpi(30),
widget = wibox.container.background
},
margins = dpi(4),
widget = wibox.container.margin
},
style = { underline_normal = false, underline_selected = true },
widget = naughty.list.actions
}
-- Notifbox Blueprint
naughty.layout.box {
notification = n,
type = 'notification',
screen = awful.screen.preferred(),
shape = gears.shape.rectangle,
widget_template = {
{
{
{
{
{
{
{
{
{
{
markup = n.app_name or 'System Notification',
font = 'Inter Bold 10',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
},
margins = beautiful.notification_margin,
widget = wibox.container.margin,
},
bg = beautiful.background,
widget = wibox.container.background,
},
{
{
{
resize_strategy = 'center',
widget = naughty.widget.icon,
},
margins = beautiful.notification_margin,
widget = wibox.container.margin,
},
{
{
layout = wibox.layout.align.vertical,
expand = 'none',
nil,
{
{
align = 'left',
widget = naughty.widget.title
},
{
align = 'left',
widget = naughty.widget.message,
},
layout = wibox.layout.fixed.vertical
},
nil
},
margins = beautiful.notification_margin,
widget = wibox.container.margin,
},
layout = wibox.layout.fixed.horizontal,
},
fill_space = true,
spacing = beautiful.notification_margin,
layout = wibox.layout.fixed.vertical,
},
-- Margin between the fake background
-- Set to 0 to preserve the 'titlebar' effect
margins = dpi(0),
widget = wibox.container.margin,
},
bg = beautiful.transparent,
widget = wibox.container.background,
},
-- Actions
actions_template,
spacing = dpi(4),
layout = wibox.layout.fixed.vertical,
},
bg = beautiful.transparent,
id = 'background_role',
widget = naughty.container.background,
},
strategy = 'min',
width = dpi(160),
widget = wibox.container.constraint,
},
strategy = 'max',
width = beautiful.notification_max_width or dpi(500),
widget = wibox.container.constraint
},
bg = beautiful.background,
shape = gears.shape.rounded_rect,
widget = wibox.container.background
}
}
-- Destroy popups if dont_disturb mode is on
-- Or if the right_panel is visible
local focused = awful.screen.focused()
if _G.dont_disturb or
(focused.right_panel and focused.right_panel.visible) then
naughty.destroy_all_notifications(nil, 1)
end
end
)