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.

rect {
    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)
                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_percent?integerKeyboard backlight, 0 to 100, or nil 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: numberSets the keyboard backlight, 0 to 100, fractions allowed; values outside clamp to it.
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 polled every 250 ms; with none of those, false
BacklightReads sysfs *::kbd_backlight, writes through logind’s SetBrightnessbacklight_percent = nil; set_backlight is logged and ignored
LayoutThe event stream workspaces reads: niri’s layout events, Hyprland’s devices for the keyboard marked main (the one typed on last), sway’s GET_INPUTS for the first keyboard that lists layouts, or mango’s keyboardlayout nameactive_layout = "", layout_count = 0; switch_layout is logged and ignored. On mango only active_layout is set, so layout_count stays 0 and switch_layout is ignored

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

Gotchas

TrapFix
caps_lock changes up to 250 ms after the keyThe Supervisor cannot read /dev/input, so it polls sysfs. Add the user to the input group
backlight_percent 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/