From 00f130c102005f5e9de2bb2c10b266b9353ed8d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 04:19:10 +0000 Subject: [PATCH] feat(noctalia): stoa-keybinds bar plugin showing the keybind cheatsheet Keyboard pill in the bar; click opens an attached panel with every bind grouped by section, right click opens the Super+/ yad cheatsheet. Data is read from stoa-keybinds-bar text, so the script stays the single source (including the niri substitutions). Optional compact apps line in the bar. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01UckMrz997J3c6sMq3qn9Yt --- config/noctalia/config.toml | 13 +- dotfiles/.local/state/noctalia/settings.toml | 5 +- install.sh | 4 +- .../noctalia-plugins/stoa-keybinds/panel.luau | 145 ++++++++++++++++++ .../stoa-keybinds/plugin.toml | 61 ++++++++ .../stoa-keybinds/translations/en.json | 12 ++ .../stoa-keybinds/widget.luau | 121 +++++++++++++++ 7 files changed, 353 insertions(+), 8 deletions(-) create mode 100644 theme/noctalia-plugins/stoa-keybinds/panel.luau create mode 100644 theme/noctalia-plugins/stoa-keybinds/plugin.toml create mode 100644 theme/noctalia-plugins/stoa-keybinds/translations/en.json create mode 100644 theme/noctalia-plugins/stoa-keybinds/widget.luau diff --git a/config/noctalia/config.toml b/config/noctalia/config.toml index ef6ea7a..d273aaf 100644 --- a/config/noctalia/config.toml +++ b/config/noctalia/config.toml @@ -196,10 +196,10 @@ reserve_space = true start = ["launcher", "workspaces", "taskbar"] center = ["clock"] -# `stoa/drive:pill` and `stoa/health:pill` are the local plugins in -# theme/noctalia-plugins/{stoa-drive,stoa-health} (plugin widgets are -# addressed as :). -end = ["media", "tray", "notifications", "clipboard", "stoa/drive:pill", "stoa/health:pill", "sysmon", "network", "bluetooth", "volume", "brightness", "battery", "control-center", "session"] +# `stoa/drive:pill`, `stoa/health:pill` and `stoa/keybinds:pill` are the local +# plugins in theme/noctalia-plugins/{stoa-drive,stoa-health,stoa-keybinds} +# (plugin widgets are addressed as :). +end = ["media", "tray", "notifications", "clipboard", "stoa/drive:pill", "stoa/health:pill", "stoa/keybinds:pill", "sysmon", "network", "bluetooth", "volume", "brightness", "battery", "control-center", "session"] # ── Control centre shortcuts ────────────────────────────────────────── @@ -239,7 +239,8 @@ started = "~/.local/bin/stoa-doctor" # ── Plugins ─────────────────────────────────────────────────────────── # Stoa's local plugins live in theme/noctalia-plugins/ and are symlinked # into ~/.local/share/noctalia/plugins by install.sh: -# stoa/drive, stoa/health bar pills (see [bar.default] above) +# stoa/drive, stoa/health, bar pills (see [bar.default] above) +# stoa/keybinds # stoa/memento Memento Mori desktop widget (below) # stoa/predict text-prediction popup (Super+Shift+S) # alexander/screen-toolkit comes from the built-in community source: screen @@ -251,7 +252,7 @@ started = "~/.local/bin/stoa-doctor" # plugins over IPC so an existing install picks up new ones too. [plugins] -enabled = ["stoa/drive", "stoa/health", "stoa/memento", "stoa/predict", "alexander/screen-toolkit"] +enabled = ["stoa/drive", "stoa/health", "stoa/keybinds", "stoa/memento", "stoa/predict", "alexander/screen-toolkit"] # ── Desktop widgets ─────────────────────────────────────────────────── # One Memento Mori tile. No `output`: Noctalia puts it on the focused diff --git a/dotfiles/.local/state/noctalia/settings.toml b/dotfiles/.local/state/noctalia/settings.toml index 44cda6c..8340ece 100644 --- a/dotfiles/.local/state/noctalia/settings.toml +++ b/dotfiles/.local/state/noctalia/settings.toml @@ -168,11 +168,14 @@ manage_open_near_click = true [plugin_settings."stoa/health"] manage_open_near_click = true +[plugin_settings."stoa/keybinds"] +manage_open_near_click = true + [plugin_settings."stoa/predict"] popup_placement = "attached" [plugins] -enabled = [ "stoa/drive", "stoa/health", "alexander/screen-toolkit", "stoa/memento", "stoa/predict" ] +enabled = [ "stoa/drive", "stoa/health", "stoa/keybinds", "alexander/screen-toolkit", "stoa/memento", "stoa/predict" ] [shell] external_ip_enabled = true diff --git a/install.sh b/install.sh index 2b5eb72..0726806 100755 --- a/install.sh +++ b/install.sh @@ -150,6 +150,8 @@ _link "${STOA_DIR}/theme/noctalia-plugins/stoa-drive" \ "${NOCTALIA_PLUGINS}/stoa-drive" _link "${STOA_DIR}/theme/noctalia-plugins/stoa-health" \ "${NOCTALIA_PLUGINS}/stoa-health" +_link "${STOA_DIR}/theme/noctalia-plugins/stoa-keybinds" \ + "${NOCTALIA_PLUGINS}/stoa-keybinds" _link "${STOA_DIR}/theme/noctalia-plugins/stoa-memento" \ "${NOCTALIA_PLUGINS}/stoa-memento" _link "${STOA_DIR}/theme/noctalia-plugins/stoa-predict" \ @@ -161,7 +163,7 @@ _link "${STOA_DIR}/theme/noctalia-plugins/stoa-predict" \ # On a live shell, enable each through IPC instead; it appends to whatever # the user already has and is a no-op for one already enabled. if command -v noctalia &>/dev/null && noctalia msg plugins list &>/dev/null; then - for plugin in stoa/drive stoa/health stoa/memento stoa/predict alexander/screen-toolkit; do + for plugin in stoa/drive stoa/health stoa/keybinds stoa/memento stoa/predict alexander/screen-toolkit; do noctalia msg plugins enable "$plugin" &>/dev/null || \ echo -e " ${S}[~] Could not enable ${plugin} (enable it in Settings → Plugins).${R}" done diff --git a/theme/noctalia-plugins/stoa-keybinds/panel.luau b/theme/noctalia-plugins/stoa-keybinds/panel.luau new file mode 100644 index 0000000..b24ef5f --- /dev/null +++ b/theme/noctalia-plugins/stoa-keybinds/panel.luau @@ -0,0 +1,145 @@ +-- ╔══════════════════════════════════════════════════════════════╗ +-- ║ STOA LINUX — Keybinds panel ║ +-- ║ The cheatsheet, laid out. ║ +-- ╚══════════════════════════════════════════════════════════════╝ +-- +-- Renders the output of `stoa-keybinds-bar text` — the same text Super+/ +-- shows in the yad dialog — as a scrollable list: one block per "▸" +-- section, each bind as key (left) + description (right). Nothing is +-- hard-coded here, so the panel follows the script, including its niri +-- substitutions. +-- +-- Written in the Lua 5.4-compatible subset of Luau (no type annotations, +-- no if-expressions) so the CI lua step can actually parse it. + +local KEYBINDS_BIN = "$HOME/.local/bin/stoa-keybinds-bar" +local TOGGLE_BIN = "$HOME/.local/bin/stoa-keybinds-toggle" + +-- ── UI tree node builders (same helpers as the stoa-health panel) ── +local function node(kind, props, children) + return { type = kind, props = props or {}, children = children or {} } +end +local function col(props, children) return node("column", props, children) end +local function rowN(props, children) return node("row", props, children) end +local function lbl(props) return node("label", props) end +local function btn(props) return node("button", props) end +local function sep(props) return node("separator", props) end +local function scr(props, children) return node("scroll", props, children) end + +-- ── State ── + +local state = { + loaded = false, + failed = false, + -- { { title = "Window", binds = { { key = "...", desc = "..." }, ... } }, ... } + sections = {}, + binds = 0, +} + +-- ── Data ── + +-- " Super+Return Terminal (kitty)" → key, desc. Key and +-- description are separated by two or more spaces; the key never contains +-- a space. The box-drawing banner lines and blank lines match neither +-- pattern and are skipped. +local function parseText(text) + local sections, current, binds = {}, nil, 0 + for line in string.gmatch(text, "[^\n]+") do + local title = string.match(line, "^▸%s*(.+)$") + if title then + current = { title = title, binds = {} } + sections[#sections + 1] = current + elseif current then + local key, desc = string.match(line, "^%s+(%S+)%s%s+(%S.*)$") + if key then + current.binds[#current.binds + 1] = { key = key, desc = desc } + binds = binds + 1 + end + end + end + state.sections = sections + state.binds = binds +end + +local function load() + noctalia.runAsync(KEYBINDS_BIN .. " text", function(result) + state.loaded = true + if result.exitCode == 0 and result.stdout ~= "" then + state.failed = false + parseText(result.stdout) + else + state.failed = true + end + render() + end) +end + +-- ── Rendering ── + +local function bindRow(b) + return rowN({ align = "center", gap = 10 }, { + lbl({ text = b.key, fontSize = 12, fontWeight = "bold", color = "primary", width = 150 }), + lbl({ text = b.desc, fontSize = 12, flexGrow = 1 }), + }) +end + +local function sectionBlock(section) + local children = { + lbl({ text = section.title, fontWeight = "bold", fontSize = 13 }), + } + for _, b in ipairs(section.binds) do + children[#children + 1] = bindRow(b) + end + return col({ gap = 4 }, children) +end + +local function body() + if not state.loaded then + return col({ flexGrow = 1, align = "center", justify = "center" }, { + lbl({ text = "…", color = "on_surface_variant" }), + }) + end + if state.failed or #state.sections == 0 then + return col({ flexGrow = 1, align = "center", justify = "center", gap = 6 }, { + lbl({ text = "Could not read the cheatsheet", color = "error" }), + lbl({ text = "stoa-keybinds-bar text failed", color = "on_surface_variant", fontSize = 12 }), + }) + end + + local children = {} + for i, section in ipairs(state.sections) do + if i > 1 then children[#children + 1] = sep({ opacity = 0.3 }) end + children[#children + 1] = sectionBlock(section) + end + return scr({ flexGrow = 1, gap = 10 }, children) +end + +function render() + local subtitle = "" + if state.loaded and not state.failed then + subtitle = string.format("%d binds", state.binds) + end + + panel.render(col({ flexGrow = 1, gap = 10, padding = 12 }, { + rowN({ align = "center" }, { + lbl({ text = "Stoa Keybinds", fontWeight = "bold", flexGrow = 1 }), + lbl({ text = subtitle, color = "on_surface_variant", fontSize = 12 }), + }), + sep({}), + body(), + sep({}), + rowN({ gap = 6 }, { + btn({ text = "Open as window", flexGrow = 1, controlSize = "sm", variant = "outline", + onClick = function() noctalia.runAsync(TOGGLE_BIN) end }), + }), + })) +end + +-- ── Lifecycle ── + +function onOpen(context) + -- Re-read on every open: cheap, and it picks up a changed script or a + -- compositor switch without restarting the shell. + render() + load() +end diff --git a/theme/noctalia-plugins/stoa-keybinds/plugin.toml b/theme/noctalia-plugins/stoa-keybinds/plugin.toml new file mode 100644 index 0000000..e95af6c --- /dev/null +++ b/theme/noctalia-plugins/stoa-keybinds/plugin.toml @@ -0,0 +1,61 @@ +# ╔══════════════════════════════════════════════════════════════╗ +# ║ STOA LINUX — Keybinds pill (Noctalia v5 plugin) ║ +# ║ The cheatsheet one click away, in the bar. ║ +# ╚══════════════════════════════════════════════════════════════╝ +# +# Noctalia v5 ships no cheatsheet widget, so Super+/ used to be the only +# way to see the binds (a yad text dialog, scripts/stoa-keybinds-toggle.sh). +# This puts the same cheatsheet in the bar: a keyboard icon whose tooltip +# lists the sections, and an attached panel with every bind grouped the +# way the cheatsheet groups them. +# +# The data is NOT duplicated here. scripts/stoa-keybinds-bar.sh stays the +# single source of truth (it already swaps the navigation lines on niri), +# and this plugin only reads its `text` output and lays it out — so a new +# bind added to that script shows up in the panel with no change here. +# +# Optionally the compact "most-used apps" line the old waybar module +# carried can be shown next to the icon (setting `show_apps`); it follows +# STOA_SHOW_KEYBINDS from stoa.conf, same as before. + +id = "stoa/keybinds" +name = "Stoa Keybinds" +version = "1.0.0" +author = "stoa" +icon = "keyboard" +description = "Keyboard shortcut cheatsheet — one icon, opens a panel with every bind" +tags = ["bar", "keybinds", "help"] + +# Same floor as the other Stoa plugins: panel.luau hands inline Lua +# closures as onClick props (plugin API level 9, see stoa-drive). +plugin_api = 9 + +[[widget]] +id = "pill" +entry = "widget.luau" + +# Attached: opens anchored below the bar icon that toggled it, same as +# stoa-drive and stoa-health. +[[panel]] +id = "cheatsheet" +entry = "panel.luau" +placement = "attached" +width = 380 +height = 560 + +# Settings are an ARRAY of tables named `setting` (singular), each with an +# explicit `key`; `label_key` is a translation key resolved against +# translations/en.json. +[[setting]] +key = "icon" +type = "glyph" +default = "keyboard" +label_key = "settings.icon.label" +description_key = "settings.icon.description" + +[[setting]] +key = "show_apps" +type = "bool" +default = false +label_key = "settings.show_apps.label" +description_key = "settings.show_apps.description" diff --git a/theme/noctalia-plugins/stoa-keybinds/translations/en.json b/theme/noctalia-plugins/stoa-keybinds/translations/en.json new file mode 100644 index 0000000..22c5f7a --- /dev/null +++ b/theme/noctalia-plugins/stoa-keybinds/translations/en.json @@ -0,0 +1,12 @@ +{ + "settings": { + "icon": { + "label": "Icon", + "description": "Glyph shown in the bar." + }, + "show_apps": { + "label": "Show app shortcuts in the bar", + "description": "Display the compact line of the most-used app binds (Terminal, Launcher, Brave, Files…) next to the icon. Follows STOA_SHOW_KEYBINDS in stoa.conf." + } + } +} diff --git a/theme/noctalia-plugins/stoa-keybinds/widget.luau b/theme/noctalia-plugins/stoa-keybinds/widget.luau new file mode 100644 index 0000000..887a47f --- /dev/null +++ b/theme/noctalia-plugins/stoa-keybinds/widget.luau @@ -0,0 +1,121 @@ +-- ╔══════════════════════════════════════════════════════════════╗ +-- ║ STOA LINUX — Keybinds pill ║ +-- ║ "Learn the rules so you know how to break them." — attrib. ║ +-- ╚══════════════════════════════════════════════════════════════╝ +-- +-- A keyboard icon in the bar. Left click opens the cheatsheet panel +-- (panel.luau, entry id "cheatsheet"); right click shows the same +-- cheatsheet in the yad dialog Super+/ uses; the tooltip lists the +-- sections so the icon says what is inside before it is opened. +-- +-- Written in the Lua 5.4-compatible subset of Luau (no type annotations, +-- no if-expressions) so the CI lua step can actually parse it — luac5.4 +-- rejects Luau-only syntax, and CI has no Luau front end. +-- +-- Data comes from ~/.local/bin/stoa-keybinds-bar: +-- text the full cheatsheet as plain text (sections start with "▸") +-- bar {"text": "⏎ Term • ␣ Launcher • ...", "tooltip": ...} +-- or an empty line when STOA_SHOW_KEYBINDS is not "true" + +local KEYBINDS_BIN = "$HOME/.local/bin/stoa-keybinds-bar" +local TOGGLE_BIN = "$HOME/.local/bin/stoa-keybinds-toggle" + +local state = { + sections = {}, -- section titles, in order + binds = 0, + apps = "", -- compact apps line, "" when hidden +} + +-- getConfig reads THIS plugin's own [[setting]] entries from plugin.toml +-- (not getSetting, which reads the shell's own config.toml). +local function configIcon() + local configured = noctalia.getConfig("icon") + if type(configured) == "string" and configured ~= "" then + return configured + end + return "keyboard" +end + +local function showApps() + local configured = noctalia.getConfig("show_apps") + if type(configured) == "boolean" then + return configured + end + return false +end + +local function tooltip() + if #state.sections == 0 then + return "Stoa Keybinds — click to open" + end + return string.format("Stoa Keybinds — %d binds\n%s", + state.binds, table.concat(state.sections, " · ")) +end + +local function paint() + barWidget.setGlyph(configIcon()) + barWidget.setGlyphColor("on_surface_variant") + if showApps() and state.apps ~= "" then + barWidget.setText(state.apps) + else + barWidget.setText("") + end + barWidget.setTooltip(tooltip()) +end + +-- Section titles and bind count from the plain-text cheatsheet. A bind +-- line is indented and has its key and description split by 2+ spaces. +local function parseText(text) + local sections, binds = {}, 0 + for line in string.gmatch(text, "[^\n]+") do + local title = string.match(line, "^▸%s*(.+)$") + if title then + sections[#sections + 1] = title + elseif string.match(line, "^%s+%S.-%s%s+%S") then + binds = binds + 1 + end + end + state.sections = sections + state.binds = binds +end + +local function refresh() + noctalia.runAsync(KEYBINDS_BIN .. " text", function(result) + if result.exitCode == 0 and result.stdout ~= "" then + parseText(result.stdout) + end + paint() + end) + + if not showApps() then + state.apps = "" + return + end + noctalia.runAsync(KEYBINDS_BIN .. " bar", function(result) + state.apps = "" + if result.exitCode == 0 and result.stdout ~= "" then + local ok, parsed = pcall(noctalia.json.decode, result.stdout) + if ok and type(parsed) == "table" and type(parsed.text) == "string" then + state.apps = parsed.text + end + end + paint() + end) +end + +function update() + -- The cheatsheet is static; this only picks up a settings change or an + -- edit to stoa-keybinds-bar, so a slow poll is plenty. + noctalia.setUpdateInterval(300 * 1000) + refresh() +end + +-- Per-button click callbacks: PluginWidget dispatches BTN_LEFT/RIGHT to +-- these global names for a [[widget]] entry (see stoa-health). +function onClick() + noctalia.togglePanel("stoa/keybinds:cheatsheet") +end + +function onRightClick() + noctalia.runAsync(TOGGLE_BIN) +end