-
Notifications
You must be signed in to change notification settings - Fork 242
/
exit-screen.lua
201 lines (183 loc) · 4.14 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
local awful = require('awful')
local gears = require('gears')
local wibox = require('wibox')
local beautiful = require('beautiful')
local icons = require('theme.icons')
local clickable_container = require('widget.material.clickable-container')
local apps = require('configuration.apps')
local dpi = require('beautiful').xresources.apply_dpi
-- Appearance
local icon_size = beautiful.exit_screen_icon_size or dpi(140)
local buildButton = function(icon)
local abutton =
wibox.widget {
wibox.widget {
wibox.widget {
wibox.widget {
image = icon,
widget = wibox.widget.imagebox
},
top = dpi(16),
bottom = dpi(16),
left = dpi(16),
right = dpi(16),
widget = wibox.container.margin
},
shape = gears.shape.circle,
forced_width = icon_size,
forced_height = icon_size,
widget = clickable_container
},
left = dpi(24),
right = dpi(24),
widget = wibox.container.margin
}
return abutton
end
function suspend_command()
exit_screen_hide()
awful.spawn.with_shell(apps.default.lock .. ' & systemctl suspend')
end
function exit_command()
_G.awesome.quit()
end
function lock_command()
exit_screen_hide()
awful.spawn.with_shell('sleep 1 && ' .. apps.default.lock)
end
function poweroff_command()
awful.spawn.with_shell('poweroff')
awful.keygrabber.stop(_G.exit_screen_grabber)
end
function reboot_command()
awful.spawn.with_shell('reboot')
awful.keygrabber.stop(_G.exit_screen_grabber)
end
local poweroff = buildButton(icons.power, 'Shutdown')
poweroff:connect_signal(
'button::release',
function()
poweroff_command()
end
)
local reboot = buildButton(icons.restart, 'Restart')
reboot:connect_signal(
'button::release',
function()
reboot_command()
end
)
local suspend = buildButton(icons.sleep, 'Sleep')
suspend:connect_signal(
'button::release',
function()
suspend_command()
end
)
local exit = buildButton(icons.logout, 'Logout')
exit:connect_signal(
'button::release',
function()
exit_command()
end
)
local lock = buildButton(icons.lock, 'Lock')
lock:connect_signal(
'button::release',
function()
lock_command()
end
)
-- Get screen geometry
local screen_geometry = awful.screen.focused().geometry
-- Create the widget
exit_screen =
wibox(
{
x = screen_geometry.x,
y = screen_geometry.y,
visible = false,
ontop = true,
type = 'splash',
height = screen_geometry.height,
width = screen_geometry.width
}
)
exit_screen.bg = beautiful.background.hue_800 .. 'dd'
exit_screen.fg = beautiful.exit_screen_fg or beautiful.wibar_fg or '#FEFEFE'
local exit_screen_grabber
function exit_screen_hide()
awful.keygrabber.stop(exit_screen_grabber)
exit_screen.visible = false
end
function exit_screen_show()
-- naughty.notify({text = "starting the keygrabber"})
exit_screen_grabber =
awful.keygrabber.run(
function(_, key, event)
if event == 'release' then
return
end
if key == 's' then
suspend_command()
elseif key == 'e' then
exit_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
-- naughty.notify({text = "Cancel"})
exit_screen_hide()
-- else awful.keygrabber.stop(exit_screen_grabber)
end
end
)
exit_screen.visible = true
end
exit_screen:buttons(
gears.table.join(
-- Middle click - Hide exit_screen
awful.button(
{},
2,
function()
exit_screen_hide()
end
),
-- Right click - Hide exit_screen
awful.button(
{},
3,
function()
exit_screen_hide()
end
)
)
)
-- Item placement
exit_screen:setup {
nil,
{
nil,
{
-- {
poweroff,
reboot,
suspend,
exit,
lock,
layout = wibox.layout.fixed.horizontal
-- },
-- widget = exit_screen_box
},
nil,
expand = 'none',
layout = wibox.layout.align.horizontal
},
nil,
expand = 'none',
layout = wibox.layout.align.vertical
}