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.
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
# Hyprland Submap
|
||||||
|
|
||||||
|
Add simple bar widget to show Hyprland's current submap.
|
||||||
|
|
||||||
|
## Plugin
|
||||||
|
|
||||||
|
|
||||||
|
| Field | Value |
|
||||||
|
| --- | --- |
|
||||||
|
| ID | `k4n4t4/hypr-submap` |
|
||||||
|
| Entries | Bar widget: `hypr-submap` |
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
The following utilities must be installed and available on `PATH`:
|
||||||
|
- `socat`
|
||||||
|
- `stdbuf`
|
||||||
|
- `hyprctl`
|
||||||
|
Execution within a Hyprland environment is required.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Add the widget to the bar via the Noctalia Settings.
|
||||||
|
Clicking the widget executes `hyprctl dispatch 'hl.dsp.submap("reset")'`.
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
|
||||||
|
| Setting | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `hide_when_default` | `bool` | `false` | Hides the bar widget when the current submap is default. |
|
||||||
|
| `prefix` | `string` | `""` | Add the prefix text to the submap name displayed on the widget. |
|
||||||
|
| `glyph` | `glyph` | `"keyboard"` | Specifies the glyph displayed on the widget. |
|
||||||
|
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
This plugin continuously runs a background subprocess using `socat` and `stdbuf` to monitor Hyprland's IPC socket for submap changes.
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
id = "k4n4t4/hypr-submap"
|
||||||
|
name = "Hyprland Submap"
|
||||||
|
version = "1.0.0"
|
||||||
|
plugin_api = 6
|
||||||
|
author = "k4n4t4"
|
||||||
|
license = "MIT"
|
||||||
|
dependencies = ["socat", "stdbuf", "hyprctl"]
|
||||||
|
deprecated = false
|
||||||
|
tags = ["hyprland", "bar"]
|
||||||
|
icon = "keyboard"
|
||||||
|
description = "Hyprland submap plugin for Noctalia"
|
||||||
|
|
||||||
|
|
||||||
|
[[widget]]
|
||||||
|
id = "hypr-submap"
|
||||||
|
entry = "submap.luau"
|
||||||
|
|
||||||
|
[[widget.setting]]
|
||||||
|
key = "hide_when_default"
|
||||||
|
type = "bool"
|
||||||
|
label_key = "settings.hide_when_default.label"
|
||||||
|
description_key = "settings.hide_when_default.description"
|
||||||
|
default = false
|
||||||
|
|
||||||
|
[[widget.setting]]
|
||||||
|
key = "prefix"
|
||||||
|
type = "string"
|
||||||
|
label_key = "settings.prefix.label"
|
||||||
|
description_key = "settings.prefix.description"
|
||||||
|
default = ""
|
||||||
|
|
||||||
|
[[widget.setting]]
|
||||||
|
key = "glyph"
|
||||||
|
type = "glyph"
|
||||||
|
label_key = "settings.glyph.label"
|
||||||
|
description_key = "settings.glyph.description"
|
||||||
|
default = "keyboard"
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
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
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"settings": {
|
||||||
|
"hide_when_default": {
|
||||||
|
"label": "Hide when default submap",
|
||||||
|
"description": "Hides the bar widget when the current submap is default."
|
||||||
|
},
|
||||||
|
"prefix": {
|
||||||
|
"label": "Add a prefix to the submap name",
|
||||||
|
"description": "Add the prefix text to the submap name displayed on the widget."
|
||||||
|
|
||||||
|
},
|
||||||
|
"glyph": {
|
||||||
|
"label": "Icon to show on bar",
|
||||||
|
"description": "Specifies the glyph displayed on the widget."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user