diff --git a/hypr-submap/README.md b/hypr-submap/README.md new file mode 100644 index 0000000..3f6b897 --- /dev/null +++ b/hypr-submap/README.md @@ -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. diff --git a/hypr-submap/plugin.toml b/hypr-submap/plugin.toml new file mode 100644 index 0000000..d2f0667 --- /dev/null +++ b/hypr-submap/plugin.toml @@ -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" diff --git a/hypr-submap/submap.luau b/hypr-submap/submap.luau new file mode 100644 index 0000000..c260cd2 --- /dev/null +++ b/hypr-submap/submap.luau @@ -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 diff --git a/hypr-submap/thumbnail.webp b/hypr-submap/thumbnail.webp new file mode 100644 index 0000000..8fae367 Binary files /dev/null and b/hypr-submap/thumbnail.webp differ diff --git a/hypr-submap/translations/en.json b/hypr-submap/translations/en.json new file mode 100644 index 0000000..75df62f --- /dev/null +++ b/hypr-submap/translations/en.json @@ -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." + } + } +}