Files
community-plugins/hypr-submap/submap.luau
T
kanataandGitHub 2dd05ef8bc feat: add hypr-submap plugin (#101)
* feat: add hypr-submap plugin

* fix(hypr-submap): add description key and glyph default value

* fix(hypr-submap): update dependencies and fix glyph default value in README

- Add stdbuf and hyprctl to the dependencies list in `README.md` and `plugin.toml`.
- Correct the documented default value of glyph to match the actual implementation.
2026-07-26 08:37:37 -04:00

59 lines
1.5 KiB
Luau

local currentSubmap = ""
local function socketPath()
local sig = noctalia.getenv("HYPRLAND_INSTANCE_SIGNATURE")
local runtimeDir = noctalia.getenv("XDG_RUNTIME_DIR")
if sig == nil or runtimeDir == nil then
return nil
end
return `{runtimeDir}/hypr/{sig}/.socket2.sock`
end
local function render()
local hideWhenDefault = noctalia.getConfig("hide_when_default")
local prefix = noctalia.getConfig("prefix")
local glyph = noctalia.getConfig("glyph")
if glyph and glyph ~= "" then
barWidget.setGlyph(glyph)
end
if currentSubmap == "" or currentSubmap == "default" then
if hideWhenDefault then
barWidget.setVisible(false)
return
end
barWidget.setVisible(true)
barWidget.setText(`{prefix}default`)
return
end
barWidget.setVisible(true)
barWidget.setText(`{prefix}{currentSubmap}`)
end
local sock = socketPath()
if sock ~= nil then
noctalia.runAsync("hyprctl submap", function(output)
if output ~= nil then
currentSubmap = noctalia.string.trim(output)
render()
end
end)
noctalia.runStream(`stdbuf -oL -eL socat -u UNIX-CONNECT:{sock} -`, function(line)
local match = line:match("submap>>(.*)")
if match ~= nil then
currentSubmap = noctalia.string.trim(match)
render()
end
end)
end
function update()
render()
end
function onClick()
noctalia.runAsync("hyprctl dispatch 'hl.dsp.submap(\"reset\")' ")
end