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 pathexit-screen.lua
344 lines (311 loc) · 7.16 KB
/
exit-screen.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
local awful = require('awful')
local gears = require('gears')
local wibox = require('wibox')
local beautiful = require('beautiful')
local filesystem = gears.filesystem
local dpi = beautiful.xresources.apply_dpi
local icons = require('theme.icons')
local apps = require('configuration.apps')
local clickable_container = require('widget.clickable-container')
local config_dir = filesystem.get_configuration_dir()
local widget_icon_dir = config_dir .. 'configuration/user-profile/'
local msg_table = {
'Stay out of trouble.',
'I’m out of here.',
'Peace out!',
'Gotta get going.',
'Don\'t forget to come back!',
'Adios, amigo.',
'Are you leaving?',
'Arrivederci.',
'Au revoir!',
'Happy trails!',
'Sayonara!',
'Ciao!',
'Well... bye.',
'Go out there and make a difference.',
'Change da world. My final message. Goodbye.',
'Find out on the next episode of Dragonball Z...',
'Choose wisely!'
}
local greeter_message = wibox.widget {
markup = 'Choose wisely!',
font = 'Inter UltraLight 48',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local profile_name = wibox.widget {
markup = 'hk@tr192x',
font = 'Inter Bold 12',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local profile_imagebox = wibox.widget {
image = widget_icon_dir .. 'default.svg',
resize = true,
forced_height = dpi(140),
clip_shape = gears.shape.circle,
widget = wibox.widget.imagebox
}
local update_profile_pic = function()
awful.spawn.easy_async_with_shell(
apps.utils.update_profile,
function(stdout)
stdout = stdout:gsub('%\n','')
if not stdout:match('default') then
profile_imagebox:set_image(stdout)
else
profile_imagebox:set_image(widget_icon_dir .. 'default.svg')
end
profile_imagebox:emit_signal('widget::redraw_needed')
end
)
end
update_profile_pic()
local update_user_name = function()
awful.spawn.easy_async_with_shell(
[[
fullname="$(getent passwd `whoami` | cut -d ':' -f 5 | cut -d ',' -f 1 | tr -d "\n")"
if [ -z "$fullname" ];
then
printf "$(whoami)@$(hostname)"
else
printf "$fullname"
fi
]],
function(stdout)
stdout = stdout:gsub('%\n','')
local first_name = stdout:match('(.*)@') or stdout:match('(.-)%s')
first_name = first_name:sub(1, 1):upper() .. first_name:sub(2)
profile_name:set_markup(stdout)
profile_name:emit_signal('widget::redraw_needed')
end
)
end
update_user_name()
local update_greeter_msg = function()
greeter_message:set_markup(msg_table[math.random(#msg_table)])
greeter_message:emit_signal('widget::redraw_needed')
end
update_greeter_msg()
local build_power_button = function(name, icon, callback)
local power_button_label= wibox.widget {
text = name,
font = 'Inter Regular 10',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local power_button = wibox.widget {
{
{
{
{
image = icon,
widget = wibox.widget.imagebox
},
margins = dpi(16),
widget = wibox.container.margin
},
bg = beautiful.groups_bg,
widget = wibox.container.background
},
shape = gears.shape.rounded_rect,
forced_width = dpi(90),
forced_height = dpi(90),
widget = clickable_container
},
left = dpi(24),
right = dpi(24),
widget = wibox.container.margin
}
local exit_screen_item = wibox.widget {
layout = wibox.layout.fixed.vertical,
spacing = dpi(5),
power_button,
power_button_label
}
exit_screen_item:connect_signal(
'button::release',
function()
callback()
end
)
return exit_screen_item
end
local suspend_command = function()
awesome.emit_signal('module::exit_screen:hide')
awful.spawn.with_shell(apps.default.lock .. ' & systemctl suspend')
end
local logout_command = function()
awesome.quit()
end
local lock_command = function()
awesome.emit_signal('module::exit_screen:hide')
awful.spawn.with_shell(apps.default.lock)
end
local poweroff_command = function()
awful.spawn.with_shell('poweroff')
awesome.emit_signal('module::exit_screen:hide')
end
local reboot_command = function()
awful.spawn.with_shell('reboot')
awesome.emit_signal('module::exit_screen:hide')
end
local poweroff = build_power_button('Shutdown', icons.power, poweroff_command)
local reboot = build_power_button('Restart', icons.restart, reboot_command)
local suspend = build_power_button('Sleep', icons.sleep, suspend_command)
local logout = build_power_button('Logout', icons.logout, logout_command)
local lock = build_power_button('Lock', icons.lock, lock_command)
local create_exit_screen = function(s)
s.exit_screen = wibox
{
screen = s,
type = 'splash',
visible = false,
ontop = true,
bg = beautiful.background,
fg = beautiful.fg_normal,
height = s.geometry.height,
width = s.geometry.width,
x = s.geometry.x,
y = s.geometry.y
}
s.exit_screen:buttons(
gears.table.join(
awful.button(
{},
2,
function()
awesome.emit_signal('module::exit_screen:hide')
end
),
awful.button(
{},
3,
function()
awesome.emit_signal('module::exit_screen:hide')
end
)
)
)
s.exit_screen : setup {
layout = wibox.layout.align.vertical,
expand = 'none',
nil,
{
layout = wibox.layout.align.vertical,
{
nil,
{
layout = wibox.layout.fixed.vertical,
spacing = dpi(5),
{
layout = wibox.layout.align.vertical,
expand = 'none',
nil,
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
profile_imagebox,
nil
},
nil
},
profile_name
},
nil,
expand = 'none',
layout = wibox.layout.align.horizontal
},
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
{
widget = wibox.container.margin,
margins = dpi(15),
greeter_message
},
nil
},
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
{
{
{
poweroff,
reboot,
suspend,
logout,
lock,
layout = wibox.layout.fixed.horizontal
},
spacing = dpi(30),
layout = wibox.layout.fixed.vertical
},
widget = wibox.container.margin,
margins = dpi(15)
},
nil
}
},
nil
}
end
screen.connect_signal(
'request::desktop_decoration',
function(s)
create_exit_screen(s)
end
)
screen.connect_signal(
'removed',
function(s)
create_exit_screen(s)
end
)
local exit_screen_grabber = awful.keygrabber {
auto_start = true,
stop_event = 'release',
keypressed_callback = function(self, mod, key, command)
if key == 's' then
suspend_command()
elseif key == 'e' then
logout_command()
elseif key == 'l' then
lock_command()
elseif key == 'p' then
poweroff_command()
elseif key == 'r' then
reboot_command()
elseif key == 'Escape' or key == 'q' or key == 'x' then
awesome.emit_signal('module::exit_screen:hide')
end
end
}
awesome.connect_signal(
'module::exit_screen:show',
function()
for s in screen do
s.exit_screen.visible = false
end
awful.screen.focused().exit_screen.visible = true
exit_screen_grabber:start()
end
)
awesome.connect_signal(
'module::exit_screen:hide',
function()
update_greeter_msg()
exit_screen_grabber:stop()
for s in screen do
s.exit_screen.visible = false
end
end
)