18 changed files with 381 additions and 156 deletions
@ -1,5 +1,8 @@ |
|||
{ |
|||
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", |
|||
"runtime.version": "Lua 5.5", |
|||
"workspace.library": ["/usr/share/hypr/stubs"] |
|||
"runtime": { |
|||
"version": "Lua 5.5", |
|||
"path": ["/usr/share/lua/5.5/?/init.lua"] |
|||
}, |
|||
"workspace.library": ["/usr/share/hypr/stubs", "/usr/share/lua/5.5"] |
|||
} |
|||
|
|||
@ -0,0 +1,27 @@ |
|||
local M = { dsp = {} } |
|||
|
|||
---@param entryfile string |
|||
---@param action? string |
|||
---@param rules? table<string, string|number|boolean> |
|||
function M.dsp.exec(entryfile, action, rules) |
|||
local file = io.open(entryfile, 'r') |
|||
if file then |
|||
local group_line = action and '[Desktop Action ' .. action .. ']' or '[Desktop Entry]' |
|||
local line |
|||
local cmd |
|||
repeat line = file:read('l') |
|||
until line == group_line |
|||
repeat line = file:read('l') |
|||
if line:sub(1, 5) == 'Exec=' then |
|||
cmd = line:sub(6, -1) |
|||
break |
|||
end |
|||
until not line or (line:sub(1, 1) == '[' and line:sub(-1, -1) == ']') |
|||
cmd = cmd:gsub(' *%%[fFuUdDnNickvm] *', ' ') -- https://specifications.freedesktop.org/desktop-entry/latest-single/#exec-variables |
|||
if cmd then |
|||
return hl.dsp.exec_cmd(cmd, rules) |
|||
end |
|||
end |
|||
end |
|||
|
|||
return M |
|||
@ -0,0 +1,43 @@ |
|||
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 |
|||
Loading…
Reference in new issue