You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.1 KiB

local unistd = require('posix.unistd')
local M = { dsp = {} }
local dsps = {}
dsps['󰗽 Logout'] = hl.dsp.exit
dsps['󰖔 Suspend'] = hl.dsp.exec_raw('systemctl suspend')
dsps['󰑐 Reboot'] = hl.dsp.exec_raw('systemctl reboot')
dsps['󰐥 Shutdown'] = hl.dsp.exec_raw('systemctl poweroff -i')
local tofi_text = ''
for text, _ in pairs(dsps) do
tofi_text = tofi_text .. text .. '\n'
end
function M.dsp.run()
return function()
local fd_r, fd_w = unistd.pipe()
assert(fd_r);
local pid = unistd.fork()
if pid == -1 then
return
elseif pid == 0 then
-- sub process
unistd.dup2(fd_r, 0)
unistd.dup2(fd_w, 1)
unistd.close(fd_r)
unistd.close(fd_w)
unistd.exec('/usr/bin/tofi', { '--height=240' })
os.exit(127)
end
unistd.write(fd_w, tofi_text)
unistd.close(fd_w)
local selected = unistd.read(fd_r, 16)
unistd.close(fd_r)
if selected then
--hl.dispatch(dsps[selected])
hl.notification.create { text = selected, timeout = 10000 }
end
end
end
return M