Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

keyboard

Lock keys, the active layout and the keyboard backlight.

button {
    on_click = function()
        local keyboard = mantle.keyboard:get()
        if keyboard and keyboard.layout_count > 1 then
            mantle.keyboard:switch_layout((keyboard.active_layout_index + 1) % keyboard.layout_count)
        end
    end,
    children = {
        text {
            content = mantle.keyboard:map(function(keyboard)
                if keyboard == nil then
                    return ""
                end
                return keyboard.active_layout .. (keyboard.caps_lock and " ⇪" or "")
            end),
        },
    },
}

State

mantle.keyboard:get() returns KeyboardState, nil before the first push. A field marked ? may be absent.

mantle.keyboard’s payload. Lock keys read false when no source resolves.

FieldTypeDescription
active_layoutstringLayout display name, e.g. "English (US)"; empty before the compositor answers or without one.
active_layout_indexinteger0-based position of the active layout, as switch_layout takes it.
backlight_pctintegerKeyboard backlight, 0 to 100, or -1 without a backlight device or readable level. Refreshes on hardware hotkeys and set_backlight only, not on other software writes.
caps_lockbooleanCaps Lock is on.
layout_countintegerConfigured layout count; below 2 there is nothing to switch.
num_lockbooleanNum Lock is on.
scroll_lockbooleanScroll Lock is on.

Actions

Call each as mantle.keyboard:<action>(arguments...); ? marks an argument you may omit.

ActionArgumentsDescription
set_backlightpercent: integerSets the keyboard backlight, 0 to 100; higher clamps to 100.
switch_layoutindex: integerSwitches to the 0-based configured layout index.

Backend

PartSourceWithout it
Lock keysEV_LED events from the first /dev/input device with a Caps Lock LED; a replugged keyboard is reopenedsysfs *::capslock, *::numlock, *::scrolllock read once, then frozen; with none of those, false
BacklightReads sysfs *::kbd_backlight, writes through logind’s SetBrightnessbacklight_pct = -1; set_backlight is logged and ignored
LayoutThe event stream workspaces reads: niri’s layout events, or Hyprland’s devices for the keyboard marked main (the one typed on last)active_layout = "", layout_count = 0; switch_layout is logged and ignored

The first push comes when keyboard starts, with whatever layout the compositor has reported.

Gotchas

TrapFix
caps_lock never changesThe Supervisor cannot read /dev/input, so the sysfs fallback was read once. Add the user to the input group
backlight_pct misses a change another program madeIt refreshes only on hardware hotkeys and set_backlight. Change it through set_backlight
switch_layout on niri with an index above 255 does nothingniri takes a u8; the call is logged and dropped

See also: brightness for the screen backlight.

Source: supervisor/src/capabilities/keyboard/